@Test public void testNoLogging() throws Exception { TestLoggerFactory factory = testLogging(); assertFalse(factory.hasName("io.netty.handler.codec.http2.Http2FrameLogger")); }
@Test public void testRequestTimeoutCanceledWhenRequestHasAnOtherError() { AtomicReference<Throwable> exception = new AtomicReference<>(); // There is no server running, should fail to connect client.request(HttpMethod.GET, DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, DEFAULT_TEST_URI, onFailure(exception::set)) .setTimeout(800) .end(); vertx.setTimer(1500, id -> { assertNotNull("Expected an exception to be set", exception.get()); assertFalse("Expected to not end with timeout exception, but did: " + exception.get(), exception.get() instanceof TimeoutException); testComplete(); }); await(); }
HttpConnection conn = req.connection(); req.exceptionHandler(err -> { assertFalse(Thread.holdsLock(conn)); complete(); }); HttpServerResponse resp = req.response(); resp.exceptionHandler(err -> { assertFalse(Thread.holdsLock(conn)); complete(); }); resp.closeHandler(v -> { assertFalse(Thread.holdsLock(conn)); complete(); }); conn.closeHandler(err -> { assertFalse(Thread.holdsLock(conn)); complete(); }); HttpConnection conn = resp.request().connection(); resp.exceptionHandler(err -> { assertFalse(Thread.holdsLock(conn)); complete(); }); conn.closeHandler(v -> { assertFalse(Thread.holdsLock(conn)); complete(); });
@Test public void testUseResponseAfterComplete() throws Exception { server.requestHandler(req -> { HttpServerResponse resp = req.response(); assertFalse(resp.ended()); resp.end(); assertTrue(resp.ended()); checkHttpServerResponse(resp); testComplete(); }); startServer(); client.getNow(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, DEFAULT_TEST_URI, noOpHandler()); await(); }
assertEquals(1, respEndHandlerCount.get()); assertTrue(resp.closed()); assertFalse(resp.ended()); try { resp.end();
Buffer body = Buffer.buffer(); req.handler(buff -> { assertFalse(paused.get()); body.appendBuffer(buff); });
private void drainingServer(Consumer<Future<Void>> consumer) { Future<Void> resumeFuture = Future.future(); server.requestHandler(req -> { req.response().setChunked(true); assertFalse(req.response().writeQueueFull()); req.response().setWriteQueueMaxSize(1000); Buffer buff = TestUtils.randomBuffer(10000); //Send data until the buffer is full vertx.setPeriodic(1, id -> { req.response().write(buff); if (req.response().writeQueueFull()) { vertx.cancelTimer(id); req.response().drainHandler(v -> { assertFalse(req.response().writeQueueFull()); testComplete(); }); // Tell the client to resume resumeFuture.complete(); } }); }); server.listen(onSuccess(s -> consumer.accept(resumeFuture))); }
@Test public void testContainsValueString() { server.requestHandler(req -> { assertTrue(req.headers().contains("Foo", "foo", false)); assertFalse(req.headers().contains("Foo", "fOo", false)); req.response().putHeader("quux", "quux"); req.response().end(); }); server.listen(onSuccess(server -> { HttpClientRequest req = client.request(HttpMethod.GET, DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, DEFAULT_TEST_URI, onSuccess(resp -> { assertTrue(resp.headers().contains("Quux", "quux", false)); assertFalse(resp.headers().contains("Quux", "quUx", false)); testComplete(); })); req.putHeader("foo", "foo"); req.end(); })); await(); }
@Test public void testClientRequestExceptionHandlerCalledWhenExceptionOnDrainHandler() { pausingServer(resumeFuture -> { HttpClientRequest req = client.request(HttpMethod.GET, DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, DEFAULT_TEST_URI, noOpHandler()); req.setChunked(true); assertFalse(req.writeQueueFull()); req.setWriteQueueMaxSize(1000); Buffer buff = TestUtils.randomBuffer(10000); AtomicBoolean failed = new AtomicBoolean(); vertx.setPeriodic(1, id -> { req.write(buff); if (req.writeQueueFull()) { vertx.cancelTimer(id); req.drainHandler(v -> { throw new RuntimeException("error"); }) .exceptionHandler(t -> { // Called a second times when testComplete is called and close the http client if (failed.compareAndSet(false, true)) { testComplete(); } }); // Tell the server to resume resumeFuture.complete(); } }); }); await(); }
@Test public void testClientDrainHandler() { pausingServer(resumeFuture -> { HttpClientRequest req = client.request(HttpMethod.GET, DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, DEFAULT_TEST_URI, noOpHandler()); req.setChunked(true); assertFalse(req.writeQueueFull()); req.setWriteQueueMaxSize(1000); Buffer buff = TestUtils.randomBuffer(10000); vertx.setPeriodic(1, id -> { req.write(buff); if (req.writeQueueFull()) { vertx.cancelTimer(id); req.drainHandler(v -> { assertFalse(req.writeQueueFull()); testComplete(); }); // Tell the server to resume resumeFuture.complete(); } }); }); await(); }
@Test public void testDisableIdleTimeoutInPool() throws Exception { server.requestHandler(req -> { req.response().end(); }); startServer(); client.close(); client = vertx.createHttpClient(createBaseClientOptions() .setIdleTimeout(1) .setMaxPoolSize(1) .setKeepAliveTimeout(10) ); client.getNow(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, DEFAULT_TEST_URI, onSuccess(resp -> { resp.endHandler(v1 -> { AtomicBoolean closed = new AtomicBoolean(); resp.request().connection().closeHandler(v2 -> { closed.set(true); }); vertx.setTimer(2000, id -> { assertFalse(closed.get()); testComplete(); }); }); })); await(); }
assertFalse(req.response().headWritten()); if (chunked) { req.response().setChunked(true); req.response().headers().set("Content-Length", String.valueOf(numWrites * chunkSize)); assertFalse(req.response().headWritten()); for (int i = 0; i < numWrites; i++) { Buffer b = TestUtils.randomBuffer(chunkSize);
@Test public void testContainsValueCharSequence() { CharSequence Foo = HttpHeaders.createOptimized("Foo"); CharSequence foo = HttpHeaders.createOptimized("foo"); CharSequence fOo = HttpHeaders.createOptimized("fOo"); CharSequence Quux = HttpHeaders.createOptimized("Quux"); CharSequence quux = HttpHeaders.createOptimized("quux"); CharSequence quUx = HttpHeaders.createOptimized("quUx"); server.requestHandler(req -> { assertTrue(req.headers().contains(Foo, foo, false)); assertFalse(req.headers().contains(Foo, fOo, false)); req.response().putHeader(quux, quux); req.response().end(); }); server.listen(onSuccess(server -> { HttpClientRequest req = client.request(HttpMethod.GET, DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, DEFAULT_TEST_URI, onSuccess(resp -> { assertTrue(resp.headers().contains(Quux, quux, false)); assertFalse(resp.headers().contains(Quux, quUx, false)); testComplete(); })); req.putHeader(foo, foo); req.end(); })); await(); }
@Test public void testRequestEnded() { server.requestHandler(req -> { assertFalse(req.isEnded()); req.endHandler(v -> { assertTrue(req.isEnded());
@Test public void testRequestEndedNoEndHandler() { server.requestHandler(req -> { assertFalse(req.isEnded()); req.response().setStatusCode(200).end(); vertx.setTimer(500, v -> {
@Test public void testNoLogging() throws Exception { TestLoggerFactory factory = testLogging(); assertFalse(factory.hasName("io.netty.handler.codec.http2.Http2FrameLogger")); }
@Test public void testRequestTimeoutCanceledWhenRequestHasAnOtherError() { AtomicReference<Throwable> exception = new AtomicReference<>(); // There is no server running, should fail to connect HttpClientRequest req = client.request(HttpMethod.GET, DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, DEFAULT_TEST_URI, resp -> { fail("End should not be called because the request should fail to connect"); }); req.exceptionHandler(exception::set); req.setTimeout(800); req.end(); vertx.setTimer(1500, id -> { assertNotNull("Expected an exception to be set", exception.get()); assertFalse("Expected to not end with timeout exception, but did: " + exception.get(), exception.get() instanceof TimeoutException); testComplete(); }); await(); }
@Test public void testUseResponseAfterComplete() throws Exception { server.requestHandler(req -> { HttpServerResponse resp = req.response(); assertFalse(resp.ended()); resp.end(); assertTrue(resp.ended()); checkHttpServerResponse(resp); testComplete(); }); startServer(); client.getNow(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, DEFAULT_TEST_URI, noOpHandler()); await(); }
private void drainingServer(Consumer<Future<Void>> consumer) { Future<Void> resumeFuture = Future.future(); server.requestHandler(req -> { req.response().setChunked(true); assertFalse(req.response().writeQueueFull()); req.response().setWriteQueueMaxSize(1000); Buffer buff = TestUtils.randomBuffer(10000); //Send data until the buffer is full vertx.setPeriodic(1, id -> { req.response().write(buff); if (req.response().writeQueueFull()) { vertx.cancelTimer(id); req.response().drainHandler(v -> { assertFalse(req.response().writeQueueFull()); testComplete(); }); // Tell the client to resume resumeFuture.complete(); } }); }); server.listen(onSuccess(s -> consumer.accept(resumeFuture))); }
@Test public void testContainsValueString() { server.requestHandler(req -> { assertTrue(req.headers().contains("Foo", "foo", false)); assertFalse(req.headers().contains("Foo", "fOo", false)); req.response().putHeader("quux", "quux"); req.response().end(); }); server.listen(onSuccess(server -> { HttpClientRequest req = client.request(HttpMethod.GET, DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, DEFAULT_TEST_URI, resp -> { assertTrue(resp.headers().contains("Quux", "quux", false)); assertFalse(resp.headers().contains("Quux", "quUx", false)); testComplete(); }); req.putHeader("foo", "foo"); req.end(); })); await(); }