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.157 by jsr166, Sat Oct 3 22:20:05 2015 UTC vs.
Revision 1.159 by jsr166, Sun Oct 4 00:30:50 2015 UTC

# Line 541 | Line 541 | public class JSR166TestCase extends Test
541       * the same test have no effect.
542       */
543      public void threadRecordFailure(Throwable t) {
544 +        System.err.println(t);
545          dumpTestThreads();
546          threadFailure.compareAndSet(null, t);
547      }
# Line 769 | Line 770 | public class JSR166TestCase extends Test
770      /**
771       * Allows use of try-with-resources with per-test thread pools.
772       */
773 <    static class PoolCloser<T extends ExecutorService>
773 >    class PoolCleaner<T extends ExecutorService>
774              implements AutoCloseable {
775          public final T pool;
776 <        public PoolCloser(T pool) { this.pool = pool; }
776 >        public PoolCleaner(T pool) { this.pool = pool; }
777          public void close() { joinPool(pool); }
778      }
779  
780 +    <T extends ExecutorService> PoolCleaner<T> cleaner(T pool) {
781 +        return new PoolCleaner<T>(pool);
782 +    }
783 +
784      /**
785       * Waits out termination of a thread pool or fails doing so.
786       */
787 <    static void joinPool(ExecutorService pool) {
787 >    void joinPool(ExecutorService pool) {
788          try {
789              pool.shutdown();
790 <            if (!pool.awaitTermination(2 * LONG_DELAY_MS, MILLISECONDS))
791 <                fail("ExecutorService " + pool +
792 <                     " did not terminate in a timely manner");
790 >            if (!pool.awaitTermination(2 * LONG_DELAY_MS, MILLISECONDS)) {
791 >                try {
792 >                    threadFail("ExecutorService " + pool +
793 >                               " did not terminate in a timely manner");
794 >                } finally {
795 >                    // last resort, for the benefit of subsequent tests
796 >                    pool.shutdownNow();
797 >                    pool.awaitTermination(SMALL_DELAY_MS, MILLISECONDS);
798 >                }
799 >            }
800          } catch (SecurityException ok) {
801              // Allowed in case test doesn't have privs
802          } catch (InterruptedException fail) {
803 <            fail("Unexpected InterruptedException");
803 >            threadFail("Unexpected InterruptedException");
804          }
805      }
806  
# Line 801 | Line 813 | public class JSR166TestCase extends Test
813       * necessarily individually slow because they must block.
814       */
815      void testInParallel(Action ... actions) {
816 <        try (PoolCloser<ExecutorService> poolCloser
817 <             = new PoolCloser<>(Executors.newCachedThreadPool())) {
818 <            ExecutorService pool = poolCloser.pool;
816 >        try (PoolCleaner<ExecutorService> cleaner
817 >             = cleaner(Executors.newCachedThreadPool())) {
818 >            ExecutorService pool = cleaner.pool;
819              ArrayList<Future<?>> futures = new ArrayList<>(actions.length);
820              for (final Action action : actions)
821                  futures.add(pool.submit(new CheckedRunnable() {
# Line 860 | Line 872 | public class JSR166TestCase extends Test
872              delay(millis);
873              assertTrue(thread.isAlive());
874          } catch (InterruptedException fail) {
875 <            fail("Unexpected InterruptedException");
875 >            threadFail("Unexpected InterruptedException");
876          }
877      }
878  
# Line 882 | Line 894 | public class JSR166TestCase extends Test
894              for (Thread thread : threads)
895                  assertTrue(thread.isAlive());
896          } catch (InterruptedException fail) {
897 <            fail("Unexpected InterruptedException");
897 >            threadFail("Unexpected InterruptedException");
898          }
899      }
900  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines