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); |
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 { |
3597 |
< |
assertEquals(1, (int) f.get(LONG_DELAY_MS, MILLISECONDS)); |
3598 |
< |
} 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 |
|
} |
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, |
3617 |
|
long startTime = System.nanoTime(); |
3618 |
|
CompletableFuture<Integer> f = CompletableFuture.supplyAsync(() -> 1, d); |
3619 |
|
assertNull(f.getNow(null)); |
3620 |
< |
try { |
3616 |
< |
assertEquals(1, (int) f.get(LONG_DELAY_MS, MILLISECONDS)); |
3617 |
< |
} 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 |
|
} |