--- jsr166/src/test/tck/CompletableFutureTest.java 2016/06/26 17:45:35 1.151 +++ jsr166/src/test/tck/CompletableFutureTest.java 2016/06/26 19:03:27 1.152 @@ -30,6 +30,7 @@ import java.util.concurrent.ExecutionExc import java.util.concurrent.Executor; import java.util.concurrent.ForkJoinPool; import java.util.concurrent.ForkJoinTask; +import java.util.concurrent.RejectedExecutionException; import java.util.concurrent.TimeoutException; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; @@ -3317,6 +3318,92 @@ public class CompletableFutureTest exten } /** + * Test submissions to an executor that rejects all tasks. + */ + public void testRejectingExecutor() { + final RejectedExecutionException ex = new RejectedExecutionException(); + final Executor e = (Runnable r) -> { throw ex; }; + + for (Integer v : new Integer[] { 1, null }) { + + 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); + + for (CompletableFuture src : srcs) { + List> fs = new ArrayList<>(); + fs.add(src.thenRunAsync(() -> {}, e)); + fs.add(src.thenAcceptAsync((z) -> {}, e)); + fs.add(src.thenApplyAsync((z) -> z, e)); + + fs.add(src.thenCombineAsync(src, (x, y) -> x, e)); + fs.add(src.thenAcceptBothAsync(src, (x, y) -> {}, e)); + fs.add(src.runAfterBothAsync(src, () -> {}, e)); + + fs.add(src.applyToEitherAsync(src, (z) -> z, e)); + fs.add(src.acceptEitherAsync(src, (z) -> {}, e)); + fs.add(src.runAfterEitherAsync(src, () -> {}, e)); + + fs.add(src.thenComposeAsync((z) -> null, e)); + fs.add(src.whenCompleteAsync((z, t) -> {}, e)); + fs.add(src.handleAsync((z, t) -> null, e)); + + for (CompletableFuture future : fs) { + if (src.isDone()) + checkCompletedWithWrappedException(future, ex); + else + checkIncomplete(future); + } + futures.addAll(fs); + } + + { + List> fs = new ArrayList<>(); + + fs.add(complete.thenCombineAsync(incomplete, (x, y) -> x, e)); + fs.add(incomplete.thenCombineAsync(complete, (x, y) -> x, e)); + + fs.add(complete.thenAcceptBothAsync(incomplete, (x, y) -> {}, e)); + fs.add(incomplete.thenAcceptBothAsync(complete, (x, y) -> {}, e)); + + fs.add(complete.runAfterBothAsync(incomplete, () -> {}, e)); + fs.add(incomplete.runAfterBothAsync(complete, () -> {}, e)); + + for (CompletableFuture future : fs) + checkIncomplete(future); + futures.addAll(fs); + } + + { + List> fs = new ArrayList<>(); + + fs.add(complete.applyToEitherAsync(incomplete, (z) -> z, e)); + fs.add(incomplete.applyToEitherAsync(complete, (z) -> z, e)); + + fs.add(complete.acceptEitherAsync(incomplete, (z) -> {}, e)); + fs.add(incomplete.acceptEitherAsync(complete, (z) -> {}, e)); + + fs.add(complete.runAfterEitherAsync(incomplete, () -> {}, e)); + fs.add(incomplete.runAfterEitherAsync(complete, () -> {}, e)); + + for (CompletableFuture future : fs) + checkCompletedWithWrappedException(future, ex); + futures.addAll(fs); + } + + incomplete.complete(v); + + for (CompletableFuture future : futures) + checkCompletedWithWrappedException(future, ex); + } + } + + /** * toCompletableFuture returns this CompletableFuture. */ public void testToCompletableFuture() {