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.161 by jsr166, Sun Oct 4 03:49:33 2015 UTC vs.
Revision 1.167 by jsr166, Mon Oct 5 22:34:45 2015 UTC

# Line 201 | Line 201 | public class JSR166TestCase extends Test
201                          ("Looks like we're stuck running test: "
202                           + lastTestCase);
203                      dumpTestThreads();
204 +                    // one stack dump is probably enough; more would be spam
205 +                    break;
206                  }
207                  lastTestCase = currentTestCase;
208              }}};
# Line 590 | Line 592 | public class JSR166TestCase extends Test
592      }
593  
594      /**
595 <     * Finds missing try { ... } finally { joinPool(e); }
595 >     * Finds missing PoolCleaners
596       */
597      void checkForkJoinPoolThreadLeaks() throws InterruptedException {
598          Thread[] survivors = new Thread[7];
# Line 749 | Line 751 | public class JSR166TestCase extends Test
751      /**
752       * Delays, via Thread.sleep, for the given millisecond delay, but
753       * if the sleep is shorter than specified, may re-sleep or yield
754 <     * until time elapses.
754 >     * until time elapses.  Ensures that the given time, as measured
755 >     * by System.nanoTime(), has elapsed.
756       */
757      static void delay(long millis) throws InterruptedException {
758 <        long startTime = System.nanoTime();
759 <        long ns = millis * 1000 * 1000;
760 <        for (;;) {
758 >        long nanos = millis * (1000 * 1000);
759 >        final long wakeupTime = System.nanoTime() + nanos;
760 >        do {
761              if (millis > 0L)
762                  Thread.sleep(millis);
763              else // too short to sleep
764                  Thread.yield();
765 <            long d = ns - (System.nanoTime() - startTime);
766 <            if (d > 0L)
767 <                millis = d / (1000 * 1000);
765 <            else
766 <                break;
767 <        }
765 >            nanos = wakeupTime - System.nanoTime();
766 >            millis = nanos / (1000 * 1000);
767 >        } while (nanos >= 0L);
768      }
769  
770      /**
# Line 776 | Line 776 | public class JSR166TestCase extends Test
776          public void close() { joinPool(pool); }
777      }
778  
779 +    /**
780 +     * An extension of PoolCleaner that has an action to release the pool.
781 +     */
782 +    class PoolCleanerWithReleaser extends PoolCleaner {
783 +        private final Runnable releaser;
784 +        public PoolCleanerWithReleaser(ExecutorService pool, Runnable releaser) {
785 +            super(pool);
786 +            this.releaser = releaser;
787 +        }
788 +        public void close() {
789 +            try {
790 +                releaser.run();
791 +            } finally {
792 +                super.close();
793 +            }
794 +        }
795 +    }
796 +
797      PoolCleaner cleaner(ExecutorService pool) {
798          return new PoolCleaner(pool);
799      }
800  
801 +    PoolCleaner cleaner(ExecutorService pool, Runnable releaser) {
802 +        return new PoolCleanerWithReleaser(pool, releaser);
803 +    }
804 +
805 +    PoolCleaner cleaner(ExecutorService pool, CountDownLatch latch) {
806 +        return new PoolCleanerWithReleaser(pool, releaser(latch));
807 +    }
808 +
809 +    Runnable releaser(final CountDownLatch latch) {
810 +        return new Runnable() { public void run() {
811 +            do { latch.countDown(); }
812 +            while (latch.getCount() > 0);
813 +        }};
814 +    }
815 +
816      /**
817       * Waits out termination of a thread pool or fails doing so.
818       */
# Line 793 | Line 826 | public class JSR166TestCase extends Test
826                  } finally {
827                      // last resort, for the benefit of subsequent tests
828                      pool.shutdownNow();
829 <                    pool.awaitTermination(SMALL_DELAY_MS, MILLISECONDS);
829 >                    pool.awaitTermination(MEDIUM_DELAY_MS, MILLISECONDS);
830                  }
831              }
832          } catch (SecurityException ok) {
# Line 1319 | Line 1352 | public class JSR166TestCase extends Test
1352      }
1353  
1354      class LatchAwaiter extends CheckedRunnable {
1355 <        final static int NEW = 0;
1356 <        final static int RUNNING = 1;
1357 <        final static int DONE = 2;
1355 >        static final int NEW = 0;
1356 >        static final int RUNNING = 1;
1357 >        static final int DONE = 2;
1358          final CountDownLatch latch;
1359          int state = NEW;
1360          LatchAwaiter(CountDownLatch latch) { this.latch = latch; }
# Line 1331 | Line 1364 | public class JSR166TestCase extends Test
1364              state = 2;
1365          }
1366      }
1367 <    
1367 >
1368      public LatchAwaiter awaiter(CountDownLatch latch) {
1369          return new LatchAwaiter(latch);
1370      }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines