3317 |
|
assertEquals(0, exec.count.get()); |
3318 |
|
} |
3319 |
|
|
3320 |
+ |
static class CountingRejectingExecutor implements Executor { |
3321 |
+ |
final RejectedExecutionException ex = new RejectedExecutionException(); |
3322 |
+ |
final AtomicInteger count = new AtomicInteger(0); |
3323 |
+ |
public void execute(Runnable r) { |
3324 |
+ |
count.getAndIncrement(); |
3325 |
+ |
throw ex; |
3326 |
+ |
} |
3327 |
+ |
} |
3328 |
+ |
|
3329 |
|
/** |
3330 |
|
* Test submissions to an executor that rejects all tasks. |
3331 |
|
*/ |
3332 |
|
public void testRejectingExecutor() { |
3324 |
– |
final RejectedExecutionException ex = new RejectedExecutionException(); |
3325 |
– |
final Executor e = (Runnable r) -> { throw ex; }; |
3326 |
– |
|
3333 |
|
for (Integer v : new Integer[] { 1, null }) { |
3334 |
|
|
3335 |
+ |
final CountingRejectingExecutor e = new CountingRejectingExecutor(); |
3336 |
+ |
|
3337 |
|
final CompletableFuture<Integer> complete = CompletableFuture.completedFuture(v); |
3338 |
|
final CompletableFuture<Integer> incomplete = new CompletableFuture<>(); |
3339 |
|
|
3363 |
|
|
3364 |
|
for (CompletableFuture<?> future : fs) { |
3365 |
|
if (src.isDone()) |
3366 |
< |
checkCompletedWithWrappedException(future, ex); |
3366 |
> |
checkCompletedWithWrappedException(future, e.ex); |
3367 |
|
else |
3368 |
|
checkIncomplete(future); |
3369 |
|
} |
3400 |
|
fs.add(incomplete.runAfterEitherAsync(complete, () -> {}, e)); |
3401 |
|
|
3402 |
|
for (CompletableFuture<?> future : fs) |
3403 |
< |
checkCompletedWithWrappedException(future, ex); |
3403 |
> |
checkCompletedWithWrappedException(future, e.ex); |
3404 |
|
futures.addAll(fs); |
3405 |
|
} |
3406 |
|
|
3407 |
|
incomplete.complete(v); |
3408 |
|
|
3409 |
|
for (CompletableFuture<?> future : futures) |
3410 |
< |
checkCompletedWithWrappedException(future, ex); |
3410 |
> |
checkCompletedWithWrappedException(future, e.ex); |
3411 |
> |
|
3412 |
> |
assertEquals(futures.size(), e.count.get()); |
3413 |
> |
|
3414 |
|
} |
3415 |
|
} |
3416 |
|
|
3420 |
|
* explicitly completed. |
3421 |
|
*/ |
3422 |
|
public void testRejectingExecutorNeverInvoked() { |
3412 |
– |
final RejectedExecutionException ex = new RejectedExecutionException(); |
3413 |
– |
class CountingRejectingExecutor implements Executor { |
3414 |
– |
final AtomicInteger count = new AtomicInteger(0); |
3415 |
– |
public void execute(Runnable r) { |
3416 |
– |
count.getAndIncrement(); |
3417 |
– |
throw ex; |
3418 |
– |
} |
3419 |
– |
} |
3423 |
|
final CountingRejectingExecutor e = new CountingRejectingExecutor(); |
3424 |
|
|
3425 |
|
for (Integer v : new Integer[] { 1, null }) { |