3354 |
|
* Test submissions to an executor that rejects all tasks. |
3355 |
|
*/ |
3356 |
|
public void testRejectingExecutor() { |
3357 |
< |
for (Integer v : new Integer[] { 1, null }) { |
3358 |
< |
|
3357 |
> |
for (Integer v : new Integer[] { 1, null }) |
3358 |
> |
{ |
3359 |
|
final CountingRejectingExecutor e = new CountingRejectingExecutor(); |
3360 |
|
|
3361 |
|
final CompletableFuture<Integer> complete = CompletableFuture.completedFuture(v); |
3434 |
|
checkCompletedWithWrappedException(future, e.ex); |
3435 |
|
|
3436 |
|
assertEquals(futures.size(), e.count.get()); |
3437 |
< |
|
3438 |
< |
} |
3439 |
< |
} |
3437 |
> |
}} |
3438 |
|
|
3439 |
|
/** |
3440 |
|
* Test submissions to an executor that rejects all tasks, but |
3442 |
|
* explicitly completed. |
3443 |
|
*/ |
3444 |
|
public void testRejectingExecutorNeverInvoked() { |
3445 |
+ |
for (Integer v : new Integer[] { 1, null }) |
3446 |
+ |
{ |
3447 |
|
final CountingRejectingExecutor e = new CountingRejectingExecutor(); |
3448 |
|
|
3449 |
– |
for (Integer v : new Integer[] { 1, null }) { |
3450 |
– |
|
3449 |
|
final CompletableFuture<Integer> complete = CompletableFuture.completedFuture(v); |
3450 |
|
final CompletableFuture<Integer> incomplete = new CompletableFuture<>(); |
3451 |
|
|
3493 |
|
checkCompletedNormally(future, null); |
3494 |
|
|
3495 |
|
assertEquals(0, e.count.get()); |
3496 |
< |
|
3499 |
< |
} |
3500 |
< |
} |
3496 |
> |
}} |
3497 |
|
|
3498 |
|
/** |
3499 |
|
* toCompletableFuture returns this CompletableFuture. |
4139 |
|
* A demo of scalability - runtime is O(n). |
4140 |
|
*/ |
4141 |
|
public void testManyDependents() throws Throwable { |
4142 |
< |
final int n = 1_000; |
4142 |
> |
final int n = expensiveTests ? 1_000_000 : 10; |
4143 |
|
final CompletableFuture<Void> head = new CompletableFuture<>(); |
4144 |
|
final CompletableFuture<Void> complete = CompletableFuture.completedFuture((Void)null); |
4145 |
|
final AtomicInteger count = new AtomicInteger(0); |
4166 |
|
assertEquals(5 * 3 * n, count.get()); |
4167 |
|
} |
4168 |
|
|
4169 |
< |
/** a66 -Dvmoptions=-Xmx8m -Djsr166.tckTestClass=CompletableFutureTest tck */ |
4170 |
< |
public void testCoCompletionGarbage() throws Throwable { |
4171 |
< |
// final int n = 3_000_000; |
4176 |
< |
final int n = 100; |
4169 |
> |
/** ant -Dvmoptions=-Xmx8m -Djsr166.expensiveTests=true -Djsr166.tckTestClass=CompletableFutureTest tck */ |
4170 |
> |
public void testCoCompletionGarbageRetention() throws Throwable { |
4171 |
> |
final int n = expensiveTests ? 1_000_000 : 10; |
4172 |
|
final CompletableFuture<Integer> incomplete = new CompletableFuture<>(); |
4173 |
|
CompletableFuture<Integer> f; |
4174 |
|
for (int i = 0; i < n; i++) { |
4208 |
|
} |
4209 |
|
} |
4210 |
|
|
4211 |
+ |
/* |
4212 |
+ |
* Tests below currently fail in stress mode due to memory retention. |
4213 |
+ |
* ant -Dvmoptions=-Xmx8m -Djsr166.expensiveTests=true -Djsr166.tckTestClass=CompletableFutureTest tck |
4214 |
+ |
*/ |
4215 |
+ |
|
4216 |
+ |
/** Checks for garbage retention with anyOf. */ |
4217 |
+ |
public void testAnyOfGarbageRetention() throws Throwable { |
4218 |
+ |
for (Integer v : new Integer[] { 1, null }) |
4219 |
+ |
{ |
4220 |
+ |
final int n = expensiveTests ? 100_000 : 10; |
4221 |
+ |
CompletableFuture<Integer>[] fs |
4222 |
+ |
= (CompletableFuture<Integer>[]) new CompletableFuture<?>[100]; |
4223 |
+ |
for (int i = 0; i < fs.length; i++) |
4224 |
+ |
fs[i] = new CompletableFuture<>(); |
4225 |
+ |
fs[fs.length - 1].complete(v); |
4226 |
+ |
for (int i = 0; i < n; i++) |
4227 |
+ |
checkCompletedNormally(CompletableFuture.anyOf(fs), v); |
4228 |
+ |
}} |
4229 |
+ |
|
4230 |
+ |
/** Checks for garbage retention with allOf. */ |
4231 |
+ |
public void testCancelledAllOfGarbageRetention() throws Throwable { |
4232 |
+ |
final int n = expensiveTests ? 100_000 : 10; |
4233 |
+ |
CompletableFuture<Integer>[] fs |
4234 |
+ |
= (CompletableFuture<Integer>[]) new CompletableFuture<?>[100]; |
4235 |
+ |
for (int i = 0; i < fs.length; i++) |
4236 |
+ |
fs[i] = new CompletableFuture<>(); |
4237 |
+ |
for (int i = 0; i < n; i++) |
4238 |
+ |
assertTrue(CompletableFuture.allOf(fs).cancel(false)); |
4239 |
+ |
} |
4240 |
+ |
|
4241 |
|
// static <U> U join(CompletionStage<U> stage) { |
4242 |
|
// CompletableFuture<U> f = new CompletableFuture<>(); |
4243 |
|
// stage.whenComplete((v, ex) -> { |