--- jsr166/src/test/tck/CompletableFutureTest.java 2018/09/24 17:13:37 1.213 +++ jsr166/src/test/tck/CompletableFutureTest.java 2018/11/24 21:23:31 1.220 @@ -926,17 +926,19 @@ public class CompletableFutureTest exten for (boolean createIncomplete : new boolean[] { true, false }) for (Integer v1 : new Integer[] { 1, null }) { + final AtomicInteger ran = new AtomicInteger(0); final CompletableFuture f = new CompletableFuture<>(); if (!createIncomplete) assertTrue(f.complete(v1)); final CompletableFuture g = m.exceptionally (f, (Throwable t) -> { - threadFail("should not be called"); - return null; // unreached + ran.getAndIncrement(); + throw new AssertionError("should not be called"); }); if (createIncomplete) assertTrue(f.complete(v1)); checkCompletedNormally(g, v1); checkCompletedNormally(f, v1); + assertEquals(0, ran.get()); }} /** @@ -948,21 +950,21 @@ public class CompletableFutureTest exten for (boolean createIncomplete : new boolean[] { true, false }) for (Integer v1 : new Integer[] { 1, null }) { - final AtomicInteger a = new AtomicInteger(0); + final AtomicInteger ran = new AtomicInteger(0); final CFException ex = new CFException(); final CompletableFuture f = new CompletableFuture<>(); if (!createIncomplete) f.completeExceptionally(ex); final CompletableFuture g = m.exceptionally (f, (Throwable t) -> { m.checkExecutionMode(); - threadAssertSame(t, ex); - a.getAndIncrement(); + assertSame(t, ex); + ran.getAndIncrement(); return v1; }); if (createIncomplete) f.completeExceptionally(ex); checkCompletedNormally(g, v1); - assertEquals(1, a.get()); + assertEquals(1, ran.get()); }} /** @@ -973,7 +975,7 @@ public class CompletableFutureTest exten for (ExecutionMode m : ExecutionMode.values()) for (boolean createIncomplete : new boolean[] { true, false }) { - final AtomicInteger a = new AtomicInteger(0); + final AtomicInteger ran = new AtomicInteger(0); final CFException ex1 = new CFException(); final CFException ex2 = new CFException(); final CompletableFuture f = new CompletableFuture<>(); @@ -981,15 +983,15 @@ public class CompletableFutureTest exten final CompletableFuture g = m.exceptionally (f, (Throwable t) -> { m.checkExecutionMode(); - threadAssertSame(t, ex1); - a.getAndIncrement(); + assertSame(t, ex1); + ran.getAndIncrement(); throw ex2; }); if (createIncomplete) f.completeExceptionally(ex1); checkCompletedWithWrappedException(g, ex2); checkCompletedExceptionally(f, ex1); - assertEquals(1, a.get()); + assertEquals(1, ran.get()); }} /** @@ -1001,22 +1003,22 @@ public class CompletableFutureTest exten for (boolean createIncomplete : new boolean[] { true, false }) for (Integer v1 : new Integer[] { 1, null }) { - final AtomicInteger a = new AtomicInteger(0); + final AtomicInteger ran = new AtomicInteger(0); final CompletableFuture f = new CompletableFuture<>(); if (!createIncomplete) assertTrue(f.complete(v1)); final CompletableFuture g = m.whenComplete (f, (Integer result, Throwable t) -> { m.checkExecutionMode(); - threadAssertSame(result, v1); - threadAssertNull(t); - a.getAndIncrement(); + assertSame(result, v1); + assertNull(t); + ran.getAndIncrement(); }); if (createIncomplete) assertTrue(f.complete(v1)); checkCompletedNormally(g, v1); checkCompletedNormally(f, v1); - assertEquals(1, a.get()); + assertEquals(1, ran.get()); }} /** @@ -1027,7 +1029,7 @@ public class CompletableFutureTest exten for (ExecutionMode m : ExecutionMode.values()) for (boolean createIncomplete : new boolean[] { true, false }) { - final AtomicInteger a = new AtomicInteger(0); + final AtomicInteger ran = new AtomicInteger(0); final CFException ex = new CFException(); final CompletableFuture f = new CompletableFuture<>(); if (!createIncomplete) f.completeExceptionally(ex); @@ -1035,15 +1037,15 @@ public class CompletableFutureTest exten (f, (Integer result, Throwable t) -> { m.checkExecutionMode(); - threadAssertNull(result); - threadAssertSame(t, ex); - a.getAndIncrement(); + assertNull(result); + assertSame(t, ex); + ran.getAndIncrement(); }); if (createIncomplete) f.completeExceptionally(ex); checkCompletedWithWrappedException(g, ex); checkCompletedExceptionally(f, ex); - assertEquals(1, a.get()); + assertEquals(1, ran.get()); }} /** @@ -1055,22 +1057,22 @@ public class CompletableFutureTest exten for (boolean mayInterruptIfRunning : new boolean[] { true, false }) for (boolean createIncomplete : new boolean[] { true, false }) { - final AtomicInteger a = new AtomicInteger(0); + final AtomicInteger ran = new AtomicInteger(0); final CompletableFuture f = new CompletableFuture<>(); if (!createIncomplete) assertTrue(f.cancel(mayInterruptIfRunning)); final CompletableFuture g = m.whenComplete (f, (Integer result, Throwable t) -> { m.checkExecutionMode(); - threadAssertNull(result); - threadAssertTrue(t instanceof CancellationException); - a.getAndIncrement(); + assertNull(result); + assertTrue(t instanceof CancellationException); + ran.getAndIncrement(); }); if (createIncomplete) assertTrue(f.cancel(mayInterruptIfRunning)); checkCompletedWithWrappedCancellationException(g); checkCancelled(f); - assertEquals(1, a.get()); + assertEquals(1, ran.get()); }} /** @@ -1082,7 +1084,7 @@ public class CompletableFutureTest exten for (ExecutionMode m : ExecutionMode.values()) for (Integer v1 : new Integer[] { 1, null }) { - final AtomicInteger a = new AtomicInteger(0); + final AtomicInteger ran = new AtomicInteger(0); final CFException ex = new CFException(); final CompletableFuture f = new CompletableFuture<>(); if (!createIncomplete) assertTrue(f.complete(v1)); @@ -1090,16 +1092,16 @@ public class CompletableFutureTest exten (f, (Integer result, Throwable t) -> { m.checkExecutionMode(); - threadAssertSame(result, v1); - threadAssertNull(t); - a.getAndIncrement(); + assertSame(result, v1); + assertNull(t); + ran.getAndIncrement(); throw ex; }); if (createIncomplete) assertTrue(f.complete(v1)); checkCompletedWithWrappedException(g, ex); checkCompletedNormally(f, v1); - assertEquals(1, a.get()); + assertEquals(1, ran.get()); }} /** @@ -1111,7 +1113,7 @@ public class CompletableFutureTest exten for (boolean createIncomplete : new boolean[] { true, false }) for (ExecutionMode m : ExecutionMode.values()) { - final AtomicInteger a = new AtomicInteger(0); + final AtomicInteger ran = new AtomicInteger(0); final CFException ex1 = new CFException(); final CFException ex2 = new CFException(); final CompletableFuture f = new CompletableFuture<>(); @@ -1121,9 +1123,9 @@ public class CompletableFutureTest exten (f, (Integer result, Throwable t) -> { m.checkExecutionMode(); - threadAssertSame(t, ex1); - threadAssertNull(result); - a.getAndIncrement(); + assertSame(t, ex1); + assertNull(result); + ran.getAndIncrement(); throw ex2; }); if (createIncomplete) f.completeExceptionally(ex1); @@ -1134,7 +1136,7 @@ public class CompletableFutureTest exten assertEquals(1, ex1.getSuppressed().length); assertSame(ex2, ex1.getSuppressed()[0]); } - assertEquals(1, a.get()); + assertEquals(1, ran.get()); }} /** @@ -1147,22 +1149,22 @@ public class CompletableFutureTest exten for (Integer v1 : new Integer[] { 1, null }) { final CompletableFuture f = new CompletableFuture<>(); - final AtomicInteger a = new AtomicInteger(0); + final AtomicInteger ran = new AtomicInteger(0); if (!createIncomplete) assertTrue(f.complete(v1)); final CompletableFuture g = m.handle (f, (Integer result, Throwable t) -> { m.checkExecutionMode(); - threadAssertSame(result, v1); - threadAssertNull(t); - a.getAndIncrement(); + assertSame(result, v1); + assertNull(t); + ran.getAndIncrement(); return inc(v1); }); if (createIncomplete) assertTrue(f.complete(v1)); checkCompletedNormally(g, inc(v1)); checkCompletedNormally(f, v1); - assertEquals(1, a.get()); + assertEquals(1, ran.get()); }} /** @@ -1175,23 +1177,23 @@ public class CompletableFutureTest exten for (Integer v1 : new Integer[] { 1, null }) { final CompletableFuture f = new CompletableFuture<>(); - final AtomicInteger a = new AtomicInteger(0); + final AtomicInteger ran = new AtomicInteger(0); final CFException ex = new CFException(); if (!createIncomplete) f.completeExceptionally(ex); final CompletableFuture g = m.handle (f, (Integer result, Throwable t) -> { m.checkExecutionMode(); - threadAssertNull(result); - threadAssertSame(t, ex); - a.getAndIncrement(); + assertNull(result); + assertSame(t, ex); + ran.getAndIncrement(); return v1; }); if (createIncomplete) f.completeExceptionally(ex); checkCompletedNormally(g, v1); checkCompletedExceptionally(f, ex); - assertEquals(1, a.get()); + assertEquals(1, ran.get()); }} /** @@ -1205,22 +1207,22 @@ public class CompletableFutureTest exten for (Integer v1 : new Integer[] { 1, null }) { final CompletableFuture f = new CompletableFuture<>(); - final AtomicInteger a = new AtomicInteger(0); + final AtomicInteger ran = new AtomicInteger(0); if (!createIncomplete) assertTrue(f.cancel(mayInterruptIfRunning)); final CompletableFuture g = m.handle (f, (Integer result, Throwable t) -> { m.checkExecutionMode(); - threadAssertNull(result); - threadAssertTrue(t instanceof CancellationException); - a.getAndIncrement(); + assertNull(result); + assertTrue(t instanceof CancellationException); + ran.getAndIncrement(); return v1; }); if (createIncomplete) assertTrue(f.cancel(mayInterruptIfRunning)); checkCompletedNormally(g, v1); checkCancelled(f); - assertEquals(1, a.get()); + assertEquals(1, ran.get()); }} /** @@ -1233,23 +1235,23 @@ public class CompletableFutureTest exten for (Integer v1 : new Integer[] { 1, null }) { final CompletableFuture f = new CompletableFuture<>(); - final AtomicInteger a = new AtomicInteger(0); + final AtomicInteger ran = new AtomicInteger(0); final CFException ex = new CFException(); if (!createIncomplete) assertTrue(f.complete(v1)); final CompletableFuture g = m.handle (f, (Integer result, Throwable t) -> { m.checkExecutionMode(); - threadAssertSame(result, v1); - threadAssertNull(t); - a.getAndIncrement(); + assertSame(result, v1); + assertNull(t); + ran.getAndIncrement(); throw ex; }); if (createIncomplete) assertTrue(f.complete(v1)); checkCompletedWithWrappedException(g, ex); checkCompletedNormally(f, v1); - assertEquals(1, a.get()); + assertEquals(1, ran.get()); }} /** @@ -1261,7 +1263,7 @@ public class CompletableFutureTest exten for (boolean createIncomplete : new boolean[] { true, false }) for (ExecutionMode m : ExecutionMode.values()) { - final AtomicInteger a = new AtomicInteger(0); + final AtomicInteger ran = new AtomicInteger(0); final CFException ex1 = new CFException(); final CFException ex2 = new CFException(); final CompletableFuture f = new CompletableFuture<>(); @@ -1271,16 +1273,16 @@ public class CompletableFutureTest exten (f, (Integer result, Throwable t) -> { m.checkExecutionMode(); - threadAssertNull(result); - threadAssertSame(ex1, t); - a.getAndIncrement(); + assertNull(result); + assertSame(ex1, t); + ran.getAndIncrement(); throw ex2; }); if (createIncomplete) f.completeExceptionally(ex1); checkCompletedWithWrappedException(g, ex2); checkCompletedExceptionally(f, ex1); - assertEquals(1, a.get()); + assertEquals(1, ran.get()); }} /** @@ -3116,30 +3118,30 @@ public class CompletableFutureTest exten case 0: assertTrue(f.complete(v1)); assertTrue(g.completeExceptionally(ex)); - h = m.thenCompose(f, (x -> g)); + h = m.thenCompose(f, x -> g); break; case 1: assertTrue(f.complete(v1)); - h = m.thenCompose(f, (x -> g)); + h = m.thenCompose(f, x -> g); assertTrue(g.completeExceptionally(ex)); break; case 2: assertTrue(g.completeExceptionally(ex)); assertTrue(f.complete(v1)); - h = m.thenCompose(f, (x -> g)); + h = m.thenCompose(f, x -> g); break; case 3: assertTrue(g.completeExceptionally(ex)); - h = m.thenCompose(f, (x -> g)); + h = m.thenCompose(f, x -> g); assertTrue(f.complete(v1)); break; case 4: - h = m.thenCompose(f, (x -> g)); + h = m.thenCompose(f, x -> g); assertTrue(f.complete(v1)); assertTrue(g.completeExceptionally(ex)); break; case 5: - h = m.thenCompose(f, (x -> g)); + h = m.thenCompose(f, x -> g); assertTrue(f.complete(v1)); assertTrue(g.completeExceptionally(ex)); break; @@ -3199,7 +3201,6 @@ public class CompletableFutureTest exten public void testExceptionallyCompose_actionFailed() { for (ExecutionMode m : ExecutionMode.values()) for (boolean createIncomplete : new boolean[] { true, false }) - for (Integer v1 : new Integer[] { 1, null }) { final CFException ex = new CFException(); final CompletableFuture f = new CompletableFuture<>(); @@ -3221,7 +3222,6 @@ public class CompletableFutureTest exten public void testExceptionallyCompose_actionReturnsFailingFuture() { for (ExecutionMode m : ExecutionMode.values()) for (int order = 0; order < 6; order++) - for (Integer v1 : new Integer[] { 1, null }) { final CFException ex0 = new CFException(); final CFException ex = new CFException(); @@ -3233,30 +3233,30 @@ public class CompletableFutureTest exten case 0: assertTrue(f.completeExceptionally(ex0)); assertTrue(g.completeExceptionally(ex)); - h = m.exceptionallyCompose(f, (x -> g)); + h = m.exceptionallyCompose(f, x -> g); break; case 1: assertTrue(f.completeExceptionally(ex0)); - h = m.exceptionallyCompose(f, (x -> g)); + h = m.exceptionallyCompose(f, x -> g); assertTrue(g.completeExceptionally(ex)); break; case 2: assertTrue(g.completeExceptionally(ex)); assertTrue(f.completeExceptionally(ex0)); - h = m.exceptionallyCompose(f, (x -> g)); + h = m.exceptionallyCompose(f, x -> g); break; case 3: assertTrue(g.completeExceptionally(ex)); - h = m.exceptionallyCompose(f, (x -> g)); + h = m.exceptionallyCompose(f, x -> g); assertTrue(f.completeExceptionally(ex0)); break; case 4: - h = m.exceptionallyCompose(f, (x -> g)); + h = m.exceptionallyCompose(f, x -> g); assertTrue(f.completeExceptionally(ex0)); assertTrue(g.completeExceptionally(ex)); break; case 5: - h = m.exceptionallyCompose(f, (x -> g)); + h = m.exceptionallyCompose(f, x -> g); assertTrue(f.completeExceptionally(ex0)); assertTrue(g.completeExceptionally(ex)); break; @@ -3647,12 +3647,6 @@ public class CompletableFutureTest exten final CompletableFuture complete = CompletableFuture.completedFuture(v); final CompletableFuture incomplete = new CompletableFuture<>(); - List> futures = new ArrayList<>(); - - List> srcs = new ArrayList<>(); - srcs.add(complete); - srcs.add(incomplete); - List> fs = new ArrayList<>(); fs.add(incomplete.thenRunAsync(() -> {}, e)); fs.add(incomplete.thenAcceptAsync(z -> {}, e)); @@ -4837,18 +4831,21 @@ public class CompletableFutureTest exten for (boolean createIncomplete : new boolean[] { true, false }) for (Integer v1 : new Integer[] { 1, null }) { + final AtomicInteger ran = new AtomicInteger(0); final CompletableFuture f = new CompletableFuture<>(); final DelegatedCompletionStage d = new DelegatedCompletionStage(f); if (!createIncomplete) assertTrue(f.complete(v1)); final CompletionStage g = d.exceptionallyAsync ((Throwable t) -> { - threadFail("should not be called"); - return null; // unreached + ran.getAndIncrement(); + throw new AssertionError("should not be called"); }); if (createIncomplete) assertTrue(f.complete(v1)); checkCompletedNormally(g.toCompletableFuture(), v1); + checkCompletedNormally(f, v1); + assertEquals(0, ran.get()); }} /** @@ -4859,7 +4856,7 @@ public class CompletableFutureTest exten for (boolean createIncomplete : new boolean[] { true, false }) for (Integer v1 : new Integer[] { 1, null }) { - final AtomicInteger a = new AtomicInteger(0); + final AtomicInteger ran = new AtomicInteger(0); final CFException ex = new CFException(); final CompletableFuture f = new CompletableFuture<>(); final DelegatedCompletionStage d = @@ -4867,14 +4864,15 @@ public class CompletableFutureTest exten if (!createIncomplete) f.completeExceptionally(ex); final CompletionStage g = d.exceptionallyAsync ((Throwable t) -> { - threadAssertSame(t, ex); - a.getAndIncrement(); + assertSame(t, ex); + ran.getAndIncrement(); return v1; }); if (createIncomplete) f.completeExceptionally(ex); checkCompletedNormally(g.toCompletableFuture(), v1); - assertEquals(1, a.get()); + checkCompletedExceptionally(f, ex); + assertEquals(1, ran.get()); }} /** @@ -4885,7 +4883,7 @@ public class CompletableFutureTest exten public void testDefaultExceptionallyAsync_exceptionalCompletionActionFailed() { for (boolean createIncomplete : new boolean[] { true, false }) { - final AtomicInteger a = new AtomicInteger(0); + final AtomicInteger ran = new AtomicInteger(0); final CFException ex1 = new CFException(); final CFException ex2 = new CFException(); final CompletableFuture f = new CompletableFuture<>(); @@ -4894,8 +4892,8 @@ public class CompletableFutureTest exten if (!createIncomplete) f.completeExceptionally(ex1); final CompletionStage g = d.exceptionallyAsync ((Throwable t) -> { - threadAssertSame(t, ex1); - a.getAndIncrement(); + assertSame(t, ex1); + ran.getAndIncrement(); throw ex2; }); if (createIncomplete) f.completeExceptionally(ex1); @@ -4903,7 +4901,7 @@ public class CompletableFutureTest exten checkCompletedWithWrappedException(g.toCompletableFuture(), ex2); checkCompletedExceptionally(f, ex1); checkCompletedExceptionally(d.toCompletableFuture(), ex1); - assertEquals(1, a.get()); + assertEquals(1, ran.get()); }} /** @@ -4956,7 +4954,6 @@ public class CompletableFutureTest exten */ public void testDefaultExceptionallyCompose_actionFailed() { for (boolean createIncomplete : new boolean[] { true, false }) - for (Integer v1 : new Integer[] { 1, null }) { final CFException ex = new CFException(); final CompletableFuture f = new CompletableFuture<>(); @@ -5023,7 +5020,6 @@ public class CompletableFutureTest exten */ public void testDefaultExceptionallyComposeAsync_actionFailed() { for (boolean createIncomplete : new boolean[] { true, false }) - for (Integer v1 : new Integer[] { 1, null }) { final CFException ex = new CFException(); final CompletableFuture f = new CompletableFuture<>(); @@ -5090,7 +5086,6 @@ public class CompletableFutureTest exten */ public void testDefaultExceptionallyComposeAsyncExecutor_actionFailed() { for (boolean createIncomplete : new boolean[] { true, false }) - for (Integer v1 : new Integer[] { 1, null }) { final CFException ex = new CFException(); final CompletableFuture f = new CompletableFuture<>();