ServerImpl extends io.grpc.Server { @Override public ServerImpl start() throws IOException { synchronized (lock) { checkState(!started, "Already started"); checkState(!shutdown, "Shutting down"); usingSharedExecutor = executor == null; if (usingSharedExecutor) { executor = SharedResourceHolder.get(GrpcUtil.SHARED_CHANNEL_EXECUTOR); } transportServer.start(new ServerListenerImpl()); started = true; return this; } } ServerImpl(Executor executor, InternalHandlerRegistry registry, HandlerRegistry fallbackRegistry,
      InternalServer transportServer, Context rootContext,
      DecompressorRegistry decompressorRegistry, CompressorRegistry compressorRegistry); @Override ServerImpl start(); @Override int getPort(); @Override ServerImpl shutdown(); @Override ServerImpl shutdownNow(); @Override boolean isShutdown(); @Override boolean awaitTermination(long timeout, TimeUnit unit); @Override void awaitTermination(); @Override boolean isTerminated();  }
@Test public void transportServerFailsStartup() { final IOException ex = new IOException(); class FailingStartupServer extends SimpleServer { @Override public void start(ServerListener listener) throws IOException { throw ex; } } ServerImpl server = new ServerImpl(executor, registry, fallbackRegistry, new FailingStartupServer(), SERVER_CONTEXT, decompressorRegistry, compressorRegistry); try { server.start(); fail("expected exception"); } catch (IOException e) { assertSame(ex, e); } }
@Test public void handlerRegistryPriorities() throws Exception { HandlerRegistry fallbackRegistry = mock(HandlerRegistry.class); MethodDescriptor<String, Integer> method1 = MethodDescriptor.create( MethodType.UNKNOWN, "Service1/Method1", STRING_MARSHALLER, INTEGER_MARSHALLER); registry = new InternalHandlerRegistry.Builder() .addService(ServerServiceDefinition.builder("Service1") .addMethod(method1, callHandler).build()) .build(); transportServer = new SimpleServer(); ServerImpl server = new ServerImpl(executor, registry, fallbackRegistry, transportServer, SERVER_CONTEXT, decompressorRegistry, compressorRegistry); server.start(); ServerTransportListener transportListener = transportServer.registerNewServerTransport(new SimpleServerTransport()); transportListener.streamCreated(stream, "Service1/Method1", new Metadata()); transportListener.streamCreated(stream, "Service1/Method2", new Metadata()); verify(callHandler, timeout(2000)).startCall(same(method1), Matchers.<ServerCall<Integer>>anyObject(), Matchers.<Metadata>anyObject()); verify(fallbackRegistry, timeout(2000)).lookupMethod("Service1/Method2", null); verifyNoMoreInteractions(callHandler); verifyNoMoreInteractions(fallbackRegistry); }