HelloWorldServer { private void start() throws IOException { int port = 50051; server = ServerBuilder.forPort(port) .addService(new GreeterImpl()) .build() .start(); logger.info("server started, listening on: " + port); Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { logger.info("*** shutting down gRPC server since JVM is shutting down ***"); HelloWorldServer.this.stop(); logger.info("*** server shut down ***"); } }); }  static void main(String[] args);  }
@Test public void greeterImpl_replyMessage() throws Exception { String serverName = InProcessServerBuilder.generateName(); grpcCleanup.register(InProcessServerBuilder .forName(serverName).directExecutor().addService(new HelloWorldServer.GreeterImpl()).build().start()); GreeterGrpc.GreeterBlockingStub blockingStub = GreeterGrpc.newBlockingStub( grpcCleanup.register(InProcessChannelBuilder.forName(serverName).directExecutor().build())); HelloReply reply = blockingStub.sayHello(HelloRequest.newBuilder().setName("test name").build()); assertEquals("Hello test name", reply.getMessage()); }