ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/tck/JSR166TestCase.java
(Generate patch)

Comparing jsr166/src/test/tck/JSR166TestCase.java (file contents):
Revision 1.135 by jsr166, Fri Jul 3 05:48:30 2015 UTC vs.
Revision 1.140 by dl, Mon Sep 7 17:14:06 2015 UTC

# Line 37 | Line 37 | import java.util.concurrent.BlockingQueu
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;
# Line 281 | Line 283 | public class JSR166TestCase extends Test
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.
# Line 369 | Line 379 | public class JSR166TestCase extends Test
379                  "LongAdderTest",
380                  "SplittableRandomTest",
381                  "StampedLockTest",
382 +                "SubmissionPublisherTest",
383                  "ThreadLocalRandom8Test",
384              };
385              addNamedTestClasses(suite, java8TestClassNames);
# Line 377 | Line 388 | public class JSR166TestCase extends Test
388          // Java9+ test classes
389          if (atLeastJava9()) {
390              String[] java9TestClassNames = {
391 <                "ThreadPoolExecutor9Test",
391 >                // Currently empty
392              };
393              addNamedTestClasses(suite, java9TestClassNames);
394          }
# Line 719 | Line 730 | public class JSR166TestCase extends Test
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
# Line 732 | Line 743 | public class JSR166TestCase extends Test
743          }
744      }
745  
746 +    /** Like Runnable, but with the freedom to throw anything */
747 +    interface Thunk { public void run() throws Throwable; }
748 +
749 +    /**
750 +     * Runs all the given tasks 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) {
755 +        ExecutorService pool = Executors.newCachedThreadPool();
756 +        try {
757 +            ArrayList<Future<?>> futures = new ArrayList<>(thunks.length);
758 +            for (final Thunk thunk : thunks)
759 +                futures.add(pool.submit(new CheckedRunnable() {
760 +                    public void realRun() throws Throwable { thunk.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       */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines