# HG changeset patch # User dfuchs # Date 1520618463 0 # Node ID 329e410c9a01efbcbf0205acb83757066a216583 # Parent 7394452786ba2b2c3bde5d42e19bcc5b1e1f7c32 http-client-branch: improved failure report in ThrowingSubscribers diff -r 7394452786ba -r 329e410c9a01 test/jdk/java/net/httpclient/ThrowingSubscribers.java --- a/test/jdk/java/net/httpclient/ThrowingSubscribers.java Fri Mar 09 17:59:11 2018 +0000 +++ b/test/jdk/java/net/httpclient/ThrowingSubscribers.java Fri Mar 09 18:01:03 2018 +0000 @@ -180,16 +180,13 @@ public Object[][] noThrows() { String[] uris = uris(); Object[][] result = new Object[uris.length * 2][]; - //Object[][] result = new Object[uris.length][]; int i = 0; for (boolean sameClient : List.of(false, true)) { - //if (!sameClient) continue; for (String uri: uris()) { result[i++] = new Object[] {uri, sameClient}; } } assert i == uris.length * 2; - // assert i == uris.length ; return result; } @@ -197,21 +194,17 @@ public Object[][] variants() { String[] uris = uris(); Object[][] result = new Object[uris.length * 2 * 2][]; - //Object[][] result = new Object[(uris.length/2) * 2 * 2][]; int i = 0; for (Thrower thrower : List.of( new UncheckedIOExceptionThrower(), new UncheckedCustomExceptionThrower())) { for (boolean sameClient : List.of(false, true)) { for (String uri : uris()) { - // if (uri.contains("http2") || uri.contains("https2")) continue; - // if (!sameClient) continue; result[i++] = new Object[]{uri, sameClient, thrower}; } } } assert i == uris.length * 2 * 2; - //assert Stream.of(result).filter(o -> o != null).count() == result.length; return result; } @@ -367,7 +360,7 @@ response = client.sendAsync(req, handler).join(); } catch (Error | Exception x) { Throwable cause = findCause(x, thrower); - if (cause == null) throw x; + if (cause == null) throw causeNotFound(where, x); System.out.println(now() + "Got expected exception: " + cause); } } else { @@ -376,7 +369,7 @@ } catch (Error | Exception t) { if (thrower.test(t)) { System.out.println(now() + "Got expected exception: " + t); - } else throw t; + } else throw causeNotFound(where, t); } } if (response != null) { @@ -399,6 +392,10 @@ } } + static AssertionError causeNotFound(Where w, Throwable t) { + return new AssertionError("Expected exception not found in " + w, t); + } + interface Thrower extends Consumer, Predicate { } @@ -408,7 +405,11 @@ } final U shouldHaveThrown(Where w, HttpResponse resp, Thrower thrower) { - throw new RuntimeException("Expected exception not thrown in " + w); + String msg = "Expected exception not thrown in " + w + + "\n\tReceived: " + resp + + "\n\tWith body: " + resp.body(); + System.out.println(msg); + throw new RuntimeException(msg); } final List checkAsLines(Where w, HttpResponse> resp, Thrower thrower) { @@ -428,7 +429,7 @@ out.println(now() + "Got expected exception in " + w + ": " + cause); return result; } - throw x; + throw causeNotFound(w, x); } throw new RuntimeException("Expected exception not thrown in " + w); } @@ -455,7 +456,7 @@ out.println(now() + "Got expected exception in " + w + ": " + cause); return result; } - throw x; + throw causeNotFound(w, x); } } return shouldHaveThrown(w, resp, thrower);