diff --git a/thrift/lib/go/thrift/client_test.go b/thrift/lib/go/thrift/client_test.go index 08d588e34fb..e3d1ed54896 100644 --- a/thrift/lib/go/thrift/client_test.go +++ b/thrift/lib/go/thrift/client_test.go @@ -26,6 +26,7 @@ import ( "testing" "time" + "github.com/facebook/fbthrift/thrift/lib/go/thrift/dummy" "github.com/facebook/fbthrift/thrift/lib/go/thrift/types" ) @@ -34,7 +35,8 @@ func TestClient(t *testing.T) { if err != nil { t.Fatalf("failed to listen: %v", err) } - server := NewServer(&testProcessor{}, listener, TransportIDRocket) + processor := dummy.NewDummyProcessor(&dummy.DummyHandler{}) + server := NewServer(processor, listener, TransportIDRocket) serverCtx, cancel := context.WithCancel(context.Background()) defer cancel() go func() { diff --git a/thrift/lib/go/thrift/header_simple_server_test.go b/thrift/lib/go/thrift/header_simple_server_test.go index 8441063660c..81aa46a5cd3 100644 --- a/thrift/lib/go/thrift/header_simple_server_test.go +++ b/thrift/lib/go/thrift/header_simple_server_test.go @@ -22,34 +22,9 @@ import ( "testing" "time" - "github.com/facebook/fbthrift/thrift/lib/go/thrift/types" - "github.com/facebook/fbthrift/thrift/lib/thrift/metadata" + "github.com/facebook/fbthrift/thrift/lib/go/thrift/dummy" ) -type headerServerTestProcessor struct { - requests chan<- *MyTestStruct -} - -func (t *headerServerTestProcessor) ProcessorFunctionMap() map[string]types.ProcessorFunction { - return map[string]types.ProcessorFunction{"test": &headerServerTestProcessorFunction{&testProcessorFunction{}, t.requests}} -} - -func (t *headerServerTestProcessor) GetThriftMetadata() *metadata.ThriftMetadata { - return nil -} - -type headerServerTestProcessorFunction struct { - types.ProcessorFunction - requests chan<- *MyTestStruct -} - -func (p *headerServerTestProcessorFunction) RunContext(ctx context.Context, reqStruct types.Struct) (types.WritableStruct, types.ApplicationException) { - if p.requests != nil { - p.requests <- reqStruct.(*MyTestStruct) - } - return reqStruct, nil -} - // Test that header server stops serving if listener is closed. func TestHeaderServerCloseListener(t *testing.T) { ctx, cancel := context.WithCancel(context.Background()) @@ -60,7 +35,8 @@ func TestHeaderServerCloseListener(t *testing.T) { if err != nil { t.Fatalf("failed to listen: %v", err) } - server := NewSimpleServer(&headerServerTestProcessor{}, listener, TransportIDHeader) + processor := dummy.NewDummyProcessor(&dummy.DummyHandler{}) + server := NewSimpleServer(processor, listener, TransportIDHeader) go func() { errChan <- server.ServeContext(ctx) }() @@ -73,16 +49,14 @@ func TestHeaderServerCloseListener(t *testing.T) { if err != nil { t.Fatalf("could not create client protocol: %s", err) } - client := NewSerialChannel(proto) - req := &MyTestStruct{ - St: "hello", - } - resp := &MyTestStruct{} - if err := client.Call(context.Background(), "test", req, resp); err != nil { + client := dummy.NewDummyChannelClient(NewSerialChannel(proto)) + defer client.Close() + result, err := client.Echo(context.TODO(), "hello") + if err != nil { t.Fatalf("could not complete call: %v", err) } - if resp.St != "hello" { - t.Fatalf("expected response to be a hello, got %s", resp.St) + if result != "hello" { + t.Fatalf("expected response to be a hello, got %s", result) } listener.Close() select { diff --git a/thrift/lib/go/thrift/rocket_client_test.go b/thrift/lib/go/thrift/rocket_client_test.go index b87c3a9b48b..9560747c7dd 100644 --- a/thrift/lib/go/thrift/rocket_client_test.go +++ b/thrift/lib/go/thrift/rocket_client_test.go @@ -17,12 +17,12 @@ package thrift import ( - "bytes" "context" "net" "testing" "time" + "github.com/facebook/fbthrift/thrift/lib/go/thrift/dummy" "github.com/facebook/fbthrift/thrift/lib/go/thrift/types" ) @@ -44,7 +44,8 @@ func TestRocketClientClose(t *testing.T) { if err != nil { t.Fatalf("failed to listen: %v", err) } - server := NewSimpleServer(&rocketServerTestProcessor{}, listener, TransportIDRocket) + processor := dummy.NewDummyProcessor(&dummy.DummyHandler{}) + server := NewSimpleServer(processor, listener, TransportIDRocket) go func() { errChan <- server.ServeContext(ctx) }() @@ -58,19 +59,13 @@ func TestRocketClientClose(t *testing.T) { if err != nil { t.Fatalf("could not create client protocol: %s", err) } - client := NewSerialChannel(proto) - req := &MyTestStruct{ - St: "hello", - } - resp := &MyTestStruct{} - if err := client.Call(context.Background(), "test", req, resp); err != nil { + client := dummy.NewDummyChannelClient(NewSerialChannel(proto)) + result, err := client.Echo(context.TODO(), "hello") + if err != nil { t.Fatalf("could not complete call: %v", err) } - if resp.St != "hello" { - t.Fatalf("expected response to be a hello, got %s", resp.St) - } - if !bytes.Equal(resp.GetBin(), []byte(conn.LocalAddr().String())) { - t.Fatalf("expected response to be an address %s, got %s", conn.LocalAddr().String(), resp.GetBin()) + if result != "hello" { + t.Fatalf("expected response to be a hello, got %s", result) } go client.Close() select { @@ -90,7 +85,8 @@ func TestRocketClientUnix(t *testing.T) { if err != nil { t.Fatalf("failed to listen: %v", err) } - server := NewSimpleServer(&rocketServerTestProcessor{}, listener, TransportIDRocket) + processor := dummy.NewDummyProcessor(&dummy.DummyHandler{}) + server := NewSimpleServer(processor, listener, TransportIDRocket) go func() { errChan <- server.ServeContext(ctx) }() @@ -103,19 +99,14 @@ func TestRocketClientUnix(t *testing.T) { if err != nil { t.Fatalf("could not create client protocol: %s", err) } - client := NewSerialChannel(proto) - req := &MyTestStruct{ - St: "hello", - } - resp := &MyTestStruct{} - if err := client.Call(context.Background(), "test", req, resp); err != nil { + client := dummy.NewDummyChannelClient(NewSerialChannel(proto)) + defer client.Close() + result, err := client.Echo(context.TODO(), "hello") + if err != nil { t.Fatalf("could not complete call: %v", err) } - if resp.St != "hello" { - t.Fatalf("expected response to be a hello, got %s", resp.St) - } - if !bytes.Equal(resp.GetBin(), []byte(conn.LocalAddr().String())) { - t.Fatalf("expected response to be an address %s, got %s", conn.LocalAddr().String(), resp.GetBin()) + if result != "hello" { + t.Fatalf("expected response to be a hello, got %s", result) } cancel() <-errChan diff --git a/thrift/lib/go/thrift/rocket_simple_server_test.go b/thrift/lib/go/thrift/rocket_simple_server_test.go index 22c72f59ede..59068c75987 100644 --- a/thrift/lib/go/thrift/rocket_simple_server_test.go +++ b/thrift/lib/go/thrift/rocket_simple_server_test.go @@ -17,44 +17,15 @@ package thrift import ( - "bytes" "context" "net" "testing" "time" + "github.com/facebook/fbthrift/thrift/lib/go/thrift/dummy" "github.com/facebook/fbthrift/thrift/lib/go/thrift/types" - "github.com/facebook/fbthrift/thrift/lib/thrift/metadata" ) -type rocketServerTestProcessor struct { - requests chan<- *MyTestStruct -} - -func (t *rocketServerTestProcessor) ProcessorFunctionMap() map[string]types.ProcessorFunction { - return map[string]types.ProcessorFunction{"test": &rocketServerTestProcessorFunction{&testProcessorFunction{}, t.requests}} -} - -func (t *rocketServerTestProcessor) GetThriftMetadata() *metadata.ThriftMetadata { - return nil -} - -type rocketServerTestProcessorFunction struct { - types.ProcessorFunction - requests chan<- *MyTestStruct -} - -func (p *rocketServerTestProcessorFunction) RunContext(ctx context.Context, reqStruct types.Struct) (types.WritableStruct, types.ApplicationException) { - v, ok := ConnInfoFromContext(ctx) - if ok { - reqStruct.(*MyTestStruct).Bin = []byte(v.RemoteAddr.String()) - } - if p.requests != nil { - p.requests <- reqStruct.(*MyTestStruct) - } - return reqStruct, nil -} - // Make sure that ConnInfo is added to the context of a rocket server. func TestRocketServerConnInfo(t *testing.T) { ctx, cancel := context.WithCancel(context.Background()) @@ -65,7 +36,8 @@ func TestRocketServerConnInfo(t *testing.T) { if err != nil { t.Fatalf("failed to listen: %v", err) } - server := NewSimpleServer(&rocketServerTestProcessor{}, listener, TransportIDRocket) + processor := dummy.NewDummyProcessor(&dummy.DummyHandler{}) + server := NewSimpleServer(processor, listener, TransportIDRocket) go func() { errChan <- server.ServeContext(ctx) }() @@ -78,19 +50,14 @@ func TestRocketServerConnInfo(t *testing.T) { if err != nil { t.Fatalf("could not create client protocol: %s", err) } - client := NewSerialChannel(proto) - req := &MyTestStruct{ - St: "hello", - } - resp := &MyTestStruct{} - if err := client.Call(context.Background(), "test", req, resp); err != nil { + client := dummy.NewDummyChannelClient(NewSerialChannel(proto)) + defer client.Close() + result, err := client.Echo(context.TODO(), "hello") + if err != nil { t.Fatalf("could not complete call: %v", err) } - if resp.St != "hello" { - t.Fatalf("expected response to be a hello, got %s", resp.St) - } - if !bytes.Equal(resp.GetBin(), []byte(conn.LocalAddr().String())) { - t.Fatalf("expected response to be an address %s, got %s", conn.LocalAddr().String(), resp.GetBin()) + if result != "hello" { + t.Fatalf("expected response to be a hello, got %s", result) } cancel() <-errChan @@ -106,8 +73,9 @@ func TestRocketServerOneWay(t *testing.T) { if err != nil { t.Fatalf("failed to listen: %v", err) } - received := make(chan *MyTestStruct) - server := NewSimpleServer(&rocketServerTestProcessor{received}, listener, TransportIDRocket) + received := make(chan string) + processor := dummy.NewDummyProcessor(&dummy.DummyHandler{OnewayRPCRequests: received}) + server := NewSimpleServer(processor, listener, TransportIDRocket) go func() { errChan <- server.ServeContext(ctx) }() @@ -120,11 +88,10 @@ func TestRocketServerOneWay(t *testing.T) { if err != nil { t.Fatalf("could not create client protocol: %s", err) } - client := NewSerialChannel(proto) - req := &MyTestStruct{ - St: "hello", - } - if err := client.Oneway(context.Background(), "test", req); err != nil { + client := dummy.NewDummyChannelClient(NewSerialChannel(proto)) + defer client.Close() + err = client.OnewayRPC(context.TODO(), "hello") + if err != nil { t.Fatalf("could not complete call: %v", err) } <-received @@ -142,7 +109,8 @@ func TestRocketServerCloseListener(t *testing.T) { if err != nil { t.Fatalf("failed to listen: %v", err) } - server := NewSimpleServer(&rocketServerTestProcessor{}, listener, TransportIDRocket) + processor := dummy.NewDummyProcessor(&dummy.DummyHandler{}) + server := NewSimpleServer(processor, listener, TransportIDRocket) go func() { errChan <- server.ServeContext(ctx) }() @@ -155,16 +123,14 @@ func TestRocketServerCloseListener(t *testing.T) { if err != nil { t.Fatalf("could not create client protocol: %s", err) } - client := NewSerialChannel(proto) - req := &MyTestStruct{ - St: "hello", - } - resp := &MyTestStruct{} - if err := client.Call(context.Background(), "test", req, resp); err != nil { + client := dummy.NewDummyChannelClient(NewSerialChannel(proto)) + defer client.Close() + result, err := client.Echo(context.TODO(), "hello") + if err != nil { t.Fatalf("could not complete call: %v", err) } - if resp.St != "hello" { - t.Fatalf("expected response to be a hello, got %s", resp.St) + if result != "hello" { + t.Fatalf("expected response to be a hello, got %s", result) } listener.Close() select { diff --git a/thrift/lib/go/thrift/rocket_test.go b/thrift/lib/go/thrift/rocket_test.go index 182d54a2c5f..7fd3cdb3bc5 100644 --- a/thrift/lib/go/thrift/rocket_test.go +++ b/thrift/lib/go/thrift/rocket_test.go @@ -21,6 +21,7 @@ import ( "net" "testing" + "github.com/facebook/fbthrift/thrift/lib/go/thrift/dummy" "github.com/facebook/fbthrift/thrift/lib/go/thrift/types" ) @@ -34,7 +35,8 @@ func TestRocket(t *testing.T) { if err != nil { t.Fatalf("failed to listen: %v", err) } - server := NewSimpleServer(&testProcessor{}, listener, TransportIDRocket) + processor := dummy.NewDummyProcessor(&dummy.DummyHandler{}) + server := NewSimpleServer(processor, listener, TransportIDRocket) go func() { errChan <- server.ServeContext(ctx) }() @@ -47,16 +49,14 @@ func TestRocket(t *testing.T) { if err != nil { t.Fatalf("could not create client protocol: %s", err) } - client := NewSerialChannel(proto) - req := &MyTestStruct{ - St: "hello", - } - resp := &MyTestStruct{} - if err := client.Call(context.Background(), "test", req, resp); err != nil { + client := dummy.NewDummyChannelClient(NewSerialChannel(proto)) + defer client.Close() + result, err := client.Echo(context.TODO(), "hello") + if err != nil { t.Fatalf("could not complete call: %v", err) } - if resp.St != "hello" { - t.Fatalf("expected response to be %s, got %s", "hello", resp.St) + if result != "hello" { + t.Fatalf("expected response to be a hello, got %s", result) } cancel() <-errChan diff --git a/thrift/lib/go/thrift/rocket_upgrade_client_test.go b/thrift/lib/go/thrift/rocket_upgrade_client_test.go index 73b96a034c9..a21603e34e4 100644 --- a/thrift/lib/go/thrift/rocket_upgrade_client_test.go +++ b/thrift/lib/go/thrift/rocket_upgrade_client_test.go @@ -17,11 +17,11 @@ package thrift import ( - "bytes" "context" "net" "testing" + "github.com/facebook/fbthrift/thrift/lib/go/thrift/dummy" "github.com/facebook/fbthrift/thrift/lib/go/thrift/types" ) @@ -54,7 +54,8 @@ func TestUpgradeToRocketClientUnix(t *testing.T) { if err != nil { t.Fatalf("failed to listen: %v", err) } - server := NewSimpleServer(&rocketServerTestProcessor{}, listener, TransportIDUpgradeToRocket) + processor := dummy.NewDummyProcessor(&dummy.DummyHandler{}) + server := NewSimpleServer(processor, listener, TransportIDUpgradeToRocket) go func() { errChan <- server.ServeContext(ctx) }() @@ -66,19 +67,14 @@ func TestUpgradeToRocketClientUnix(t *testing.T) { if err != nil { t.Fatalf("could not create client protocol: %s", err) } - client := NewSerialChannel(proto) - req := &MyTestStruct{ - St: "hello", - } - resp := &MyTestStruct{} - if err := client.Call(context.Background(), "test", req, resp); err != nil { + client := dummy.NewDummyChannelClient(NewSerialChannel(proto)) + defer client.Close() + result, err := client.Echo(context.TODO(), "hello") + if err != nil { t.Fatalf("could not complete call: %v", err) } - if resp.St != "hello" { - t.Fatalf("expected response to be a hello, got %s", resp.St) - } - if !bytes.Equal(resp.GetBin(), []byte(conn.LocalAddr().String())) { - t.Fatalf("expected response to be an address %s, got %s", conn.LocalAddr().String(), resp.GetBin()) + if result != "hello" { + t.Fatalf("expected response to be a hello, got %s", result) } cancel() <-errChan diff --git a/thrift/lib/go/thrift/rocket_upgrade_simple_server_test.go b/thrift/lib/go/thrift/rocket_upgrade_simple_server_test.go index 21406cd9f4f..68971618da4 100644 --- a/thrift/lib/go/thrift/rocket_upgrade_simple_server_test.go +++ b/thrift/lib/go/thrift/rocket_upgrade_simple_server_test.go @@ -21,6 +21,7 @@ import ( "net" "testing" + "github.com/facebook/fbthrift/thrift/lib/go/thrift/dummy" "github.com/facebook/fbthrift/thrift/lib/go/thrift/types" ) @@ -34,8 +35,9 @@ func TestUpgradeToRocketServerOneWay(t *testing.T) { if err != nil { t.Fatalf("failed to listen: %v", err) } - received := make(chan *MyTestStruct) - server := NewSimpleServer(&rocketServerTestProcessor{received}, listener, TransportIDUpgradeToRocket) + received := make(chan string) + processor := dummy.NewDummyProcessor(&dummy.DummyHandler{OnewayRPCRequests: received}) + server := NewSimpleServer(processor, listener, TransportIDUpgradeToRocket) go func() { errChan <- server.ServeContext(ctx) }() @@ -48,11 +50,10 @@ func TestUpgradeToRocketServerOneWay(t *testing.T) { if err != nil { t.Fatalf("could not create client protocol: %s", err) } - client := NewSerialChannel(proto) - req := &MyTestStruct{ - St: "hello", - } - if err := client.Oneway(context.Background(), "test", req); err != nil { + client := dummy.NewDummyChannelClient(NewSerialChannel(proto)) + defer client.Close() + err = client.OnewayRPC(context.TODO(), "hello") + if err != nil { t.Fatalf("could not complete call: %v", err) } <-received diff --git a/thrift/lib/go/thrift/rocket_upgrade_test.go b/thrift/lib/go/thrift/rocket_upgrade_test.go index 31f367b2f30..c097e1b088a 100644 --- a/thrift/lib/go/thrift/rocket_upgrade_test.go +++ b/thrift/lib/go/thrift/rocket_upgrade_test.go @@ -21,6 +21,7 @@ import ( "net" "testing" + "github.com/facebook/fbthrift/thrift/lib/go/thrift/dummy" "github.com/facebook/fbthrift/thrift/lib/go/thrift/types" ) @@ -34,7 +35,8 @@ func TestUpgradeToRocketFallbackAgainstHeaderServer(t *testing.T) { if err != nil { t.Fatalf("failed to listen: %v", err) } - server := NewSimpleServer(&testProcessor{}, listener, TransportIDHeader) + processor := dummy.NewDummyProcessor(&dummy.DummyHandler{}) + server := NewSimpleServer(processor, listener, TransportIDHeader) go func() { errChan <- server.ServeContext(ctx) }() @@ -47,16 +49,14 @@ func TestUpgradeToRocketFallbackAgainstHeaderServer(t *testing.T) { if err != nil { t.Fatalf("could not create client protocol: %s", err) } - client := NewSerialChannel(proto) - req := &MyTestStruct{ - St: "hello", - } - resp := &MyTestStruct{} - if err := client.Call(context.Background(), "test", req, resp); err != nil { + client := dummy.NewDummyChannelClient(NewSerialChannel(proto)) + defer client.Close() + result, err := client.Echo(context.TODO(), "hello") + if err != nil { t.Fatalf("could not complete call: %v", err) } - if resp.St != "hello" { - t.Fatalf("expected response to be %s, got %s", "hello", resp.St) + if result != "hello" { + t.Fatalf("expected response to be a hello, got %s", result) } cancel() <-errChan @@ -72,7 +72,8 @@ func TestUpgradeToRocketServerAgainstHeaderClient(t *testing.T) { if err != nil { t.Fatalf("failed to listen: %v", err) } - server := NewSimpleServer(&testProcessor{}, listener, TransportIDUpgradeToRocket) + processor := dummy.NewDummyProcessor(&dummy.DummyHandler{}) + server := NewSimpleServer(processor, listener, TransportIDUpgradeToRocket) go func() { errChan <- server.ServeContext(ctx) }() @@ -85,16 +86,14 @@ func TestUpgradeToRocketServerAgainstHeaderClient(t *testing.T) { if err != nil { t.Fatalf("could not create client protocol: %s", err) } - client := NewSerialChannel(proto) - req := &MyTestStruct{ - St: "hello", - } - resp := &MyTestStruct{} - if err := client.Call(context.Background(), "test", req, resp); err != nil { + client := dummy.NewDummyChannelClient(NewSerialChannel(proto)) + defer client.Close() + result, err := client.Echo(context.TODO(), "hello") + if err != nil { t.Fatalf("could not complete call: %v", err) } - if resp.St != "hello" { - t.Fatalf("expected response to be %s, got %s", "hello", resp.St) + if result != "hello" { + t.Fatalf("expected response to be a hello, got %s", result) } cancel() <-errChan @@ -110,7 +109,8 @@ func TestUpgradeToRocketAgainstUpgradeToRocketServer(t *testing.T) { if err != nil { t.Fatalf("failed to listen: %v", err) } - server := NewSimpleServer(&testProcessor{}, listener, TransportIDUpgradeToRocket) + processor := dummy.NewDummyProcessor(&dummy.DummyHandler{}) + server := NewSimpleServer(processor, listener, TransportIDUpgradeToRocket) go func() { errChan <- server.ServeContext(ctx) }() @@ -123,16 +123,14 @@ func TestUpgradeToRocketAgainstUpgradeToRocketServer(t *testing.T) { if err != nil { t.Fatalf("could not create client protocol: %s", err) } - client := NewSerialChannel(proto) - req := &MyTestStruct{ - St: "hello", - } - resp := &MyTestStruct{} - if err := client.Call(context.Background(), "test", req, resp); err != nil { + client := dummy.NewDummyChannelClient(NewSerialChannel(proto)) + defer client.Close() + result, err := client.Echo(context.TODO(), "hello") + if err != nil { t.Fatalf("could not complete call: %v", err) } - if resp.St != "hello" { - t.Fatalf("expected response to be %s, got %s", "hello", resp.St) + if result != "hello" { + t.Fatalf("expected response to be a hello, got %s", result) } // check if client was really upgraded to rocket and is not using header upgradeToRocketClient := proto.(*upgradeToRocketClient) diff --git a/thrift/lib/go/thrift/simple_server_test.go b/thrift/lib/go/thrift/simple_server_test.go index 0cf0fee4637..ca5194d704a 100644 --- a/thrift/lib/go/thrift/simple_server_test.go +++ b/thrift/lib/go/thrift/simple_server_test.go @@ -22,8 +22,8 @@ import ( "net" "testing" + "github.com/facebook/fbthrift/thrift/lib/go/thrift/dummy" "github.com/facebook/fbthrift/thrift/lib/go/thrift/types" - "github.com/facebook/fbthrift/thrift/lib/thrift/metadata" ) // TestSimpleServer is a simple tests that simple sends an empty message to a server and receives an empty result. @@ -33,8 +33,8 @@ func TestSimpleServer(t *testing.T) { t.Fatalf("could not create listener: %s", err) } addr := listener.Addr() - handler := &testProcessor{} - server := NewSimpleServer(handler, listener, TransportIDHeader) + processor := dummy.NewDummyProcessor(&dummy.DummyHandler{}) + server := NewSimpleServer(processor, listener, TransportIDHeader) errChan := make(chan error) ctx, cancel := context.WithCancel(context.Background()) go func() { @@ -50,9 +50,14 @@ func TestSimpleServer(t *testing.T) { if err != nil { t.Fatalf("could not create client protocol: %s", err) } - client := NewSerialChannel(proto) - if err := client.Call(context.Background(), "test", &MyTestStruct{}, &MyTestStruct{}); err != nil { - t.Fatalf("could not send message: %s", err) + client := dummy.NewDummyChannelClient(NewSerialChannel(proto)) + defer client.Close() + result, err := client.Echo(context.TODO(), "hello") + if err != nil { + t.Fatalf("could not complete call: %v", err) + } + if result != "hello" { + t.Fatalf("expected response to be a hello, got %s", result) } cancel() err = <-errChan @@ -61,55 +66,6 @@ func TestSimpleServer(t *testing.T) { } } -type testProcessor struct { -} - -func (t *testProcessor) ProcessorFunctionMap() map[string]types.ProcessorFunction { - return map[string]types.ProcessorFunction{"test": &testProcessorFunction{}} -} - -func (t *testProcessor) GetThriftMetadata() *metadata.ThriftMetadata { - return nil -} - -type testProcessorFunction struct{} - -func (p *testProcessorFunction) Read(prot types.Decoder) (types.Struct, types.Exception) { - args := NewMyTestStruct() - if err := args.Read(prot); err != nil { - return nil, err - } - prot.ReadMessageEnd() - return args, nil -} - -func (p *testProcessorFunction) Write(seqID int32, result types.WritableStruct, oprot types.Encoder) (err types.Exception) { - var err2 error - messageType := types.REPLY - switch result.(type) { - case types.ApplicationException: - messageType = types.EXCEPTION - } - - if err2 = oprot.WriteMessageBegin("test", messageType, seqID); err2 != nil { - err = err2 - } - if err2 = result.Write(oprot); err == nil && err2 != nil { - err = err2 - } - if err2 = oprot.WriteMessageEnd(); err == nil && err2 != nil { - err = err2 - } - if err2 = oprot.Flush(); err == nil && err2 != nil { - err = err2 - } - return err -} - -func (p *testProcessorFunction) RunContext(ctx context.Context, reqStruct types.Struct) (types.WritableStruct, types.ApplicationException) { - return reqStruct, nil -} - // This tests that S425600 does not happen again. // The client is allowed to set a serializaton format to the non default and the server should adjust accordingly. func TestSimpleServerClientSetsDifferentProtocol(t *testing.T) { @@ -118,8 +74,8 @@ func TestSimpleServerClientSetsDifferentProtocol(t *testing.T) { t.Fatalf("could not create listener: %s", err) } addr := listener.Addr() - handler := &testProcessor{} - server := NewSimpleServer(handler, listener, TransportIDHeader) + processor := dummy.NewDummyProcessor(&dummy.DummyHandler{}) + server := NewSimpleServer(processor, listener, TransportIDHeader) errChan := make(chan error) ctx, cancel := context.WithCancel(context.Background()) go func() { @@ -137,9 +93,14 @@ func TestSimpleServerClientSetsDifferentProtocol(t *testing.T) { if err != nil { t.Fatalf("could not create client protocol: %s", err) } - client := NewSerialChannel(proto) - if err := client.Call(context.Background(), "test", &MyTestStruct{}, &MyTestStruct{}); err != nil { - t.Fatalf("could not send message: %s", err) + client := dummy.NewDummyChannelClient(NewSerialChannel(proto)) + defer client.Close() + result, err := client.Echo(context.TODO(), "hello") + if err != nil { + t.Fatalf("could not complete call: %v", err) + } + if result != "hello" { + t.Fatalf("expected response to be a hello, got %s", result) } cancel() <-errChan