use of io.servicetalk.http.api.HttpResponseStatus.BAD_REQUEST in project servicetalk by apple.
the class HttpServerMultipleRequestsTest method consumeOfRequestBodyDoesNotCloseConnection.
@Disabled("https://github.com/apple/servicetalk/issues/981")
@Test
void consumeOfRequestBodyDoesNotCloseConnection() throws Exception {
StreamingHttpService service = (ctx, request, responseFactory) -> {
request.messageBody().ignoreElements().subscribe();
CharSequence requestId = request.headers().get(REQUEST_ID_HEADER);
if (requestId != null) {
StreamingHttpResponse response = responseFactory.ok();
response.headers().set(REQUEST_ID_HEADER, requestId);
return succeeded(response);
} else {
return succeeded(responseFactory.newResponse(BAD_REQUEST));
}
};
final int concurrency = 10;
final int numRequests = 10;
CompositeCloseable compositeCloseable = AsyncCloseables.newCompositeCloseable();
ServerContext ctx = compositeCloseable.append(HttpServers.forAddress(localAddress(0)).ioExecutor(serverContext.ioExecutor()).executor(serverContext.executor()).executionStrategy(defaultStrategy()).listenStreamingAndAwait(service));
ExecutorService executorService = Executors.newCachedThreadPool();
try {
AtomicReference<Throwable> causeRef = new AtomicReference<>();
CyclicBarrier barrier = new CyclicBarrier(concurrency);
CountDownLatch latch = new CountDownLatch(concurrency);
for (int i = 0; i < concurrency; ++i) {
final int finalI = i;
executorService.execute(() -> {
try {
StreamingHttpClient client = compositeCloseable.append(HttpClients.forResolvedAddress(serverHostAndPort(ctx)).protocols(h1().maxPipelinedRequests(numRequests).build()).ioExecutor(clientContext.ioExecutor()).executor(clientContext.executor()).executionStrategy(defaultStrategy()).buildStreaming());
ReservedStreamingHttpConnection connection = client.reserveConnection(client.get("/")).toFuture().get();
compositeCloseable.append(connection);
barrier.await();
for (int x = 0; x < numRequests; ++x) {
makeClientRequestWithId(connection, "thread=" + finalI + " request=" + x);
}
} catch (Throwable cause) {
causeRef.compareAndSet(null, cause);
} finally {
latch.countDown();
}
});
}
latch.await();
assertNull(causeRef.get());
} finally {
executorService.shutdown();
compositeCloseable.close();
}
}
Aggregations