func newTestServer(t *testing.T, ctx *rpc.Context) (*rpc.Server, net.Listener) { s := rpc.NewServer(ctx) tlsConfig, err := ctx.GetServerTLSConfig() if err != nil { t.Fatal(err) } addr := util.CreateTestAddr("tcp") ln, err := util.ListenAndServe(ctx.Stopper, s, addr, tlsConfig) if err != nil { t.Fatal(err) } return s, ln }
func (lt *localRPCTransport) Listen(id roachpb.StoreID, handler RaftMessageHandler) error { ctx := crpc.Context{ Context: base.Context{ Insecure: true, }, Stopper: lt.stopper, DisableCache: true, } rpcServer := crpc.NewServer(&ctx) err := rpcServer.RegisterAsync(raftMessageName, false, /*not public*/ func(argsI proto.Message, callback func(proto.Message, error)) { defer func() { // TODO(bdarnell): the http/rpc code is swallowing panics somewhere. if p := recover(); p != nil { log.Fatalf("caught panic: %s", p) } }() args := argsI.(*RaftMessageRequest) err := handler(args) callback(&RaftMessageResponse{}, err) }, &RaftMessageRequest{}) if err != nil { return err } tlsConfig, err := ctx.GetServerTLSConfig() if err != nil { return err } addr := util.CreateTestAddr("tcp") ln, err := util.ListenAndServe(ctx.Stopper, rpcServer, addr, tlsConfig) if err != nil { return err } lt.mu.Lock() if _, ok := lt.servers[id]; ok { log.Fatalf("node %d already listening", id) } lt.servers[id] = serverWithAddr{rpcServer, ln.Addr()} lt.mu.Unlock() return nil }
func newTestServer(t *testing.T, ctx *rpc.Context) (*rpc.Server, net.Listener) { s := rpc.NewServer(ctx) tlsConfig, err := ctx.GetServerTLSConfig() if err != nil { t.Fatal(err) } // We may be called in a loop, meaning tlsConfig is may be in used by a // running server during a call to `util.ListenAndServe`, which may // mutate it (due to http2.ConfigureServer). Make a copy to avoid trouble. tlsConfigCopy := *tlsConfig addr := util.CreateTestAddr("tcp") ln, err := util.ListenAndServe(ctx.Stopper, s, addr, &tlsConfigCopy) if err != nil { t.Fatal(err) } return s, ln }
func newTestServer(t *testing.T, ctx *rpc.Context, manual bool) (*rpc.Server, net.Listener) { var s *rpc.Server if manual { s = rpc.NewManualServer(ctx) } else { s = rpc.NewServer(ctx) } tlsConfig, err := ctx.GetServerTLSConfig() if err != nil { t.Fatal(err) } addr := util.CreateTestAddr("tcp") ln, err := util.ListenAndServe(ctx.Stopper, s, addr, tlsConfig) if err != nil { t.Fatal(err) } return s, ln }
func (lt *localRPCTransport) Listen(id roachpb.StoreID, server ServerInterface) error { ctx := crpc.Context{ Context: base.Context{ Insecure: true, }, Stopper: lt.stopper, DisableCache: true, } rpcServer := crpc.NewServer(&ctx) err := rpcServer.RegisterAsync(raftMessageName, false, /*not public*/ func(argsI proto.Message, callback func(proto.Message, error)) { args := argsI.(*RaftMessageRequest) resp, err := server.RaftMessage(args) callback(resp, err) }, &RaftMessageRequest{}) if err != nil { return err } tlsConfig, err := ctx.GetServerTLSConfig() if err != nil { return err } addr := util.CreateTestAddr("tcp") ln, err := util.ListenAndServe(ctx.Stopper, rpcServer, addr, tlsConfig) if err != nil { return err } lt.mu.Lock() if _, ok := lt.servers[id]; ok { log.Fatalf("node %d already listening", id) } lt.servers[id] = serverWithAddr{rpcServer, ln.Addr()} lt.mu.Unlock() return nil }