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 { |
3597 |
< |
assertEquals(1, (int) f.get(LONG_DELAY_MS, MILLISECONDS)); |
3598 |
< |
} 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 { |
3616 |
< |
assertEquals(1, (int) f.get(LONG_DELAY_MS, MILLISECONDS)); |
3617 |
< |
} 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 |
|
} |