@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(); }
private void testAccessNetSocketPendingResponseData(boolean pause) { server.requestHandler(req -> { NetSocket so = req.netSocket(); so.write("hello"); }); server.listen(onSuccess(s -> { HttpClientRequest req = client.request(HttpMethod.CONNECT, DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, DEFAULT_TEST_URI, onSuccess(resp -> { NetSocket so = resp.netSocket(); assertNotNull(so); so.handler(buff -> { // With HTTP/1.1 the buffer is received immediately but delivered asynchronously assertEquals("hello", buff.toString()); testComplete(); }); if (pause) { so.pause(); vertx.setTimer(100, id -> { so.resume(); }); } })); req.sendHead(); })); await(); }
@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(); }
private void testAccessNetSocketPendingResponseData(boolean pause) { server.requestHandler(req -> { NetSocket so = req.netSocket(); so.write("hello"); }); server.listen(onSuccess(s -> { HttpClientRequest req = client.request(HttpMethod.CONNECT, DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, DEFAULT_TEST_URI, resp -> { NetSocket so = resp.netSocket(); assertNotNull(so); so.handler(buff -> { // With HTTP/1.1 the buffer is received immediately but delivered asynchronously assertEquals("hello", buff.toString()); testComplete(); }); if (pause) { so.pause(); vertx.setTimer(100, id -> { so.resume(); }); } }); req.sendHead(); })); await(); }