@Override protected InternalServer buildTransportServer(List<Factory> streamTracerFactories) { Object registryBuilder = getFieldByReflection("registryBuilder", this, AbstractServerImplBuilder.class); Map<String, ServerServiceDefinition> services = getFieldByReflection("services", registryBuilder, null); services.values().forEach(grpcServiceBuilder::addService); armeriaServerBuilder.serviceUnder("/", grpcServiceBuilder.build() .decorate((delegate, ctx, req) -> { ctxCapture.set(ctx); return delegate.serve(ctx, req); })); return new ArmeriaGrpcServer(armeriaServerBuilder.build()); }
@Override protected InternalServer newServer(List<ServerStreamTracer.Factory> streamTracerFactories) { return AccessProtectedHack.serverBuilderBuildTransportServer( NettyServerBuilder .forPort(0) .flowControlWindow(65 * 1024), streamTracerFactories, fakeClockTransportTracer); }
@Override protected InternalServer newServer( InternalServer server, List<ServerStreamTracer.Factory> streamTracerFactories) { int port = server.getPort(); return AccessProtectedHack.serverBuilderBuildTransportServer( NettyServerBuilder .forPort(port) .flowControlWindow(65 * 1024), streamTracerFactories, fakeClockTransportTracer); }
@Override protected ManagedClientTransport newClientTransport(InternalServer server) { int port = server.getPort(); return clientFactory.newClientTransport( new InetSocketAddress("localhost", port), testAuthority(server), null /* agent */, null /* proxy */); }
@Override protected InternalServer newServer(List<ServerStreamTracer.Factory> streamTracerFactories) { return NettyServerBuilder .forPort(0) .flowControlWindow(65 * 1024) .setTransportTracerFactory(fakeClockTransportTracer) .buildTransportServer(streamTracerFactories); }
@Override protected InternalServer newServer( InternalServer server, List<ServerStreamTracer.Factory> streamTracerFactories) { int port = server.getPort(); return NettyServerBuilder .forPort(port) .flowControlWindow(65 * 1024) .setTransportTracerFactory(fakeClockTransportTracer) .buildTransportServer(streamTracerFactories); }
@Test public void serverAlreadyListening() throws Exception { client = null; server.start(serverListener); InternalServer server2 = newServer(server, Arrays.asList(serverStreamTracerFactory)); thrown.expect(IOException.class); server2.start(new MockServerListener()); }
@Override protected String testAuthority(InternalServer server) { return "thebestauthority:" + server.getPort(); }
@Override protected String testAuthority(InternalServer server) { return "localhost:" + server.getPort(); }
@Override protected InternalServer newServer(List<ServerStreamTracer.Factory> streamTracerFactories) { return new InProcessServer(TRANSPORT_NAME, GrpcUtil.TIMER_SERVICE, streamTracerFactories); }
@Override protected InternalServer newServer( InternalServer server, List<ServerStreamTracer.Factory> streamTracerFactories) { return newServer(streamTracerFactories); }
@Override protected String testAuthority(InternalServer server) { return AUTHORITY; }
@Override protected ManagedClientTransport newClientTransport(InternalServer server) { return new InProcessTransport(TRANSPORT_NAME, testAuthority(server), USER_AGENT); }
/** * Returns a new server that when started will be able to be connected to from the client. Each * returned instance should be new and yet be accessible by new client transports. */ protected abstract InternalServer newServer( List<ServerStreamTracer.Factory> streamTracerFactories);
/** * Builds a new server that is listening on the same location as the given server instance does. */ protected abstract InternalServer newServer( InternalServer server, List<ServerStreamTracer.Factory> streamTracerFactories);
/** * Returns a new transport that when started will be able to connect to {@code server}. */ protected abstract ManagedClientTransport newClientTransport(InternalServer server);
/** * Returns the authority string used by a client to connect to {@code server}. */ protected abstract String testAuthority(InternalServer server);