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), |
3360 |
|
} |
3361 |
|
|
3362 |
|
// jdk9 |
3363 |
< |
|
3363 |
> |
|
3364 |
|
/** |
3365 |
|
* newIncompleteFuture returns an incomplete CompletableFuture |
3366 |
|
*/ |
3385 |
|
|
3386 |
|
/** |
3387 |
|
* defaultExecutor by default returns the commonPool if |
3388 |
< |
* it supports at least one thread. |
3388 |
> |
* it supports more than one thread. |
3389 |
|
*/ |
3390 |
|
public void testDefaultExecutor() { |
3391 |
|
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3392 |
|
Executor e = f.defaultExecutor(); |
3393 |
< |
Executor c = ForkJoinPool.commonPool(); |
3394 |
< |
if (ForkJoinPool.getCommonPoolParallelism() > 0) |
3393 |
> |
Executor c = ForkJoinPool.commonPool(); |
3394 |
> |
if (ForkJoinPool.getCommonPoolParallelism() > 1) |
3395 |
|
assertSame(e, c); |
3396 |
+ |
else |
3397 |
+ |
assertNotSame(e, c); |
3398 |
|
} |
3399 |
|
|
3400 |
|
/** |
3413 |
|
public void testFailedFuture2() { |
3414 |
|
try { |
3415 |
|
CompletableFuture<Integer> f = CompletableFuture.failedFuture(null); |
3416 |
< |
} catch(NullPointerException success) { |
3417 |
< |
} |
3416 |
> |
shouldThrow(); |
3417 |
> |
} catch (NullPointerException success) {} |
3418 |
|
} |
3419 |
|
|
3420 |
|
/** |
3482 |
|
} |
3483 |
|
|
3484 |
|
/** |
3485 |
< |
* failedStage returns a Completionstage completed |
3485 |
> |
* failedStage returns a CompletionStage completed |
3486 |
|
* exceptionally with the given Exception |
3487 |
|
*/ |
3488 |
|
public void testFailedStage() { |
3515 |
|
try { |
3516 |
|
f.join(); |
3517 |
|
shouldThrow(); |
3518 |
< |
} catch(Exception success) { |
3516 |
< |
} |
3518 |
> |
} catch (Exception success) {} |
3519 |
|
checkCompletedWithWrappedCFException(f); |
3520 |
|
} |
3521 |
|
|
3540 |
|
try { |
3541 |
|
f.join(); |
3542 |
|
shouldThrow(); |
3543 |
< |
} catch(Exception success) { |
3542 |
< |
} |
3543 |
> |
} catch (Exception success) {} |
3544 |
|
checkCompletedWithWrappedCFException(f); |
3545 |
|
} |
3546 |
|
|
3547 |
|
/** |
3548 |
< |
* orTimeout completes with TimeoutException if not complete |
3548 |
> |
* orTimeout completes with TimeoutException if not complete |
3549 |
|
*/ |
3550 |
|
public void testOrTimeout() { |
3551 |
|
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3552 |
< |
f.orTimeout(SHORT_DELAY_MS, TimeUnit.MILLISECONDS); |
3552 |
> |
f.orTimeout(SHORT_DELAY_MS, MILLISECONDS); |
3553 |
|
checkCompletedExceptionallyWithTimeout(f); |
3554 |
|
} |
3555 |
|
|
3556 |
|
/** |
3557 |
< |
* orTimeout completes normally if completed before timeout |
3557 |
> |
* orTimeout completes normally if completed before timeout |
3558 |
|
*/ |
3559 |
|
public void testOrTimeout2() { |
3560 |
|
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3561 |
|
f.complete(1); |
3562 |
< |
f.orTimeout(SHORT_DELAY_MS, TimeUnit.MILLISECONDS); |
3562 |
> |
f.orTimeout(SHORT_DELAY_MS, MILLISECONDS); |
3563 |
|
checkCompletedNormally(f, 1); |
3564 |
|
} |
3565 |
|
|
3566 |
|
/** |
3567 |
< |
* completeOnTimeout completes with given value if not complete |
3567 |
> |
* completeOnTimeout completes with given value if not complete |
3568 |
|
*/ |
3569 |
|
public void testCompleteOnTimeout() { |
3570 |
|
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3571 |
< |
f.completeOnTimeout(-1, SHORT_DELAY_MS, TimeUnit.MILLISECONDS); |
3571 |
> |
f.completeOnTimeout(-1, SHORT_DELAY_MS, MILLISECONDS); |
3572 |
|
f.join(); |
3573 |
|
checkCompletedNormally(f, -1); |
3574 |
|
} |
3575 |
|
|
3576 |
|
/** |
3577 |
< |
* completeOnTimeout has no effect if completed within timeout |
3577 |
> |
* completeOnTimeout has no effect if completed within timeout |
3578 |
|
*/ |
3579 |
|
public void testCompleteOnTimeout2() { |
3580 |
|
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3581 |
|
f.complete(1); |
3582 |
< |
f.completeOnTimeout(-1, SHORT_DELAY_MS, TimeUnit.MILLISECONDS); |
3582 |
> |
f.completeOnTimeout(-1, SHORT_DELAY_MS, MILLISECONDS); |
3583 |
|
checkCompletedNormally(f, 1); |
3584 |
|
} |
3585 |
|
|
3586 |
|
/** |
3587 |
|
* delayedExecutor returns an executor that delays submission |
3588 |
|
*/ |
3589 |
< |
public void testDelayedExecutor() { |
3589 |
> |
public void testDelayedExecutor() throws Exception { |
3590 |
|
long timeoutMillis = SMALL_DELAY_MS; |
3591 |
|
Executor d = CompletableFuture.delayedExecutor(timeoutMillis, |
3592 |
|
MILLISECONDS); |
3593 |
|
long startTime = System.nanoTime(); |
3594 |
|
CompletableFuture<Integer> f = CompletableFuture.supplyAsync(() -> 1, d); |
3595 |
|
assertNull(f.getNow(null)); |
3596 |
< |
try { |
3596 |
< |
f.get(LONG_DELAY_MS, MILLISECONDS); |
3597 |
< |
} catch (Throwable fail) { threadUnexpectedException(fail); } |
3596 |
> |
assertEquals(1, (int) f.get(LONG_DELAY_MS, MILLISECONDS)); |
3597 |
|
assertTrue(millisElapsedSince(startTime) > timeoutMillis/2); |
3598 |
|
checkCompletedNormally(f, 1); |
3599 |
|
} |
3602 |
|
* delayedExecutor for a given executor returns an executor that |
3603 |
|
* delays submission |
3604 |
|
*/ |
3605 |
< |
public void testDelayedExecutor2() { |
3605 |
> |
public void testDelayedExecutor2() throws Exception { |
3606 |
|
long timeoutMillis = SMALL_DELAY_MS; |
3607 |
|
Executor d = CompletableFuture.delayedExecutor(timeoutMillis, |
3608 |
|
MILLISECONDS, |
3610 |
|
long startTime = System.nanoTime(); |
3611 |
|
CompletableFuture<Integer> f = CompletableFuture.supplyAsync(() -> 1, d); |
3612 |
|
assertNull(f.getNow(null)); |
3613 |
< |
try { |
3615 |
< |
f.get(LONG_DELAY_MS, MILLISECONDS); |
3616 |
< |
} catch (Throwable fail) { threadUnexpectedException(fail); } |
3613 |
> |
assertEquals(1, (int) f.get(LONG_DELAY_MS, MILLISECONDS)); |
3614 |
|
assertTrue(millisElapsedSince(startTime) > timeoutMillis/2); |
3615 |
|
checkCompletedNormally(f, 1); |
3616 |
|
} |