Search in sources :

Example 1 with HttpClientRequestImpl

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();
}
Also used : IntStream(java.util.stream.IntStream) java.util(java.util) io.vertx.core(io.vertx.core) io.vertx.core.impl(io.vertx.core.impl) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) TimeoutException(java.util.concurrent.TimeoutException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TooLongFrameException(io.netty.handler.codec.TooLongFrameException) Test(org.junit.Test) CompletableFuture(java.util.concurrent.CompletableFuture) io.vertx.core.net(io.vertx.core.net) AtomicReference(java.util.concurrent.atomic.AtomicReference) io.vertx.core.http(io.vertx.core.http) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) JsonArray(io.vertx.core.json.JsonArray) CountDownLatch(java.util.concurrent.CountDownLatch) HttpClientRequestImpl(io.vertx.core.http.impl.HttpClientRequestImpl) Buffer(io.vertx.core.buffer.Buffer) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TestUtils(io.vertx.test.core.TestUtils) RecordParser(io.vertx.core.parsetools.RecordParser) Pump(io.vertx.core.streams.Pump) JsonObject(io.vertx.core.json.JsonObject) HttpClientRequestImpl(io.vertx.core.http.impl.HttpClientRequestImpl) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Aggregations

TooLongFrameException (io.netty.handler.codec.TooLongFrameException)1 io.vertx.core (io.vertx.core)1 Buffer (io.vertx.core.buffer.Buffer)1 io.vertx.core.http (io.vertx.core.http)1 HttpClientRequestImpl (io.vertx.core.http.impl.HttpClientRequestImpl)1 io.vertx.core.impl (io.vertx.core.impl)1 JsonArray (io.vertx.core.json.JsonArray)1 JsonObject (io.vertx.core.json.JsonObject)1 io.vertx.core.net (io.vertx.core.net)1 RecordParser (io.vertx.core.parsetools.RecordParser)1 Pump (io.vertx.core.streams.Pump)1 TestUtils (io.vertx.test.core.TestUtils)1 java.util (java.util)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 TimeUnit (java.util.concurrent.TimeUnit)1 TimeoutException (java.util.concurrent.TimeoutException)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1