// This test makes sure the go rpc service works func TestGoRPCTabletConn(t *testing.T) { // fake service service := tabletconntest.CreateFakeServer(t) // listen on a random port listener, err := net.Listen("tcp", ":0") if err != nil { t.Fatalf("Cannot listen: %v", err) } host := listener.Addr().(*net.TCPAddr).IP.String() port := listener.Addr().(*net.TCPAddr).Port // Create a gRPC server and listen on the port server := grpc.NewServer() grpcqueryservice.RegisterForTest(server, service) go server.Serve(listener) // Create a gRPC client connecting to the server ctx := context.Background() client, err := DialTablet(ctx, &pb.EndPoint{ Host: host, PortMap: map[string]int32{ "grpc": int32(port), }, }, tabletconntest.TestKeyspace, tabletconntest.TestShard, 30*time.Second) if err != nil { t.Fatalf("dial failed: %v", err) } // run the test suite tabletconntest.TestSuite(t, client, service) // and clean up client.Close() }
// This test makes sure the go rpc service works func TestGoRPCTabletConn(t *testing.T) { // fake service service := tabletconntest.CreateFakeServer(t) // listen on a random port listener, err := net.Listen("tcp", ":0") if err != nil { t.Fatalf("Cannot listen: %v", err) } host := listener.Addr().(*net.TCPAddr).IP.String() port := listener.Addr().(*net.TCPAddr).Port // Create a gRPC server and listen on the port server := grpc.NewServer() grpcqueryservice.RegisterForTest(server, service) go server.Serve(listener) // run the test suite tabletconntest.TestSuite(t, protocolName, &pb.EndPoint{ Host: host, PortMap: map[string]int32{ "grpc": int32(port), }, }, service) }
// CreateFakeServers returns the servers to use for these tests func CreateFakeServers(t *testing.T) (*tabletconntest.FakeQueryService, topo.Server, string) { cell := "local" // the FakeServer is just slightly modified f := tabletconntest.CreateFakeServer(t) f.TestingGateway = true f.StreamHealthResponse = &querypb.StreamHealthResponse{ Target: tabletconntest.TestTarget, Serving: true, TabletExternallyReparentedTimestamp: 1234589, RealtimeStats: &querypb.RealtimeStats{ SecondsBehindMaster: 1, }, } // The topo server has a single SrvKeyspace ts := zktestserver.New(t, []string{cell}) if err := ts.UpdateSrvKeyspace(context.Background(), cell, tabletconntest.TestTarget.Keyspace, &topodatapb.SrvKeyspace{ Partitions: []*topodatapb.SrvKeyspace_KeyspacePartition{ { ServedType: topodatapb.TabletType_MASTER, ShardReferences: []*topodatapb.ShardReference{ { Name: tabletconntest.TestTarget.Shard, }, }, }, }, }); err != nil { t.Fatalf("can't add srvKeyspace: %v", err) } return f, ts, cell }
// This test makes sure the go rpc service works func testGoRPCTabletConn(t *testing.T) { // fake service service := tabletconntest.CreateFakeServer(t) // listen on a random port listener, err := net.Listen("tcp", ":0") if err != nil { t.Fatalf("Cannot listen: %v", err) } defer listener.Close() port := listener.Addr().(*net.TCPAddr).Port // Create a Go Rpc server and listen on the port server := rpcplus.NewServer() server.Register(gorpcqueryservice.New(service)) // create the HTTP server, serve the server from it handler := http.NewServeMux() bsonrpc.ServeCustomRPC(handler, server) httpServer := http.Server{ Handler: handler, } go httpServer.Serve(listener) // run the test suite tabletconntest.TestSuite(t, protocolName, &pb.EndPoint{ Host: "localhost", PortMap: map[string]int32{ "vt": int32(port), }, }, service) }
// This test makes sure the go rpc service works func testGoRPCTabletConn(t *testing.T, rpcOnlyInReply bool) { // fake service service := tabletconntest.CreateFakeServer(t) // listen on a random port listener, err := net.Listen("tcp", ":0") if err != nil { t.Fatalf("Cannot listen: %v", err) } defer listener.Close() port := listener.Addr().(*net.TCPAddr).Port // Create a Go Rpc server and listen on the port server := rpcplus.NewServer() server.Register(gorpcqueryservice.New(service)) // create the HTTP server, serve the server from it handler := http.NewServeMux() bsonrpc.ServeCustomRPC(handler, server, false) httpServer := http.Server{ Handler: handler, } go httpServer.Serve(listener) // Handle errors appropriately *tabletserver.RPCErrorOnlyInReply = rpcOnlyInReply // Create a Go RPC client connecting to the server ctx := context.Background() client, err := DialTablet(ctx, topo.EndPoint{ Host: "localhost", NamedPortMap: map[string]int{ "vt": port, }, }, tabletconntest.TestKeyspace, tabletconntest.TestShard, 30*time.Second) if err != nil { t.Fatalf("dial failed: %v", err) } // run the test suite tabletconntest.TestSuite(t, client, service) // and clean up client.Close() }
// This test makes sure the go rpc service works func TestGRPCTabletConn(t *testing.T) { // fake service service := tabletconntest.CreateFakeServer(t) // listen on a random port listener, err := net.Listen("tcp", ":0") if err != nil { t.Fatalf("Cannot listen: %v", err) } host := listener.Addr().(*net.TCPAddr).IP.String() port := listener.Addr().(*net.TCPAddr).Port // Create a gRPC server and listen on the port server := grpc.NewServer() grpcqueryservice.Register(server, service) go server.Serve(listener) // run the test suite tabletconntest.TestSuite(t, protocolName, &topodatapb.Tablet{ Keyspace: tabletconntest.TestTarget.Keyspace, Shard: tabletconntest.TestTarget.Shard, Type: tabletconntest.TestTarget.TabletType, Hostname: host, PortMap: map[string]int32{ "grpc": int32(port), }, }, service) // run it again with combo enabled t.Log("Enabling combo Begin / Execute{,Batch}") *combo = true tabletconntest.TestSuite(t, protocolName, &topodatapb.Tablet{ Keyspace: tabletconntest.TestTarget.Keyspace, Shard: tabletconntest.TestTarget.Shard, Type: tabletconntest.TestTarget.TabletType, Hostname: host, PortMap: map[string]int32{ "grpc": int32(port), }, }, service) }