Checking in vendor folder for ease of using go get.

This commit is contained in:
Renan DelValle 2018-10-23 23:32:59 -07:00
parent 7a1251853b
commit cdb4b5a1d0
No known key found for this signature in database
GPG key ID: C240AD6D6F443EC9
3554 changed files with 1270116 additions and 0 deletions

View file

@ -0,0 +1,114 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package common
import (
"compress/zlib"
"crypto/tls"
"flag"
"fmt"
"gen/thrifttest"
"net/http"
"thrift"
)
var debugClientProtocol bool
func init() {
flag.BoolVar(&debugClientProtocol, "debug_client_protocol", false, "turn client protocol trace on")
}
func StartClient(
host string,
port int64,
domain_socket string,
transport string,
protocol string,
ssl bool) (client *thrifttest.ThriftTestClient, err error) {
hostPort := fmt.Sprintf("%s:%d", host, port)
var protocolFactory thrift.TProtocolFactory
switch protocol {
case "compact":
protocolFactory = thrift.NewTCompactProtocolFactory()
case "simplejson":
protocolFactory = thrift.NewTSimpleJSONProtocolFactory()
case "json":
protocolFactory = thrift.NewTJSONProtocolFactory()
case "binary":
protocolFactory = thrift.NewTBinaryProtocolFactoryDefault()
default:
return nil, fmt.Errorf("Invalid protocol specified %s", protocol)
}
if debugClientProtocol {
protocolFactory = thrift.NewTDebugProtocolFactory(protocolFactory, "client:")
}
var trans thrift.TTransport
if ssl {
trans, err = thrift.NewTSSLSocket(hostPort, &tls.Config{InsecureSkipVerify: true})
} else {
if domain_socket != "" {
trans, err = thrift.NewTSocket(domain_socket)
} else {
trans, err = thrift.NewTSocket(hostPort)
}
}
if err != nil {
return nil, err
}
switch transport {
case "http":
if ssl {
tr := &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
}
client := &http.Client{Transport: tr}
trans, err = thrift.NewTHttpPostClientWithOptions(fmt.Sprintf("https://%s/", hostPort), thrift.THttpClientOptions{Client: client})
fmt.Println(hostPort)
} else {
trans, err = thrift.NewTHttpPostClient(fmt.Sprintf("http://%s/", hostPort))
}
if err != nil {
return nil, err
}
case "framed":
trans = thrift.NewTFramedTransport(trans)
case "buffered":
trans = thrift.NewTBufferedTransport(trans, 8192)
case "zlib":
trans, err = thrift.NewTZlibTransport(trans, zlib.BestCompression)
if err != nil {
return nil, err
}
case "":
trans = trans
default:
return nil, fmt.Errorf("Invalid transport specified %s", transport)
}
if err = trans.Open(); err != nil {
return nil, err
}
client = thrifttest.NewThriftTestClientFactory(trans, protocolFactory)
return
}

View file

