Class InProcessServerBuilder


@ExperimentalApi("https://github.com/grpc/grpc-java/issues/1783") public final class InProcessServerBuilder extends ForwardingServerBuilder<InProcessServerBuilder>
Builder for a server that services in-process requests. Clients identify the in-process server by its name.

The server is intended to be fully-featured, high performance, and useful in testing.

Using JUnit TestRule

The class "GrpcServerRule" (from "grpc-java/testing") is a JUnit TestRule that creates a InProcessServer and a ManagedChannel. This test rule contains the boilerplate code shown below. The classes "HelloWorldServerTest" and "HelloWorldClientTest" (from "grpc-java/examples") demonstrate basic usage.

Usage example

Server and client channel setup

   String uniqueName = InProcessServerBuilder.generateName();
   Server server = InProcessServerBuilder.forName(uniqueName)
       .directExecutor() // directExecutor is fine for unit tests
       .addService(/* your code here */)
       .build().start();
   ManagedChannel channel = InProcessChannelBuilder.forName(uniqueName)
       .directExecutor()
       .build();
 

Usage in tests

The channel can be used normally. A blocking stub example:
   TestServiceGrpc.TestServiceBlockingStub blockingStub =
       TestServiceGrpc.newBlockingStub(channel);