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); |
3397 |
|
Executor c = ForkJoinPool.commonPool(); |
3398 |
|
if (ForkJoinPool.getCommonPoolParallelism() > 1) |
3399 |
|
assertSame(e, c); |
3400 |
+ |
else |
3401 |
+ |
assertNotSame(e, c); |
3402 |
|
} |
3403 |
|
|
3404 |
|
/** |
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 |
|
|
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 |
|
|
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 |
|
} |
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 { |
3595 |
< |
f.get(LONG_DELAY_MS, MILLISECONDS); |
3596 |
< |
} 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 |
|
} |
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, |
3614 |
|
long startTime = System.nanoTime(); |
3615 |
|
CompletableFuture<Integer> f = CompletableFuture.supplyAsync(() -> 1, d); |
3616 |
|
assertNull(f.getNow(null)); |
3617 |
< |
try { |
3614 |
< |
f.get(LONG_DELAY_MS, MILLISECONDS); |
3615 |
< |
} 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 |
|
} |