@ -0,0 +1,317 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package common
import (
"errors"
"gen/thrifttest"
"reflect"
"testing"
"thrift"
"github.com/golang/mock/gomock"
)
type test_unit struct {
host string
port int64
domain_socket string
transport string
protocol string
ssl bool
}
var units = []test_unit{
{"127.0.0.1", 9095, "", "", "binary", false},
{"127.0.0.1", 9091, "", "", "compact", false},
{"127.0.0.1", 9092, "", "", "binary", true},
{"127.0.0.1", 9093, "", "", "compact", true},
}
func TestAllConnection(t *testing.T) {
certPath = "../../../keys"
for _, unit := range units {
t.Logf("%#v", unit)
doUnit(t, &unit)
}
}
func doUnit(t *testing.T, unit *test_unit) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
handler := NewMockThriftTest(ctrl)
processor, serverTransport, transportFactory, protocolFactory, err := GetServerParams(unit.host, unit.port, unit.domain_socket, unit.transport, unit.protocol, unit.ssl, "../../../keys", handler)
server := thrift.NewTSimpleServer4(processor, serverTransport, transportFactory, protocolFactory)
if err = server.Listen(); err != nil {
t.Errorf("Unable to start server", err)
t.FailNow()
}
go server.AcceptLoop()
defer server.Stop()
client, err := StartClient(unit.host, unit.port, unit.domain_socket, unit.transport, unit.protocol, unit.ssl)
if err != nil {
t.Errorf("Unable to start client", err)
t.FailNow()
}
defer client.Transport.Close()
callEverythingWithMock(t, client, handler)
}
var rmapmap = map[int32]map[int32]int32{
-4: map[int32]int32{-4: -4, -3: -3, -2: -2, -1: -1},
4: map[int32]int32{4: 4, 3: 3, 2: 2, 1: 1},
}
var xxs = &thrifttest.Xtruct{
StringThing: "Hello2",
ByteThing: 42,
I32Thing: 4242,
I64Thing: 424242,
}
var xcept = &thrifttest.Xception{ErrorCode: 1001, Message: "some"}
func callEverythingWithMock(t *testing.T, client *thrifttest.ThriftTestClient, handler *MockThriftTest) {
gomock.InOrder(
handler.EXPECT().TestVoid(),
handler.EXPECT().TestString("thing").Return("thing", nil),
handler.EXPECT().TestBool(true).Return(true, nil),
handler.EXPECT().TestBool(false).Return(false, nil),
handler.EXPECT().TestByte(int8(42)).Return(int8(42), nil),
handler.EXPECT().TestI32(int32(4242)).Return(int32(4242), nil),
handler.EXPECT().TestI64(int64(424242)).Return(int64(424242), nil),
// TODO: add TestBinary()
handler.EXPECT().TestDouble(float64(42.42)).Return(float64(42.42), nil),
handler.EXPECT().TestStruct(&thrifttest.Xtruct{StringThing: "thing", ByteThing: 42, I32Thing: 4242, I64Thing: 424242}).Return(&thrifttest.Xtruct{StringThing: "thing", ByteThing: 42, I32Thing: 4242, I64Thing: 424242}, nil),
handler.EXPECT().TestNest(&thrifttest.Xtruct2{StructThing: &thrifttest.Xtruct{StringThing: "thing", ByteThing: 42, I32Thing: 4242, I64Thing: 424242}}).Return(&thrifttest.Xtruct2{StructThing: &thrifttest.Xtruct{StringThing: "thing", ByteThing: 42, I32Thing: 4242, I64Thing: 424242}}, nil),
handler.EXPECT().TestMap(map[int32]int32{1: 2, 3: 4, 5: 42}).Return(map[int32]int32{1: 2, 3: 4, 5: 42}, nil),
handler.EXPECT().TestStringMap(map[string]string{"a": "2", "b": "blah", "some": "thing"}).Return(map[string]string{"a": "2", "b": "blah", "some": "thing"}, nil),
handler.EXPECT().TestSet(map[int32]struct{}{1: struct{}{}, 2: struct{}{}, 42: struct{}{}}).Return(map[int32]struct{}{1: struct{}{}, 2: struct{}{}, 42: struct{}{}}, nil),
handler.EXPECT().TestList([]int32{1, 2, 42}).Return([]int32{1, 2, 42}, nil),
handler.EXPECT().TestEnum(thrifttest.Numberz_TWO).Return(thrifttest.Numberz_TWO, nil),
handler.EXPECT().TestTypedef(thrifttest.UserId(42)).Return(thrifttest.UserId(42), nil),
handler.EXPECT().TestMapMap(int32(42)).Return(rmapmap, nil),
// TODO: not testing insanity
handler.EXPECT().TestMulti(int8(42), int32(4242), int64(424242), map[int16]string{1: "blah", 2: "thing"}, thrifttest.Numberz_EIGHT, thrifttest.UserId(24)).Return(xxs, nil),
handler.EXPECT().TestException("some").Return(xcept),
handler.EXPECT().TestException("TException").Return(errors.New("Just random exception")),
handler.EXPECT().TestMultiException("Xception", "ignoreme").Return(nil, &thrifttest.Xception{ErrorCode: 1001, Message: "This is an Xception"}),
handler.EXPECT().TestMultiException("Xception2", "ignoreme").Return(nil, &thrifttest.Xception2{ErrorCode: 2002, StructThing: &thrifttest.Xtruct{StringThing: "This is an Xception2"}}),
handler.EXPECT().TestOneway(int32(2)).Return(nil),
handler.EXPECT().TestVoid(),
)
var err error
if err = client.TestVoid(); err != nil {
t.Errorf("Unexpected error in TestVoid() call: ", err)
}
thing, err := client.TestString("thing")
if err != nil {
t.Errorf("Unexpected error in TestString() call: ", err)
}
if thing != "thing" {
t.Errorf("Unexpected TestString() result, expected 'thing' got '%s' ", thing)
}
bl, err := client.TestBool(true)
if err != nil {
t.Errorf("Unexpected error in TestBool() call: ", err)
}
if !bl {
t.Errorf("Unexpected TestBool() result expected true, got %f ", bl)
}
bl, err = client.TestBool(false)
if err != nil {
t.Errorf("Unexpected error in TestBool() call: ", err)
}
if bl {
t.Errorf("Unexpected TestBool() result expected false, got %f ", bl)
}
b, err := client.TestByte(42)
if err != nil {
t.Errorf("Unexpected error in TestByte() call: ", err)
}
if b != 42 {
t.Errorf("Unexpected TestByte() result expected 42, got %d ", b)
}
i32, err := client.TestI32(4242)
if err != nil {
t.Errorf("Unexpected error in TestI32() call: ", err)
}
if i32 != 4242 {
t.Errorf("Unexpected TestI32() result expected 4242, got %d ", i32)
}
i64, err := client.TestI64(424242)
if err != nil {
t.Errorf("Unexpected error in TestI64() call: ", err)
}
if i64 != 424242 {
t.Errorf("Unexpected TestI64() result expected 424242, got %d ", i64)
}
d, err := client.TestDouble(42.42)
if err != nil {
t.Errorf("Unexpected error in TestDouble() call: ", err)
}
if d != 42.42 {
t.Errorf("Unexpected TestDouble() result expected 42.42, got %f ", d)
}
// TODO: add TestBinary() call
xs := thrifttest.NewXtruct()
xs.StringThing = "thing"
xs.ByteThing = 42
xs.I32Thing = 4242
xs.I64Thing = 424242
xsret, err := client.TestStruct(xs)
if err != nil {
t.Errorf("Unexpected error in TestStruct() call: ", err)
}
if *xs != *xsret {
t.Errorf("Unexpected TestStruct() result expected %#v, got %#v ", xs, xsret)
}
x2 := thrifttest.NewXtruct2()
x2.StructThing = xs
x2ret, err := client.TestNest(x2)
if err != nil {
t.Errorf("Unexpected error in TestNest() call: ", err)
}
if !reflect.DeepEqual(x2, x2ret) {
t.Errorf("Unexpected TestNest() result expected %#v, got %#v ", x2, x2ret)
}
m := map[int32]int32{1: 2, 3: 4, 5: 42}
mret, err := client.TestMap(m)
if err != nil {
t.Errorf("Unexpected error in TestMap() call: ", err)
}
if !reflect.DeepEqual(m, mret) {
t.Errorf("Unexpected TestMap() result expected %#v, got %#v ", m, mret)
}
sm := map[string]string{"a": "2", "b": "blah", "some": "thing"}
smret, err := client.TestStringMap(sm)
if err != nil {
t.Errorf("Unexpected error in TestStringMap() call: ", err)
}
if !reflect.DeepEqual(sm, smret) {
t.Errorf("Unexpected TestStringMap() result expected %#v, got %#v ", sm, smret)
}
s := map[int32]struct{}{1: struct{}{}, 2: struct{}{}, 42: struct{}{}}
sret, err := client.TestSet(s)
if err != nil {
t.Errorf("Unexpected error in TestSet() call: ", err)
}
if !reflect.DeepEqual(s, sret) {
t.Errorf("Unexpected TestSet() result expected %#v, got %#v ", s, sret)
}
l := []int32{1, 2, 42}
lret, err := client.TestList(l)
if err != nil {
t.Errorf("Unexpected error in TestList() call: ", err)
}
if !reflect.DeepEqual(l, lret) {
t.Errorf("Unexpected TestSet() result expected %#v, got %#v ", l, lret)
}
eret, err := client.TestEnum(thrifttest.Numberz_TWO)
if err != nil {
t.Errorf("Unexpected error in TestEnum() call: ", err)
}
if eret != thrifttest.Numberz_TWO {
t.Errorf("Unexpected TestEnum() result expected %#v, got %#v ", thrifttest.Numberz_TWO, eret)
}
tret, err := client.TestTypedef(thrifttest.UserId(42))
if err != nil {
t.Errorf("Unexpected error in TestTypedef() call: ", err)
}
if tret != thrifttest.UserId(42) {
t.Errorf("Unexpected TestTypedef() result expected %#v, got %#v ", thrifttest.UserId(42), tret)
}
mapmap, err := client.TestMapMap(42)
if err != nil {
t.Errorf("Unexpected error in TestMapmap() call: ", err)
}
if !reflect.DeepEqual(mapmap, rmapmap) {
t.Errorf("Unexpected TestMapmap() result expected %#v, got %#v ", rmapmap, mapmap)
}
xxsret, err := client.TestMulti(42, 4242, 424242, map[int16]string{1: "blah", 2: "thing"}, thrifttest.Numberz_EIGHT, thrifttest.UserId(24))
if err != nil {
t.Errorf("Unexpected error in TestMulti() call: ", err)
}
if !reflect.DeepEqual(xxs, xxsret) {
t.Errorf("Unexpected TestMulti() result expected %#v, got %#v ", xxs, xxsret)
}
err = client.TestException("some")
if err == nil {
t.Errorf("Expecting exception in TestException() call")
}
if !reflect.DeepEqual(err, xcept) {
t.Errorf("Unexpected TestException() result expected %#v, got %#v ", xcept, err)
}
// TODO: connection is being closed on this
err = client.TestException("TException")
tex, ok := err.(thrift.TApplicationException)
if err == nil || !ok || tex.TypeId() != thrift.INTERNAL_ERROR {
t.Errorf("Unexpected TestException() result expected ApplicationError, got %#v ", err)
}
ign, err := client.TestMultiException("Xception", "ignoreme")
if ign != nil || err == nil {
t.Errorf("Expecting exception in TestMultiException() call")
}
if !reflect.DeepEqual(err, &thrifttest.Xception{ErrorCode: 1001, Message: "This is an Xception"}) {
t.Errorf("Unexpected TestMultiException() %#v ", err)
}
ign, err = client.TestMultiException("Xception2", "ignoreme")
if ign != nil || err == nil {
t.Errorf("Expecting exception in TestMultiException() call")
}
expecting := &thrifttest.Xception2{ErrorCode: 2002, StructThing: &thrifttest.Xtruct{StringThing: "This is an Xception2"}}
if !reflect.DeepEqual(err, expecting) {
t.Errorf("Unexpected TestMultiException() %#v ", err)
}
err = client.TestOneway(2)
if err != nil {
t.Errorf("Unexpected error in TestOneway() call: ", err)
}
//Make sure the connection still alive
if err = client.TestVoid(); err != nil {
t.Errorf("Unexpected error in TestVoid() call: ", err)
}
}

View file

@ -0,0 +1,289 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
// Automatically generated by MockGen. DO NOT EDIT!
// Source: gen/thrifttest (interfaces: ThriftTest)
package common
import (
gomock "github.com/golang/mock/gomock"
thrifttest "gen/thrifttest"
)
// Mock of ThriftTest interface
type MockThriftTest struct {
ctrl *gomock.Controller
recorder *_MockThriftTestRecorder
}
// Recorder for MockThriftTest (not exported)
type _MockThriftTestRecorder struct {
mock *MockThriftTest
}
func NewMockThriftTest(ctrl *gomock.Controller) *MockThriftTest {
mock := &MockThriftTest{ctrl: ctrl}
mock.recorder = &_MockThriftTestRecorder{mock}
return mock
}
func (_m *MockThriftTest) EXPECT() *_MockThriftTestRecorder {
return _m.recorder
}
func (_m *MockThriftTest) TestBool(_param0 bool) (bool, error) {
ret := _m.ctrl.Call(_m, "TestBool", _param0)
ret0, _ := ret[0].(bool)
ret1, _ := ret[1].(error)
return ret0, ret1
}
func (_mr *_MockThriftTestRecorder) TestBool(arg0 interface{}) *gomock.Call {
return _mr.mock.ctrl.RecordCall(_mr.mock, "TestBool", arg0)
}
func (_m *MockThriftTest) TestByte(_param0 int8) (int8, error) {
ret := _m.ctrl.Call(_m, "TestByte", _param0)
ret0, _ := ret[0].(int8)
ret1, _ := ret[1].(error)
return ret0, ret1
}
func (_mr *_MockThriftTestRecorder) TestByte(arg0 interface{}) *gomock.Call {
return _mr.mock.ctrl.RecordCall(_mr.mock, "TestByte", arg0)
}
func (_m *MockThriftTest) TestDouble(_param0 float64) (float64, error) {
ret := _m.ctrl.Call(_m, "TestDouble", _param0)
ret0, _ := ret[0].(float64)
ret1, _ := ret[1].(error)
return ret0, ret1
}
func (_mr *_MockThriftTestRecorder) TestDouble(arg0 interface{}) *gomock.Call {
return _mr.mock.ctrl.RecordCall(_mr.mock, "TestDouble", arg0)
}
func (_m *MockThriftTest) TestBinary(_param0 []byte) ([]byte, error) {
ret := _m.ctrl.Call(_m, "TestBinary", _param0)
ret0, _ := ret[0].([]byte)
ret1, _ := ret[1].(error)
return ret0, ret1
}
func (_mr *_MockThriftTestRecorder) TestBinary(arg0 interface{}) *gomock.Call {
return _mr.mock.ctrl.RecordCall(_mr.mock, "TestBinary", arg0)
}
func (_m *MockThriftTest) TestEnum(_param0 thrifttest.Numberz) (thrifttest.Numberz, error) {
ret := _m.ctrl.Call(_m, "TestEnum", _param0)
ret0, _ := ret[0].(thrifttest.Numberz)
ret1, _ := ret[1].(error)
return ret0, ret1
}
func (_mr *_MockThriftTestRecorder) TestEnum(arg0 interface{}) *gomock.Call {
return _mr.mock.ctrl.RecordCall(_mr.mock, "TestEnum", arg0)
}
func (_m *MockThriftTest) TestException(_param0 string) error {
ret := _m.ctrl.Call(_m, "TestException", _param0)
ret0, _ := ret[0].(error)
return ret0
}
func (_mr *_MockThriftTestRecorder) TestException(arg0 interface{}) *gomock.Call {
return _mr.mock.ctrl.RecordCall(_mr.mock, "TestException", arg0)
}
func (_m *MockThriftTest) TestI32(_param0 int32) (int32, error) {
ret := _m.ctrl.Call(_m, "TestI32", _param0)
ret0, _ := ret[0].(int32)
ret1, _ := ret[1].(error)
return ret0, ret1
}
func (_mr *_MockThriftTestRecorder) TestI32(arg0 interface{}) *gomock.Call {
return _mr.mock.ctrl.RecordCall(_mr.mock, "TestI32", arg0)
}
func (_m *MockThriftTest) TestI64(_param0 int64) (int64, error) {
ret := _m.ctrl.Call(_m, "TestI64", _param0)
ret0, _ := ret[0].(int64)
ret1, _ := ret[1].(error)
return ret0, ret1
}
func (_mr *_MockThriftTestRecorder) TestI64(arg0 interface{}) *gomock.Call {
return _mr.mock.ctrl.RecordCall(_mr.mock, "TestI64", arg0)
}
func (_m *MockThriftTest) TestInsanity(_param0 *thrifttest.Insanity) (map[thrifttest.UserId]map[thrifttest.Numberz]*thrifttest.Insanity, error) {
ret := _m.ctrl.Call(_m, "TestInsanity", _param0)
ret0, _ := ret[0].(map[thrifttest.UserId]map[thrifttest.Numberz]*thrifttest.Insanity)
ret1, _ := ret[1].(error)
return ret0, ret1
}
func (_mr *_MockThriftTestRecorder) TestInsanity(arg0 interface{}) *gomock.Call {
return _mr.mock.ctrl.RecordCall(_mr.mock, "TestInsanity", arg0)
}
func (_m *MockThriftTest) TestList(_param0 []int32) ([]int32, error) {
ret := _m.ctrl.Call(_m, "TestList", _param0)
ret0, _ := ret[0].([]int32)
ret1, _ := ret[1].(error)
return ret0, ret1
}
func (_mr *_MockThriftTestRecorder) TestList(arg0 interface{}) *gomock.Call {
return _mr.mock.ctrl.RecordCall(_mr.mock, "TestList", arg0)
}
func (_m *MockThriftTest) TestMap(_param0 map[int32]int32) (map[int32]int32, error) {
ret := _m.ctrl.Call(_m, "TestMap", _param0)
ret0, _ := ret[0].(map[int32]int32)
ret1, _ := ret[1].(error)
return ret0, ret1
}
func (_mr *_MockThriftTestRecorder) TestMap(arg0 interface{}) *gomock.Call {
return _mr.mock.ctrl.RecordCall(_mr.mock, "TestMap", arg0)
}
func (_m *MockThriftTest) TestMapMap(_param0 int32) (map[int32]map[int32]int32, error) {
ret := _m.ctrl.Call(_m, "TestMapMap", _param0)
ret0, _ := ret[0].(map[int32]map[int32]int32)
ret1, _ := ret[1].(error)
return ret0, ret1
}
func (_mr *_MockThriftTestRecorder) TestMapMap(arg0 interface{}) *gomock.Call {
return _mr.mock.ctrl.RecordCall(_mr.mock, "TestMapMap", arg0)
}
func (_m *MockThriftTest) TestMulti(_param0 int8, _param1 int32, _param2 int64, _param3 map[int16]string, _param4 thrifttest.Numberz, _param5 thrifttest.UserId) (*thrifttest.Xtruct, error) {
ret := _m.ctrl.Call(_m, "TestMulti", _param0, _param1, _param2, _param3, _param4, _param5)
ret0, _ := ret[0].(*thrifttest.Xtruct)
ret1, _ := ret[1].(error)
return ret0, ret1
}
func (_mr *_MockThriftTestRecorder) TestMulti(arg0, arg1, arg2, arg3, arg4, arg5 interface{}) *gomock.Call {
return _mr.mock.ctrl.RecordCall(_mr.mock, "TestMulti", arg0, arg1, arg2, arg3, arg4, arg5)
}
func (_m *MockThriftTest) TestMultiException(_param0 string, _param1 string) (*thrifttest.Xtruct, error) {
ret := _m.ctrl.Call(_m, "TestMultiException", _param0, _param1)
ret0, _ := ret[0].(*thrifttest.Xtruct)
ret1, _ := ret[1].(error)
return ret0, ret1
}
func (_mr *_MockThriftTestRecorder) TestMultiException(arg0, arg1 interface{}) *gomock.Call {
return _mr.mock.ctrl.RecordCall(_mr.mock, "TestMultiException", arg0, arg1)
}
func (_m *MockThriftTest) TestNest(_param0 *thrifttest.Xtruct2) (*thrifttest.Xtruct2, error) {
ret := _m.ctrl.Call(_m, "TestNest", _param0)
ret0, _ := ret[0].(*thrifttest.Xtruct2)
ret1, _ := ret[1].(error)
return ret0, ret1
}
func (_mr *_MockThriftTestRecorder) TestNest(arg0 interface{}) *gomock.Call {
return _mr.mock.ctrl.RecordCall(_mr.mock, "TestNest", arg0)
}
func (_m *MockThriftTest) TestOneway(_param0 int32) error {
ret := _m.ctrl.Call(_m, "TestOneway", _param0)
ret0, _ := ret[0].(error)
return ret0
}
func (_mr *_MockThriftTestRecorder) TestOneway(arg0 interface{}) *gomock.Call {
return _mr.mock.ctrl.RecordCall(_mr.mock, "TestOneway", arg0)
}
func (_m *MockThriftTest) TestSet(_param0 map[int32]struct{}) (map[int32]struct{}, error) {
ret := _m.ctrl.Call(_m, "TestSet", _param0)
ret0, _ := ret[0].(map[int32]struct{})
ret1, _ := ret[1].(error)
return ret0, ret1
}
func (_mr *_MockThriftTestRecorder) TestSet(arg0 interface{}) *gomock.Call {
return _mr.mock.ctrl.RecordCall(_mr.mock, "TestSet", arg0)
}
func (_m *MockThriftTest) TestString(_param0 string) (string, error) {
ret := _m.ctrl.Call(_m, "TestString", _param0)
ret0, _ := ret[0].(string)
ret1, _ := ret[1].(error)
return ret0, ret1
}
func (_mr *_MockThriftTestRecorder) TestString(arg0 interface{}) *gomock.Call {
return _mr.mock.ctrl.RecordCall(_mr.mock, "TestString", arg0)
}
func (_m *MockThriftTest) TestStringMap(_param0 map[string]string) (map[string]string, error) {
ret := _m.ctrl.Call(_m, "TestStringMap", _param0)
ret0, _ := ret[0].(map[string]string)
ret1, _ := ret[1].(error)
return ret0, ret1
}
func (_mr *_MockThriftTestRecorder) TestStringMap(arg0 interface{}) *gomock.Call {
return _mr.mock.ctrl.RecordCall(_mr.mock, "TestStringMap", arg0)
}
func (_m *MockThriftTest) TestStruct(_param0 *thrifttest.Xtruct) (*thrifttest.Xtruct, error) {
ret := _m.ctrl.Call(_m, "TestStruct", _param0)
ret0, _ := ret[0].(*thrifttest.Xtruct)
ret1, _ := ret[1].(error)
return ret0, ret1
}
func (_mr *_MockThriftTestRecorder) TestStruct(arg0 interface{}) *gomock.Call {
return _mr.mock.ctrl.RecordCall(_mr.mock, "TestStruct", arg0)
}
func (_m *MockThriftTest) TestTypedef(_param0 thrifttest.UserId) (thrifttest.UserId, error) {
ret := _m.ctrl.Call(_m, "TestTypedef", _param0)
ret0, _ := ret[0].(thrifttest.UserId)
ret1, _ := ret[1].(error)
return ret0, ret1
}
func (_mr *_MockThriftTestRecorder) TestTypedef(arg0 interface{}) *gomock.Call {
return _mr.mock.ctrl.RecordCall(_mr.mock, "TestTypedef", arg0)
}
func (_m *MockThriftTest) TestVoid() error {
ret := _m.ctrl.Call(_m, "TestVoid")
ret0, _ := ret[0].(error)
return ret0
}
func (_mr *_MockThriftTestRecorder) TestVoid() *gomock.Call {
return _mr.mock.ctrl.RecordCall(_mr.mock, "TestVoid")
}

View file

@ -0,0 +1,383 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package common
import (
"errors"
"fmt"
"encoding/hex"
. "gen/thrifttest"
"time"
)
var PrintingHandler = &printingHandler{}
type printingHandler struct{}
// Prints "testVoid()" and returns nothing.
func (p *printingHandler) TestVoid() (err error) {
fmt.Println("testVoid()")
return nil
}
// Prints 'testString("%s")' with thing as '%s'
// @param string thing - the string to print
// @return string - returns the string 'thing'
//
// Parameters:
// - Thing
func (p *printingHandler) TestString(thing string) (r string, err error) {
fmt.Printf("testString(\"%s\")\n", thing)
return thing, nil
}
// Prints 'testBool("%t")' with thing as 'true' or 'false'
// @param bool thing - the bool to print
// @return bool - returns the bool 'thing'
//
// Parameters:
// - Thing
func (p *printingHandler) TestBool(thing bool) (r bool, err error) {
fmt.Printf("testBool(%t)\n", thing)
return thing, nil
}
// Prints 'testByte("%d")' with thing as '%d'
// @param byte thing - the byte to print
// @return byte - returns the byte 'thing'
//
// Parameters:
// - Thing
func (p *printingHandler) TestByte(thing int8) (r int8, err error) {
fmt.Printf("testByte(%d)\n", thing)
return thing, nil
}
// Prints 'testI32("%d")' with thing as '%d'
// @param i32 thing - the i32 to print
// @return i32 - returns the i32 'thing'
//
// Parameters:
// - Thing
func (p *printingHandler) TestI32(thing int32) (r int32, err error) {
fmt.Printf("testI32(%d)\n", thing)
return thing, nil
}
// Prints 'testI64("%d")' with thing as '%d'
// @param i64 thing - the i64 to print
// @return i64 - returns the i64 'thing'
//
// Parameters:
// - Thing
func (p *printingHandler) TestI64(thing int64) (r int64, err error) {
fmt.Printf("testI64(%d)\n", thing)
return thing, nil
}
// Prints 'testDouble("%f")' with thing as '%f'
// @param double thing - the double to print
// @return double - returns the double 'thing'
//
// Parameters:
// - Thing
func (p *printingHandler) TestDouble(thing float64) (r float64, err error) {
fmt.Printf("testDouble(%f)\n", thing)
return thing, nil
}
// Prints 'testBinary("%s")' where '%s' is a hex-formatted string of thing's data
// @param []byte thing - the binary to print
// @return []byte - returns the binary 'thing'
//
// Parameters:
// - Thing
func (p *printingHandler) TestBinary(thing []byte) (r []byte, err error) {
fmt.Printf("testBinary(%s)\n", hex.EncodeToString(thing))
return thing, nil
}
// Prints 'testStruct("{%s}")' where thing has been formatted into a string of comma separated values
// @param Xtruct thing - the Xtruct to print
// @return Xtruct - returns the Xtruct 'thing'
//
// Parameters:
// - Thing
func (p *printingHandler) TestStruct(thing *Xtruct) (r *Xtruct, err error) {
fmt.Printf("testStruct({\"%s\", %d, %d, %d})\n", thing.StringThing, thing.ByteThing, thing.I32Thing, thing.I64Thing)
return thing, err
}
// Prints 'testNest("{%s}")' where thing has been formatted into a string of the nested struct
// @param Xtruct2 thing - the Xtruct2 to print
// @return Xtruct2 - returns the Xtruct2 'thing'
//
// Parameters:
// - Thing
func (p *printingHandler) TestNest(nest *Xtruct2) (r *Xtruct2, err error) {
thing := nest.StructThing
fmt.Printf("testNest({%d, {\"%s\", %d, %d, %d}, %d})\n", nest.ByteThing, thing.StringThing, thing.ByteThing, thing.I32Thing, thing.I64Thing, nest.I32Thing)
return nest, nil
}
// Prints 'testMap("{%s")' where thing has been formatted into a string of 'key => value' pairs
// separated by commas and new lines
// @param map<i32,i32> thing - the map<i32,i32> to print
// @return map<i32,i32> - returns the map<i32,i32> 'thing'
//
// Parameters:
// - Thing
func (p *printingHandler) TestMap(thing map[int32]int32) (r map[int32]int32, err error) {
fmt.Printf("testMap({")
first := true
for k, v := range thing {
if first {
first = false
} else {
fmt.Printf(", ")
}
fmt.Printf("%d => %d", k, v)
}
fmt.Printf("})\n")
return thing, nil
}
// Prints 'testStringMap("{%s}")' where thing has been formatted into a string of 'key => value' pairs
// separated by commas and new lines
// @param map<string,string> thing - the map<string,string> to print
// @return map<string,string> - returns the map<string,string> 'thing'
//
// Parameters:
// - Thing
func (p *printingHandler) TestStringMap(thing map[string]string) (r map[string]string, err error) {
fmt.Printf("testStringMap({")
first := true
for k, v := range thing {
if first {
first = false
} else {
fmt.Printf(", ")
}
fmt.Printf("%s => %s", k, v)
}
fmt.Printf("})\n")
return thing, nil
}
// Prints 'testSet("{%s}")' where thing has been formatted into a string of values
// separated by commas and new lines
// @param set<i32> thing - the set<i32> to print
// @return set<i32> - returns the set<i32> 'thing'
//
// Parameters:
// - Thing
func (p *printingHandler) TestSet(thing map[int32]struct{}) (r map[int32]struct{}, err error) {
fmt.Printf("testSet({")
first := true
for k, _ := range thing {
if first {
first = false
} else {
fmt.Printf(", ")
}
fmt.Printf("%d", k)
}
fmt.Printf("})\n")
return thing, nil
}
// Prints 'testList("{%s}")' where thing has been formatted into a string of values
// separated by commas and new lines
// @param list<i32> thing - the list<i32> to print
// @return list<i32> - returns the list<i32> 'thing'
//
// Parameters:
// - Thing
func (p *printingHandler) TestList(thing []int32) (r []int32, err error) {
fmt.Printf("testList({")
for i, v := range thing {
if i != 0 {
fmt.Printf(", ")
}
fmt.Printf("%d", v)
}
fmt.Printf("})\n")
return thing, nil
}
// Prints 'testEnum("%d")' where thing has been formatted into it's numeric value
// @param Numberz thing - the Numberz to print
// @return Numberz - returns the Numberz 'thing'
//
// Parameters:
// - Thing
func (p *printingHandler) TestEnum(thing Numberz) (r Numberz, err error) {
fmt.Printf("testEnum(%d)\n", thing)
return thing, nil
}
// Prints 'testTypedef("%d")' with thing as '%d'
// @param UserId thing - the UserId to print
// @return UserId - returns the UserId 'thing'
//
// Parameters:
// - Thing
func (p *printingHandler) TestTypedef(thing UserId) (r UserId, err error) {
fmt.Printf("testTypedef(%d)\n", thing)
return thing, nil
}
// Prints 'testMapMap("%d")' with hello as '%d'
// @param i32 hello - the i32 to print
// @return map<i32,map<i32,i32>> - returns a dictionary with these values:
// {-4 => {-4 => -4, -3 => -3, -2 => -2, -1 => -1, }, 4 => {1 => 1, 2 => 2, 3 => 3, 4 => 4, }, }
//
// Parameters:
// - Hello
func (p *printingHandler) TestMapMap(hello int32) (r map[int32]map[int32]int32, err error) {
fmt.Printf("testMapMap(%d)\n", hello)
r = map[int32]map[int32]int32{
-4: map[int32]int32{-4: -4, -3: -3, -2: -2, -1: -1},
4: map[int32]int32{4: 4, 3: 3, 2: 2, 1: 1},
}
return
}
// So you think you've got this all worked, out eh?
//
// Creates a the returned map with these values and prints it out:
// { 1 => { 2 => argument,
// 3 => argument,
// },
// 2 => { 6 => <empty Insanity struct>, },
// }
// @return map<UserId, map<Numberz,Insanity>> - a map with the above values
//
// Parameters:
// - Argument
func (p *printingHandler) TestInsanity(argument *Insanity) (r map[UserId]map[Numberz]*Insanity, err error) {
fmt.Printf("testInsanity()\n")
r = make(map[UserId]map[Numberz]*Insanity)
r[1] = map[Numberz]*Insanity {
2: argument,
3: argument,
}
r[2] = map[Numberz]*Insanity {
6: NewInsanity(),
}
return
}
// Prints 'testMulti()'
// @param byte arg0 -
// @param i32 arg1 -
// @param i64 arg2 -
// @param map<i16, string> arg3 -
// @param Numberz arg4 -
// @param UserId arg5 -
// @return Xtruct - returns an Xtruct with StringThing = "Hello2, ByteThing = arg0, I32Thing = arg1
// and I64Thing = arg2
//
// Parameters:
// - Arg0
// - Arg1
// - Arg2
// - Arg3
// - Arg4
// - Arg5
func (p *printingHandler) TestMulti(arg0 int8, arg1 int32, arg2 int64, arg3 map[int16]string, arg4 Numberz, arg5 UserId) (r *Xtruct, err error) {
fmt.Printf("testMulti()\n")
r = NewXtruct()
r.StringThing = "Hello2"
r.ByteThing = arg0
r.I32Thing = arg1
r.I64Thing = arg2
return
}
// Print 'testException(%s)' with arg as '%s'
// @param string arg - a string indication what type of exception to throw
// if arg == "Xception" throw Xception with errorCode = 1001 and message = arg
// elsen if arg == "TException" throw TException
// else do not throw anything
//
// Parameters:
// - Arg
func (p *printingHandler) TestException(arg string) (err error) {
fmt.Printf("testException(%s)\n", arg)
switch arg {
case "Xception":
e := NewXception()
e.ErrorCode = 1001
e.Message = arg
return e
case "TException":
return errors.New("Just TException")
}
return
}
// Print 'testMultiException(%s, %s)' with arg0 as '%s' and arg1 as '%s'
// @param string arg - a string indication what type of exception to throw
// if arg0 == "Xception" throw Xception with errorCode = 1001 and message = "This is an Xception"
// elsen if arg0 == "Xception2" throw Xception2 with errorCode = 2002 and message = "This is an Xception2"
// else do not throw anything
// @return Xtruct - an Xtruct with StringThing = arg1
//
// Parameters:
// - Arg0
// - Arg1
func (p *printingHandler) TestMultiException(arg0 string, arg1 string) (r *Xtruct, err error) {
fmt.Printf("testMultiException(%s, %s)\n", arg0, arg1)
switch arg0 {
case "Xception":
e := NewXception()
e.ErrorCode = 1001
e.Message = "This is an Xception"
return nil, e
case "Xception2":
e := NewXception2()
e.ErrorCode = 2002
e.StructThing = NewXtruct()
e.StructThing.StringThing = "This is an Xception2"
return nil, e
default:
r = NewXtruct()
r.StringThing = arg1
return
}
}
// Print 'testOneway(%d): Sleeping...' with secondsToSleep as '%d'
// sleep 'secondsToSleep'
// Print 'testOneway(%d): done sleeping!' with secondsToSleep as '%d'
// @param i32 secondsToSleep - the number of seconds to sleep
//
// Parameters:
// - SecondsToSleep
func (p *printingHandler) TestOneway(secondsToSleep int32) (err error) {
fmt.Printf("testOneway(%d): Sleeping...\n", secondsToSleep)
time.Sleep(time.Second * time.Duration(secondsToSleep))
fmt.Printf("testOneway(%d): done sleeping!\n", secondsToSleep)
return
}

View file

@ -0,0 +1,111 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package common
import (
"compress/zlib"
"crypto/tls"
"flag"
"fmt"
"gen/thrifttest"
"thrift"
)
var (
debugServerProtocol bool
certPath string
)
func init() {
flag.BoolVar(&debugServerProtocol, "debug_server_protocol", false, "turn server protocol trace on")
}
func GetServerParams(
host string,
port int64,
domain_socket string,
transport string,
protocol string,
ssl bool,
certPath string,
handler thrifttest.ThriftTest) (thrift.TProcessor, thrift.TServerTransport, thrift.TTransportFactory, thrift.TProtocolFactory, error) {
var err error
hostPort := fmt.Sprintf("%s:%d", host, port)
var protocolFactory thrift.TProtocolFactory
switch protocol {
case "compact":
protocolFactory = thrift.NewTCompactProtocolFactory()
case "simplejson":
protocolFactory = thrift.NewTSimpleJSONProtocolFactory()
case "json":
protocolFactory = thrift.NewTJSONProtocolFactory()
case "binary":
protocolFactory = thrift.NewTBinaryProtocolFactoryDefault()
default:
return nil, nil, nil, nil, fmt.Errorf("Invalid protocol specified %s", protocol)
}
if debugServerProtocol {
protocolFactory = thrift.NewTDebugProtocolFactory(protocolFactory, "server:")
}
var serverTransport thrift.TServerTransport
if ssl {
cfg := new(tls.Config)
if cert, err := tls.LoadX509KeyPair(certPath+"/server.crt", certPath+"/server.key"); err != nil {
return nil, nil, nil, nil, err
} else {
cfg.Certificates = append(cfg.Certificates, cert)
}
serverTransport, err = thrift.NewTSSLServerSocket(hostPort, cfg)
} else {
if domain_socket != "" {
serverTransport, err = thrift.NewTServerSocket(domain_socket)
} else {
serverTransport, err = thrift.NewTServerSocket(hostPort)
}
}
if err != nil {
return nil, nil, nil, nil, err
}
var transportFactory thrift.TTransportFactory
switch transport {
case "http":
// there is no such factory, and we don't need any
transportFactory = nil
case "framed":
transportFactory = thrift.NewTTransportFactory()
transportFactory = thrift.NewTFramedTransportFactory(transportFactory)
case "buffered":
transportFactory = thrift.NewTBufferedTransportFactory(8192)
case "zlib":
transportFactory = thrift.NewTZlibTransportFactory(zlib.BestCompression)
case "":
transportFactory = thrift.NewTTransportFactory()
default:
return nil, nil, nil, nil, fmt.Errorf("Invalid transport specified %s", transport)
}
processor := thrifttest.NewThriftTestProcessor(handler)
return processor, serverTransport, transportFactory, protocolFactory, nil
}

View file

@ -0,0 +1,155 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package common
import (
"errors"
. "gen/thrifttest"
"time"
)
var SimpleHandler = &simpleHandler{}
type simpleHandler struct{}
func (p *simpleHandler) TestVoid() (err error) {
return nil
}
func (p *simpleHandler) TestString(thing string) (r string, err error) {
return thing, nil
}
func (p *simpleHandler) TestBool(thing []byte) (r []byte, err error) {
return thing, nil
}
func (p *simpleHandler) TestByte(thing int8) (r int8, err error) {
return thing, nil
}
func (p *simpleHandler) TestI32(thing int32) (r int32, err error) {
return thing, nil
}
func (p *simpleHandler) TestI64(thing int64) (r int64, err error) {
return thing, nil
}
func (p *simpleHandler) TestDouble(thing float64) (r float64, err error) {
return thing, nil
}
func (p *simpleHandler) TestBinary(thing []byte) (r []byte, err error) {
return thing, nil
}
func (p *simpleHandler) TestStruct(thing *Xtruct) (r *Xtruct, err error) {
return r, err
}
func (p *simpleHandler) TestNest(nest *Xtruct2) (r *Xtruct2, err error) {
return nest, nil
}
func (p *simpleHandler) TestMap(thing map[int32]int32) (r map[int32]int32, err error) {
return thing, nil
}
func (p *simpleHandler) TestStringMap(thing map[string]string) (r map[string]string, err error) {
return thing, nil
}
func (p *simpleHandler) TestSet(thing map[int32]struct{}) (r map[int32]struct{}, err error) {
return thing, nil
}
func (p *simpleHandler) TestList(thing []int32) (r []int32, err error) {
return thing, nil
}
func (p *simpleHandler) TestEnum(thing Numberz) (r Numberz, err error) {
return thing, nil
}
func (p *simpleHandler) TestTypedef(thing UserId) (r UserId, err error) {
return thing, nil
}
func (p *simpleHandler) TestMapMap(hello int32) (r map[int32]map[int32]int32, err error) {
r = map[int32]map[int32]int32{
-4: map[int32]int32{-4: -4, -3: -3, -2: -2, -1: -1},
4: map[int32]int32{4: 4, 3: 3, 2: 2, 1: 1},
}
return
}
func (p *simpleHandler) TestInsanity(argument *Insanity) (r map[UserId]map[Numberz]*Insanity, err error) {
return nil, errors.New("No Insanity")
}
func (p *simpleHandler) TestMulti(arg0 int8, arg1 int32, arg2 int64, arg3 map[int16]string, arg4 Numberz, arg5 UserId) (r *Xtruct, err error) {
r = NewXtruct()
r.StringThing = "Hello2"
r.ByteThing = arg0
r.I32Thing = arg1
r.I64Thing = arg2
return
}
func (p *simpleHandler) TestException(arg string) (err error) {
switch arg {
case "Xception":
e := NewXception()
e.ErrorCode = 1001
e.Message = arg
return e
case "TException":
return errors.New("Just TException")
}
return
}
func (p *simpleHandler) TestMultiException(arg0 string, arg1 string) (r *Xtruct, err error) {
switch arg0 {
case "Xception":
e := NewXception()
e.ErrorCode = 1001
e.Message = "This is an Xception"
return nil, e
case "Xception2":
e := NewXception2()
e.ErrorCode = 2002
e.StructThing.StringThing = "This is an Xception2"
return nil, e
default:
r = NewXtruct()
r.StringThing = arg1
return
}
}
func (p *simpleHandler) TestOneway(secondsToSleep int32) (err error) {
time.Sleep(time.Second * time.Duration(secondsToSleep))
return
}