--- jsr166/src/test/tck/CompletableFutureTest.java 2018/09/22 21:04:48 1.201 +++ jsr166/src/test/tck/CompletableFutureTest.java 2018/09/23 15:29:31 1.208 @@ -551,9 +551,7 @@ public class CompletableFutureTest exten public CompletableFuture apply(Integer x) { invoked(); value = x; - CompletableFuture f = new CompletableFuture<>(); - assertTrue(f.complete(inc(x))); - return f; + return CompletableFuture.completedFuture(inc(x)); } } @@ -574,9 +572,7 @@ public class CompletableFutureTest exten ExceptionalCompletableFutureFunction(ExecutionMode m) { super(m); } public CompletionStage apply(Throwable x) { invoked(); - CompletableFuture d = new CompletableFuture(); - d.complete(value); - return d; + return CompletableFuture.completedFuture(value); } } @@ -930,12 +926,10 @@ 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 CompletableFuture f = new CompletableFuture<>(); if (!createIncomplete) assertTrue(f.complete(v1)); final CompletableFuture g = m.exceptionally (f, (Throwable t) -> { - a.getAndIncrement(); threadFail("should not be called"); return null; // unreached }); @@ -943,7 +937,6 @@ public class CompletableFutureTest exten checkCompletedNormally(g, v1); checkCompletedNormally(f, v1); - assertEquals(0, a.get()); }} /** @@ -3174,6 +3167,8 @@ public class CompletableFutureTest exten final CompletableFuture g = m.exceptionallyCompose(f, r); if (createIncomplete) assertTrue(f.complete(v1)); + if (!createIncomplete && testImplementationDetails) + assertSame(f, g); checkCompletedNormally(f, v1); checkCompletedNormally(g, v1); r.assertNotInvoked(); @@ -4784,10 +4779,32 @@ public class CompletableFutureTest exten } /** + * default-implemented exceptionallyAsync action is not invoked when + * source completes normally, and source result is propagated + */ + public void testDefaultExceptionallyAsync_normalCompletion() { + for (boolean createIncomplete : new boolean[] { true, false }) + for (Integer v1 : new Integer[] { 1, null }) + { + 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 + }); + if (createIncomplete) assertTrue(f.complete(v1)); + + checkCompletedNormally(g.toCompletableFuture(), v1); + }} + + /** * default-implemented exceptionallyAsync action completes with * function value on source exception */ - public void testDefaulExceptionallyAsync_exceptionalCompletion() { + public void testDefaultExceptionallyAsync_exceptionalCompletion() { for (boolean createIncomplete : new boolean[] { true, false }) for (Integer v1 : new Integer[] { 1, null }) { @@ -4814,7 +4831,7 @@ public class CompletableFutureTest exten * throws an exception, it completes exceptionally with that * exception */ - public void testDefaulExceptionallyAsync_exceptionalCompletionActionFailed() { + public void testDefaultExceptionallyAsync_exceptionalCompletionActionFailed() { for (boolean createIncomplete : new boolean[] { true, false }) { final AtomicInteger a = new AtomicInteger(0); @@ -4987,7 +5004,7 @@ public class CompletableFutureTest exten final DelegatedCompletionStage d = new DelegatedCompletionStage(f); if (!createIncomplete) assertTrue(f.complete(v1)); - final CompletionStage g = d.exceptionallyComposeAsync(r, new ThreadExecutor()); + final CompletionStage g = d.exceptionallyComposeAsync(r, new ThreadExecutor()); if (createIncomplete) assertTrue(f.complete(v1)); checkCompletedNormally(f, v1); @@ -5009,7 +5026,7 @@ public class CompletableFutureTest exten final DelegatedCompletionStage d = new DelegatedCompletionStage(f); if (!createIncomplete) f.completeExceptionally(ex); - final CompletionStage g = d.exceptionallyComposeAsync(r, new ThreadExecutor()); + final CompletionStage g = d.exceptionallyComposeAsync(r, new ThreadExecutor()); if (createIncomplete) f.completeExceptionally(ex); checkCompletedExceptionally(f, ex); @@ -5032,7 +5049,7 @@ public class CompletableFutureTest exten final DelegatedCompletionStage d = new DelegatedCompletionStage(f); if (!createIncomplete) f.completeExceptionally(ex); - final CompletionStage g = d.exceptionallyComposeAsync(r, new ThreadExecutor()); + final CompletionStage g = d.exceptionallyComposeAsync(r, new ThreadExecutor()); if (createIncomplete) f.completeExceptionally(ex); checkCompletedExceptionally(f, ex);