use of io.servicetalk.http.api.HttpServerBuilder in project servicetalk by apple.
the class HttpProtocolConfigTest method serverWithDuplicatedH1ProtocolConfig.
@Test
void serverWithDuplicatedH1ProtocolConfig() {
HttpServerBuilder builder = HttpServers.forAddress(localAddress(0));
Exception e = assertThrows(IllegalArgumentException.class, () -> builder.protocols(h1Default(), h1Default()));
assertThat(e.getMessage(), startsWith("Duplicated configuration"));
}
use of io.servicetalk.http.api.HttpServerBuilder in project servicetalk by apple.
the class HttpProtocolConfigTest method serverWithDuplicatedH2ProtocolConfig.
@Test
void serverWithDuplicatedH2ProtocolConfig() {
HttpServerBuilder builder = HttpServers.forAddress(localAddress(0));
Exception e = assertThrows(IllegalArgumentException.class, () -> builder.protocols(h2Default(), h2Default()));
assertThat(e.getMessage(), startsWith("Duplicated configuration"));
}
use of io.servicetalk.http.api.HttpServerBuilder in project servicetalk by apple.
the class HttpProtocolConfigTest method serverWithEmptyProtocolConfig.
@Test
void serverWithEmptyProtocolConfig() {
HttpServerBuilder builder = HttpServers.forAddress(localAddress(0));
Exception e = assertThrows(IllegalArgumentException.class, () -> builder.protocols(new HttpProtocolConfig[0]));
assertEquals("No protocols specified", e.getMessage());
}
use of io.servicetalk.http.api.HttpServerBuilder in project servicetalk by apple.
the class AbstractJerseyStreamingHttpServiceTest method setUp.
protected void setUp(final RouterApi api) throws Exception {
this.api = api;
HttpServerBuilder serverBuilder = HttpServers.forAddress(localAddress(0));
HttpJerseyRouterBuilder routerBuilder = new HttpJerseyRouterBuilder();
configureBuilders(serverBuilder, routerBuilder);
DefaultJerseyStreamingHttpRouter router = routerBuilder.from(application());
final Configuration config = router.configuration();
streamingJsonEnabled = getValue(config.getProperties(), config.getRuntimeType(), JSON_FEATURE, "", String.class).toLowerCase().contains("servicetalk");
HttpServerBuilder httpServerBuilder = serverBuilder.ioExecutor(serverCtx.ioExecutor()).bufferAllocator(serverCtx.bufferAllocator());
switch(api) {
case ASYNC_AGGREGATED:
serverContext = buildRouter(httpServerBuilder, toAggregated(router));
break;
case ASYNC_STREAMING:
serverContext = buildRouter(httpServerBuilder, router);
break;
case BLOCKING_AGGREGATED:
serverContext = buildRouter(httpServerBuilder, toBlocking(router));
break;
case BLOCKING_STREAMING:
serverContext = buildRouter(httpServerBuilder, toBlockingStreaming(router));
break;
default:
throw new IllegalArgumentException(api.name());
}
final HostAndPort hostAndPort = serverHostAndPort(serverContext);
httpClient = HttpClients.forSingleAddress(hostAndPort).buildStreaming();
hostHeader = hostHeader(hostAndPort);
}
use of io.servicetalk.http.api.HttpServerBuilder in project servicetalk by apple.
the class NettyHttpServerConnectionDrainTest method server.
private static ServerContext server(boolean autoDrain, StreamingHttpService handler) throws Exception {
HttpServerBuilder httpServerBuilder = HttpServers.forAddress(AddressUtils.localAddress(0));
if (!autoDrain) {
httpServerBuilder = httpServerBuilder.drainRequestPayloadBody(false);
}
ServerContext serverContext = httpServerBuilder.listenStreamingAndAwait(handler);
return new ServerContext() {
@Override
public SocketAddress listenAddress() {
return serverContext.listenAddress();
}
@Override
public ExecutionContext<?> executionContext() {
return serverContext.executionContext();
}
@Override
public void acceptConnections(final boolean accept) {
serverContext.acceptConnections(accept);
}
@Override
public Completable onClose() {
return serverContext.onClose();
}
@Override
public Completable closeAsync() {
return serverContext.closeAsync();
}
@Override
public void close() {
// Without draining the request is expected to hang, don't wait too long unless on CI
int timeoutSeconds = CI ? 15 : 1;
awaitTermination(serverContext.closeAsyncGracefully().timeout(timeoutSeconds, SECONDS).onErrorResume(t -> serverContext.closeAsync().concat(Completable.failed(t))).toFuture());
}
};
}
Aggregations