@Test public void testIncorrectHttpVersion() throws Exception { server.requestHandler(req -> { NetSocket so = req.netSocket(); so.write(Buffer.buffer("HTTP/1.2 200 OK\r\nContent-Length:5\r\n\r\nHELLO")); so.close(); }); startServer(); AtomicBoolean a = new AtomicBoolean(); HttpClientRequest req = client.request(HttpMethod.GET, DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, DEFAULT_TEST_URI, onFailure(err -> { if (a.compareAndSet(false, true)) { assertTrue("message " + err.getMessage() + " should contain HTTP/1.2", err.getMessage().contains("HTTP/1.2")); } })); req.exceptionHandler(err -> { fail("Should not be called"); }).putHeader("connection", "close") .connectionHandler(conn -> conn.closeHandler(v -> testComplete())) .end(); await(); }
@Test public void testConnectionCloseDuringShouldCallHandleExceptionOnlyOnce() throws Exception { server.requestHandler(req -> { vertx.setTimer(500, id -> { req.connection().close(); }); }); AtomicInteger count = new AtomicInteger(); startServer(); HttpClientRequest post = client.post(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, "/", onFailure(res -> {})); post.setChunked(true); post.write(TestUtils.randomBuffer(10000)); CountDownLatch latch = new CountDownLatch(1); post.exceptionHandler(x-> { count.incrementAndGet(); vertx.setTimer(10, id -> { latch.countDown(); }); }); // then stall until timeout and the exception handler will be called. awaitLatch(latch); assertEquals(count.get(), 1); }
HttpClientRequest req1 = client.get(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, "/somepath", onFailure(err -> { if (fail1.compareAndSet(false, true)) { assertEquals(IllegalArgumentException.class, err.getClass()); // invalid version format HttpClientRequest req2 = client.get(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, "/somepath", onFailure(err -> { if (fail2.compareAndSet(false, true)) { assertEquals(IllegalArgumentException.class, err.getClass()); // Closed
}); startServer(); HttpClientRequest req = client.get(DEFAULT_HTTP_PORT, DEFAULT_HTTPS_HOST, "/", onFailure(err -> {})); req.setChunked(true); for (int i = 0; i < buffer.length() / 8192; i++) {
@Test public void testMaxWaitQueueSizeIsRespected() throws Exception { client.close(); client = vertx.createHttpClient(new HttpClientOptions().setDefaultHost(DEFAULT_HTTP_HOST).setDefaultPort(DEFAULT_HTTP_PORT) .setPipelining(false).setMaxWaitQueueSize(0).setMaxPoolSize(2)); waitFor(3); Set<String> expected = new HashSet<>(Arrays.asList("/1", "/2")); server.requestHandler(req -> { assertTrue(expected.contains(req.path())); complete(); }); startServer(); HttpClientRequest req1 = client.get("/1", onFailure(err -> { })); HttpClientRequest req2 = client.get("/2", onFailure(resp -> { })); HttpClientRequest req3 = client.get("/3", onFailure(t -> { assertTrue("Incorrect exception: " + t.getClass().getName(), t instanceof ConnectionPoolTooBusyException); complete(); })); req1.end(); req2.end(); req3.end(); await(); }
@Repeat(times = 10) @Test public void testCloseServerConnectionWithPendingMessages() throws Exception { int n = 5; server.requestHandler(req -> { vertx.setTimer(100, id -> { req.response().close(); }); }); startServer(); client.close(); client = vertx.createHttpClient(new HttpClientOptions().setMaxPoolSize(n).setPipelining(true)); AtomicBoolean completed = new AtomicBoolean(); for (int i = 0; i < n * 2; i++) { client.get(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, DEFAULT_TEST_URI, onFailure(resp -> { })) .connectionHandler(conn -> { conn.closeHandler(v -> { if (completed.compareAndSet(false, true)) { testComplete(); } }); }).end(); } await(); }
req = client.request(HttpMethod.GET, reqOptions, onFailure(err -> { latch.countDown(); }));
}); req1.end(); HttpClientRequest req2 = client.post(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, "/somepath", onFailure(err -> complete())); req2.sendHead(v -> { assertTrue(req2.reset());
}); req1.end(); HttpClientRequest req2 = client.post(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, "/somepath", onFailure(resp -> { })); req2.sendHead();
client.close(); client = vertx.createHttpClient(new HttpClientOptions().setMaxPoolSize(1).setPipelining(pipelined).setKeepAlive(true)); HttpClientRequest req1 = client.get(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, "/1", onFailure(err -> {})); if (pipelined) { requestReceived.thenAccept(v -> {
HttpClientRequest req = client.request(HttpMethod.GET, DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, DEFAULT_TEST_URI, onFailure(t -> { assertTrue(t instanceof TimeoutException); }));
client.close(); client = vertx.createHttpClient(new HttpClientOptions().setMaxPoolSize(1).setPipelining(pipelined).setKeepAlive(true)); HttpClientRequest req1 = client.get(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, "/somepath", onFailure(err -> {})); if (pipelined) { req1.connectionHandler(conn -> conn.closeHandler(v2 -> {