From ceabb5d352d047a3c9aa77620842375e2c53627f Mon Sep 17 00:00:00 2001 From: Julien Viet Date: Thu, 13 Feb 2020 18:06:03 +0100 Subject: [PATCH] Improve Http1xTest#testHttpClientResponseThrowsExceptionXXXHandler --- .../java/io/vertx/core/http/Http1xTest.java | 30 +++++++++++-------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/src/test/java/io/vertx/core/http/Http1xTest.java b/src/test/java/io/vertx/core/http/Http1xTest.java index e1edefaa9..1c51624dd 100644 --- a/src/test/java/io/vertx/core/http/Http1xTest.java +++ b/src/test/java/io/vertx/core/http/Http1xTest.java @@ -4234,35 +4234,32 @@ public class Http1xTest extends HttpTest { @Test public void testHttpClientResponseThrowsExceptionInResponseHandler() throws Exception { - testHttpClientResponseThrowsExceptionInHandler(null, (resp, latch) -> { - latch.countDown(); - throw new RuntimeException(); + testHttpClientResponseThrowsExceptionInHandler(null, (resp, failure) -> { + throw failure; }); } @Test public void testHttpClientResponseThrowsExceptionInChunkHandler() throws Exception { - testHttpClientResponseThrowsExceptionInHandler("blah", (resp, latch) -> { + testHttpClientResponseThrowsExceptionInHandler("blah", (resp, failure) -> { resp.handler(chunk -> { - latch.countDown(); - throw new RuntimeException(); + throw failure; }); }); } @Test public void testHttpClientResponseThrowsExceptionInEndHandler() throws Exception { - testHttpClientResponseThrowsExceptionInHandler(null, (resp, latch) -> { + testHttpClientResponseThrowsExceptionInHandler(null, (resp, failure) -> { resp.endHandler(v -> { - latch.countDown(); - throw new RuntimeException(); + throw failure; }); }); } private void testHttpClientResponseThrowsExceptionInHandler( String chunk, - BiConsumer handler) throws Exception { + BiConsumer handler) throws Exception { server.requestHandler(req -> { HttpServerResponse resp = req.response(); if (chunk != null) { @@ -4273,15 +4270,22 @@ public class Http1xTest extends HttpTest { }); startServer(testAddress); int num = 50; - CountDownLatch latch = new CountDownLatch(num); + waitFor(num); + RuntimeException failure = new RuntimeException(); for (int i = 0;i < num;i++) { client.request(HttpMethod.GET, testAddress, DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, "/someuri") .setHandler(onSuccess(resp -> { - handler.accept(resp, latch); + ContextInternal ctx = (ContextInternal) vertx.getOrCreateContext(); + ctx.exceptionHandler(err -> { + if (err == failure) { + complete(); + } + }); + handler.accept(resp, failure); })) .end(); } - awaitLatch(latch); + await(); } @Test