use of io.servicetalk.http.api.BlockingHttpClient in project servicetalk by apple.
the class MalformedDataAfterHttpMessageTest method afterRequest.
@Test
void afterRequest() throws Exception {
try (ServerContext server = stServer();
BlockingHttpClient client = stClient(server.listenAddress())) {
Buffer malformedBody = client.executionContext().bufferAllocator().fromAscii(CONTENT).writeShort(// malformed data at the end of the request msg
0);
HttpRequest request = client.post("/").setHeader(CONTENT_LENGTH, valueOf(CONTENT.length())).setHeader(CONTENT_TYPE, TEXT_PLAIN).payloadBody(malformedBody);
ReservedBlockingHttpConnection connection = client.reserveConnection(request);
CountDownLatch connectionClosedLatch = new CountDownLatch(1);
connection.connectionContext().onClose().whenFinally(connectionClosedLatch::countDown).subscribe();
assertThrows(IOException.class, () -> connection.request(request));
// Server should close the connection:
connectionClosedLatch.await();
}
}
use of io.servicetalk.http.api.BlockingHttpClient in project servicetalk by apple.
the class ServerEffectiveStrategyTest method asyncStreaming.
@ParameterizedTest
@EnumSource(ServerStrategyCase.class)
void asyncStreaming(final ServerStrategyCase strategyCase) throws Exception {
try (Params params = strategyCase.apply(ServiceType.AsyncStreaming)) {
assertThat("Null params supplied", params, notNullValue());
BlockingHttpClient client = params.startAsyncStreaming();
client.request(client.get("/").payloadBody(client.executionContext().bufferAllocator().fromAscii("Hello")));
params.verifyOffloads();
}
}
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 BasicAuthStrategyInfluencerTest method defaultOffloads.
@Test
void defaultOffloads() throws Exception {
BlockingHttpClient client = setup(false);
assert service != null;
HttpResponse response = makeRequest(client);
assertThat("Unexpected response.", response.status().code(), is(200));
service.assertHandleOffload(not(startsWith(IO_EXECUTOR_NAME_PREFIX)));
service.assertRequestOffload(not(startsWith(IO_EXECUTOR_NAME_PREFIX)));
service.assertResponseOffload(not(startsWith(IO_EXECUTOR_NAME_PREFIX)));
}
use of io.servicetalk.http.api.BlockingHttpClient in project servicetalk by apple.
the class PredicateRouterOffloadingTest method predicateOffloadedAndNotRoute.
@ParameterizedTest
@EnumSource(RouteServiceType.class)
void predicateOffloadedAndNotRoute(RouteServiceType routeServiceType) throws Exception {
this.routeServiceType = routeServiceType;
assumeSafeToDisableOffloading(routeServiceType);
final HttpPredicateRouterBuilder routerBuilder = newRouterBuilder();
serverBuilder.executor(executionContextRule.executor());
routeServiceType.addThreadRecorderService(routerBuilder.when(this::recordRouterThread).executionStrategy(offloadNever()), this::recordThread);
final BlockingHttpClient client = buildServerAndClient(routerBuilder.buildStreaming());
client.request(client.get("/"));
verifyAllOffloadPointsRecorded();
// Server is still offloaded, noOffloadsStrategy at route level isn't enough to disable offloading
assertRouteAndPredicateOffloaded();
}
Aggregations