2700 |
|
for (ExecutionMode m : ExecutionMode.values()) |
2701 |
|
for (Integer v1 : new Integer[] { 1, null }) |
2702 |
|
for (Integer v2 : new Integer[] { 2, null }) |
2703 |
+ |
for (boolean pushNop : new boolean[] { true, false }) |
2704 |
|
{ |
2705 |
|
final CompletableFuture<Integer> f = new CompletableFuture<>(); |
2706 |
|
final CompletableFuture<Integer> g = new CompletableFuture<>(); |
2713 |
|
checkIncomplete(h1); |
2714 |
|
rs[0].assertNotInvoked(); |
2715 |
|
rs[1].assertNotInvoked(); |
2716 |
+ |
if (pushNop) { // ad hoc test of intra-completion interference |
2717 |
+ |
m.thenRun(f, () -> {}); |
2718 |
+ |
m.thenRun(g, () -> {}); |
2719 |
+ |
} |
2720 |
|
f.complete(v1); |
2721 |
|
checkCompletedNormally(h0, null); |
2722 |
|
checkCompletedNormally(h1, null); |
3359 |
|
* Test submissions to an executor that rejects all tasks. |
3360 |
|
*/ |
3361 |
|
public void testRejectingExecutor() { |
3362 |
< |
for (Integer v : new Integer[] { 1, null }) { |
3363 |
< |
|
3362 |
> |
for (Integer v : new Integer[] { 1, null }) |
3363 |
> |
{ |
3364 |
|
final CountingRejectingExecutor e = new CountingRejectingExecutor(); |
3365 |
|
|
3366 |
|
final CompletableFuture<Integer> complete = CompletableFuture.completedFuture(v); |
3439 |
|
checkCompletedWithWrappedException(future, e.ex); |
3440 |
|
|
3441 |
|
assertEquals(futures.size(), e.count.get()); |
3442 |
< |
|
3438 |
< |
} |
3439 |
< |
} |
3442 |
> |
}} |
3443 |
|
|
3444 |
|
/** |
3445 |
|
* Test submissions to an executor that rejects all tasks, but |
3447 |
|
* explicitly completed. |
3448 |
|
*/ |
3449 |
|
public void testRejectingExecutorNeverInvoked() { |
3450 |
+ |
for (Integer v : new Integer[] { 1, null }) |
3451 |
+ |
{ |
3452 |
|
final CountingRejectingExecutor e = new CountingRejectingExecutor(); |
3453 |
|
|
3449 |
– |
for (Integer v : new Integer[] { 1, null }) { |
3450 |
– |
|
3454 |
|
final CompletableFuture<Integer> complete = CompletableFuture.completedFuture(v); |
3455 |
|
final CompletableFuture<Integer> incomplete = new CompletableFuture<>(); |
3456 |
|
|
3498 |
|
checkCompletedNormally(future, null); |
3499 |
|
|
3500 |
|
assertEquals(0, e.count.get()); |
3501 |
< |
|
3499 |
< |
} |
3500 |
< |
} |
3501 |
> |
}} |
3502 |
|
|
3503 |
|
/** |
3504 |
|
* toCompletableFuture returns this CompletableFuture. |
4139 |
|
Monad.plus(godot, Monad.unit(5L))); |
4140 |
|
} |
4141 |
|
|
4142 |
+ |
/** Test long recursive chains of CompletableFutures with cascading completions */ |
4143 |
+ |
public void testRecursiveChains() throws Throwable { |
4144 |
+ |
for (ExecutionMode m : ExecutionMode.values()) |
4145 |
+ |
for (boolean addDeadEnds : new boolean[] { true, false }) |
4146 |
+ |
{ |
4147 |
+ |
final int val = 42; |
4148 |
+ |
final int n = expensiveTests ? 1_000 : 2; |
4149 |
+ |
CompletableFuture<Integer> head = new CompletableFuture<>(); |
4150 |
+ |
CompletableFuture<Integer> tail = head; |
4151 |
+ |
for (int i = 0; i < n; i++) { |
4152 |
+ |
if (addDeadEnds) m.thenApply(tail, v -> v + 1); |
4153 |
+ |
tail = m.thenApply(tail, v -> v + 1); |
4154 |
+ |
if (addDeadEnds) m.applyToEither(tail, tail, v -> v + 1); |
4155 |
+ |
tail = m.applyToEither(tail, tail, v -> v + 1); |
4156 |
+ |
if (addDeadEnds) m.thenCombine(tail, tail, (v, w) -> v + 1); |
4157 |
+ |
tail = m.thenCombine(tail, tail, (v, w) -> v + 1); |
4158 |
+ |
} |
4159 |
+ |
head.complete(val); |
4160 |
+ |
assertEquals(val + 3 * n, (int) tail.join()); |
4161 |
+ |
}} |
4162 |
+ |
|
4163 |
|
/** |
4164 |
|
* A single CompletableFuture with many dependents. |
4165 |
|
* A demo of scalability - runtime is O(n). |
4192 |
|
assertEquals(5 * 3 * n, count.get()); |
4193 |
|
} |
4194 |
|
|
4195 |
< |
/** ant -Dvmoptions=-Xmx8m -Djsr166.tckTestClass=CompletableFutureTest tck */ |
4196 |
< |
public void testCoCompletionGarbage() throws Throwable { |
4195 |
> |
/** ant -Dvmoptions=-Xmx8m -Djsr166.expensiveTests=true -Djsr166.tckTestClass=CompletableFutureTest tck */ |
4196 |
> |
public void testCoCompletionGarbageRetention() throws Throwable { |
4197 |
|
final int n = expensiveTests ? 1_000_000 : 10; |
4198 |
|
final CompletableFuture<Integer> incomplete = new CompletableFuture<>(); |
4199 |
|
CompletableFuture<Integer> f; |