use of io.vertx.core.http.impl.HttpClientRequestImpl in project vert.x by eclipse.
the class Http1xTest method testRecyclePipelinedConnection.
@Test
public void testRecyclePipelinedConnection() throws Exception {
CountDownLatch listenLatch = new CountDownLatch(1);
CountDownLatch doneLatch = new CountDownLatch(2);
List<String> responses = new ArrayList<>();
server.requestHandler(req -> {
responses.add(req.path());
req.response().end();
doneLatch.countDown();
});
server.listen(onSuccess(s -> {
listenLatch.countDown();
}));
awaitLatch(listenLatch);
client.close();
client = vertx.createHttpClient(new HttpClientOptions().setMaxPoolSize(1).setPipelining(true).setKeepAlive(true));
CountDownLatch respLatch = new CountDownLatch(2);
HttpClientRequestImpl req = (HttpClientRequestImpl) client.get(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, "/first", resp -> {
fail();
});
// Simulate the connection timed out
req.handleException(new Throwable());
// When connected, the connection should be recycled
req.end();
client.get(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, "/second", resp -> {
assertEquals(200, resp.statusCode());
resp.endHandler(v -> {
respLatch.countDown();
});
}).exceptionHandler(this::fail).end();
client.get(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, "/third", resp -> {
assertEquals(200, resp.statusCode());
resp.endHandler(v -> {
respLatch.countDown();
});
}).exceptionHandler(this::fail).end();
awaitLatch(doneLatch);
assertEquals(Arrays.asList("/second", "/third"), responses);
awaitLatch(respLatch);
server.close();
}
Aggregations