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.154 by jsr166, Sun Jun 26 19:27:42 2016 UTC

# Line 3317 | Line 3317 | public class CompletableFutureTest exten
3317          assertEquals(0, exec.count.get());
3318      }
3319  
3320 +    static class CountingRejectingExecutor implements Executor {
3321 +        final RejectedExecutionException ex = new RejectedExecutionException();
3322 +        final AtomicInteger count = new AtomicInteger(0);
3323 +        public void execute(Runnable r) {
3324 +            count.getAndIncrement();
3325 +            throw ex;
3326 +        }
3327 +    }
3328 +
3329      /**
3330       * Test submissions to an executor that rejects all tasks.
3331       */
3332      public void testRejectingExecutor() {
3324        final RejectedExecutionException ex = new RejectedExecutionException();
3325        final Executor e = (Runnable r) -> { throw ex; };
3326
3333          for (Integer v : new Integer[] { 1, null }) {
3334  
3335 +        final CountingRejectingExecutor e = new CountingRejectingExecutor();
3336 +
3337          final CompletableFuture<Integer> complete = CompletableFuture.completedFuture(v);
3338          final CompletableFuture<Integer> incomplete = new CompletableFuture<>();
3339  
# Line 3355 | Line 3363 | public class CompletableFutureTest exten
3363  
3364              for (CompletableFuture<?> future : fs) {
3365                  if (src.isDone())
3366 <                    checkCompletedWithWrappedException(future, ex);
3366 >                    checkCompletedWithWrappedException(future, e.ex);
3367                  else
3368                      checkIncomplete(future);
3369              }
# Line 3392 | Line 3400 | public class CompletableFutureTest exten
3400              fs.add(incomplete.runAfterEitherAsync(complete, () -> {}, e));
3401  
3402              for (CompletableFuture<?> future : fs)
3403 <                checkCompletedWithWrappedException(future, ex);
3403 >                checkCompletedWithWrappedException(future, e.ex);
3404              futures.addAll(fs);
3405          }
3406  
3407          incomplete.complete(v);
3408  
3409          for (CompletableFuture<?> future : futures)
3410 <            checkCompletedWithWrappedException(future, ex);
3410 >            checkCompletedWithWrappedException(future, e.ex);
3411 >
3412 >        assertEquals(futures.size(), e.count.get());
3413 >
3414 >        }
3415 >    }
3416 >
3417 >    /**
3418 >     * Test submissions to an executor that rejects all tasks, but
3419 >     * should never be invoked because the dependent future is
3420 >     * explicitly completed.
3421 >     */
3422 >    public void testRejectingExecutorNeverInvoked() {
3423 >        final CountingRejectingExecutor e = new CountingRejectingExecutor();
3424 >
3425 >        for (Integer v : new Integer[] { 1, null }) {
3426 >
3427 >        final CompletableFuture<Integer> complete = CompletableFuture.completedFuture(v);
3428 >        final CompletableFuture<Integer> incomplete = new CompletableFuture<>();
3429 >
3430 >        List<CompletableFuture<?>> futures = new ArrayList<>();
3431 >
3432 >        List<CompletableFuture<Integer>> srcs = new ArrayList<>();
3433 >        srcs.add(complete);
3434 >        srcs.add(incomplete);
3435 >
3436 >        List<CompletableFuture<?>> fs = new ArrayList<>();
3437 >        fs.add(incomplete.thenRunAsync(() -> {}, e));
3438 >        fs.add(incomplete.thenAcceptAsync((z) -> {}, e));
3439 >        fs.add(incomplete.thenApplyAsync((z) -> z, e));
3440 >
3441 >        fs.add(incomplete.thenCombineAsync(incomplete, (x, y) -> x, e));
3442 >        fs.add(incomplete.thenAcceptBothAsync(incomplete, (x, y) -> {}, e));
3443 >        fs.add(incomplete.runAfterBothAsync(incomplete, () -> {}, e));
3444 >
3445 >        fs.add(incomplete.applyToEitherAsync(incomplete, (z) -> z, e));
3446 >        fs.add(incomplete.acceptEitherAsync(incomplete, (z) -> {}, e));
3447 >        fs.add(incomplete.runAfterEitherAsync(incomplete, () -> {}, e));
3448 >
3449 >        fs.add(incomplete.thenComposeAsync((z) -> null, e));
3450 >        fs.add(incomplete.whenCompleteAsync((z, t) -> {}, e));
3451 >        fs.add(incomplete.handleAsync((z, t) -> null, e));
3452 >
3453 >        fs.add(complete.thenCombineAsync(incomplete, (x, y) -> x, e));
3454 >        fs.add(incomplete.thenCombineAsync(complete, (x, y) -> x, e));
3455 >
3456 >        fs.add(complete.thenAcceptBothAsync(incomplete, (x, y) -> {}, e));
3457 >        fs.add(incomplete.thenAcceptBothAsync(complete, (x, y) -> {}, e));
3458 >
3459 >        fs.add(complete.runAfterBothAsync(incomplete, () -> {}, e));
3460 >        fs.add(incomplete.runAfterBothAsync(complete, () -> {}, e));
3461 >
3462 >        for (CompletableFuture<?> future : fs)
3463 >            checkIncomplete(future);
3464 >
3465 >        for (CompletableFuture<?> future : fs)
3466 >            future.complete(null);
3467 >
3468 >        incomplete.complete(v);
3469 >
3470 >        for (CompletableFuture<?> future : fs)
3471 >            checkCompletedNormally(future, null);
3472 >
3473 >        assertEquals(0, e.count.get());
3474 >
3475          }
3476      }
3477  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines