@ExperimentalApi(value="https://github.com/grpc/grpc-java/issues/1783") public final class InProcessServerBuilder extends AbstractServerImplBuilder<InProcessServerBuilder>
The server is intended to be fully-featured, high performance, and useful in testing.
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.
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();
TestServiceGrpc.TestServiceBlockingStub blockingStub = TestServiceGrpc.newBlockingStub(channel);
binlog, callTracerFactory, channelz, transportTracerFactory
Modifier and Type | Method and Description |
---|---|
protected io.grpc.inprocess.InProcessServer |
buildTransportServer(List<ServerStreamTracer.Factory> streamTracerFactories)
Children of AbstractServerBuilder should override this method to provide transport specific
information for the server.
|
static InProcessServerBuilder |
forName(String name)
Create a server builder that will bind with the given name.
|
static InProcessServerBuilder |
forPort(int port)
Always fails.
|
static String |
generateName()
Generates a new server name that is unique each time.
|
InProcessServerBuilder |
scheduledExecutorService(ScheduledExecutorService scheduledExecutorService)
Provides a custom scheduled executor service.
|
InProcessServerBuilder |
useTransportSecurity(File certChain,
File privateKey)
Makes the server use TLS.
|
addService, addService, addStreamTracerFactory, addTransportFilter, build, compressorRegistry, decompressorRegistry, directExecutor, executor, fallbackHandlerRegistry, handshakeTimeout, intercept, overrideCensusStatsModule, setBinaryLog, setStatsEnabled, setStatsRecordFinishedRpcs, setStatsRecordStartedRpcs, setTracingEnabled
maxInboundMessageSize, useTransportSecurity
public static InProcessServerBuilder forName(String name)
name
- the identity of the server for clients to connect topublic static InProcessServerBuilder forPort(int port)
forName(java.lang.String)
instead.public static String generateName()
public InProcessServerBuilder scheduledExecutorService(ScheduledExecutorService scheduledExecutorService)
It's an optional parameter. If the user has not provided a scheduled executor service when the channel is built, the builder will use a static cached thread pool.
protected io.grpc.inprocess.InProcessServer buildTransportServer(List<ServerStreamTracer.Factory> streamTracerFactories)
AbstractServerImplBuilder
buildTransportServer
in class AbstractServerImplBuilder<InProcessServerBuilder>
streamTracerFactories
- an immutable list of stream tracer factoriespublic InProcessServerBuilder useTransportSecurity(File certChain, File privateKey)
ServerBuilder
useTransportSecurity
in class ServerBuilder<InProcessServerBuilder>
certChain
- file containing the full certificate chainprivateKey
- file containing the private keyCopyright © 2018. All rights reserved.