37 |
|
import java.util.concurrent.Callable; |
38 |
|
import java.util.concurrent.CountDownLatch; |
39 |
|
import java.util.concurrent.CyclicBarrier; |
40 |
+ |
import java.util.concurrent.ExecutionException; |
41 |
+ |
import java.util.concurrent.Executors; |
42 |
|
import java.util.concurrent.ExecutorService; |
43 |
|
import java.util.concurrent.Future; |
44 |
|
import java.util.concurrent.RecursiveAction; |
283 |
|
public static boolean atLeastJava6() { return JAVA_CLASS_VERSION >= 50.0; } |
284 |
|
public static boolean atLeastJava7() { return JAVA_CLASS_VERSION >= 51.0; } |
285 |
|
public static boolean atLeastJava8() { return JAVA_CLASS_VERSION >= 52.0; } |
286 |
< |
public static boolean atLeastJava9() { return JAVA_CLASS_VERSION >= 53.0; } |
286 |
> |
public static boolean atLeastJava9() { |
287 |
> |
return JAVA_CLASS_VERSION >= 53.0 |
288 |
> |
// As of 2015-09, java9 still uses 52.0 class file version |
289 |
> |
|| JAVA_SPECIFICATION_VERSION.matches("^(1\\.)?(9|[0-9][0-9])$"); |
290 |
> |
} |
291 |
> |
public static boolean atLeastJava10() { |
292 |
> |
return JAVA_CLASS_VERSION >= 54.0 |
293 |
> |
|| JAVA_SPECIFICATION_VERSION.matches("^(1\\.)?[0-9][0-9]$"); |
294 |
> |
} |
295 |
|
|
296 |
|
/** |
297 |
|
* Collects all JSR166 unit tests as one suite. |
379 |
|
"LongAdderTest", |
380 |
|
"SplittableRandomTest", |
381 |
|
"StampedLockTest", |
382 |
+ |
"SubmissionPublisherTest", |
383 |
|
"ThreadLocalRandom8Test", |
384 |
|
}; |
385 |
|
addNamedTestClasses(suite, java8TestClassNames); |
388 |
|
// Java9+ test classes |
389 |
|
if (atLeastJava9()) { |
390 |
|
String[] java9TestClassNames = { |
391 |
< |
"ThreadPoolExecutor9Test", |
391 |
> |
// Currently empty |
392 |
|
}; |
393 |
|
addNamedTestClasses(suite, java9TestClassNames); |
394 |
|
} |
730 |
|
/** |
731 |
|
* Waits out termination of a thread pool or fails doing so. |
732 |
|
*/ |
733 |
< |
void joinPool(ExecutorService exec) { |
733 |
> |
void joinPool(ExecutorService pool) { |
734 |
|
try { |
735 |
< |
exec.shutdown(); |
736 |
< |
if (!exec.awaitTermination(2 * LONG_DELAY_MS, MILLISECONDS)) |
737 |
< |
fail("ExecutorService " + exec + |
735 |
> |
pool.shutdown(); |
736 |
> |
if (!pool.awaitTermination(2 * LONG_DELAY_MS, MILLISECONDS)) |
737 |
> |
fail("ExecutorService " + pool + |
738 |
|
" did not terminate in a timely manner"); |
739 |
|
} catch (SecurityException ok) { |
740 |
|
// Allowed in case test doesn't have privs |
743 |
|
} |
744 |
|
} |
745 |
|
|
746 |
+ |
/** Like Runnable, but with the freedom to throw anything */ |
747 |
+ |
interface Action { public void run() throws Throwable; } |
748 |
+ |
|
749 |
+ |
/** |
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(Action ... actions) { |
755 |
+ |
ExecutorService pool = Executors.newCachedThreadPool(); |
756 |
+ |
try { |
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 { action.run();}})); |
761 |
+ |
for (Future<?> future : futures) |
762 |
+ |
try { |
763 |
+ |
assertNull(future.get(LONG_DELAY_MS, MILLISECONDS)); |
764 |
+ |
} catch (ExecutionException ex) { |
765 |
+ |
threadUnexpectedException(ex.getCause()); |
766 |
+ |
} catch (Exception ex) { |
767 |
+ |
threadUnexpectedException(ex); |
768 |
+ |
} |
769 |
+ |
} finally { |
770 |
+ |
joinPool(pool); |
771 |
+ |
} |
772 |
+ |
} |
773 |
+ |
|
774 |
|
/** |
775 |
|
* A debugging tool to print all stack traces, as jstack does. |
776 |
|
*/ |