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.116 by jsr166, Fri Sep 4 20:57:10 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 +            () -> f.orTimeout(1L, null),
3354 +            () -> f.completeOnTimeout(42, 1L, null),
3355          };
3356  
3357          assertThrows(NullPointerException.class, throwingActions);
# Line 3384 | Line 3392 | public class CompletableFutureTest exten
3392  
3393      /**
3394       * defaultExecutor by default returns the commonPool if
3395 <     * it supports at least one thread.
3395 >     * it supports more than one thread.
3396       */
3397      public void testDefaultExecutor() {
3398          CompletableFuture<Integer> f = new CompletableFuture<>();
3399          Executor e = f.defaultExecutor();
3400 <        Executor c =  ForkJoinPool.commonPool();
3401 <        if (ForkJoinPool.getCommonPoolParallelism() > 0)
3400 >        Executor c = ForkJoinPool.commonPool();
3401 >        if (ForkJoinPool.getCommonPoolParallelism() > 1)
3402              assertSame(e, c);
3403 +        else
3404 +            assertNotSame(e, c);
3405      }
3406  
3407      /**
# Line 3479 | Line 3489 | public class CompletableFutureTest exten
3489      }
3490  
3491      /**
3492 <     * failedStage returns a Completionstage completed
3492 >     * failedStage returns a CompletionStage completed
3493       * exceptionally with the given Exception
3494       */
3495      public void testFailedStage() {
# Line 3542 | Line 3552 | public class CompletableFutureTest exten
3552      }
3553  
3554      /**
3555 <     *  orTimeout completes with TimeoutException if not complete
3555 >     * orTimeout completes with TimeoutException if not complete
3556       */
3557      public void testOrTimeout() {
3558          CompletableFuture<Integer> f = new CompletableFuture<>();
3559 <        f.orTimeout(SHORT_DELAY_MS, TimeUnit.MILLISECONDS);
3559 >        f.orTimeout(SHORT_DELAY_MS, MILLISECONDS);
3560          checkCompletedExceptionallyWithTimeout(f);
3561      }
3562  
3563      /**
3564 <     *  orTimeout completes normally if completed before timeout
3564 >     * orTimeout completes normally if completed before timeout
3565       */
3566      public void testOrTimeout2() {
3567          CompletableFuture<Integer> f = new CompletableFuture<>();
3568          f.complete(1);
3569 <        f.orTimeout(SHORT_DELAY_MS, TimeUnit.MILLISECONDS);
3569 >        f.orTimeout(SHORT_DELAY_MS, MILLISECONDS);
3570          checkCompletedNormally(f, 1);
3571      }
3572  
3573      /**
3574 <     *  completeOnTimeout completes with given value if not complete
3574 >     * completeOnTimeout completes with given value if not complete
3575       */
3576      public void testCompleteOnTimeout() {
3577          CompletableFuture<Integer> f = new CompletableFuture<>();
3578 <        f.completeOnTimeout(-1, SHORT_DELAY_MS, TimeUnit.MILLISECONDS);
3578 >        f.completeOnTimeout(-1, SHORT_DELAY_MS, MILLISECONDS);
3579          f.join();
3580          checkCompletedNormally(f, -1);
3581      }
3582  
3583      /**
3584 <     *  completeOnTimeout has no effect if completed within timeout
3584 >     * completeOnTimeout has no effect if completed within timeout
3585       */
3586      public void testCompleteOnTimeout2() {
3587          CompletableFuture<Integer> f = new CompletableFuture<>();
3588          f.complete(1);
3589 <        f.completeOnTimeout(-1, SHORT_DELAY_MS, TimeUnit.MILLISECONDS);
3589 >        f.completeOnTimeout(-1, SHORT_DELAY_MS, MILLISECONDS);
3590          checkCompletedNormally(f, 1);
3591      }
3592  
3593      /**
3594       * delayedExecutor returns an executor that delays submission
3595       */
3596 <    public void testDelayedExecutor() {
3596 >    public void testDelayedExecutor() throws Exception {
3597          long timeoutMillis = SMALL_DELAY_MS;
3598          Executor d = CompletableFuture.delayedExecutor(timeoutMillis,
3599                                                         MILLISECONDS);
3600          long startTime = System.nanoTime();
3601          CompletableFuture<Integer> f = CompletableFuture.supplyAsync(() -> 1, d);
3602          assertNull(f.getNow(null));
3603 <        try {
3594 <            f.get(LONG_DELAY_MS, MILLISECONDS);
3595 <        } catch (Throwable fail) { threadUnexpectedException(fail); }
3603 >        assertEquals(1, (int) f.get(LONG_DELAY_MS, MILLISECONDS));
3604          assertTrue(millisElapsedSince(startTime) > timeoutMillis/2);
3605          checkCompletedNormally(f, 1);
3606      }
# Line 3601 | Line 3609 | public class CompletableFutureTest exten
3609       * delayedExecutor for a given executor returns an executor that
3610       * delays submission
3611       */
3612 <    public void testDelayedExecutor2() {
3612 >    public void testDelayedExecutor2() throws Exception {
3613          long timeoutMillis = SMALL_DELAY_MS;
3614          Executor d = CompletableFuture.delayedExecutor(timeoutMillis,
3615                                                         MILLISECONDS,
# Line 3609 | Line 3617 | public class CompletableFutureTest exten
3617          long startTime = System.nanoTime();
3618          CompletableFuture<Integer> f = CompletableFuture.supplyAsync(() -> 1, d);
3619          assertNull(f.getNow(null));
3620 <        try {
3613 <            f.get(LONG_DELAY_MS, MILLISECONDS);
3614 <        } catch (Throwable fail) { threadUnexpectedException(fail); }
3620 >        assertEquals(1, (int) f.get(LONG_DELAY_MS, MILLISECONDS));
3621          assertTrue(millisElapsedSince(startTime) > timeoutMillis/2);
3622          checkCompletedNormally(f, 1);
3623      }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines