THRIFT-4448: Golang: do something with context.Context. Remove Go1.6 compatibility.
Client: go
This closes #1459
diff --git a/lib/go/test/tests/client_error_test.go b/lib/go/test/tests/client_error_test.go
index 5dec472..fdec4ea 100644
--- a/lib/go/test/tests/client_error_test.go
+++ b/lib/go/test/tests/client_error_test.go
@@ -20,6 +20,7 @@
package tests
import (
+ "context"
"errors"
"errortest"
"testing"
@@ -212,7 +213,7 @@
if failAt == 25 {
err = failWith
}
- last = protocol.EXPECT().Flush().Return(err).After(last)
+ last = protocol.EXPECT().Flush(context.Background()).Return(err).After(last)
if failAt == 25 {
return true
}
@@ -536,7 +537,7 @@
last = protocol.EXPECT().WriteFieldStop().After(last)
last = protocol.EXPECT().WriteStructEnd().After(last)
last = protocol.EXPECT().WriteMessageEnd().After(last)
- last = protocol.EXPECT().Flush().After(last)
+ last = protocol.EXPECT().Flush(context.Background()).After(last)
// Reading the exception, might fail.
if failAt == 0 {
@@ -704,7 +705,7 @@
protocol.EXPECT().WriteFieldStop(),
protocol.EXPECT().WriteStructEnd(),
protocol.EXPECT().WriteMessageEnd(),
- protocol.EXPECT().Flush(),
+ protocol.EXPECT().Flush(context.Background()),
protocol.EXPECT().ReadMessageBegin().Return("testString", thrift.REPLY, int32(2), nil),
)
@@ -735,7 +736,7 @@
protocol.EXPECT().WriteFieldStop(),
protocol.EXPECT().WriteStructEnd(),
protocol.EXPECT().WriteMessageEnd(),
- protocol.EXPECT().Flush(),
+ protocol.EXPECT().Flush(context.Background()),
protocol.EXPECT().ReadMessageBegin().Return("testString", thrift.REPLY, int32(2), nil),
)
@@ -764,7 +765,7 @@
protocol.EXPECT().WriteFieldStop(),
protocol.EXPECT().WriteStructEnd(),
protocol.EXPECT().WriteMessageEnd(),
- protocol.EXPECT().Flush(),
+ protocol.EXPECT().Flush(context.Background()),
protocol.EXPECT().ReadMessageBegin().Return("unknown", thrift.REPLY, int32(1), nil),
)
@@ -795,7 +796,7 @@
protocol.EXPECT().WriteFieldStop(),
protocol.EXPECT().WriteStructEnd(),
protocol.EXPECT().WriteMessageEnd(),
- protocol.EXPECT().Flush(),
+ protocol.EXPECT().Flush(context.Background()),
protocol.EXPECT().ReadMessageBegin().Return("unknown", thrift.REPLY, int32(1), nil),
)
@@ -824,7 +825,7 @@
protocol.EXPECT().WriteFieldStop(),
protocol.EXPECT().WriteStructEnd(),
protocol.EXPECT().WriteMessageEnd(),
- protocol.EXPECT().Flush(),
+ protocol.EXPECT().Flush(context.Background()),
protocol.EXPECT().ReadMessageBegin().Return("testString", thrift.INVALID_TMESSAGE_TYPE, int32(1), nil),
)
@@ -855,7 +856,7 @@
protocol.EXPECT().WriteFieldStop(),
protocol.EXPECT().WriteStructEnd(),
protocol.EXPECT().WriteMessageEnd(),
- protocol.EXPECT().Flush(),
+ protocol.EXPECT().Flush(context.Background()),
protocol.EXPECT().ReadMessageBegin().Return("testString", thrift.INVALID_TMESSAGE_TYPE, int32(1), nil),
)
diff --git a/lib/go/test/tests/go17.go b/lib/go/test/tests/context.go
similarity index 60%
rename from lib/go/test/tests/go17.go
rename to lib/go/test/tests/context.go
index dc3c9d5..a93a82b 100644
--- a/lib/go/test/tests/go17.go
+++ b/lib/go/test/tests/context.go
@@ -1,5 +1,3 @@
-// +build go1.7
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -23,25 +21,6 @@
import (
"context"
- "fmt"
)
var defaultCtx = context.Background()
-
-type FirstImpl struct{}
-
-func (f *FirstImpl) ReturnOne(ctx context.Context) (r int64, err error) {
- return 1, nil
-}
-
-type SecondImpl struct{}
-
-func (s *SecondImpl) ReturnTwo(ctx context.Context) (r int64, err error) {
- return 2, nil
-}
-
-type impl struct{}
-
-func (i *impl) Hi(ctx context.Context, in int64, s string) (err error) { fmt.Println("Hi!"); return }
-func (i *impl) Emptyfunc(ctx context.Context) (err error) { return }
-func (i *impl) EchoInt(ctx context.Context, param int64) (r int64, err error) { return param, nil }
diff --git a/lib/go/test/tests/multiplexed_protocol_test.go b/lib/go/test/tests/multiplexed_protocol_test.go
index 0b5896b..61ac628 100644
--- a/lib/go/test/tests/multiplexed_protocol_test.go
+++ b/lib/go/test/tests/multiplexed_protocol_test.go
@@ -20,6 +20,7 @@
package tests
import (
+ "context"
"multiplexedprotocoltest"
"net"
"testing"
@@ -36,6 +37,18 @@
}
}
+type FirstImpl struct{}
+
+func (f *FirstImpl) ReturnOne(ctx context.Context) (r int64, err error) {
+ return 1, nil
+}
+
+type SecondImpl struct{}
+
+func (s *SecondImpl) ReturnTwo(ctx context.Context) (r int64, err error) {
+ return 2, nil
+}
+
func createTransport(addr net.Addr) (thrift.TTransport, error) {
socket := thrift.NewTSocketFromAddrTimeout(addr, TIMEOUT)
transport := thrift.NewTFramedTransport(socket)
diff --git a/lib/go/test/tests/one_way_test.go b/lib/go/test/tests/one_way_test.go
index 8abd671..48d0bbe 100644
--- a/lib/go/test/tests/one_way_test.go
+++ b/lib/go/test/tests/one_way_test.go
@@ -20,6 +20,8 @@
package tests
import (
+ "context"
+ "fmt"
"net"
"onewaytest"
"testing"
@@ -36,6 +38,12 @@
}
}
+type impl struct{}
+
+func (i *impl) Hi(ctx context.Context, in int64, s string) (err error) { fmt.Println("Hi!"); return }
+func (i *impl) Emptyfunc(ctx context.Context) (err error) { return }
+func (i *impl) EchoInt(ctx context.Context, param int64) (r int64, err error) { return param, nil }
+
const TIMEOUT = time.Second
var addr net.Addr
diff --git a/lib/go/test/tests/pre_go17.go b/lib/go/test/tests/pre_go17.go
deleted file mode 100644
index 8ab4331..0000000
--- a/lib/go/test/tests/pre_go17.go
+++ /dev/null
@@ -1,48 +0,0 @@
-// +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 tests
-
-import (
- "fmt"
-
- "golang.org/x/net/context"
-)
-
-var defaultCtx = context.Background()
-
-type FirstImpl struct{}
-
-func (f *FirstImpl) ReturnOne(ctx context.Context) (r int64, err error) {
- return 1, nil
-}
-
-type SecondImpl struct{}
-
-func (s *SecondImpl) ReturnTwo(ctx context.Context) (r int64, err error) {
- return 2, nil
-}
-
-type impl struct{}
-
-func (i *impl) Hi(ctx context.Context, in int64, s string) (err error) { fmt.Println("Hi!"); return }
-func (i *impl) Emptyfunc(ctx context.Context) (err error) { return }
-func (i *impl) EchoInt(ctx context.Context, param int64) (r int64, err error) { return param, nil }
diff --git a/lib/go/test/tests/protocol_mock.go b/lib/go/test/tests/protocol_mock.go
index 8476c86..51d7a02 100644
--- a/lib/go/test/tests/protocol_mock.go
+++ b/lib/go/test/tests/protocol_mock.go
@@ -23,6 +23,7 @@
package tests
import (
+ "context"
thrift "thrift"
gomock "github.com/golang/mock/gomock"
@@ -49,13 +50,13 @@
return _m.recorder
}
-func (_m *MockTProtocol) Flush() error {
+func (_m *MockTProtocol) Flush(ctx context.Context) error {
ret := _m.ctrl.Call(_m, "Flush")
ret0, _ := ret[0].(error)
return ret0
}
-func (_mr *_MockTProtocolRecorder) Flush() *gomock.Call {
+func (_mr *_MockTProtocolRecorder) Flush(ctx context.Context) *gomock.Call {
return _mr.mock.ctrl.RecordCall(_mr.mock, "Flush")
}
diff --git a/lib/go/test/tests/thrifttest_handler.go b/lib/go/test/tests/thrifttest_handler.go
index 6542fac..31b9ee2 100644
--- a/lib/go/test/tests/thrifttest_handler.go
+++ b/lib/go/test/tests/thrifttest_handler.go
@@ -1,5 +1,3 @@
-// +build !go1.7
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -22,12 +20,11 @@
package tests
import (
+ "context"
"errors"
"thrift"
"thrifttest"
"time"
-
- "golang.org/x/net/context"
)
type SecondServiceHandler struct {
diff --git a/lib/go/test/tests/thrifttest_handler_go17.go b/lib/go/test/tests/thrifttest_handler_go17.go
deleted file mode 100644
index e022a3d..0000000
--- a/lib/go/test/tests/thrifttest_handler_go17.go
+++ /dev/null
@@ -1,212 +0,0 @@
-// +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 tests
-
-import (
- "context"
- "errors"
- "thrift"
- "thrifttest"
- "time"
-)
-
-type SecondServiceHandler struct {
-}
-
-func NewSecondServiceHandler() *SecondServiceHandler {
- return &SecondServiceHandler{}
-}
-
-func (p *SecondServiceHandler) BlahBlah(ctx context.Context) (err error) {
- return nil
-}
-
-func (p *SecondServiceHandler) SecondtestString(ctx context.Context, thing string) (r string, err error) {
- return thing, nil
-}
-
-type ThriftTestHandler struct {
-}
-
-func NewThriftTestHandler() *ThriftTestHandler {
- return &ThriftTestHandler{}
-}
-
-func (p *ThriftTestHandler) TestVoid(ctx context.Context) (err error) {
- return nil
-}
-
-func (p *ThriftTestHandler) TestString(ctx context.Context, thing string) (r string, err error) {
- return thing, nil
-}
-
-func (p *ThriftTestHandler) TestBool(ctx context.Context, thing bool) (r bool, err error) {
- return thing, nil
-}
-
-func (p *ThriftTestHandler) TestByte(ctx context.Context, thing int8) (r int8, err error) {
- return thing, nil
-}
-
-func (p *ThriftTestHandler) TestI32(ctx context.Context, thing int32) (r int32, err error) {
- return thing, nil
-}
-
-func (p *ThriftTestHandler) TestI64(ctx context.Context, thing int64) (r int64, err error) {
- return thing, nil
-}
-
-func (p *ThriftTestHandler) TestDouble(ctx context.Context, thing float64) (r float64, err error) {
- return thing, nil
-}
-
-func (p *ThriftTestHandler) TestBinary(ctx context.Context, thing []byte) (r []byte, err error) {
- return thing, nil
-}
-
-func (p *ThriftTestHandler) TestStruct(ctx context.Context, thing *thrifttest.Xtruct) (r *thrifttest.Xtruct, err error) {
- return thing, nil
-}
-
-func (p *ThriftTestHandler) TestNest(ctx context.Context, thing *thrifttest.Xtruct2) (r *thrifttest.Xtruct2, err error) {
- return thing, nil
-}
-
-func (p *ThriftTestHandler) TestMap(ctx context.Context, thing map[int32]int32) (r map[int32]int32, err error) {
- return thing, nil
-}
-
-func (p *ThriftTestHandler) TestStringMap(ctx context.Context, thing map[string]string) (r map[string]string, err error) {
- return thing, nil
-}
-
-func (p *ThriftTestHandler) TestSet(ctx context.Context, thing []int32) (r []int32, err error) {
- return thing, nil
-}
-
-func (p *ThriftTestHandler) TestList(ctx context.Context, thing []int32) (r []int32, err error) {
- return thing, nil
-}
-
-func (p *ThriftTestHandler) TestEnum(ctx context.Context, thing thrifttest.Numberz) (r thrifttest.Numberz, err error) {
- return thing, nil
-}
-
-func (p *ThriftTestHandler) TestTypedef(ctx context.Context, thing thrifttest.UserId) (r thrifttest.UserId, err error) {
- return thing, nil
-}
-
-func (p *ThriftTestHandler) TestMapMap(ctx context.Context, hello int32) (r map[int32]map[int32]int32, err error) {
- r = make(map[int32]map[int32]int32)
- pos := make(map[int32]int32)
- neg := make(map[int32]int32)
-
- for i := int32(1); i < 5; i++ {
- pos[i] = i
- neg[-i] = -i
- }
- r[4] = pos
- r[-4] = neg
-
- return r, nil
-}
-
-func (p *ThriftTestHandler) TestInsanity(ctx context.Context, argument *thrifttest.Insanity) (r map[thrifttest.UserId]map[thrifttest.Numberz]*thrifttest.Insanity, err error) {
- hello := thrifttest.NewXtruct()
- hello.StringThing = "Hello2"
- hello.ByteThing = 2
- hello.I32Thing = 2
- hello.I64Thing = 2
-
- goodbye := thrifttest.NewXtruct()
- goodbye.StringThing = "Goodbye4"
- goodbye.ByteThing = 4
- goodbye.I32Thing = 4
- goodbye.I64Thing = 4
-
- crazy := thrifttest.NewInsanity()
- crazy.UserMap = make(map[thrifttest.Numberz]thrifttest.UserId)
- crazy.UserMap[thrifttest.Numberz_EIGHT] = 8
- crazy.UserMap[thrifttest.Numberz_FIVE] = 5
- crazy.Xtructs = []*thrifttest.Xtruct{goodbye, hello}
-
- first_map := make(map[thrifttest.Numberz]*thrifttest.Insanity)
- second_map := make(map[thrifttest.Numberz]*thrifttest.Insanity)
-
- first_map[thrifttest.Numberz_TWO] = crazy
- first_map[thrifttest.Numberz_THREE] = crazy
-
- looney := thrifttest.NewInsanity()
- second_map[thrifttest.Numberz_SIX] = looney
-
- var insane = make(map[thrifttest.UserId]map[thrifttest.Numberz]*thrifttest.Insanity)
- insane[1] = first_map
- insane[2] = second_map
-
- return insane, nil
-}
-
-func (p *ThriftTestHandler) TestMulti(ctx context.Context, arg0 int8, arg1 int32, arg2 int64, arg3 map[int16]string, arg4 thrifttest.Numberz, arg5 thrifttest.UserId) (r *thrifttest.Xtruct, err error) {
- r = thrifttest.NewXtruct()
- r.StringThing = "Hello2"
- r.ByteThing = arg0
- r.I32Thing = arg1
- r.I64Thing = arg2
- return r, nil
-}
-
-func (p *ThriftTestHandler) TestException(ctx context.Context, arg string) (err error) {
- if arg == "Xception" {
- x := thrifttest.NewXception()
- x.ErrorCode = 1001
- x.Message = arg
- return x
- } else if arg == "TException" {
- return thrift.TException(errors.New(arg))
- } else {
- return nil
- }
-}
-
-func (p *ThriftTestHandler) TestMultiException(ctx context.Context, arg0 string, arg1 string) (r *thrifttest.Xtruct, err error) {
- if arg0 == "Xception" {
- x := thrifttest.NewXception()
- x.ErrorCode = 1001
- x.Message = "This is an Xception"
- return nil, x
- } else if arg0 == "Xception2" {
- x2 := thrifttest.NewXception2()
- x2.ErrorCode = 2002
- x2.StructThing = thrifttest.NewXtruct()
- x2.StructThing.StringThing = "This is an Xception2"
- return nil, x2
- }
-
- res := thrifttest.NewXtruct()
- res.StringThing = arg1
- return res, nil
-}
-
-func (p *ThriftTestHandler) TestOneway(ctx context.Context, secondsToSleep int32) (err error) {
- time.Sleep(time.Second * time.Duration(secondsToSleep))
- return nil
-}