640 |
|
|
641 |
|
ASYNC { |
642 |
|
public void checkExecutionMode() { |
643 |
< |
assertEquals(defaultExecutorIsCommonPool, |
644 |
< |
(ForkJoinPool.commonPool() == ForkJoinTask.getPool())); |
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())); |
649 |
|
} |
650 |
|
public CompletableFuture<Void> runAsync(Runnable a) { |
651 |
|
return CompletableFuture.runAsync(a); |
1044 |
|
|
1045 |
|
checkCompletedWithWrappedException(g, ex1); |
1046 |
|
checkCompletedExceptionally(f, ex1); |
1047 |
< |
assertEquals(1, ex1.getSuppressed().length); |
1048 |
< |
assertSame(ex2, ex1.getSuppressed()[0]); |
1047 |
> |
if (testImplementationDetails) { |
1048 |
> |
assertEquals(1, ex1.getSuppressed().length); |
1049 |
> |
assertSame(ex2, ex1.getSuppressed()[0]); |
1050 |
> |
} |
1051 |
|
assertEquals(1, a.get()); |
1052 |
|
}} |
1053 |
|
|
3929 |
|
Monad.plus(godot, Monad.unit(5L))); |
3930 |
|
} |
3931 |
|
|
3932 |
+ |
/** |
3933 |
+ |
* A single CompletableFuture with many dependents. |
3934 |
+ |
* A demo of scalability - runtime is O(n). |
3935 |
+ |
*/ |
3936 |
+ |
public void testManyDependents() throws Throwable { |
3937 |
+ |
final int n = 1_000; |
3938 |
+ |
final CompletableFuture<Void> head = new CompletableFuture<>(); |
3939 |
+ |
final CompletableFuture<Void> complete = CompletableFuture.completedFuture((Void)null); |
3940 |
+ |
final AtomicInteger count = new AtomicInteger(0); |
3941 |
+ |
for (int i = 0; i < n; i++) { |
3942 |
+ |
head.thenRun(() -> count.getAndIncrement()); |
3943 |
+ |
head.thenAccept((x) -> count.getAndIncrement()); |
3944 |
+ |
head.thenApply((x) -> count.getAndIncrement()); |
3945 |
+ |
|
3946 |
+ |
head.runAfterBoth(complete, () -> count.getAndIncrement()); |
3947 |
+ |
head.thenAcceptBoth(complete, (x, y) -> count.getAndIncrement()); |
3948 |
+ |
head.thenCombine(complete, (x, y) -> count.getAndIncrement()); |
3949 |
+ |
complete.runAfterBoth(head, () -> count.getAndIncrement()); |
3950 |
+ |
complete.thenAcceptBoth(head, (x, y) -> count.getAndIncrement()); |
3951 |
+ |
complete.thenCombine(head, (x, y) -> count.getAndIncrement()); |
3952 |
+ |
|
3953 |
+ |
head.runAfterEither(new CompletableFuture<Void>(), () -> count.getAndIncrement()); |
3954 |
+ |
head.acceptEither(new CompletableFuture<Void>(), (x) -> count.getAndIncrement()); |
3955 |
+ |
head.applyToEither(new CompletableFuture<Void>(), (x) -> count.getAndIncrement()); |
3956 |
+ |
new CompletableFuture<Void>().runAfterEither(head, () -> count.getAndIncrement()); |
3957 |
+ |
new CompletableFuture<Void>().acceptEither(head, (x) -> count.getAndIncrement()); |
3958 |
+ |
new CompletableFuture<Void>().applyToEither(head, (x) -> count.getAndIncrement()); |
3959 |
+ |
} |
3960 |
+ |
head.complete(null); |
3961 |
+ |
assertEquals(5 * 3 * n, count.get()); |
3962 |
+ |
} |
3963 |
+ |
|
3964 |
|
// static <U> U join(CompletionStage<U> stage) { |
3965 |
|
// CompletableFuture<U> f = new CompletableFuture<>(); |
3966 |
|
// stage.whenComplete((v, ex) -> { |