640 |
|
|
641 |
|
ASYNC { |
642 |
|
public void checkExecutionMode() { |
643 |
< |
// If tests are added that may run across different |
644 |
< |
// pools, this needs to be weakened to no-op. |
645 |
< |
ForkJoinPool p = ForkJoinTask.getPool(); |
646 |
< |
assertTrue(p == null || |
647 |
< |
(defaultExecutorIsCommonPool && |
648 |
< |
p == ForkJoinPool.commonPool())); |
643 |
> |
assertEquals(defaultExecutorIsCommonPool, |
644 |
> |
(ForkJoinPool.commonPool() == ForkJoinTask.getPool())); |
645 |
|
} |
646 |
|
public CompletableFuture<Void> runAsync(Runnable a) { |
647 |
|
return CompletableFuture.runAsync(a); |
3525 |
|
long timeoutMillis = timeoutMillis(); |
3526 |
|
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3527 |
|
long startTime = System.nanoTime(); |
3528 |
< |
f.orTimeout(timeoutMillis, MILLISECONDS); |
3528 |
> |
assertSame(f, f.orTimeout(timeoutMillis, MILLISECONDS)); |
3529 |
|
checkCompletedWithTimeoutException(f); |
3530 |
|
assertTrue(millisElapsedSince(startTime) >= timeoutMillis); |
3531 |
|
} |
3540 |
|
CompletableFuture<Integer> g = new CompletableFuture<>(); |
3541 |
|
long startTime = System.nanoTime(); |
3542 |
|
f.complete(v1); |
3543 |
< |
f.orTimeout(LONG_DELAY_MS, MILLISECONDS); |
3544 |
< |
g.orTimeout(LONG_DELAY_MS, MILLISECONDS); |
3543 |
> |
assertSame(f, f.orTimeout(LONG_DELAY_MS, MILLISECONDS)); |
3544 |
> |
assertSame(g, g.orTimeout(LONG_DELAY_MS, MILLISECONDS)); |
3545 |
|
g.complete(v1); |
3546 |
|
checkCompletedNormally(f, v1); |
3547 |
|
checkCompletedNormally(g, v1); |
3556 |
|
() -> testCompleteOnTimeout_timesOut(null)); |
3557 |
|
} |
3558 |
|
|
3559 |
+ |
/** |
3560 |
+ |
* completeOnTimeout completes with given value if not complete |
3561 |
+ |
*/ |
3562 |
|
public void testCompleteOnTimeout_timesOut(Integer v) { |
3563 |
|
long timeoutMillis = timeoutMillis(); |
3564 |
|
CompletableFuture<Integer> f = new CompletableFuture<>(); |
3565 |
|
long startTime = System.nanoTime(); |
3566 |
< |
f.completeOnTimeout(v, timeoutMillis, MILLISECONDS); |
3566 |
> |
assertSame(f, f.completeOnTimeout(v, timeoutMillis, MILLISECONDS)); |
3567 |
|
assertSame(v, f.join()); |
3568 |
|
assertTrue(millisElapsedSince(startTime) >= timeoutMillis); |
3569 |
|
f.complete(99); // should have no effect |
3580 |
|
CompletableFuture<Integer> g = new CompletableFuture<>(); |
3581 |
|
long startTime = System.nanoTime(); |
3582 |
|
f.complete(v1); |
3583 |
< |
f.completeOnTimeout(-1, LONG_DELAY_MS, MILLISECONDS); |
3584 |
< |
g.completeOnTimeout(-1, LONG_DELAY_MS, MILLISECONDS); |
3583 |
> |
assertSame(f, f.completeOnTimeout(-1, LONG_DELAY_MS, MILLISECONDS)); |
3584 |
> |
assertSame(g, g.completeOnTimeout(-1, LONG_DELAY_MS, MILLISECONDS)); |
3585 |
|
g.complete(v1); |
3586 |
|
checkCompletedNormally(f, v1); |
3587 |
|
checkCompletedNormally(g, v1); |
3632 |
|
//--- tests of implementation details; not part of official tck --- |
3633 |
|
|
3634 |
|
Object resultOf(CompletableFuture<?> f) { |
3635 |
+ |
SecurityManager sm = System.getSecurityManager(); |
3636 |
+ |
if (sm != null) { |
3637 |
+ |
try { |
3638 |
+ |
System.setSecurityManager(null); |
3639 |
+ |
} catch (SecurityException giveUp) { |
3640 |
+ |
return "Reflection not available"; |
3641 |
+ |
} |
3642 |
+ |
} |
3643 |
+ |
|
3644 |
|
try { |
3645 |
|
java.lang.reflect.Field resultField |
3646 |
|
= CompletableFuture.class.getDeclaredField("result"); |
3647 |
|
resultField.setAccessible(true); |
3648 |
|
return resultField.get(f); |
3649 |
< |
} catch (Throwable t) { throw new AssertionError(t); } |
3649 |
> |
} catch (Throwable t) { |
3650 |
> |
throw new AssertionError(t); |
3651 |
> |
} finally { |
3652 |
> |
if (sm != null) System.setSecurityManager(sm); |
3653 |
> |
} |
3654 |
|
} |
3655 |
|
|
3656 |
|
public void testExceptionPropagationReusesResultObject() { |
3673 |
|
funs.add((y) -> m.applyToEither(y, incomplete, new IncFunction(m))); |
3674 |
|
|
3675 |
|
funs.add((y) -> m.runAfterBoth(y, v42, new Noop(m))); |
3676 |
+ |
funs.add((y) -> m.runAfterBoth(v42, y, new Noop(m))); |
3677 |
|
funs.add((y) -> m.thenAcceptBoth(y, v42, new SubtractAction(m))); |
3678 |
+ |
funs.add((y) -> m.thenAcceptBoth(v42, y, new SubtractAction(m))); |
3679 |
|
funs.add((y) -> m.thenCombine(y, v42, new SubtractFunction(m))); |
3680 |
+ |
funs.add((y) -> m.thenCombine(v42, y, new SubtractFunction(m))); |
3681 |
|
|
3682 |
|
funs.add((y) -> m.whenComplete(y, (Integer r, Throwable t) -> {})); |
3683 |
|
|
3684 |
|
funs.add((y) -> m.thenCompose(y, new CompletableFutureInc(m))); |
3685 |
|
|
3686 |
+ |
funs.add((y) -> CompletableFuture.allOf(new CompletableFuture<?>[] {y})); |
3687 |
|
funs.add((y) -> CompletableFuture.allOf(new CompletableFuture<?>[] {y, v42})); |
3688 |
+ |
funs.add((y) -> CompletableFuture.allOf(new CompletableFuture<?>[] {v42, y})); |
3689 |
+ |
funs.add((y) -> CompletableFuture.anyOf(new CompletableFuture<?>[] {y})); |
3690 |
|
funs.add((y) -> CompletableFuture.anyOf(new CompletableFuture<?>[] {y, incomplete})); |
3691 |
+ |
funs.add((y) -> CompletableFuture.anyOf(new CompletableFuture<?>[] {incomplete, y})); |
3692 |
|
|
3693 |
|
for (Function<CompletableFuture<Integer>, CompletableFuture<?>> |
3694 |
|
fun : funs) { |