345 |
|
|
346 |
|
// Used for explicit executor tests |
347 |
|
static final class ThreadExecutor implements Executor { |
348 |
+ |
AtomicInteger count = new AtomicInteger(0); |
349 |
+ |
|
350 |
|
public void execute(Runnable r) { |
351 |
+ |
count.getAndIncrement(); |
352 |
|
new Thread(r).start(); |
353 |
|
} |
354 |
|
} |
435 |
|
*/ |
436 |
|
public void testRunAsync2() { |
437 |
|
Noop r = new Noop(); |
438 |
< |
CompletableFuture<Void> f = CompletableFuture.runAsync(r, new ThreadExecutor()); |
438 |
> |
ThreadExecutor exec = new ThreadExecutor(); |
439 |
> |
CompletableFuture<Void> f = CompletableFuture.runAsync(r, exec); |
440 |
|
assertNull(f.join()); |
441 |
|
assertTrue(r.ran); |
442 |
|
checkCompletedNormally(f, null); |
443 |
+ |
assertEquals(1, exec.count.get()); |
444 |
|
} |
445 |
|
|
446 |
|
/** |
457 |
|
* supplyAsync completes with result of supplier |
458 |
|
*/ |
459 |
|
public void testSupplyAsync() { |
460 |
< |
CompletableFuture<Integer> f = CompletableFuture.supplyAsync(supplyOne); |
460 |
> |
CompletableFuture<Integer> f; |
461 |
> |
f = CompletableFuture.supplyAsync(supplyOne); |
462 |
|
assertEquals(f.join(), one); |
463 |
+ |
checkCompletedNormally(f, one); |
464 |
|
} |
465 |
|
|
466 |
|
/** |
467 |
|
* supplyAsync with executor completes with result of supplier |
468 |
|
*/ |
469 |
|
public void testSupplyAsync2() { |
470 |
< |
CompletableFuture<Integer> f = CompletableFuture.supplyAsync(supplyOne, new ThreadExecutor()); |
470 |
> |
CompletableFuture<Integer> f; |
471 |
> |
f = CompletableFuture.supplyAsync(supplyOne, new ThreadExecutor()); |
472 |
|
assertEquals(f.join(), one); |
473 |
+ |
checkCompletedNormally(f, one); |
474 |
|
} |
475 |
|
|
476 |
|
/** |
2427 |
|
CompletableFuture<Integer> g = new CompletableFuture<Integer>(); |
2428 |
|
CompletableFuture<Integer> nullFuture = (CompletableFuture<Integer>)null; |
2429 |
|
CompletableFuture<?> h; |
2430 |
< |
Executor exec = new ThreadExecutor(); |
2430 |
> |
ThreadExecutor exec = new ThreadExecutor(); |
2431 |
|
|
2432 |
|
Runnable[] throwingActions = { |
2433 |
|
() -> { CompletableFuture.supplyAsync(null); }, |
2524 |
|
}; |
2525 |
|
|
2526 |
|
assertThrows(NullPointerException.class, throwingActions); |
2527 |
+ |
assertEquals(0, exec.count.get()); |
2528 |
|
} |
2529 |
|
|
2530 |
|
} |