summaryrefslogtreecommitdiff
path: root/test/go
diff options
context:
space:
mode:
authorD. Can Celasun <can@dcc.im>2017-09-21 15:21:00 +0200
committerJames E. King, III <jking@apache.org>2017-11-03 18:21:40 -0700
commit4f77ab8e296d64c57e6ea1c6e3f0f152bc7d6a3a (patch)
treec3acd180d98bcfdb76c40dc5b6177e16bfc13719 /test/go
parent847ecf3c1de8b297d6a29305b9f7871fcf609c36 (diff)
downloadthrift-4f77ab8e296d64c57e6ea1c6e3f0f152bc7d6a3a.tar.gz
THRIFT-4285 Move TX/RX methods from gen. code to library
This change removes a lot of duplication from generated code and allows the caller to customize how they can read from / write to the transport. Backwards compatible adapters make the change compatible with existing code in use by consuming applications. Client: Go This closes #1382
Diffstat (limited to 'test/go')
-rw-r--r--test/go/Makefile.am2
-rw-r--r--test/go/src/bin/testclient/main.go32
-rw-r--r--test/go/src/common/client.go27
-rw-r--r--test/go/src/common/clientserver_test.go33
4 files changed, 50 insertions, 44 deletions
diff --git a/test/go/Makefile.am b/test/go/Makefile.am
index db2725875..6bc97f582 100644
--- a/test/go/Makefile.am
+++ b/test/go/Makefile.am
@@ -30,6 +30,8 @@ precross: bin/testclient bin/testserver
ThriftTest.thrift: $(THRIFTTEST)
grep -v list.*map.*list.*map $(THRIFTTEST) > ThriftTest.thrift
+.PHONY: gopath
+
# Thrift for GO has problems with complex map keys: THRIFT-2063
gopath: $(THRIFT) ThriftTest.thrift
mkdir -p src/gen
diff --git a/test/go/src/bin/testclient/main.go b/test/go/src/bin/testclient/main.go
index b34c53927..ab24cbfc7 100644
--- a/test/go/src/bin/testclient/main.go
+++ b/test/go/src/bin/testclient/main.go
@@ -38,7 +38,7 @@ var testloops = flag.Int("testloops", 1, "Number of Tests")
func main() {
flag.Parse()
- client, err := common.StartClient(*host, *port, *domain_socket, *transport, *protocol, *ssl)
+ client, _, err := common.StartClient(*host, *port, *domain_socket, *transport, *protocol, *ssl)
if err != nil {
t.Fatalf("Unable to start client: ", err)
}
@@ -128,7 +128,7 @@ func callEverything(client *thrifttest.ThriftTestClient) {
}
bin, err := client.TestBinary(defaultCtx, binout)
for i := 0; i < 256; i++ {
- if (binout[i] != bin[i]) {
+ if binout[i] != bin[i] {
t.Fatalf("Unexpected TestBinary() result expected %d, got %d ", binout[i], bin[i])
}
}
@@ -224,21 +224,21 @@ func callEverything(client *thrifttest.ThriftTestClient) {
}
crazy := thrifttest.NewInsanity()
- crazy.UserMap = map[thrifttest.Numberz]thrifttest.UserId {
- thrifttest.Numberz_FIVE: 5,
+ crazy.UserMap = map[thrifttest.Numberz]thrifttest.UserId{
+ thrifttest.Numberz_FIVE: 5,
thrifttest.Numberz_EIGHT: 8,
}
truck1 := thrifttest.NewXtruct()
truck1.StringThing = "Goodbye4"
- truck1.ByteThing = 4;
- truck1.I32Thing = 4;
- truck1.I64Thing = 4;
+ truck1.ByteThing = 4
+ truck1.I32Thing = 4
+ truck1.I64Thing = 4
truck2 := thrifttest.NewXtruct()
truck2.StringThing = "Hello2"
- truck2.ByteThing = 2;
- truck2.I32Thing = 2;
- truck2.I64Thing = 2;
- crazy.Xtructs = []*thrifttest.Xtruct {
+ truck2.ByteThing = 2
+ truck2.I32Thing = 2
+ truck2.I64Thing = 2
+ crazy.Xtructs = []*thrifttest.Xtruct{
truck1,
truck2,
}
@@ -248,17 +248,17 @@ func callEverything(client *thrifttest.ThriftTestClient) {
}
if !reflect.DeepEqual(crazy, insanity[1][2]) {
t.Fatalf("Unexpected TestInsanity() first result expected %#v, got %#v ",
- crazy,
- insanity[1][2])
+ crazy,
+ insanity[1][2])
}
if !reflect.DeepEqual(crazy, insanity[1][3]) {
t.Fatalf("Unexpected TestInsanity() second result expected %#v, got %#v ",
- crazy,
- insanity[1][3])
+ crazy,
+ insanity[1][3])
}
if len(insanity[2][6].UserMap) > 0 || len(insanity[2][6].Xtructs) > 0 {
t.Fatalf("Unexpected TestInsanity() non-empty result got %#v ",
- insanity[2][6])
+ insanity[2][6])
}
xxsret, err := client.TestMulti(defaultCtx, 42, 4242, 424242, map[int16]string{1: "blah", 2: "thing"}, thrifttest.Numberz_EIGHT, thrifttest.UserId(24))
diff --git a/test/go/src/common/client.go b/test/go/src/common/client.go
index 4251d910d..236ce43ea 100644
--- a/test/go/src/common/client.go
+++ b/test/go/src/common/client.go
@@ -41,7 +41,7 @@ func StartClient(
domain_socket string,
transport string,
protocol string,
- ssl bool) (client *thrifttest.ThriftTestClient, err error) {
+ ssl bool) (client *thrifttest.ThriftTestClient, trans thrift.TTransport, err error) {
hostPort := fmt.Sprintf("%s:%d", host, port)
@@ -56,12 +56,11 @@ func StartClient(
case "binary":
protocolFactory = thrift.NewTBinaryProtocolFactoryDefault()
default:
- return nil, fmt.Errorf("Invalid protocol specified %s", protocol)
+ return nil, 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 {
@@ -72,7 +71,7 @@ func StartClient(
}
}
if err != nil {
- return nil, err
+ return nil, nil, err
}
switch transport {
case "http":
@@ -86,29 +85,25 @@ func StartClient(
} 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)
+ return nil, nil, fmt.Errorf("Invalid transport specified %s", transport)
+ }
+ if err != nil {
+ return nil, nil, err
}
-
if err = trans.Open(); err != nil {
- return nil, err
+ return nil, nil, err
}
- client = thrifttest.NewThriftTestClientFactory(trans, protocolFactory)
+ iprot := protocolFactory.GetProtocol(trans)
+ oprot := protocolFactory.GetProtocol(trans)
+ client = thrifttest.NewThriftTestClient(thrift.NewTStandardClient(iprot, oprot))
return
}
diff --git a/test/go/src/common/clientserver_test.go b/test/go/src/common/clientserver_test.go
index ecd021f3b..c4cfd44f3 100644
--- a/test/go/src/common/clientserver_test.go
+++ b/test/go/src/common/clientserver_test.go
@@ -23,6 +23,7 @@ import (
"errors"
"gen/thrifttest"
"reflect"
+ "sync"
"testing"
"thrift"
@@ -47,10 +48,15 @@ var units = []test_unit{
func TestAllConnection(t *testing.T) {
certPath = "../../../keys"
+ wg := &sync.WaitGroup{}
+ wg.Add(len(units))
for _, unit := range units {
- t.Logf("%#v", unit)
- doUnit(t, &unit)
+ go func(u test_unit) {
+ defer wg.Done()
+ doUnit(t, &u)
+ }(unit)
}
+ wg.Wait()
}
func doUnit(t *testing.T, unit *test_unit) {
@@ -62,17 +68,17 @@ func doUnit(t *testing.T, unit *test_unit) {
server := thrift.NewTSimpleServer4(processor, serverTransport, transportFactory, protocolFactory)
if err = server.Listen(); err != nil {
- t.Errorf("Unable to start server", err)
- t.FailNow()
+ t.Errorf("Unable to start server: %v", err)
+ return
}
go server.AcceptLoop()
defer server.Stop()
- client, err := StartClient(unit.host, unit.port, unit.domain_socket, unit.transport, unit.protocol, unit.ssl)
+ client, trans, 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()
+ t.Errorf("Unable to start client: %v", err)
+ return
}
- defer client.Transport.Close()
+ defer trans.Close()
callEverythingWithMock(t, client, handler)
}
@@ -273,7 +279,7 @@ func callEverythingWithMock(t *testing.T, client *thrifttest.ThriftTestClient, h
xxsret, err := client.TestMulti(defaultCtx, 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)
+ t.Errorf("Unexpected error in TestMulti() call: %v", err)
}
if !reflect.DeepEqual(xxs, xxsret) {
t.Errorf("Unexpected TestMulti() result expected %#v, got %#v ", xxs, xxsret)
@@ -289,9 +295,12 @@ func callEverythingWithMock(t *testing.T, client *thrifttest.ThriftTestClient, h
// TODO: connection is being closed on this
err = client.TestException(defaultCtx, "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)
+ if err == nil {
+ t.Error("expected exception got nil")
+ } else if tex, ok := err.(thrift.TApplicationException); !ok {
+ t.Errorf("Unexpected TestException() result expected ApplicationError, got %T ", err)
+ } else if tex.TypeId() != thrift.INTERNAL_ERROR {
+ t.Errorf("expected internal_error got %v", tex.TypeId())
}
ign, err := client.TestMultiException(defaultCtx, "Xception", "ignoreme")