use of io.servicetalk.http.api.BlockingHttpClient in project servicetalk by apple.
the class NettyHttpServerConnectionDrainTest method requestIsAutoDrainedWhenUserFailsToConsume.
@Disabled("https://github.com/apple/servicetalk/issues/981")
@Test
void requestIsAutoDrainedWhenUserFailsToConsume() throws Exception {
BlockingHttpClient client = null;
try (ServerContext serverContext = server(true, respondOkWithoutReadingRequest())) {
client = HttpClients.forSingleAddress(serverHostAndPort(serverContext)).buildBlocking();
postLargePayloadAndAssertResponseOk(client);
} finally {
closeClient(client);
}
}
use of io.servicetalk.http.api.BlockingHttpClient in project servicetalk by apple.
the class NettyHttpServerTest method testServiceThrowsReturnsErrorResponse.
@ParameterizedTest(name = "{displayName} [{index}] disableOffloading={0}")
@ValueSource(booleans = { true, false })
void testServiceThrowsReturnsErrorResponse(boolean disableOffloading) throws Exception {
// the test suite state isn't used by this individual test, but cleanup code requires it is initialized.
setUp(IMMEDIATE, IMMEDIATE);
HttpServerBuilder serverBuilder = HttpServers.forAddress(localAddress(0));
if (disableOffloading) {
serverBuilder.executionStrategy(offloadNone());
}
try (ServerContext serverCtx = serverBuilder.listenStreamingAndAwait((ctx, request, responseFactory) -> {
throw DELIBERATE_EXCEPTION;
});
BlockingHttpClient client = disableOffloading(HttpClients.forResolvedAddress(serverHostAndPort(serverCtx)), disableOffloading).buildBlocking()) {
HttpResponse resp = client.request(client.get("/"));
assertThat(resp.status(), is(INTERNAL_SERVER_ERROR));
}
}
use of io.servicetalk.http.api.BlockingHttpClient in project servicetalk by apple.
the class NoOffloadsStrategyTest method turnOffAllExecutors.
@Test
void turnOffAllExecutors() throws Exception {
serverBuilder.executor(immediate()).executionStrategy(customStrategyBuilder().offloadNone().build());
StreamingHttpServiceImpl svc = new StreamingHttpServiceImpl();
BlockingHttpClient client = initServerAndClient(svc);
client.request(client.get("/"));
assertThat("Unexpected thread for the server executor.", svc.executorThread.getName(), startsWith(IO_EXECUTOR_NAME));
}
use of io.servicetalk.http.api.BlockingHttpClient in project servicetalk by apple.
the class NoOffloadsStrategyTest method noOffloadsStillUsesAServerExecutor.
@Test
void noOffloadsStillUsesAServerExecutor() throws Exception {
serverBuilder.executionStrategy(customStrategyBuilder().offloadNone().build());
StreamingHttpServiceImpl svc = new StreamingHttpServiceImpl();
BlockingHttpClient client = initServerAndClient(svc);
client.request(client.get("/"));
assertThat("Unexpected thread for the server executor.", svc.executorThread.getName(), not(startsWith(IO_EXECUTOR_NAME)));
}
use of io.servicetalk.http.api.BlockingHttpClient in project servicetalk by apple.
the class PartitionedHttpClientTest method testPartitionByTarget.
@Test
void testPartitionByTarget() throws Exception {
final Function<HttpRequestMetaData, PartitionAttributesBuilder> selector = req -> new DefaultPartitionAttributesBuilder(1).add(SRV_NAME, req.requestTarget().substring(1));
try (BlockingHttpClient clt = HttpClients.forPartitionedAddress(psd, "test-cluster", selector).initializer((pa, builder) -> builder.unresolvedAddressToHost(addr -> pa.get(SRV_NAME))).buildBlocking()) {
sdPublisher.onSubscribe(new TestSubscription());
sdPublisher.onNext(new TestPSDE(SRV_1, (InetSocketAddress) srv1.listenAddress()), new TestPSDE(SRV_2, (InetSocketAddress) srv2.listenAddress()));
final HttpResponse httpResponse1 = clt.request(clt.get("/" + SRV_2));
final HttpResponse httpResponse2 = clt.request(clt.get("/" + SRV_1));
MatcherAssert.assertThat(httpResponse1.headers().get(X_SERVER), hasToString(SRV_2));
MatcherAssert.assertThat(httpResponse2.headers().get(X_SERVER), hasToString(SRV_1));
}
}
Aggregations