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.104 by jsr166, Thu Sep 3 14:17:25 2015 UTC vs.
Revision 1.115 by jsr166, Fri Sep 4 20:44:50 2015 UTC

# Line 3333 | Line 3333 | public class CompletableFutureTest exten
3333              () -> f.exceptionally(null),
3334  
3335              () -> f.handle(null),
3336 +
3337              () -> CompletableFuture.allOf((CompletableFuture<?>)null),
3338              () -> CompletableFuture.allOf((CompletableFuture<?>[])null),
3339              () -> CompletableFuture.allOf(f, null),
# Line 3344 | Line 3345 | public class CompletableFutureTest exten
3345              () -> CompletableFuture.anyOf(null, f),
3346  
3347              () -> f.obtrudeException(null),
3348 +
3349 +            () -> CompletableFuture.delayedExecutor(1L, SECONDS, null),
3350 +            () -> CompletableFuture.delayedExecutor(1L, null, new ThreadExecutor()),
3351 +            () -> CompletableFuture.delayedExecutor(1L, null),
3352          };
3353  
3354          assertThrows(NullPointerException.class, throwingActions);
# Line 3384 | Line 3389 | public class CompletableFutureTest exten
3389  
3390      /**
3391       * defaultExecutor by default returns the commonPool if
3392 <     * it supports at least one thread.
3392 >     * it supports more than one thread.
3393       */
3394      public void testDefaultExecutor() {
3395          CompletableFuture<Integer> f = new CompletableFuture<>();
3396          Executor e = f.defaultExecutor();
3397 <        Executor c =  ForkJoinPool.commonPool();
3398 <        if (ForkJoinPool.getCommonPoolParallelism() > 0)
3397 >        Executor c = ForkJoinPool.commonPool();
3398 >        if (ForkJoinPool.getCommonPoolParallelism() > 1)
3399              assertSame(e, c);
3400 +        else
3401 +            assertNotSame(e, c);
3402      }
3403  
3404      /**
# Line 3479 | Line 3486 | public class CompletableFutureTest exten
3486      }
3487  
3488      /**
3489 <     * failedStage returns a Completionstage completed
3489 >     * failedStage returns a CompletionStage completed
3490       * exceptionally with the given Exception
3491       */
3492      public void testFailedStage() {
# Line 3542 | Line 3549 | public class CompletableFutureTest exten
3549      }
3550  
3551      /**
3552 <     *  orTimeout completes with TimeoutException if not complete
3552 >     * orTimeout completes with TimeoutException if not complete
3553       */
3554      public void testOrTimeout() {
3555          CompletableFuture<Integer> f = new CompletableFuture<>();
3556 <        f.orTimeout(SHORT_DELAY_MS, TimeUnit.MILLISECONDS);
3556 >        f.orTimeout(SHORT_DELAY_MS, MILLISECONDS);
3557          checkCompletedExceptionallyWithTimeout(f);
3558      }
3559  
3560      /**
3561 <     *  orTimeout completes normally if completed before timeout
3561 >     * orTimeout completes normally if completed before timeout
3562       */
3563      public void testOrTimeout2() {
3564          CompletableFuture<Integer> f = new CompletableFuture<>();
3565          f.complete(1);
3566 <        f.orTimeout(SHORT_DELAY_MS, TimeUnit.MILLISECONDS);
3566 >        f.orTimeout(SHORT_DELAY_MS, MILLISECONDS);
3567          checkCompletedNormally(f, 1);
3568      }
3569  
3570      /**
3571 <     *  completeOnTimeout completes with given value if not complete
3571 >     * completeOnTimeout completes with given value if not complete
3572       */
3573      public void testCompleteOnTimeout() {
3574          CompletableFuture<Integer> f = new CompletableFuture<>();
3575 <        f.completeOnTimeout(-1, SHORT_DELAY_MS, TimeUnit.MILLISECONDS);
3575 >        f.completeOnTimeout(-1, SHORT_DELAY_MS, MILLISECONDS);
3576          f.join();
3577          checkCompletedNormally(f, -1);
3578      }
3579  
3580      /**
3581 <     *  completeOnTimeout has no effect if completed within timeout
3581 >     * completeOnTimeout has no effect if completed within timeout
3582       */
3583      public void testCompleteOnTimeout2() {
3584          CompletableFuture<Integer> f = new CompletableFuture<>();
3585          f.complete(1);
3586 <        f.completeOnTimeout(-1, SHORT_DELAY_MS, TimeUnit.MILLISECONDS);
3586 >        f.completeOnTimeout(-1, SHORT_DELAY_MS, MILLISECONDS);
3587          checkCompletedNormally(f, 1);
3588      }
3589  
3590      /**
3591       * delayedExecutor returns an executor that delays submission
3592       */
3593 <    public void testDelayedExecutor() {
3593 >    public void testDelayedExecutor() throws Exception {
3594          long timeoutMillis = SMALL_DELAY_MS;
3595          Executor d = CompletableFuture.delayedExecutor(timeoutMillis,
3596                                                         MILLISECONDS);
3597          long startTime = System.nanoTime();
3598          CompletableFuture<Integer> f = CompletableFuture.supplyAsync(() -> 1, d);
3599          assertNull(f.getNow(null));
3600 <        try {
3594 <            f.get(LONG_DELAY_MS, MILLISECONDS);
3595 <        } catch (Throwable fail) { threadUnexpectedException(fail); }
3600 >        assertEquals(1, (int) f.get(LONG_DELAY_MS, MILLISECONDS));
3601          assertTrue(millisElapsedSince(startTime) > timeoutMillis/2);
3602          checkCompletedNormally(f, 1);
3603      }
# Line 3601 | Line 3606 | public class CompletableFutureTest exten
3606       * delayedExecutor for a given executor returns an executor that
3607       * delays submission
3608       */
3609 <    public void testDelayedExecutor2() {
3609 >    public void testDelayedExecutor2() throws Exception {
3610          long timeoutMillis = SMALL_DELAY_MS;
3611          Executor d = CompletableFuture.delayedExecutor(timeoutMillis,
3612                                                         MILLISECONDS,
# Line 3609 | Line 3614 | public class CompletableFutureTest exten
3614          long startTime = System.nanoTime();
3615          CompletableFuture<Integer> f = CompletableFuture.supplyAsync(() -> 1, d);
3616          assertNull(f.getNow(null));
3617 <        try {
3613 <            f.get(LONG_DELAY_MS, MILLISECONDS);
3614 <        } catch (Throwable fail) { threadUnexpectedException(fail); }
3617 >        assertEquals(1, (int) f.get(LONG_DELAY_MS, MILLISECONDS));
3618          assertTrue(millisElapsedSince(startTime) > timeoutMillis/2);
3619          checkCompletedNormally(f, 1);
3620      }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines