diff options
author | taozle <zhangliyang26@gmail.com> | 2017-07-17 18:40:42 +0200 |
---|---|---|
committer | Jens Geyer <jensg@apache.org> | 2017-07-22 19:42:48 +0200 |
commit | c0d384a38c2b43ee47cef86b1cd054e3f84dc909 (patch) | |
tree | 8de48de44cc628d110ac6bee4bbd8fd74c86d833 /test/go | |
parent | 0dd823580c78a79ae9696eb9b3650e400fff140f (diff) | |
download | thrift-c0d384a38c2b43ee47cef86b1cd054e3f84dc909.tar.gz |
THRIFT-4236 Support context in go generated code
Client: Go
Patch: taozle <zhangliyang26@gmail.com>
This closes #1309
Diffstat (limited to 'test/go')
-rw-r--r-- | test/go/Makefile.am | 3 | ||||
-rw-r--r-- | test/go/src/bin/stress/go17.go | 62 | ||||
-rw-r--r-- | test/go/src/bin/stress/main.go | 35 | ||||
-rw-r--r-- | test/go/src/bin/stress/pre_go17.go | 63 | ||||
-rw-r--r-- | test/go/src/common/clientserver_test.go | 48 | ||||
-rw-r--r-- | test/go/src/common/mock_handler.go | 246 | ||||
-rw-r--r-- | test/go/src/common/printing_handler.go | 48 | ||||
-rw-r--r-- | test/go/src/common/printing_handler_go17.go | 386 |
8 files changed, 709 insertions, 182 deletions
diff --git a/test/go/Makefile.am b/test/go/Makefile.am index 2b2dbce68..428535984 100644 --- a/test/go/Makefile.am +++ b/test/go/Makefile.am @@ -20,7 +20,7 @@ BUILT_SOURCES = gopath THRIFT = $(top_builddir)/compiler/cpp/thrift -THRIFTCMD = $(THRIFT) -out src/gen --gen go:thrift_import=thrift +THRIFTCMD = $(THRIFT) -out src/gen --gen go:thrift_import=thrift,legacy_context THRIFTTEST = $(top_srcdir)/test/ThriftTest.thrift precross: bin/testclient bin/testserver @@ -35,6 +35,7 @@ gopath: $(THRIFT) ThriftTest.thrift $(THRIFTCMD) ../StressTest.thrift ln -nfs ../../../lib/go/thrift src/thrift GOPATH=`pwd` $(GO) get github.com/golang/mock/gomock + GOPATH=`pwd` $(GO) get golang.org/x/net/context touch gopath bin/testclient: gopath diff --git a/test/go/src/bin/stress/go17.go b/test/go/src/bin/stress/go17.go new file mode 100644 index 000000000..81f1ad8ee --- /dev/null +++ b/test/go/src/bin/stress/go17.go @@ -0,0 +1,62 @@ +// +build go1.7 + +/* + * 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 main + +import ( + "context" + "sync/atomic" +) + +type handler struct{} + +func (h *handler) EchoVoid(ctx context.Context) (err error) { + atomic.AddInt64(&counter, 1) + return nil +} +func (h *handler) EchoByte(ctx context.Context, arg int8) (r int8, err error) { + atomic.AddInt64(&counter, 1) + return arg, nil +} +func (h *handler) EchoI32(ctx context.Context, arg int32) (r int32, err error) { + atomic.AddInt64(&counter, 1) + return arg, nil +} +func (h *handler) EchoI64(ctx context.Context, arg int64) (r int64, err error) { + atomic.AddInt64(&counter, 1) + return arg, nil +} +func (h *handler) EchoString(ctx context.Context, arg string) (r string, err error) { + atomic.AddInt64(&counter, 1) + return arg, nil +} +func (h *handler) EchoList(ctx context.Context, arg []int8) (r []int8, err error) { + atomic.AddInt64(&counter, 1) + return arg, nil +} +func (h *handler) EchoSet(ctx context.Context, arg map[int8]struct{}) (r map[int8]struct{}, err error) { + atomic.AddInt64(&counter, 1) + return arg, nil +} +func (h *handler) EchoMap(ctx context.Context, arg map[int8]int8) (r map[int8]int8, err error) { + atomic.AddInt64(&counter, 1) + return arg, nil +} diff --git a/test/go/src/bin/stress/main.go b/test/go/src/bin/stress/main.go index 1f713bbd1..e8e6b2a20 100644 --- a/test/go/src/bin/stress/main.go +++ b/test/go/src/bin/stress/main.go @@ -216,38 +216,3 @@ func client(protocolFactory thrift.TProtocolFactory) { done.Done() } - -type handler struct{} - -func (h *handler) EchoVoid() (err error) { - atomic.AddInt64(&counter, 1) - return nil -} -func (h *handler) EchoByte(arg int8) (r int8, err error) { - atomic.AddInt64(&counter, 1) - return arg, nil -} -func (h *handler) EchoI32(arg int32) (r int32, err error) { - atomic.AddInt64(&counter, 1) - return arg, nil -} -func (h *handler) EchoI64(arg int64) (r int64, err error) { - atomic.AddInt64(&counter, 1) - return arg, nil -} -func (h *handler) EchoString(arg string) (r string, err error) { - atomic.AddInt64(&counter, 1) - return arg, nil -} -func (h *handler) EchoList(arg []int8) (r []int8, err error) { - atomic.AddInt64(&counter, 1) - return arg, nil -} -func (h *handler) EchoSet(arg map[int8]struct{}) (r map[int8]struct{}, err error) { - atomic.AddInt64(&counter, 1) - return arg, nil -} -func (h *handler) EchoMap(arg map[int8]int8) (r map[int8]int8, err error) { - atomic.AddInt64(&counter, 1) - return arg, nil -} diff --git a/test/go/src/bin/stress/pre_go17.go b/test/go/src/bin/stress/pre_go17.go new file mode 100644 index 000000000..07ae5c6a2 --- /dev/null +++ b/test/go/src/bin/stress/pre_go17.go @@ -0,0 +1,63 @@ +// +build !go1.7 + +/* + * 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 main + +import ( + "sync/atomic" + + "golang.org/x/net/context" +) + +type handler struct{} + +func (h *handler) EchoVoid(ctx context.Context) (err error) { + atomic.AddInt64(&counter, 1) + return nil +} +func (h *handler) EchoByte(ctx context.Context, arg int8) (r int8, err error) { + atomic.AddInt64(&counter, 1) + return arg, nil +} +func (h *handler) EchoI32(ctx context.Context, arg int32) (r int32, err error) { + atomic.AddInt64(&counter, 1) + return arg, nil +} +func (h *handler) EchoI64(ctx context.Context, arg int64) (r int64, err error) { + atomic.AddInt64(&counter, 1) + return arg, nil +} +func (h *handler) EchoString(ctx context.Context, arg string) (r string, err error) { + atomic.AddInt64(&counter, 1) + return arg, nil +} +func (h *handler) EchoList(ctx context.Context, arg []int8) (r []int8, err error) { + atomic.AddInt64(&counter, 1) + return arg, nil +} +func (h *handler) EchoSet(ctx context.Context, arg map[int8]struct{}) (r map[int8]struct{}, err error) { + atomic.AddInt64(&counter, 1) + return arg, nil +} +func (h *handler) EchoMap(ctx context.Context, arg map[int8]int8) (r map[int8]int8, err error) { + atomic.AddInt64(&counter, 1) + return arg, nil +} diff --git a/test/go/src/common/clientserver_test.go b/test/go/src/common/clientserver_test.go index 9f490eaf8..acc3dbaf8 100644 --- a/test/go/src/common/clientserver_test.go +++ b/test/go/src/common/clientserver_test.go @@ -92,32 +92,32 @@ 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), + handler.EXPECT().TestVoid(gomock.Any()), + handler.EXPECT().TestString(gomock.Any(), "thing").Return("thing", nil), + handler.EXPECT().TestBool(gomock.Any(), true).Return(true, nil), + handler.EXPECT().TestBool(gomock.Any(), false).Return(false, nil), + handler.EXPECT().TestByte(gomock.Any(), int8(42)).Return(int8(42), nil), + handler.EXPECT().TestI32(gomock.Any(), int32(4242)).Return(int32(4242), nil), + handler.EXPECT().TestI64(gomock.Any(), 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([]int32{1, 2, 42}).Return([]int32{1, 2, 42}, 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), + handler.EXPECT().TestDouble(gomock.Any(), float64(42.42)).Return(float64(42.42), nil), + handler.EXPECT().TestStruct(gomock.Any(), &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(gomock.Any(), &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(gomock.Any(), map[int32]int32{1: 2, 3: 4, 5: 42}).Return(map[int32]int32{1: 2, 3: 4, 5: 42}, nil), + handler.EXPECT().TestStringMap(gomock.Any(), map[string]string{"a": "2", "b": "blah", "some": "thing"}).Return(map[string]string{"a": "2", "b": "blah", "some": "thing"}, nil), + handler.EXPECT().TestSet(gomock.Any(), []int32{1, 2, 42}).Return([]int32{1, 2, 42}, nil), + handler.EXPECT().TestList(gomock.Any(), []int32{1, 2, 42}).Return([]int32{1, 2, 42}, nil), + handler.EXPECT().TestEnum(gomock.Any(), thrifttest.Numberz_TWO).Return(thrifttest.Numberz_TWO, nil), + handler.EXPECT().TestTypedef(gomock.Any(), thrifttest.UserId(42)).Return(thrifttest.UserId(42), nil), + handler.EXPECT().TestMapMap(gomock.Any(), 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(), + handler.EXPECT().TestMulti(gomock.Any(), 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(gomock.Any(), "some").Return(xcept), + handler.EXPECT().TestException(gomock.Any(), "TException").Return(errors.New("Just random exception")), + handler.EXPECT().TestMultiException(gomock.Any(), "Xception", "ignoreme").Return(nil, &thrifttest.Xception{ErrorCode: 1001, Message: "This is an Xception"}), + handler.EXPECT().TestMultiException(gomock.Any(), "Xception2", "ignoreme").Return(nil, &thrifttest.Xception2{ErrorCode: 2002, StructThing: &thrifttest.Xtruct{StringThing: "This is an Xception2"}}), + handler.EXPECT().TestOneway(gomock.Any(), int32(2)).Return(nil), + handler.EXPECT().TestVoid(gomock.Any()), ) var err error if err = client.TestVoid(); err != nil { diff --git a/test/go/src/common/mock_handler.go b/test/go/src/common/mock_handler.go index b6738ee16..3960e1ab7 100644 --- a/test/go/src/common/mock_handler.go +++ b/test/go/src/common/mock_handler.go @@ -23,267 +23,313 @@ package common import ( - gomock "github.com/golang/mock/gomock" thrifttest "gen/thrifttest" + gomock "github.com/golang/mock/gomock" + context "golang.org/x/net/context" ) -// Mock of ThriftTest interface +// MockThriftTest is a mock of ThriftTest interface type MockThriftTest struct { ctrl *gomock.Controller - recorder *_MockThriftTestRecorder + recorder *MockThriftTestMockRecorder } -// Recorder for MockThriftTest (not exported) -type _MockThriftTestRecorder struct { +// MockThriftTestMockRecorder is the mock recorder for MockThriftTest +type MockThriftTestMockRecorder struct { mock *MockThriftTest } +// NewMockThriftTest creates a new mock instance func NewMockThriftTest(ctrl *gomock.Controller) *MockThriftTest { mock := &MockThriftTest{ctrl: ctrl} - mock.recorder = &_MockThriftTestRecorder{mock} + mock.recorder = &MockThriftTestMockRecorder{mock} return mock } -func (_m *MockThriftTest) EXPECT() *_MockThriftTestRecorder { +// EXPECT returns an object that allows the caller to indicate expected use +func (_m *MockThriftTest) EXPECT() *MockThriftTestMockRecorder { return _m.recorder } -func (_m *MockThriftTest) TestBool(_param0 bool) (bool, error) { - ret := _m.ctrl.Call(_m, "TestBool", _param0) - ret0, _ := ret[0].(bool) +// TestBinary mocks base method +func (_m *MockThriftTest) TestBinary(_param0 context.Context, _param1 []byte) ([]byte, error) { + ret := _m.ctrl.Call(_m, "TestBinary", _param0, _param1) + ret0, _ := ret[0].([]byte) ret1, _ := ret[1].(error) return ret0, ret1 } -func (_mr *_MockThriftTestRecorder) TestBool(arg0 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "TestBool", arg0) +// TestBinary indicates an expected call of TestBinary +func (_mr *MockThriftTestMockRecorder) TestBinary(arg0, arg1 interface{}) *gomock.Call { + return _mr.mock.ctrl.RecordCall(_mr.mock, "TestBinary", arg0, arg1) } - -func (_m *MockThriftTest) TestByte(_param0 int8) (int8, error) { - ret := _m.ctrl.Call(_m, "TestByte", _param0) - ret0, _ := ret[0].(int8) +// TestBool mocks base method +func (_m *MockThriftTest) TestBool(_param0 context.Context, _param1 bool) (bool, error) { + ret := _m.ctrl.Call(_m, "TestBool", _param0, _param1) + ret0, _ := ret[0].(bool) ret1, _ := ret[1].(error) return ret0, ret1 } -func (_mr *_MockThriftTestRecorder) TestByte(arg0 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "TestByte", arg0) +// TestBool indicates an expected call of TestBool +func (_mr *MockThriftTestMockRecorder) TestBool(arg0, arg1 interface{}) *gomock.Call { + return _mr.mock.ctrl.RecordCall(_mr.mock, "TestBool", arg0, arg1) } -func (_m *MockThriftTest) TestDouble(_param0 float64) (float64, error) { - ret := _m.ctrl.Call(_m, "TestDouble", _param0) - ret0, _ := ret[0].(float64) +// TestByte mocks base method +func (_m *MockThriftTest) TestByte(_param0 context.Context, _param1 int8) (int8, error) { + ret := _m.ctrl.Call(_m, "TestByte", _param0, _param1) + ret0, _ := ret[0].(int8) ret1, _ := ret[1].(error) return ret0, ret1 } -func (_mr *_MockThriftTestRecorder) TestDouble(arg0 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "TestDouble", arg0) +// TestByte indicates an expected call of TestByte +func (_mr *MockThriftTestMockRecorder) TestByte(arg0, arg1 interface{}) *gomock.Call { + return _mr.mock.ctrl.RecordCall(_mr.mock, "TestByte", arg0, arg1) } -func (_m *MockThriftTest) TestBinary(_param0 []byte) ([]byte, error) { - ret := _m.ctrl.Call(_m, "TestBinary", _param0) - ret0, _ := ret[0].([]byte) +// TestDouble mocks base method +func (_m *MockThriftTest) TestDouble(_param0 context.Context, _param1 float64) (float64, error) { + ret := _m.ctrl.Call(_m, "TestDouble", _param0, _param1) + ret0, _ := ret[0].(float64) ret1, _ := ret[1].(error) return ret0, ret1 } -func (_mr *_MockThriftTestRecorder) TestBinary(arg0 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "TestBinary", arg0) +// TestDouble indicates an expected call of TestDouble +func (_mr *MockThriftTestMockRecorder) TestDouble(arg0, arg1 interface{}) *gomock.Call { + return _mr.mock.ctrl.RecordCall(_mr.mock, "TestDouble", arg0, arg1) } -func (_m *MockThriftTest) TestEnum(_param0 thrifttest.Numberz) (thrifttest.Numberz, error) { - ret := _m.ctrl.Call(_m, "TestEnum", _param0) +// TestEnum mocks base method +func (_m *MockThriftTest) TestEnum(_param0 context.Context, _param1 thrifttest.Numberz) (thrifttest.Numberz, error) { + ret := _m.ctrl.Call(_m, "TestEnum", _param0, _param1) 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) +// TestEnum indicates an expected call of TestEnum +func (_mr *MockThriftTestMockRecorder) TestEnum(arg0, arg1 interface{}) *gomock.Call { + return _mr.mock.ctrl.RecordCall(_mr.mock, "TestEnum", arg0, arg1) } -func (_m *MockThriftTest) TestException(_param0 string) error { - ret := _m.ctrl.Call(_m, "TestException", _param0) +// TestException mocks base method +func (_m *MockThriftTest) TestException(_param0 context.Context, _param1 string) error { + ret := _m.ctrl.Call(_m, "TestException", _param0, _param1) ret0, _ := ret[0].(error) return ret0 } -func (_mr *_MockThriftTestRecorder) TestException(arg0 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "TestException", arg0) +// TestException indicates an expected call of TestException +func (_mr *MockThriftTestMockRecorder) TestException(arg0, arg1 interface{}) *gomock.Call { + return _mr.mock.ctrl.RecordCall(_mr.mock, "TestException", arg0, arg1) } -func (_m *MockThriftTest) TestI32(_param0 int32) (int32, error) { - ret := _m.ctrl.Call(_m, "TestI32", _param0) +// TestI32 mocks base method +func (_m *MockThriftTest) TestI32(_param0 context.Context, _param1 int32) (int32, error) { + ret := _m.ctrl.Call(_m, "TestI32", _param0, _param1) 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) +// TestI32 indicates an expected call of TestI32 +func (_mr *MockThriftTestMockRecorder) TestI32(arg0, arg1 interface{}) *gomock.Call { + return _mr.mock.ctrl.RecordCall(_mr.mock, "TestI32", arg0, arg1) } -func (_m *MockThriftTest) TestI64(_param0 int64) (int64, error) { - ret := _m.ctrl.Call(_m, "TestI64", _param0) +// TestI64 mocks base method +func (_m *MockThriftTest) TestI64(_param0 context.Context, _param1 int64) (int64, error) { + ret := _m.ctrl.Call(_m, "TestI64", _param0, _param1) 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) +// TestI64 indicates an expected call of TestI64 +func (_mr *MockThriftTestMockRecorder) TestI64(arg0, arg1 interface{}) *gomock.Call { + return _mr.mock.ctrl.RecordCall(_mr.mock, "TestI64", arg0, arg1) } -func (_m *MockThriftTest) TestInsanity(_param0 *thrifttest.Insanity) (map[thrifttest.UserId]map[thrifttest.Numberz]*thrifttest.Insanity, error) { - ret := _m.ctrl.Call(_m, "TestInsanity", _param0) +// TestInsanity mocks base method +func (_m *MockThriftTest) TestInsanity(_param0 context.Context, _param1 *thrifttest.Insanity) (map[thrifttest.UserId]map[thrifttest.Numberz]*thrifttest.Insanity, error) { + ret := _m.ctrl.Call(_m, "TestInsanity", _param0, _param1) 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) +// TestInsanity indicates an expected call of TestInsanity +func (_mr *MockThriftTestMockRecorder) TestInsanity(arg0, arg1 interface{}) *gomock.Call { + return _mr.mock.ctrl.RecordCall(_mr.mock, "TestInsanity", arg0, arg1) } -func (_m *MockThriftTest) TestList(_param0 []int32) ([]int32, error) { - ret := _m.ctrl.Call(_m, "TestList", _param0) +// TestList mocks base method +func (_m *MockThriftTest) TestList(_param0 context.Context, _param1 []int32) ([]int32, error) { + ret := _m.ctrl.Call(_m, "TestList", _param0, _param1) 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) +// TestList indicates an expected call of TestList +func (_mr *MockThriftTestMockRecorder) TestList(arg0, arg1 interface{}) *gomock.Call { + return _mr.mock.ctrl.RecordCall(_mr.mock, "TestList", arg0, arg1) } -func (_m *MockThriftTest) TestMap(_param0 map[int32]int32) (map[int32]int32, error) { - ret := _m.ctrl.Call(_m, "TestMap", _param0) +// TestMap mocks base method +func (_m *MockThriftTest) TestMap(_param0 context.Context, _param1 map[int32]int32) (map[int32]int32, error) { + ret := _m.ctrl.Call(_m, "TestMap", _param0, _param1) 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) +// TestMap indicates an expected call of TestMap +func (_mr *MockThriftTestMockRecorder) TestMap(arg0, arg1 interface{}) *gomock.Call { + return _mr.mock.ctrl.RecordCall(_mr.mock, "TestMap", arg0, arg1) } -func (_m *MockThriftTest) TestMapMap(_param0 int32) (map[int32]map[int32]int32, error) { - ret := _m.ctrl.Call(_m, "TestMapMap", _param0) +// TestMapMap mocks base method +func (_m *MockThriftTest) TestMapMap(_param0 context.Context, _param1 int32) (map[int32]map[int32]int32, error) { + ret := _m.ctrl.Call(_m, "TestMapMap", _param0, _param1) 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) +// TestMapMap indicates an expected call of TestMapMap +func (_mr *MockThriftTestMockRecorder) TestMapMap(arg0, arg1 interface{}) *gomock.Call { + return _mr.mock.ctrl.RecordCall(_mr.mock, "TestMapMap", arg0, arg1) } -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) +// TestMulti mocks base method +func (_m *MockThriftTest) TestMulti(_param0 context.Context, _param1 int8, _param2 int32, _param3 int64, _param4 map[int16]string, _param5 thrifttest.Numberz, _param6 thrifttest.UserId) (*thrifttest.Xtruct, error) { + ret := _m.ctrl.Call(_m, "TestMulti", _param0, _param1, _param2, _param3, _param4, _param5, _param6) 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) +// TestMulti indicates an expected call of TestMulti +func (_mr *MockThriftTestMockRecorder) TestMulti(arg0, arg1, arg2, arg3, arg4, arg5, arg6 interface{}) *gomock.Call { + return _mr.mock.ctrl.RecordCall(_mr.mock, "TestMulti", arg0, arg1, arg2, arg3, arg4, arg5, arg6) } -func (_m *MockThriftTest) TestMultiException(_param0 string, _param1 string) (*thrifttest.Xtruct, error) { - ret := _m.ctrl.Call(_m, "TestMultiException", _param0, _param1) +// TestMultiException mocks base method +func (_m *MockThriftTest) TestMultiException(_param0 context.Context, _param1 string, _param2 string) (*thrifttest.Xtruct, error) { + ret := _m.ctrl.Call(_m, "TestMultiException", _param0, _param1, _param2) 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) +// TestMultiException indicates an expected call of TestMultiException +func (_mr *MockThriftTestMockRecorder) TestMultiException(arg0, arg1, arg2 interface{}) *gomock.Call { + return _mr.mock.ctrl.RecordCall(_mr.mock, "TestMultiException", arg0, arg1, arg2) } -func (_m *MockThriftTest) TestNest(_param0 *thrifttest.Xtruct2) (*thrifttest.Xtruct2, error) { - ret := _m.ctrl.Call(_m, "TestNest", _param0) +// TestNest mocks base method +func (_m *MockThriftTest) TestNest(_param0 context.Context, _param1 *thrifttest.Xtruct2) (*thrifttest.Xtruct2, error) { + ret := _m.ctrl.Call(_m, "TestNest", _param0, _param1) 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) +// TestNest indicates an expected call of TestNest +func (_mr *MockThriftTestMockRecorder) TestNest(arg0, arg1 interface{}) *gomock.Call { + return _mr.mock.ctrl.RecordCall(_mr.mock, "TestNest", arg0, arg1) } -func (_m *MockThriftTest) TestOneway(_param0 int32) error { - ret := _m.ctrl.Call(_m, "TestOneway", _param0) +// TestOneway mocks base method +func (_m *MockThriftTest) TestOneway(_param0 context.Context, _param1 int32) error { + ret := _m.ctrl.Call(_m, "TestOneway", _param0, _param1) ret0, _ := ret[0].(error) return ret0 } -func (_mr *_MockThriftTestRecorder) TestOneway(arg0 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "TestOneway", arg0) +// TestOneway indicates an expected call of TestOneway +func (_mr *MockThriftTestMockRecorder) TestOneway(arg0, arg1 interface{}) *gomock.Call { + return _mr.mock.ctrl.RecordCall(_mr.mock, "TestOneway", arg0, arg1) } -func (_m *MockThriftTest) TestSet(_param0 []int32) ([]int32, error) { - ret := _m.ctrl.Call(_m, "TestSet", _param0) +// TestSet mocks base method +func (_m *MockThriftTest) TestSet(_param0 context.Context, _param1 []int32) ([]int32, error) { + ret := _m.ctrl.Call(_m, "TestSet", _param0, _param1) ret0, _ := ret[0].([]int32) ret1, _ := ret[1].(error) return ret0, ret1 } -func (_mr *_MockThriftTestRecorder) TestSet(arg0 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "TestSet", arg0) +// TestSet indicates an expected call of TestSet +func (_mr *MockThriftTestMockRecorder) TestSet(arg0, arg1 interface{}) *gomock.Call { + return _mr.mock.ctrl.RecordCall(_mr.mock, "TestSet", arg0, arg1) } -func (_m *MockThriftTest) TestString(_param0 string) (string, error) { - ret := _m.ctrl.Call(_m, "TestString", _param0) +// TestString mocks base method +func (_m *MockThriftTest) TestString(_param0 context.Context, _param1 string) (string, error) { + ret := _m.ctrl.Call(_m, "TestString", _param0, _param1) 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) +// TestString indicates an expected call of TestString +func (_mr *MockThriftTestMockRecorder) TestString(arg0, arg1 interface{}) *gomock.Call { + return _mr.mock.ctrl.RecordCall(_mr.mock, "TestString", arg0, arg1) } -func (_m *MockThriftTest) TestStringMap(_param0 map[string]string) (map[string]string, error) { - ret := _m.ctrl.Call(_m, "TestStringMap", _param0) +// TestStringMap mocks base method +func (_m *MockThriftTest) TestStringMap(_param0 context.Context, _param1 map[string]string) (map[string]string, error) { + ret := _m.ctrl.Call(_m, "TestStringMap", _param0, _param1) 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) +// TestStringMap indicates an expected call of TestStringMap +func (_mr *MockThriftTestMockRecorder) TestStringMap(arg0, arg1 interface{}) *gomock.Call { + return _mr.mock.ctrl.RecordCall(_mr.mock, "TestStringMap", arg0, arg1) } -func (_m *MockThriftTest) TestStruct(_param0 *thrifttest.Xtruct) (*thrifttest.Xtruct, error) { - ret := _m.ctrl.Call(_m, "TestStruct", _param0) +// TestStruct mocks base method +func (_m *MockThriftTest) TestStruct(_param0 context.Context, _param1 *thrifttest.Xtruct) (*thrifttest.Xtruct, error) { + ret := _m.ctrl.Call(_m, "TestStruct", _param0, _param1) 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) +// TestStruct indicates an expected call of TestStruct +func (_mr *MockThriftTestMockRecorder) TestStruct(arg0, arg1 interface{}) *gomock.Call { + return _mr.mock.ctrl.RecordCall(_mr.mock, "TestStruct", arg0, arg1) } -func (_m *MockThriftTest) TestTypedef(_param0 thrifttest.UserId) (thrifttest.UserId, error) { - ret := _m.ctrl.Call(_m, "TestTypedef", _param0) +// TestTypedef mocks base method +func (_m *MockThriftTest) TestTypedef(_param0 context.Context, _param1 thrifttest.UserId) (thrifttest.UserId, error) { + ret := _m.ctrl.Call(_m, "TestTypedef", _param0, _param1) 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) +// TestTypedef indicates an expected call of TestTypedef +func (_mr *MockThriftTestMockRecorder) TestTypedef(arg0, arg1 interface{}) *gomock.Call { + return _mr.mock.ctrl.RecordCall(_mr.mock, "TestTypedef", arg0, arg1) } -func (_m *MockThriftTest) TestVoid() error { - ret := _m.ctrl.Call(_m, "TestVoid") +// TestVoid mocks base method +func (_m *MockThriftTest) TestVoid(_param0 context.Context) error { + ret := _m.ctrl.Call(_m, "TestVoid", _param0) ret0, _ := ret[0].(error) return ret0 } -func (_mr *_MockThriftTestRecorder) TestVoid() *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "TestVoid") +// TestVoid indicates an expected call of TestVoid +func (_mr *MockThriftTestMockRecorder) TestVoid(arg0 interface{}) *gomock.Call { + return _mr.mock.ctrl.RecordCall(_mr.mock, "TestVoid", arg0) } diff --git a/test/go/src/common/printing_handler.go b/test/go/src/common/printing_handler.go index d4e2be919..c0a286267 100644 --- a/test/go/src/common/printing_handler.go +++ b/test/go/src/common/printing_handler.go @@ -1,3 +1,5 @@ +// +build !go1.7 + /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -25,6 +27,8 @@ import ( "encoding/hex" . "gen/thrifttest" "time" + + "golang.org/x/net/context" ) var PrintingHandler = &printingHandler{} @@ -32,7 +36,7 @@ var PrintingHandler = &printingHandler{} type printingHandler struct{} // Prints "testVoid()" and returns nothing. -func (p *printingHandler) TestVoid() (err error) { +func (p *printingHandler) TestVoid(ctx context.Context) (err error) { fmt.Println("testVoid()") return nil } @@ -43,7 +47,7 @@ func (p *printingHandler) TestVoid() (err error) { // // Parameters: // - Thing -func (p *printingHandler) TestString(thing string) (r string, err error) { +func (p *printingHandler) TestString(ctx context.Context, thing string) (r string, err error) { fmt.Printf("testString(\"%s\")\n", thing) return thing, nil } @@ -54,7 +58,7 @@ func (p *printingHandler) TestString(thing string) (r string, err error) { // // Parameters: // - Thing -func (p *printingHandler) TestBool(thing bool) (r bool, err error) { +func (p *printingHandler) TestBool(ctx context.Context, thing bool) (r bool, err error) { fmt.Printf("testBool(%t)\n", thing) return thing, nil } @@ -65,7 +69,7 @@ func (p *printingHandler) TestBool(thing bool) (r bool, err error) { // // Parameters: // - Thing -func (p *printingHandler) TestByte(thing int8) (r int8, err error) { +func (p *printingHandler) TestByte(ctx context.Context, thing int8) (r int8, err error) { fmt.Printf("testByte(%d)\n", thing) return thing, nil } @@ -76,7 +80,7 @@ func (p *printingHandler) TestByte(thing int8) (r int8, err error) { // // Parameters: // - Thing -func (p *printingHandler) TestI32(thing int32) (r int32, err error) { +func (p *printingHandler) TestI32(ctx context.Context, thing int32) (r int32, err error) { fmt.Printf("testI32(%d)\n", thing) return thing, nil } @@ -87,7 +91,7 @@ func (p *printingHandler) TestI32(thing int32) (r int32, err error) { // // Parameters: // - Thing -func (p *printingHandler) TestI64(thing int64) (r int64, err error) { +func (p *printingHandler) TestI64(ctx context.Context, thing int64) (r int64, err error) { fmt.Printf("testI64(%d)\n", thing) return thing, nil } @@ -98,7 +102,7 @@ func (p *printingHandler) TestI64(thing int64) (r int64, err error) { // // Parameters: // - Thing -func (p *printingHandler) TestDouble(thing float64) (r float64, err error) { +func (p *printingHandler) TestDouble(ctx context.Context, thing float64) (r float64, err error) { fmt.Printf("testDouble(%f)\n", thing) return thing, nil } @@ -109,7 +113,7 @@ func (p *printingHandler) TestDouble(thing float64) (r float64, err error) { // // Parameters: // - Thing -func (p *printingHandler) TestBinary(thing []byte) (r []byte, err error) { +func (p *printingHandler) TestBinary(ctx context.Context, thing []byte) (r []byte, err error) { fmt.Printf("testBinary(%s)\n", hex.EncodeToString(thing)) return thing, nil } @@ -120,7 +124,7 @@ func (p *printingHandler) TestBinary(thing []byte) (r []byte, err error) { // // Parameters: // - Thing -func (p *printingHandler) TestStruct(thing *Xtruct) (r *Xtruct, err error) { +func (p *printingHandler) TestStruct(ctx context.Context, 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 } @@ -131,7 +135,7 @@ func (p *printingHandler) TestStruct(thing *Xtruct) (r *Xtruct, err error) { // // Parameters: // - Thing -func (p *printingHandler) TestNest(nest *Xtruct2) (r *Xtruct2, err error) { +func (p *printingHandler) TestNest(ctx context.Context, 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 @@ -144,7 +148,7 @@ func (p *printingHandler) TestNest(nest *Xtruct2) (r *Xtruct2, err error) { // // Parameters: // - Thing -func (p *printingHandler) TestMap(thing map[int32]int32) (r map[int32]int32, err error) { +func (p *printingHandler) TestMap(ctx context.Context, thing map[int32]int32) (r map[int32]int32, err error) { fmt.Printf("testMap({") first := true for k, v := range thing { @@ -166,7 +170,7 @@ func (p *printingHandler) TestMap(thing map[int32]int32) (r map[int32]int32, err // // Parameters: // - Thing -func (p *printingHandler) TestStringMap(thing map[string]string) (r map[string]string, err error) { +func (p *printingHandler) TestStringMap(ctx context.Context, thing map[string]string) (r map[string]string, err error) { fmt.Printf("testStringMap({") first := true for k, v := range thing { @@ -188,7 +192,7 @@ func (p *printingHandler) TestStringMap(thing map[string]string) (r map[string]s // // Parameters: // - Thing -func (p *printingHandler) TestSet(thing []int32) (r []int32, err error) { +func (p *printingHandler) TestSet(ctx context.Context, thing []int32) (r []int32, err error) { fmt.Printf("testSet({") first := true for k, _ := range thing { @@ -210,7 +214,7 @@ func (p *printingHandler) TestSet(thing []int32) (r []int32, err error) { // // Parameters: // - Thing -func (p *printingHandler) TestList(thing []int32) (r []int32, err error) { +func (p *printingHandler) TestList(ctx context.Context, thing []int32) (r []int32, err error) { fmt.Printf("testList({") for i, v := range thing { if i != 0 { @@ -228,7 +232,7 @@ func (p *printingHandler) TestList(thing []int32) (r []int32, err error) { // // Parameters: // - Thing -func (p *printingHandler) TestEnum(thing Numberz) (r Numberz, err error) { +func (p *printingHandler) TestEnum(ctx context.Context, thing Numberz) (r Numberz, err error) { fmt.Printf("testEnum(%d)\n", thing) return thing, nil } @@ -239,7 +243,7 @@ func (p *printingHandler) TestEnum(thing Numberz) (r Numberz, err error) { // // Parameters: // - Thing -func (p *printingHandler) TestTypedef(thing UserId) (r UserId, err error) { +func (p *printingHandler) TestTypedef(ctx context.Context, thing UserId) (r UserId, err error) { fmt.Printf("testTypedef(%d)\n", thing) return thing, nil } @@ -251,7 +255,7 @@ func (p *printingHandler) TestTypedef(thing UserId) (r UserId, err error) { // // Parameters: // - Hello -func (p *printingHandler) TestMapMap(hello int32) (r map[int32]map[int32]int32, err error) { +func (p *printingHandler) TestMapMap(ctx context.Context, hello int32) (r map[int32]map[int32]int32, err error) { fmt.Printf("testMapMap(%d)\n", hello) r = map[int32]map[int32]int32{ @@ -273,7 +277,7 @@ func (p *printingHandler) TestMapMap(hello int32) (r map[int32]map[int32]int32, // // Parameters: // - Argument -func (p *printingHandler) TestInsanity(argument *Insanity) (r map[UserId]map[Numberz]*Insanity, err error) { +func (p *printingHandler) TestInsanity(ctx context.Context, 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 { @@ -303,7 +307,7 @@ func (p *printingHandler) TestInsanity(argument *Insanity) (r map[UserId]map[Num // - 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) { +func (p *printingHandler) TestMulti(ctx context.Context, arg0 int8, arg1 int32, arg2 int64, arg3 map[int16]string, arg4 Numberz, arg5 UserId) (r *Xtruct, err error) { fmt.Printf("testMulti()\n") r = NewXtruct() @@ -322,7 +326,7 @@ func (p *printingHandler) TestMulti(arg0 int8, arg1 int32, arg2 int64, arg3 map[ // // Parameters: // - Arg -func (p *printingHandler) TestException(arg string) (err error) { +func (p *printingHandler) TestException(ctx context.Context, arg string) (err error) { fmt.Printf("testException(%s)\n", arg) switch arg { case "Xception": @@ -346,7 +350,7 @@ func (p *printingHandler) TestException(arg string) (err error) { // Parameters: // - Arg0 // - Arg1 -func (p *printingHandler) TestMultiException(arg0 string, arg1 string) (r *Xtruct, err error) { +func (p *printingHandler) TestMultiException(ctx context.Context, arg0 string, arg1 string) (r *Xtruct, err error) { fmt.Printf("testMultiException(%s, %s)\n", arg0, arg1) switch arg0 { @@ -375,7 +379,7 @@ func (p *printingHandler) TestMultiException(arg0 string, arg1 string) (r *Xtruc // // Parameters: // - SecondsToSleep -func (p *printingHandler) TestOneway(secondsToSleep int32) (err error) { +func (p *printingHandler) TestOneway(ctx context.Context, 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) diff --git a/test/go/src/common/printing_handler_go17.go b/test/go/src/common/printing_handler_go17.go new file mode 100644 index 000000000..1efae8676 --- /dev/null +++ b/test/go/src/common/printing_handler_go17.go @@ -0,0 +1,386 @@ +// +build go1.7 + +/* + * 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 ( + "context" + "errors" + "fmt" + "encoding/hex" + . "gen/thrifttest" + "time" +) + +var PrintingHandler = &printingHandler{} + +type printingHandler struct{} + +// Prints "testVoid()" and returns nothing. +func (p *printingHandler) TestVoid(ctx context.Context) (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(ctx context.Context, 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(ctx context.Context, 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(ctx context.Context, 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(ctx context.Context, 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(ctx context.Context, 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(ctx context.Context, 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(ctx context.Context, 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(ctx context.Context, 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(ctx context.Context, 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(ctx context.Context, 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(ctx context.Context, 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(ctx context.Context, thing []int32) (r []int32, 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(ctx context.Context, 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(ctx context.Context, 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(ctx context.Context, 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(ctx context.Context, 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(ctx context.Context, 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(ctx context.Context, 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(ctx context.Context, 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(ctx context.Context, 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(ctx context.Context, 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 +} |