744 |
|
} |
745 |
|
|
746 |
|
/** Like Runnable, but with the freedom to throw anything */ |
747 |
< |
interface Thunk { public void run() throws Throwable; } |
747 |
> |
interface Action { public void run() throws Throwable; } |
748 |
|
|
749 |
|
/** |
750 |
< |
* Runs all the given tasks in parallel, failing if any fail. |
750 |
> |
* Runs all the given actions in parallel, failing if any fail. |
751 |
|
* Useful for running multiple variants of tests that are |
752 |
|
* necessarily individually slow because they must block. |
753 |
|
*/ |
754 |
< |
void testInParallel(Thunk ... thunks) { |
754 |
> |
void testInParallel(Action ... actions) { |
755 |
|
ExecutorService pool = Executors.newCachedThreadPool(); |
756 |
|
try { |
757 |
< |
ArrayList<Future<?>> futures = new ArrayList<>(thunks.length); |
758 |
< |
for (final Thunk thunk : thunks) |
757 |
> |
ArrayList<Future<?>> futures = new ArrayList<>(actions.length); |
758 |
> |
for (final Action action : actions) |
759 |
|
futures.add(pool.submit(new CheckedRunnable() { |
760 |
< |
public void realRun() throws Throwable { thunk.run();}})); |
760 |
> |
public void realRun() throws Throwable { action.run();}})); |
761 |
|
for (Future<?> future : futures) |
762 |
|
try { |
763 |
|
assertNull(future.get(LONG_DELAY_MS, MILLISECONDS)); |