Class GrpcServerRule
- java.lang.Object
- 
- org.junit.rules.ExternalResource
- 
- io.grpc.testing.GrpcServerRule
 
 
- 
- All Implemented Interfaces:
- org.junit.rules.TestRule
 
 public final class GrpcServerRule extends org.junit.rules.ExternalResourceGrpcServerRuleis a JUnitTestRulethat starts an in-process gRPC service with aMutableHandlerRegistryfor adding services. PreferGrpcCleanupRulein new code.GrpcServerRuleis useful for testing gRPC-based clients and services. However, becauseGrpcServerRuledoes not support useful features such as transport types other than in-process, multiple channels per server, custom channel or server builder options, and configuration inside individual test methods, users would end up to a difficult situation when later they want to make extensions to their tests that were usingGrpcServerRule. Little benefit comes from proactively migrating existing code fromGrpcServerRule, but new code is better served by explicit channel and server creation withGrpcCleanupRulemanaging resource lifetimes.An AbstractStubcan be created against this service by using theManagedChannelprovided bygetChannel().
- 
- 
Constructor SummaryConstructors Constructor Description GrpcServerRule()
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidafter()After the test has completed, clean up the channel and server.protected voidbefore()Before the test has started, create the server and channel.GrpcServerRuledirectExecutor()ManagedChannelgetChannel()Returns aManagedChannelconnected to this service.ServergetServer()Returns the underlying gRPCServerfor this service.StringgetServerName()Returns the randomly generated server name for this service.MutableHandlerRegistrygetServiceRegistry()Returns the service registry for this service.
 
- 
- 
- 
Method Detail- 
directExecutorpublic final GrpcServerRule directExecutor() Returnsthisconfigured to use a direct executor for theManagedChannelandServer. This can only be called at the rule instantiation.
 - 
getChannelpublic final ManagedChannel getChannel() Returns aManagedChannelconnected to this service.
 - 
getServerNamepublic final String getServerName() Returns the randomly generated server name for this service.
 - 
getServiceRegistrypublic final MutableHandlerRegistry getServiceRegistry() Returns the service registry for this service. The registry is used to add service instances (e.g.BindableServiceorServerServiceDefinitionto the server.
 - 
afterprotected void after() After the test has completed, clean up the channel and server.- Overrides:
- afterin class- org.junit.rules.ExternalResource
 
 
- 
 
-