本文整理汇总了Golang中google/golang.org/grpc.Server.Stop方法的典型用法代码示例。如果您正苦于以下问题:Golang Server.Stop方法的具体用法?Golang Server.Stop怎么用?Golang Server.Stop使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类google/golang.org/grpc.Server
的用法示例。
在下文中一共展示了Server.Stop方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: setUpSignerClient
func setUpSignerClient(t *testing.T, grpcServer *grpc.Server) (*client.NotarySigner, *grpc.ClientConn, func()) {
socketFile, err := ioutil.TempFile("", "notary-grpc-test")
require.NoError(t, err)
socketFile.Close()
os.Remove(socketFile.Name())
lis, err := net.Listen("unix", socketFile.Name())
require.NoError(t, err, "unable to open socket to listen")
go grpcServer.Serve(lis)
// client setup
clientConn, err := grpc.Dial(socketFile.Name(), grpc.WithInsecure(), grpc.WithDialer(socketDialer))
require.NoError(t, err, "unable to connect to socket as a GRPC client")
signerClient := client.NewNotarySigner(clientConn)
cleanup := func() {
clientConn.Close()
grpcServer.Stop()
os.Remove(socketFile.Name())
}
return signerClient, clientConn, cleanup
}
示例2: waitShutdown
func waitShutdown(rpcSrv *grpc.Server, apiSrv *server.ApiServer) {
sigCh := make(chan os.Signal)
signal.Notify(sigCh, os.Interrupt, os.Kill)
// Block until a signal is received or we got an error
select {
case signal := <-sigCh:
log.Printf("Got signal %s, waiting for shutdown...", signal)
rpcSrv.Stop()
apiSrv.Shutdown()
return
}
}
示例3: ListenAndServeGRPC
// ListenAndServeGRPC creates a listener and serves the specified grpc Server
// on it, closing the listener when signalled by the stopper.
func ListenAndServeGRPC(stopper *stop.Stopper, server *grpc.Server,
addr net.Addr) (net.Listener, error) {
ln, err := net.Listen(addr.Network(), addr.String())
if err != nil {
return ln, err
}
stopper.RunWorker(func() {
<-stopper.ShouldDrain()
server.Stop()
})
stopper.RunWorker(func() {
FatalIfUnexpected(server.Serve(ln))
})
return ln, nil
}
示例4: tearDown
func tearDown(s *grpc.Server, cc *grpc.ClientConn) {
cc.Close()
s.Stop()
}
示例5: TestDisplay
func TestDisplay(t *testing.T) {
var tCtx context.Context
tests := []struct {
ctx context.Context
query Query
cfg *Config
generator generator
err error
}{{
ctx: tCtx,
query: Query{
Target: "test",
},
cfg: &Config{},
err: fmt.Errorf("grpc: no transport security set (use grpc.WithInsecure() explicitly or set credentials)"),
}, {
ctx: tCtx,
query: Query{
Target: "test",
},
cfg: nil,
err: fmt.Errorf("cfg must not be nil"),
}, {
ctx: tCtx,
query: Query{
Target: "localhost",
DialOptions: []grpc.DialOption{
grpc.WithInsecure(),
},
},
cfg: &Config{},
err: fmt.Errorf("query target must be specified"),
}, {
ctx: tCtx,
query: Query{
Target: "localhost",
DialOptions: []grpc.DialOption{
grpc.WithInsecure(),
},
Queries: [][]string{
[]string{"foo"},
},
},
cfg: &Config{},
generator: NewFixedGenerator(ocpb.Path{
Element: []string{"foo"},
}, ocpb.Value{
Value: []byte("42"),
}),
}}
for _, tt := range tests {
var s *grpc.Server
var ft *fakeTarget
if tt.query.Target == "localhost" {
var err error
s, ft, tt.query.Target, err = startLocalServer()
if tt.generator != nil {
ft.RegisterGenerator(tt.generator)
}
if err != nil {
t.Fatal("failed to start server")
}
defer s.Stop()
}
t.Logf("test Display(%+v, %+v, %+v)", tt.ctx, tt.query, tt.cfg)
if tt.cfg != nil {
tt.cfg.Display = fakeDisplayer(ft, t)
}
err := Display(context.Background(), tt.query, tt.cfg)
if tt.err != nil && err != nil && tt.err.Error() != err.Error() {
t.Errorf("failed Display(%+v, %+v, %+v): got %s, want %s", tt.ctx, tt.query, tt.cfg, err, tt.err)
}
}
}