ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/tck/CompletableFutureTest.java
(Generate patch)

Comparing jsr166/src/test/tck/CompletableFutureTest.java (file contents):
Revision 1.152 by jsr166, Sun Jun 26 19:03:27 2016 UTC vs.
Revision 1.153 by jsr166, Sun Jun 26 19:17:08 2016 UTC

# Line 3404 | Line 3404 | public class CompletableFutureTest exten
3404      }
3405  
3406      /**
3407 +     * Test submissions to an executor that rejects all tasks, but
3408 +     * should never be invoked because the dependent future is
3409 +     * explicitly completed.
3410 +     */
3411 +    public void testRejectingExecutorNeverInvoked() {
3412 +        final RejectedExecutionException ex = new RejectedExecutionException();
3413 +        class CountingRejectingExecutor implements Executor {
3414 +            final AtomicInteger count = new AtomicInteger(0);
3415 +            public void execute(Runnable r) {
3416 +                count.getAndIncrement();
3417 +                throw ex;
3418 +            }
3419 +        }
3420 +        final CountingRejectingExecutor e = new CountingRejectingExecutor();
3421 +
3422 +        for (Integer v : new Integer[] { 1, null }) {
3423 +
3424 +        final CompletableFuture<Integer> complete = CompletableFuture.completedFuture(v);
3425 +        final CompletableFuture<Integer> incomplete = new CompletableFuture<>();
3426 +
3427 +        List<CompletableFuture<?>> futures = new ArrayList<>();
3428 +
3429 +        List<CompletableFuture<Integer>> srcs = new ArrayList<>();
3430 +        srcs.add(complete);
3431 +        srcs.add(incomplete);
3432 +
3433 +        List<CompletableFuture<?>> fs = new ArrayList<>();
3434 +        fs.add(incomplete.thenRunAsync(() -> {}, e));
3435 +        fs.add(incomplete.thenAcceptAsync((z) -> {}, e));
3436 +        fs.add(incomplete.thenApplyAsync((z) -> z, e));
3437 +
3438 +        fs.add(incomplete.thenCombineAsync(incomplete, (x, y) -> x, e));
3439 +        fs.add(incomplete.thenAcceptBothAsync(incomplete, (x, y) -> {}, e));
3440 +        fs.add(incomplete.runAfterBothAsync(incomplete, () -> {}, e));
3441 +
3442 +        fs.add(incomplete.applyToEitherAsync(incomplete, (z) -> z, e));
3443 +        fs.add(incomplete.acceptEitherAsync(incomplete, (z) -> {}, e));
3444 +        fs.add(incomplete.runAfterEitherAsync(incomplete, () -> {}, e));
3445 +
3446 +        fs.add(incomplete.thenComposeAsync((z) -> null, e));
3447 +        fs.add(incomplete.whenCompleteAsync((z, t) -> {}, e));
3448 +        fs.add(incomplete.handleAsync((z, t) -> null, e));
3449 +
3450 +        fs.add(complete.thenCombineAsync(incomplete, (x, y) -> x, e));
3451 +        fs.add(incomplete.thenCombineAsync(complete, (x, y) -> x, e));
3452 +
3453 +        fs.add(complete.thenAcceptBothAsync(incomplete, (x, y) -> {}, e));
3454 +        fs.add(incomplete.thenAcceptBothAsync(complete, (x, y) -> {}, e));
3455 +
3456 +        fs.add(complete.runAfterBothAsync(incomplete, () -> {}, e));
3457 +        fs.add(incomplete.runAfterBothAsync(complete, () -> {}, e));
3458 +
3459 +        for (CompletableFuture<?> future : fs)
3460 +            checkIncomplete(future);
3461 +
3462 +        for (CompletableFuture<?> future : fs)
3463 +            future.complete(null);
3464 +
3465 +        incomplete.complete(v);
3466 +
3467 +        for (CompletableFuture<?> future : fs)
3468 +            checkCompletedNormally(future, null);
3469 +
3470 +        assertEquals(0, e.count.get());
3471 +
3472 +        }
3473 +    }
3474 +
3475 +    /**
3476       * toCompletableFuture returns this CompletableFuture.
3477       */
3478      public void testToCompletableFuture() {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines