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.133 by jsr166, Sun May 24 01:53:55 2015 UTC vs.
Revision 1.172 by jsr166, Fri Oct 9 01:26:36 2015 UTC

# Line 7 | Line 7
7   */
8  
9   import static java.util.concurrent.TimeUnit.MILLISECONDS;
10 + import static java.util.concurrent.TimeUnit.MINUTES;
11   import static java.util.concurrent.TimeUnit.NANOSECONDS;
12  
13   import java.io.ByteArrayInputStream;
# Line 15 | Line 16 | import java.io.ObjectInputStream;
16   import java.io.ObjectOutputStream;
17   import java.lang.management.ManagementFactory;
18   import java.lang.management.ThreadInfo;
19 + import java.lang.management.ThreadMXBean;
20 + import java.lang.reflect.Constructor;
21   import java.lang.reflect.Method;
22 + import java.lang.reflect.Modifier;
23 + import java.nio.file.Files;
24 + import java.nio.file.Paths;
25   import java.security.CodeSource;
26   import java.security.Permission;
27   import java.security.PermissionCollection;
# Line 35 | Line 41 | import java.util.concurrent.BlockingQueu
41   import java.util.concurrent.Callable;
42   import java.util.concurrent.CountDownLatch;
43   import java.util.concurrent.CyclicBarrier;
44 + import java.util.concurrent.ExecutionException;
45 + import java.util.concurrent.Executors;
46   import java.util.concurrent.ExecutorService;
47 + import java.util.concurrent.ForkJoinPool;
48   import java.util.concurrent.Future;
49   import java.util.concurrent.RecursiveAction;
50   import java.util.concurrent.RecursiveTask;
# Line 45 | Line 54 | import java.util.concurrent.ThreadFactor
54   import java.util.concurrent.ThreadPoolExecutor;
55   import java.util.concurrent.TimeoutException;
56   import java.util.concurrent.atomic.AtomicReference;
57 + import java.util.regex.Matcher;
58   import java.util.regex.Pattern;
59  
60   import junit.framework.AssertionFailedError;
# Line 63 | Line 73 | import junit.framework.TestSuite;
73   *
74   * <ol>
75   *
76 < * <li> All assertions in code running in generated threads must use
76 > * <li>All assertions in code running in generated threads must use
77   * the forms {@link #threadFail}, {@link #threadAssertTrue}, {@link
78   * #threadAssertEquals}, or {@link #threadAssertNull}, (not
79   * {@code fail}, {@code assertTrue}, etc.) It is OK (but not
80   * particularly recommended) for other code to use these forms too.
81   * Only the most typically used JUnit assertion methods are defined
82 < * this way, but enough to live with.</li>
82 > * this way, but enough to live with.
83   *
84 < * <li> If you override {@link #setUp} or {@link #tearDown}, make sure
84 > * <li>If you override {@link #setUp} or {@link #tearDown}, make sure
85   * to invoke {@code super.setUp} and {@code super.tearDown} within
86   * them. These methods are used to clear and check for thread
87 < * assertion failures.</li>
87 > * assertion failures.
88   *
89   * <li>All delays and timeouts must use one of the constants {@code
90   * SHORT_DELAY_MS}, {@code SMALL_DELAY_MS}, {@code MEDIUM_DELAY_MS},
# Line 85 | Line 95 | import junit.framework.TestSuite;
95   * is always discriminable as larger than SHORT and smaller than
96   * MEDIUM.  And so on. These constants are set to conservative values,
97   * but even so, if there is ever any doubt, they can all be increased
98 < * in one spot to rerun tests on slower platforms.</li>
98 > * in one spot to rerun tests on slower platforms.
99   *
100 < * <li> All threads generated must be joined inside each test case
100 > * <li>All threads generated must be joined inside each test case
101   * method (or {@code fail} to do so) before returning from the
102   * method. The {@code joinPool} method can be used to do this when
103 < * using Executors.</li>
103 > * using Executors.
104   *
105   * </ol>
106   *
107   * <p><b>Other notes</b>
108   * <ul>
109   *
110 < * <li> Usually, there is one testcase method per JSR166 method
110 > * <li>Usually, there is one testcase method per JSR166 method
111   * covering "normal" operation, and then as many exception-testing
112   * methods as there are exceptions the method can throw. Sometimes
113   * there are multiple tests per JSR166 method when the different
114   * "normal" behaviors differ significantly. And sometimes testcases
115   * cover multiple methods when they cannot be tested in
116 < * isolation.</li>
116 > * isolation.
117   *
118 < * <li> The documentation style for testcases is to provide as javadoc
118 > * <li>The documentation style for testcases is to provide as javadoc
119   * a simple sentence or two describing the property that the testcase
120   * method purports to test. The javadocs do not say anything about how
121 < * the property is tested. To find out, read the code.</li>
121 > * the property is tested. To find out, read the code.
122   *
123 < * <li> These tests are "conformance tests", and do not attempt to
123 > * <li>These tests are "conformance tests", and do not attempt to
124   * test throughput, latency, scalability or other performance factors
125   * (see the separate "jtreg" tests for a set intended to check these
126   * for the most central aspects of functionality.) So, most tests use
127   * the smallest sensible numbers of threads, collection sizes, etc
128 < * needed to check basic conformance.</li>
128 > * needed to check basic conformance.
129   *
130   * <li>The test classes currently do not declare inclusion in
131   * any particular package to simplify things for people integrating
132 < * them in TCK test suites.</li>
132 > * them in TCK test suites.
133   *
134 < * <li> As a convenience, the {@code main} of this class (JSR166TestCase)
135 < * runs all JSR166 unit tests.</li>
134 > * <li>As a convenience, the {@code main} of this class (JSR166TestCase)
135 > * runs all JSR166 unit tests.
136   *
137   * </ul>
138   */
# Line 166 | Line 176 | public class JSR166TestCase extends Test
176      private static final int suiteRuns =
177          Integer.getInteger("jsr166.suiteRuns", 1);
178  
179 +    public JSR166TestCase() { super(); }
180 +    public JSR166TestCase(String name) { super(name); }
181 +
182      /**
183       * A filter for tests to run, matching strings of the form
184       * methodName(className), e.g. "testInvokeAll5(ForkJoinPoolTest)"
# Line 178 | Line 191 | public class JSR166TestCase extends Test
191          return (regex == null) ? null : Pattern.compile(regex);
192      }
193  
194 <    protected void runTest() throws Throwable {
194 >    // Instrumentation to debug very rare, but very annoying hung test runs.
195 >    static volatile TestCase currentTestCase;
196 >    static volatile int currentRun = 0;
197 >    static {
198 >        Runnable checkForWedgedTest = new Runnable() { public void run() {
199 >            // avoid spurious reports with enormous runsPerTest
200 >            final int timeoutMinutes = Math.max(runsPerTest / 10, 1);
201 >            for (TestCase lastTestCase = currentTestCase;;) {
202 >                try { MINUTES.sleep(timeoutMinutes); }
203 >                catch (InterruptedException unexpected) { break; }
204 >                if (lastTestCase == currentTestCase) {
205 >                    System.err.printf(
206 >                        "Looks like we're stuck running test: %s (%d/%d)%n",
207 >                        lastTestCase, currentRun, runsPerTest);
208 >                    System.err.println("availableProcessors=" +
209 >                        Runtime.getRuntime().availableProcessors());
210 >                    System.err.printf("cpu model = %s%n", cpuModel());
211 >                    dumpTestThreads();
212 >                    // one stack dump is probably enough; more would be spam
213 >                    break;
214 >                }
215 >                lastTestCase = currentTestCase;
216 >            }}};
217 >        Thread thread = new Thread(checkForWedgedTest, "checkForWedgedTest");
218 >        thread.setDaemon(true);
219 >        thread.start();
220 >    }
221 >
222 >    public static String cpuModel() {
223 >        try {
224 >            Matcher matcher = Pattern.compile("model name\\s*: (.*)")
225 >                .matcher(new String(
226 >                     Files.readAllBytes(Paths.get("/proc/cpuinfo")), "UTF-8"));
227 >            matcher.find();
228 >            return matcher.group(1);
229 >        } catch (Exception ex) { return null; }
230 >    }
231 >
232 >    public void runBare() throws Throwable {
233 >        currentTestCase = this;
234          if (methodFilter == null
235 <            || methodFilter.matcher(toString()).find()) {
236 <            for (int i = 0; i < runsPerTest; i++) {
237 <                if (profileTests)
238 <                    runTestProfiled();
239 <                else
240 <                    super.runTest();
241 <            }
235 >            || methodFilter.matcher(toString()).find())
236 >            super.runBare();
237 >    }
238 >
239 >    protected void runTest() throws Throwable {
240 >        for (int i = 0; i < runsPerTest; i++) {
241 >            currentRun = i;
242 >            if (profileTests)
243 >                runTestProfiled();
244 >            else
245 >                super.runTest();
246          }
247      }
248  
249      protected void runTestProfiled() throws Throwable {
250 <        // Warmup run, notably to trigger all needed classloading.
251 <        super.runTest();
196 <        long t0 = System.nanoTime();
197 <        try {
250 >        for (int i = 0; i < 2; i++) {
251 >            long startTime = System.nanoTime();
252              super.runTest();
253 <        } finally {
254 <            long elapsedMillis = millisElapsedSince(t0);
255 <            if (elapsedMillis >= profileThreshold)
253 >            long elapsedMillis = millisElapsedSince(startTime);
254 >            if (elapsedMillis < profileThreshold)
255 >                break;
256 >            // Never report first run of any test; treat it as a
257 >            // warmup run, notably to trigger all needed classloading,
258 >            if (i > 0)
259                  System.out.printf("%n%s: %d%n", toString(), elapsedMillis);
260          }
261      }
# Line 276 | Line 333 | public class JSR166TestCase extends Test
333      public static boolean atLeastJava6() { return JAVA_CLASS_VERSION >= 50.0; }
334      public static boolean atLeastJava7() { return JAVA_CLASS_VERSION >= 51.0; }
335      public static boolean atLeastJava8() { return JAVA_CLASS_VERSION >= 52.0; }
336 <    public static boolean atLeastJava9() { return JAVA_CLASS_VERSION >= 53.0; }
336 >    public static boolean atLeastJava9() {
337 >        return JAVA_CLASS_VERSION >= 53.0
338 >            // As of 2015-09, java9 still uses 52.0 class file version
339 >            || JAVA_SPECIFICATION_VERSION.matches("^(1\\.)?(9|[0-9][0-9])$");
340 >    }
341 >    public static boolean atLeastJava10() {
342 >        return JAVA_CLASS_VERSION >= 54.0
343 >            || JAVA_SPECIFICATION_VERSION.matches("^(1\\.)?[0-9][0-9]$");
344 >    }
345  
346      /**
347       * Collects all JSR166 unit tests as one suite.
# Line 364 | Line 429 | public class JSR166TestCase extends Test
429                  "LongAdderTest",
430                  "SplittableRandomTest",
431                  "StampedLockTest",
432 +                "SubmissionPublisherTest",
433                  "ThreadLocalRandom8Test",
434              };
435              addNamedTestClasses(suite, java8TestClassNames);
# Line 372 | Line 438 | public class JSR166TestCase extends Test
438          // Java9+ test classes
439          if (atLeastJava9()) {
440              String[] java9TestClassNames = {
441 <                "ThreadPoolExecutor9Test",
441 >                // Currently empty, but expecting varhandle tests
442              };
443              addNamedTestClasses(suite, java9TestClassNames);
444          }
# Line 380 | Line 446 | public class JSR166TestCase extends Test
446          return suite;
447      }
448  
449 +    /** Returns list of junit-style test method names in given class. */
450 +    public static ArrayList<String> testMethodNames(Class<?> testClass) {
451 +        Method[] methods = testClass.getDeclaredMethods();
452 +        ArrayList<String> names = new ArrayList<String>(methods.length);
453 +        for (Method method : methods) {
454 +            if (method.getName().startsWith("test")
455 +                && Modifier.isPublic(method.getModifiers())
456 +                // method.getParameterCount() requires jdk8+
457 +                && method.getParameterTypes().length == 0) {
458 +                names.add(method.getName());
459 +            }
460 +        }
461 +        return names;
462 +    }
463 +
464 +    /**
465 +     * Returns junit-style testSuite for the given test class, but
466 +     * parameterized by passing extra data to each test.
467 +     */
468 +    public static <ExtraData> Test parameterizedTestSuite
469 +        (Class<? extends JSR166TestCase> testClass,
470 +         Class<ExtraData> dataClass,
471 +         ExtraData data) {
472 +        try {
473 +            TestSuite suite = new TestSuite();
474 +            Constructor c =
475 +                testClass.getDeclaredConstructor(dataClass, String.class);
476 +            for (String methodName : testMethodNames(testClass))
477 +                suite.addTest((Test) c.newInstance(data, methodName));
478 +            return suite;
479 +        } catch (Exception e) {
480 +            throw new Error(e);
481 +        }
482 +    }
483 +
484 +    /**
485 +     * Returns junit-style testSuite for the jdk8 extension of the
486 +     * given test class, but parameterized by passing extra data to
487 +     * each test.  Uses reflection to allow compilation in jdk7.
488 +     */
489 +    public static <ExtraData> Test jdk8ParameterizedTestSuite
490 +        (Class<? extends JSR166TestCase> testClass,
491 +         Class<ExtraData> dataClass,
492 +         ExtraData data) {
493 +        if (atLeastJava8()) {
494 +            String name = testClass.getName();
495 +            String name8 = name.replaceAll("Test$", "8Test");
496 +            if (name.equals(name8)) throw new Error(name);
497 +            try {
498 +                return (Test)
499 +                    Class.forName(name8)
500 +                    .getMethod("testSuite", new Class[] { dataClass })
501 +                    .invoke(null, data);
502 +            } catch (Exception e) {
503 +                throw new Error(e);
504 +            }
505 +        } else {
506 +            return new TestSuite();
507 +        }
508 +    }
509 +
510      // Delays for timing-dependent tests, in milliseconds.
511  
512      public static long SHORT_DELAY_MS;
# Line 414 | Line 541 | public class JSR166TestCase extends Test
541      }
542  
543      /**
544 <     * Returns a new Date instance representing a time delayMillis
545 <     * milliseconds in the future.
544 >     * Returns a new Date instance representing a time at least
545 >     * delayMillis milliseconds in the future.
546       */
547      Date delayedDate(long delayMillis) {
548 <        return new Date(System.currentTimeMillis() + delayMillis);
548 >        // Add 1 because currentTimeMillis is known to round into the past.
549 >        return new Date(System.currentTimeMillis() + delayMillis + 1);
550      }
551  
552      /**
# Line 434 | Line 562 | public class JSR166TestCase extends Test
562       * the same test have no effect.
563       */
564      public void threadRecordFailure(Throwable t) {
565 +        System.err.println(t);
566 +        dumpTestThreads();
567          threadFailure.compareAndSet(null, t);
568      }
569  
# Line 441 | Line 571 | public class JSR166TestCase extends Test
571          setDelays();
572      }
573  
574 +    void tearDownFail(String format, Object... args) {
575 +        String msg = toString() + ": " + String.format(format, args);
576 +        System.err.println(msg);
577 +        dumpTestThreads();
578 +        throw new AssertionFailedError(msg);
579 +    }
580 +
581      /**
582       * Extra checks that get done for all test cases.
583       *
# Line 468 | Line 605 | public class JSR166TestCase extends Test
605          }
606  
607          if (Thread.interrupted())
608 <            throw new AssertionFailedError("interrupt status set in main thread");
608 >            tearDownFail("interrupt status set in main thread");
609  
610          checkForkJoinPoolThreadLeaks();
611      }
612  
613      /**
614 <     * Finds missing try { ... } finally { joinPool(e); }
614 >     * Finds missing PoolCleaners
615       */
616      void checkForkJoinPoolThreadLeaks() throws InterruptedException {
617 <        Thread[] survivors = new Thread[5];
617 >        Thread[] survivors = new Thread[7];
618          int count = Thread.enumerate(survivors);
619          for (int i = 0; i < count; i++) {
620              Thread thread = survivors[i];
# Line 485 | Line 622 | public class JSR166TestCase extends Test
622              if (name.startsWith("ForkJoinPool-")) {
623                  // give thread some time to terminate
624                  thread.join(LONG_DELAY_MS);
625 <                if (!thread.isAlive()) continue;
626 <                throw new AssertionFailedError
627 <                    (String.format("Found leaked ForkJoinPool thread test=%s thread=%s%n",
491 <                                   toString(), name));
625 >                if (thread.isAlive())
626 >                    tearDownFail("Found leaked ForkJoinPool thread thread=%s",
627 >                                 thread);
628              }
629          }
630 +
631 +        if (!ForkJoinPool.commonPool()
632 +            .awaitQuiescence(LONG_DELAY_MS, MILLISECONDS))
633 +            tearDownFail("ForkJoin common pool thread stuck");
634      }
635  
636      /**
# Line 503 | Line 643 | public class JSR166TestCase extends Test
643              fail(reason);
644          } catch (AssertionFailedError t) {
645              threadRecordFailure(t);
646 <            fail(reason);
646 >            throw t;
647          }
648      }
649  
# Line 630 | Line 770 | public class JSR166TestCase extends Test
770      /**
771       * Delays, via Thread.sleep, for the given millisecond delay, but
772       * if the sleep is shorter than specified, may re-sleep or yield
773 <     * until time elapses.
773 >     * until time elapses.  Ensures that the given time, as measured
774 >     * by System.nanoTime(), has elapsed.
775       */
776      static void delay(long millis) throws InterruptedException {
777 <        long startTime = System.nanoTime();
778 <        long ns = millis * 1000 * 1000;
779 <        for (;;) {
777 >        long nanos = millis * (1000 * 1000);
778 >        final long wakeupTime = System.nanoTime() + nanos;
779 >        do {
780              if (millis > 0L)
781                  Thread.sleep(millis);
782              else // too short to sleep
783                  Thread.yield();
784 <            long d = ns - (System.nanoTime() - startTime);
785 <            if (d > 0L)
786 <                millis = d / (1000 * 1000);
787 <            else
788 <                break;
784 >            nanos = wakeupTime - System.nanoTime();
785 >            millis = nanos / (1000 * 1000);
786 >        } while (nanos >= 0L);
787 >    }
788 >
789 >    /**
790 >     * Allows use of try-with-resources with per-test thread pools.
791 >     */
792 >    class PoolCleaner implements AutoCloseable {
793 >        private final ExecutorService pool;
794 >        public PoolCleaner(ExecutorService pool) { this.pool = pool; }
795 >        public void close() { joinPool(pool); }
796 >    }
797 >
798 >    /**
799 >     * An extension of PoolCleaner that has an action to release the pool.
800 >     */
801 >    class PoolCleanerWithReleaser extends PoolCleaner {
802 >        private final Runnable releaser;
803 >        public PoolCleanerWithReleaser(ExecutorService pool, Runnable releaser) {
804 >            super(pool);
805 >            this.releaser = releaser;
806 >        }
807 >        public void close() {
808 >            try {
809 >                releaser.run();
810 >            } finally {
811 >                super.close();
812 >            }
813          }
814      }
815  
816 +    PoolCleaner cleaner(ExecutorService pool) {
817 +        return new PoolCleaner(pool);
818 +    }
819 +
820 +    PoolCleaner cleaner(ExecutorService pool, Runnable releaser) {
821 +        return new PoolCleanerWithReleaser(pool, releaser);
822 +    }
823 +
824 +    PoolCleaner cleaner(ExecutorService pool, CountDownLatch latch) {
825 +        return new PoolCleanerWithReleaser(pool, releaser(latch));
826 +    }
827 +
828 +    Runnable releaser(final CountDownLatch latch) {
829 +        return new Runnable() { public void run() {
830 +            do { latch.countDown(); }
831 +            while (latch.getCount() > 0);
832 +        }};
833 +    }
834 +
835      /**
836       * Waits out termination of a thread pool or fails doing so.
837       */
838 <    void joinPool(ExecutorService exec) {
838 >    void joinPool(ExecutorService pool) {
839          try {
840 <            exec.shutdown();
841 <            if (!exec.awaitTermination(2 * LONG_DELAY_MS, MILLISECONDS))
842 <                fail("ExecutorService " + exec +
843 <                     " did not terminate in a timely manner");
840 >            pool.shutdown();
841 >            if (!pool.awaitTermination(2 * LONG_DELAY_MS, MILLISECONDS)) {
842 >                try {
843 >                    threadFail("ExecutorService " + pool +
844 >                               " did not terminate in a timely manner");
845 >                } finally {
846 >                    // last resort, for the benefit of subsequent tests
847 >                    pool.shutdownNow();
848 >                    pool.awaitTermination(MEDIUM_DELAY_MS, MILLISECONDS);
849 >                }
850 >            }
851          } catch (SecurityException ok) {
852              // Allowed in case test doesn't have privs
853          } catch (InterruptedException fail) {
854 <            fail("Unexpected InterruptedException");
854 >            threadFail("Unexpected InterruptedException");
855          }
856      }
857  
858 +    /** Like Runnable, but with the freedom to throw anything */
859 +    interface Action { public void run() throws Throwable; }
860 +
861      /**
862 <     * A debugging tool to print all stack traces, as jstack does.
862 >     * Runs all the given actions in parallel, failing if any fail.
863 >     * Useful for running multiple variants of tests that are
864 >     * necessarily individually slow because they must block.
865       */
866 <    static void printAllStackTraces() {
867 <        for (ThreadInfo info :
868 <                 ManagementFactory.getThreadMXBean()
869 <                 .dumpAllThreads(true, true))
866 >    void testInParallel(Action ... actions) {
867 >        ExecutorService pool = Executors.newCachedThreadPool();
868 >        try (PoolCleaner cleaner = cleaner(pool)) {
869 >            ArrayList<Future<?>> futures = new ArrayList<>(actions.length);
870 >            for (final Action action : actions)
871 >                futures.add(pool.submit(new CheckedRunnable() {
872 >                    public void realRun() throws Throwable { action.run();}}));
873 >            for (Future<?> future : futures)
874 >                try {
875 >                    assertNull(future.get(LONG_DELAY_MS, MILLISECONDS));
876 >                } catch (ExecutionException ex) {
877 >                    threadUnexpectedException(ex.getCause());
878 >                } catch (Exception ex) {
879 >                    threadUnexpectedException(ex);
880 >                }
881 >        }
882 >    }
883 >
884 >    /**
885 >     * A debugging tool to print stack traces of most threads, as jstack does.
886 >     * Uninteresting threads are filtered out.
887 >     */
888 >    static void dumpTestThreads() {
889 >        ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean();
890 >        System.err.println("------ stacktrace dump start ------");
891 >        for (ThreadInfo info : threadMXBean.dumpAllThreads(true, true)) {
892 >            String name = info.getThreadName();
893 >            if ("Signal Dispatcher".equals(name))
894 >                continue;
895 >            if ("Reference Handler".equals(name)
896 >                && info.getLockName().startsWith("java.lang.ref.Reference$Lock"))
897 >                continue;
898 >            if ("Finalizer".equals(name)
899 >                && info.getLockName().startsWith("java.lang.ref.ReferenceQueue$Lock"))
900 >                continue;
901 >            if ("checkForWedgedTest".equals(name))
902 >                continue;
903              System.err.print(info);
904 +        }
905 +        System.err.println("------ stacktrace dump end ------");
906      }
907  
908      /**
# Line 691 | Line 922 | public class JSR166TestCase extends Test
922              delay(millis);
923              assertTrue(thread.isAlive());
924          } catch (InterruptedException fail) {
925 <            fail("Unexpected InterruptedException");
925 >            threadFail("Unexpected InterruptedException");
926          }
927      }
928  
# Line 713 | Line 944 | public class JSR166TestCase extends Test
944              for (Thread thread : threads)
945                  assertTrue(thread.isAlive());
946          } catch (InterruptedException fail) {
947 <            fail("Unexpected InterruptedException");
947 >            threadFail("Unexpected InterruptedException");
948          }
949      }
950  
# Line 991 | Line 1222 | public class JSR166TestCase extends Test
1222          } finally {
1223              if (t.getState() != Thread.State.TERMINATED) {
1224                  t.interrupt();
1225 <                fail("Test timed out");
1225 >                threadFail("Test timed out");
1226              }
1227          }
1228      }
# Line 1116 | Line 1347 | public class JSR166TestCase extends Test
1347      public static final String TEST_STRING = "a test string";
1348  
1349      public static class StringTask implements Callable<String> {
1350 <        public String call() { return TEST_STRING; }
1350 >        final String value;
1351 >        public StringTask() { this(TEST_STRING); }
1352 >        public StringTask(String value) { this.value = value; }
1353 >        public String call() { return value; }
1354      }
1355  
1356      public Callable<String> latchAwaitingStringTask(final CountDownLatch latch) {
# Line 1129 | Line 1363 | public class JSR166TestCase extends Test
1363              }};
1364      }
1365  
1366 <    public Runnable awaiter(final CountDownLatch latch) {
1366 >    public Runnable countDowner(final CountDownLatch latch) {
1367          return new CheckedRunnable() {
1368              public void realRun() throws InterruptedException {
1369 <                await(latch);
1369 >                latch.countDown();
1370              }};
1371      }
1372  
1373 +    class LatchAwaiter extends CheckedRunnable {
1374 +        static final int NEW = 0;
1375 +        static final int RUNNING = 1;
1376 +        static final int DONE = 2;
1377 +        final CountDownLatch latch;
1378 +        int state = NEW;
1379 +        LatchAwaiter(CountDownLatch latch) { this.latch = latch; }
1380 +        public void realRun() throws InterruptedException {
1381 +            state = 1;
1382 +            await(latch);
1383 +            state = 2;
1384 +        }
1385 +    }
1386 +
1387 +    public LatchAwaiter awaiter(CountDownLatch latch) {
1388 +        return new LatchAwaiter(latch);
1389 +    }
1390 +
1391      public void await(CountDownLatch latch) {
1392          try {
1393              assertTrue(latch.await(LONG_DELAY_MS, MILLISECONDS));

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines