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), |
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); |
3367 |
|
} |
3368 |
|
|
3369 |
|
// jdk9 |
3370 |
< |
|
3370 |
> |
|
3371 |
|
/** |
3372 |
|
* newIncompleteFuture returns an incomplete CompletableFuture |
3373 |
|
*/ |
3374 |
|
public void testNewIncompleteFuture() { |
3375 |
+ |
for (Integer v1 : new Integer[] { 1, null }) |
3376 |
+ |
{ |
3377 |
|
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3378 |
|
CompletableFuture<Integer> g = f.newIncompleteFuture(); |
3379 |
|
checkIncomplete(f); |
3380 |
|
checkIncomplete(g); |
3381 |
< |
} |
3381 |
> |
f.complete(v1); |
3382 |
> |
checkCompletedNormally(f, v1); |
3383 |
> |
checkIncomplete(g); |
3384 |
> |
g.complete(v1); |
3385 |
> |
checkCompletedNormally(g, v1); |
3386 |
> |
assertSame(g.getClass(), CompletableFuture.class); |
3387 |
> |
}} |
3388 |
|
|
3389 |
|
/** |
3390 |
|
* completedStage returns a completed CompletionStage |
3400 |
|
|
3401 |
|
/** |
3402 |
|
* defaultExecutor by default returns the commonPool if |
3403 |
< |
* it supports at least one thread. |
3403 |
> |
* it supports more than one thread. |
3404 |
|
*/ |
3405 |
|
public void testDefaultExecutor() { |
3406 |
|
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3407 |
|
Executor e = f.defaultExecutor(); |
3408 |
< |
Executor c = ForkJoinPool.commonPool(); |
3409 |
< |
if (ForkJoinPool.getCommonPoolParallelism() > 0) |
3408 |
> |
Executor c = ForkJoinPool.commonPool(); |
3409 |
> |
if (ForkJoinPool.getCommonPoolParallelism() > 1) |
3410 |
|
assertSame(e, c); |
3411 |
+ |
else |
3412 |
+ |
assertNotSame(e, c); |
3413 |
|
} |
3414 |
|
|
3415 |
|
/** |
3425 |
|
/** |
3426 |
|
* failedFuture(null) throws NPE |
3427 |
|
*/ |
3428 |
< |
public void testFailedFuture2() { |
3428 |
> |
public void testFailedFuture_null() { |
3429 |
|
try { |
3430 |
|
CompletableFuture<Integer> f = CompletableFuture.failedFuture(null); |
3431 |
< |
} catch(NullPointerException success) { |
3432 |
< |
} |
3431 |
> |
shouldThrow(); |
3432 |
> |
} catch (NullPointerException success) {} |
3433 |
|
} |
3434 |
|
|
3435 |
|
/** |
3497 |
|
} |
3498 |
|
|
3499 |
|
/** |
3500 |
< |
* failedStage returns a Completionstage completed |
3500 |
> |
* failedStage returns a CompletionStage completed |
3501 |
|
* exceptionally with the given Exception |
3502 |
|
*/ |
3503 |
|
public void testFailedStage() { |
3530 |
|
try { |
3531 |
|
f.join(); |
3532 |
|
shouldThrow(); |
3533 |
< |
} catch(Exception success) { |
3516 |
< |
} |
3533 |
> |
} catch (Exception success) {} |
3534 |
|
checkCompletedWithWrappedCFException(f); |
3535 |
|
} |
3536 |
|
|
3555 |
|
try { |
3556 |
|
f.join(); |
3557 |
|
shouldThrow(); |
3558 |
< |
} catch(Exception success) { |
3542 |
< |
} |
3558 |
> |
} catch (Exception success) {} |
3559 |
|
checkCompletedWithWrappedCFException(f); |
3560 |
|
} |
3561 |
|
|
3562 |
|
/** |
3563 |
< |
* orTimeout completes with TimeoutException if not complete |
3563 |
> |
* orTimeout completes with TimeoutException if not complete |
3564 |
|
*/ |
3565 |
|
public void testOrTimeout() { |
3566 |
|
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3567 |
< |
f.orTimeout(SHORT_DELAY_MS, TimeUnit.MILLISECONDS); |
3567 |
> |
f.orTimeout(SHORT_DELAY_MS, MILLISECONDS); |
3568 |
|
checkCompletedExceptionallyWithTimeout(f); |
3569 |
|
} |
3570 |
|
|
3571 |
|
/** |
3572 |
< |
* orTimeout completes normally if completed before timeout |
3572 |
> |
* orTimeout completes normally if completed before timeout |
3573 |
|
*/ |
3574 |
|
public void testOrTimeout2() { |
3575 |
|
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3576 |
|
f.complete(1); |
3577 |
< |
f.orTimeout(SHORT_DELAY_MS, TimeUnit.MILLISECONDS); |
3577 |
> |
f.orTimeout(SHORT_DELAY_MS, MILLISECONDS); |
3578 |
|
checkCompletedNormally(f, 1); |
3579 |
|
} |
3580 |
|
|
3581 |
|
/** |
3582 |
< |
* completeOnTimeout completes with given value if not complete |
3582 |
> |
* completeOnTimeout completes with given value if not complete |
3583 |
|
*/ |
3584 |
|
public void testCompleteOnTimeout() { |
3585 |
|
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3586 |
< |
f.completeOnTimeout(-1, SHORT_DELAY_MS, TimeUnit.MILLISECONDS); |
3586 |
> |
f.completeOnTimeout(-1, SHORT_DELAY_MS, MILLISECONDS); |
3587 |
|
f.join(); |
3588 |
|
checkCompletedNormally(f, -1); |
3589 |
|
} |
3590 |
|
|
3591 |
|
/** |
3592 |
< |
* completeOnTimeout has no effect if completed within timeout |
3592 |
> |
* completeOnTimeout has no effect if completed within timeout |
3593 |
|
*/ |
3594 |
|
public void testCompleteOnTimeout2() { |
3595 |
|
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3596 |
|
f.complete(1); |
3597 |
< |
f.completeOnTimeout(-1, SHORT_DELAY_MS, TimeUnit.MILLISECONDS); |
3597 |
> |
f.completeOnTimeout(-1, SHORT_DELAY_MS, MILLISECONDS); |
3598 |
|
checkCompletedNormally(f, 1); |
3599 |
|
} |
3600 |
|
|
3601 |
|
/** |
3602 |
|
* delayedExecutor returns an executor that delays submission |
3603 |
|
*/ |
3604 |
< |
public void testDelayedExecutor() { |
3604 |
> |
public void testDelayedExecutor() throws Exception { |
3605 |
|
long timeoutMillis = SMALL_DELAY_MS; |
3606 |
|
Executor d = CompletableFuture.delayedExecutor(timeoutMillis, |
3607 |
|
MILLISECONDS); |
3608 |
|
long startTime = System.nanoTime(); |
3609 |
|
CompletableFuture<Integer> f = CompletableFuture.supplyAsync(() -> 1, d); |
3610 |
|
assertNull(f.getNow(null)); |
3611 |
< |
try { |
3596 |
< |
f.get(LONG_DELAY_MS, MILLISECONDS); |
3597 |
< |
} catch (Throwable fail) { threadUnexpectedException(fail); } |
3611 |
> |
assertEquals(1, (int) f.get(LONG_DELAY_MS, MILLISECONDS)); |
3612 |
|
assertTrue(millisElapsedSince(startTime) > timeoutMillis/2); |
3613 |
|
checkCompletedNormally(f, 1); |
3614 |
|
} |
3617 |
|
* delayedExecutor for a given executor returns an executor that |
3618 |
|
* delays submission |
3619 |
|
*/ |
3620 |
< |
public void testDelayedExecutor2() { |
3620 |
> |
public void testDelayedExecutor2() throws Exception { |
3621 |
|
long timeoutMillis = SMALL_DELAY_MS; |
3622 |
|
Executor d = CompletableFuture.delayedExecutor(timeoutMillis, |
3623 |
|
MILLISECONDS, |
3625 |
|
long startTime = System.nanoTime(); |
3626 |
|
CompletableFuture<Integer> f = CompletableFuture.supplyAsync(() -> 1, d); |
3627 |
|
assertNull(f.getNow(null)); |
3628 |
< |
try { |
3615 |
< |
f.get(LONG_DELAY_MS, MILLISECONDS); |
3616 |
< |
} catch (Throwable fail) { threadUnexpectedException(fail); } |
3628 |
> |
assertEquals(1, (int) f.get(LONG_DELAY_MS, MILLISECONDS)); |
3629 |
|
assertTrue(millisElapsedSince(startTime) > timeoutMillis/2); |
3630 |
|
checkCompletedNormally(f, 1); |
3631 |
|
} |