use of io.servicetalk.transport.api.ServerContext in project servicetalk by apple.
the class DefaultHealthServiceTest method defaultWatch.
@Test
void defaultWatch() throws Exception {
DefaultHealthService service = new DefaultHealthService();
try (ServerContext serverCtx = GrpcServers.forAddress(localAddress(0)).listenAndAwait(service)) {
try (Health.BlockingHealthClient client = GrpcClients.forResolvedAddress((InetSocketAddress) serverCtx.listenAddress()).buildBlocking(new Health.ClientFactory())) {
BlockingIterator<HealthCheckResponse> itr = client.watch(newRequest(OVERALL_SERVICE_NAME)).iterator();
assertThat(itr.next().getStatus(), equalTo(SERVING));
assertThat(service.setStatus(OVERALL_SERVICE_NAME, NOT_SERVING), equalTo(true));
assertThat(itr.next().getStatus(), equalTo(NOT_SERVING));
}
}
}
use of io.servicetalk.transport.api.ServerContext in project servicetalk by apple.
the class DefaultHealthServiceTest method statusChangeCheck.
@Test
void statusChangeCheck() throws Exception {
DefaultHealthService service = new DefaultHealthService();
String serviceName = "service";
ServingStatus serviceStatus = NOT_SERVING;
service.setStatus(serviceName, serviceStatus);
try (ServerContext serverCtx = GrpcServers.forAddress(localAddress(0)).listenAndAwait(service)) {
try (Health.BlockingHealthClient client = GrpcClients.forResolvedAddress((InetSocketAddress) serverCtx.listenAddress()).buildBlocking(new Health.ClientFactory())) {
assertThat(client.check(newRequest(serviceName)).getStatus(), equalTo(serviceStatus));
}
}
}
use of io.servicetalk.transport.api.ServerContext in project servicetalk by apple.
the class ClosureTest method startServerAndClose.
private void startServerAndClose(final ServiceFactory serviceFactory, final CloseSignal signal) throws Exception {
ServerContext serverContext = forAddress(localAddress(0)).listenAndAwait(serviceFactory);
if (closeGracefully) {
serverContext.closeGracefully();
} else {
serverContext.close();
}
signal.await();
}
use of io.servicetalk.transport.api.ServerContext in project servicetalk by apple.
the class FlushStrategyOnServerTest method setUp.
private void setUp(final Param param) {
this.interceptor = new OutboundWriteEventsInterceptor();
this.headersFactory = DefaultHttpHeadersFactory.INSTANCE;
final StreamingHttpService service = (ctx, request, responseFactory) -> {
StreamingHttpResponse resp = responseFactory.ok();
if (request.headers().get(USE_EMPTY_RESP_BODY) == null) {
resp.payloadBody(from("Hello", "World"), appSerializerUtf8FixLen());
}
if (request.headers().get(USE_AGGREGATED_RESP) != null) {
return resp.toResponse().map(HttpResponse::toStreamingResponse);
}
return succeeded(resp);
};
final DefaultHttpExecutionContext httpExecutionContext = new DefaultHttpExecutionContext(DEFAULT_ALLOCATOR, globalExecutionContext().ioExecutor(), EXECUTOR_RULE.executor(), param.executionStrategy);
final ReadOnlyHttpServerConfig config = new HttpServerConfig().asReadOnly();
final ReadOnlyTcpServerConfig tcpReadOnly = new TcpServerConfig().asReadOnly();
try {
serverContext = TcpServerBinder.bind(localAddress(0), tcpReadOnly, true, httpExecutionContext, null, (channel, observer) -> {
final ConnectionObserver connectionObserver = config.tcpConfig().transportObserver().onNewConnection(channel.localAddress(), channel.remoteAddress());
return initChannel(channel, httpExecutionContext, config, new TcpServerChannelInitializer(tcpReadOnly, connectionObserver).andThen(channel1 -> channel1.pipeline().addLast(interceptor)), service, true, connectionObserver);
}, connection -> connection.process(true)).map(delegate -> new NettyHttpServerContext(delegate, service, httpExecutionContext)).toFuture().get();
} catch (Exception e) {
fail(e);
}
client = HttpClients.forSingleAddress(serverHostAndPort(serverContext)).protocols(h1Default()).buildBlocking();
}
use of io.servicetalk.transport.api.ServerContext in project servicetalk by apple.
the class H2PriorKnowledgeFeatureParityTest method h2LayerFiltersOutProhibitedH1HeadersOnServerSide.
@Test
void h2LayerFiltersOutProhibitedH1HeadersOnServerSide() throws Exception {
setUp(DEFAULT, true);
try (ServerContext serverContext = HttpServers.forAddress(localAddress(0)).protocols(HttpProtocol.HTTP_2.config).enableWireLogging("servicetalk-tests-wire-logger", LogLevel.TRACE, () -> true).listenBlockingAndAwait((ctx, request, responseFactory) -> addProhibitedHeaders(responseFactory.ok()));
BlockingHttpClient client = forSingleAddress(serverHostAndPort(serverContext)).protocols(HttpProtocol.HTTP_2.config).enableWireLogging("servicetalk-tests-wire-logger", LogLevel.TRACE, () -> true).executionStrategy(clientExecutionStrategy).buildBlocking()) {
HttpResponse response = client.request(client.get("/"));
assertThat(response.status(), is(OK));
for (CharSequence headerName : PROHIBITED_HEADERS) {
assertThat("Unexpected headerName: " + headerName, response.headers().contains(headerName), is(false));
}
}
}
Aggregations