@Test public void testServerDrainHandler() { drainingServer(resumeFuture -> { client.request(HttpMethod.GET, DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, DEFAULT_TEST_URI, onSuccess(resp -> { resp.pause(); resumeFuture.setHandler(ar -> resp.resume()); })).end(); }); await(); }
vertx.setTimer(500, id -> { paused.set(false); resp.resume(); }); }));
@Test public void testHttpClientResumeConnectionOnResponseOnLastMessage() throws Exception { server.requestHandler(req -> req.response().end("ok")); startServer(); client.close(); client = vertx.createHttpClient(new HttpClientOptions().setKeepAlive(true).setMaxPoolSize(1)); client.getNow(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, DEFAULT_TEST_URI, onSuccess(resp1 -> { resp1.pause(); // The connection resume is asynchronous and the end message will be received before connection resume happens resp1.resume(); client.getNow(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, DEFAULT_TEST_URI, onSuccess(resp2 -> { testComplete(); })); })); await(); }
testComplete(); }); resp.resume(); }); });
resp.pause(); vertx.setTimer(1, id -> { resp.resume(); }); });
}); whenFull.setHandler(v -> { resp.resume(); }); }));
@Test public void testHttpClientResponseBufferedWithPausedEnd() throws Exception { AtomicInteger i = new AtomicInteger(); server.requestHandler(req -> { req.response().end("HelloWorld" + i.incrementAndGet()); }); startServer(); client.close(); client = vertx.createHttpClient(new HttpClientOptions().setMaxPoolSize(1).setKeepAlive(true)); client.getNow(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, DEFAULT_TEST_URI, onSuccess(resp1 -> { // Response is paused but request is put back in the pool since the HTTP response fully arrived // but the response it's not yet delivered to the application as we pause the response resp1.pause(); // Do a request on the same connection client.getNow(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, DEFAULT_TEST_URI, onSuccess(resp2 -> { resp2.bodyHandler(body2 -> { // When the response arrives -> resume the first request assertEquals("HelloWorld2", body2.toString()); resp1.bodyHandler(body1 -> { assertEquals("HelloWorld1", body1.toString()); testComplete(); }); resp1.resume(); }); })); })); await(); }
@Override public ReadStream<Buffer> resume() { if (httpClientResponse != null) { httpClientResponse.resume(); } else { endHandler.handle(null); } return null; } }
@Test public void testClearPausedBuffersWhenResponseEnds() throws Exception { Buffer data = TestUtils.randomBuffer(20); int num = 10; waitFor(num); server.requestHandler(req -> { req.response().end(data); }); startServer(); client.close(); client = vertx.createHttpClient(createBaseClientOptions().setMaxPoolSize(1).setKeepAlive(true)); for (int i = 0;i < num;i++) { client.request(HttpMethod.GET, DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, DEFAULT_TEST_URI, onSuccess(resp -> { resp.bodyHandler(buff -> { assertEquals(data, buff); complete(); }); resp.pause(); vertx.setTimer(10, id -> { resp.resume(); }); })).end(); } await(); }
@Test public void testServerDrainHandler() { drainingServer(resumeFuture -> { client.request(HttpMethod.GET, DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, DEFAULT_TEST_URI, resp -> { resp.pause(); resumeFuture.setHandler(ar -> resp.resume()); }).end(); }); await(); }
vertx.setTimer(500, id -> { paused.set(false); resp.resume(); }); });
@Test public void testHttpClientResumeConnectionOnResponseOnLastMessage() throws Exception { server.requestHandler(req -> req.response().end("ok")); startServer(); client.close(); client = vertx.createHttpClient(new HttpClientOptions().setKeepAlive(true).setMaxPoolSize(1)); client.getNow(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, DEFAULT_TEST_URI, resp1 -> { resp1.pause(); // The connection resume is asynchronous and the end message will be received before connection resume happens resp1.resume(); client.getNow(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, DEFAULT_TEST_URI, resp2 -> { testComplete(); }); }); await(); }
testComplete(); }); resp.resume(); }); });
@Override public void transmit() { logger.debug("Resuming"); clientResponse.resume(); }
@Override public ReadStream<Buffer> resume() { if (httpClientResponse != null) { httpClientResponse.resume(); } else { endHandler.handle(null); } return null; } }
@Override public ReadStream<Buffer> resume() { if (httpClientResponse != null) { httpClientResponse.resume(); } else { endHandler.handle(null); } return null; } }
resp.pause(); vertx.setTimer(1, id -> { resp.resume(); }); });
}); whenFull.setHandler(v -> { resp.resume(); }); });
@Test public void testHttpClientResponseBufferedWithPausedEnd() throws Exception { AtomicInteger i = new AtomicInteger(); server.requestHandler(req -> { req.response().end("HelloWorld" + i.incrementAndGet()); }); startServer(); client.close(); client = vertx.createHttpClient(new HttpClientOptions().setMaxPoolSize(1).setKeepAlive(true)); client.getNow(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, DEFAULT_TEST_URI, resp1 -> { // Response is paused but request is put back in the pool since the HTTP response fully arrived // but the response it's not yet delivered to the application as we pause the response resp1.pause(); // Do a request on the same connection client.getNow(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, DEFAULT_TEST_URI, resp2 -> { resp2.bodyHandler(body2 -> { // When the response arrives -> resume the first request assertEquals("HelloWorld2", body2.toString()); resp1.bodyHandler(body1 -> { assertEquals("HelloWorld1", body1.toString()); testComplete(); }); resp1.resume(); }); }); }); await(); }
@Test public void testClearPausedBuffersWhenResponseEnds() throws Exception { Buffer data = TestUtils.randomBuffer(20); int num = 10; waitFor(num); server.requestHandler(req -> { req.response().end(data); }); startServer(); client.close(); client = vertx.createHttpClient(createBaseClientOptions().setMaxPoolSize(1).setKeepAlive(true)); for (int i = 0;i < num;i++) { client.request(HttpMethod.GET, DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, DEFAULT_TEST_URI, resp -> { resp.bodyHandler(buff -> { assertEquals(data, buff); complete(); }); resp.pause(); vertx.setTimer(10, id -> { resp.resume(); }); }).end(); } await(); }