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.110 by jsr166, Sun Jul 14 22:39:31 2013 UTC vs.
Revision 1.145 by jsr166, Fri Sep 25 05:41:29 2015 UTC

# Line 6 | Line 6
6   * Pat Fisher, Mike Judd.
7   */
8  
9 < import junit.framework.*;
9 > import static java.util.concurrent.TimeUnit.MILLISECONDS;
10 > import static java.util.concurrent.TimeUnit.NANOSECONDS;
11 >
12   import java.io.ByteArrayInputStream;
13   import java.io.ByteArrayOutputStream;
14   import java.io.ObjectInputStream;
15   import java.io.ObjectOutputStream;
16   import java.lang.management.ManagementFactory;
17   import java.lang.management.ThreadInfo;
18 + import java.lang.reflect.Constructor;
19   import java.lang.reflect.Method;
20 + import java.lang.reflect.Modifier;
21 + import java.security.CodeSource;
22 + import java.security.Permission;
23 + import java.security.PermissionCollection;
24 + import java.security.Permissions;
25 + import java.security.Policy;
26 + import java.security.ProtectionDomain;
27 + import java.security.SecurityPermission;
28   import java.util.ArrayList;
29   import java.util.Arrays;
30   import java.util.Date;
31   import java.util.Enumeration;
32 + import java.util.Iterator;
33   import java.util.List;
34   import java.util.NoSuchElementException;
35   import java.util.PropertyPermission;
36 < import java.util.concurrent.*;
37 < import java.util.concurrent.atomic.AtomicBoolean;
36 > import java.util.concurrent.BlockingQueue;
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;
45 > import java.util.concurrent.RecursiveTask;
46 > import java.util.concurrent.RejectedExecutionHandler;
47 > import java.util.concurrent.Semaphore;
48 > import java.util.concurrent.ThreadFactory;
49 > import java.util.concurrent.ThreadPoolExecutor;
50 > import java.util.concurrent.TimeoutException;
51   import java.util.concurrent.atomic.AtomicReference;
52 < import static java.util.concurrent.TimeUnit.MILLISECONDS;
53 < import static java.util.concurrent.TimeUnit.NANOSECONDS;
54 < import java.security.CodeSource;
55 < import java.security.Permission;
56 < import java.security.PermissionCollection;
57 < import java.security.Permissions;
58 < import java.security.Policy;
34 < import java.security.ProtectionDomain;
35 < import java.security.SecurityPermission;
52 > import java.util.regex.Pattern;
53 >
54 > import junit.framework.AssertionFailedError;
55 > import junit.framework.Test;
56 > import junit.framework.TestCase;
57 > import junit.framework.TestResult;
58 > import junit.framework.TestSuite;
59  
60   /**
61   * Base class for JSR166 Junit TCK tests.  Defines some constants,
# Line 44 | Line 67 | import java.security.SecurityPermission;
67   *
68   * <ol>
69   *
70 < * <li> All assertions in code running in generated threads must use
70 > * <li>All assertions in code running in generated threads must use
71   * the forms {@link #threadFail}, {@link #threadAssertTrue}, {@link
72   * #threadAssertEquals}, or {@link #threadAssertNull}, (not
73   * {@code fail}, {@code assertTrue}, etc.) It is OK (but not
74   * particularly recommended) for other code to use these forms too.
75   * Only the most typically used JUnit assertion methods are defined
76 < * this way, but enough to live with.</li>
76 > * this way, but enough to live with.
77   *
78 < * <li> If you override {@link #setUp} or {@link #tearDown}, make sure
78 > * <li>If you override {@link #setUp} or {@link #tearDown}, make sure
79   * to invoke {@code super.setUp} and {@code super.tearDown} within
80   * them. These methods are used to clear and check for thread
81 < * assertion failures.</li>
81 > * assertion failures.
82   *
83   * <li>All delays and timeouts must use one of the constants {@code
84   * SHORT_DELAY_MS}, {@code SMALL_DELAY_MS}, {@code MEDIUM_DELAY_MS},
# Line 66 | Line 89 | import java.security.SecurityPermission;
89   * is always discriminable as larger than SHORT and smaller than
90   * MEDIUM.  And so on. These constants are set to conservative values,
91   * but even so, if there is ever any doubt, they can all be increased
92 < * in one spot to rerun tests on slower platforms.</li>
92 > * in one spot to rerun tests on slower platforms.
93   *
94 < * <li> All threads generated must be joined inside each test case
94 > * <li>All threads generated must be joined inside each test case
95   * method (or {@code fail} to do so) before returning from the
96   * method. The {@code joinPool} method can be used to do this when
97 < * using Executors.</li>
97 > * using Executors.
98   *
99   * </ol>
100   *
101   * <p><b>Other notes</b>
102   * <ul>
103   *
104 < * <li> Usually, there is one testcase method per JSR166 method
104 > * <li>Usually, there is one testcase method per JSR166 method
105   * covering "normal" operation, and then as many exception-testing
106   * methods as there are exceptions the method can throw. Sometimes
107   * there are multiple tests per JSR166 method when the different
108   * "normal" behaviors differ significantly. And sometimes testcases
109   * cover multiple methods when they cannot be tested in
110 < * isolation.</li>
110 > * isolation.
111   *
112 < * <li> The documentation style for testcases is to provide as javadoc
112 > * <li>The documentation style for testcases is to provide as javadoc
113   * a simple sentence or two describing the property that the testcase
114   * method purports to test. The javadocs do not say anything about how
115 < * the property is tested. To find out, read the code.</li>
115 > * the property is tested. To find out, read the code.
116   *
117 < * <li> These tests are "conformance tests", and do not attempt to
117 > * <li>These tests are "conformance tests", and do not attempt to
118   * test throughput, latency, scalability or other performance factors
119   * (see the separate "jtreg" tests for a set intended to check these
120   * for the most central aspects of functionality.) So, most tests use
121   * the smallest sensible numbers of threads, collection sizes, etc
122 < * needed to check basic conformance.</li>
122 > * needed to check basic conformance.
123   *
124   * <li>The test classes currently do not declare inclusion in
125   * any particular package to simplify things for people integrating
126 < * them in TCK test suites.</li>
126 > * them in TCK test suites.
127   *
128 < * <li> As a convenience, the {@code main} of this class (JSR166TestCase)
129 < * runs all JSR166 unit tests.</li>
128 > * <li>As a convenience, the {@code main} of this class (JSR166TestCase)
129 > * runs all JSR166 unit tests.
130   *
131   * </ul>
132   */
# Line 115 | Line 138 | public class JSR166TestCase extends Test
138          Boolean.getBoolean("jsr166.expensiveTests");
139  
140      /**
141 +     * If true, also run tests that are not part of the official tck
142 +     * because they test unspecified implementation details.
143 +     */
144 +    protected static final boolean testImplementationDetails =
145 +        Boolean.getBoolean("jsr166.testImplementationDetails");
146 +
147 +    /**
148       * If true, report on stdout all "slow" tests, that is, ones that
149       * take more than profileThreshold milliseconds to execute.
150       */
# Line 134 | Line 164 | public class JSR166TestCase extends Test
164      private static final int runsPerTest =
165          Integer.getInteger("jsr166.runsPerTest", 1);
166  
167 +    /**
168 +     * The number of repetitions of the test suite (for finding leaks?).
169 +     */
170 +    private static final int suiteRuns =
171 +        Integer.getInteger("jsr166.suiteRuns", 1);
172 +
173 +    public JSR166TestCase() { super(); }
174 +    public JSR166TestCase(String name) { super(name); }
175 +
176 +    /**
177 +     * A filter for tests to run, matching strings of the form
178 +     * methodName(className), e.g. "testInvokeAll5(ForkJoinPoolTest)"
179 +     * Usefully combined with jsr166.runsPerTest.
180 +     */
181 +    private static final Pattern methodFilter = methodFilter();
182 +
183 +    private static Pattern methodFilter() {
184 +        String regex = System.getProperty("jsr166.methodFilter");
185 +        return (regex == null) ? null : Pattern.compile(regex);
186 +    }
187 +
188      protected void runTest() throws Throwable {
189 <        for (int i = 0; i < runsPerTest; i++) {
190 <            if (profileTests)
191 <                runTestProfiled();
192 <            else
193 <                super.runTest();
189 >        if (methodFilter == null
190 >            || methodFilter.matcher(toString()).find()) {
191 >            for (int i = 0; i < runsPerTest; i++) {
192 >                if (profileTests)
193 >                    runTestProfiled();
194 >                else
195 >                    super.runTest();
196 >            }
197          }
198      }
199  
200      protected void runTestProfiled() throws Throwable {
201 <        long t0 = System.nanoTime();
202 <        try {
201 >        for (int i = 0; i < 2; i++) {
202 >            long startTime = System.nanoTime();
203              super.runTest();
204 <        } finally {
205 <            long elapsedMillis =
206 <                (System.nanoTime() - t0) / (1000L * 1000L);
207 <            if (elapsedMillis >= profileThreshold)
204 >            long elapsedMillis = millisElapsedSince(startTime);
205 >            if (elapsedMillis < profileThreshold)
206 >                break;
207 >            // Never report first run of any test; treat it as a
208 >            // warmup run, notably to trigger all needed classloading,
209 >            if (i > 0)
210                  System.out.printf("%n%s: %d%n", toString(), elapsedMillis);
211          }
212      }
213  
214      /**
215       * Runs all JSR166 unit tests using junit.textui.TestRunner.
160     * Optional command line arg provides the number of iterations to
161     * repeat running the tests.
216       */
217      public static void main(String[] args) {
218 +        main(suite(), args);
219 +    }
220 +
221 +    /**
222 +     * Runs all unit tests in the given test suite.
223 +     * Actual behavior influenced by jsr166.* system properties.
224 +     */
225 +    static void main(Test suite, String[] args) {
226          if (useSecurityManager) {
227              System.err.println("Setting a permissive security manager");
228              Policy.setPolicy(permissivePolicy());
229              System.setSecurityManager(new SecurityManager());
230          }
231 <        int iters = (args.length == 0) ? 1 : Integer.parseInt(args[0]);
232 <
233 <        Test s = suite();
234 <        for (int i = 0; i < iters; ++i) {
173 <            junit.textui.TestRunner.run(s);
231 >        for (int i = 0; i < suiteRuns; i++) {
232 >            TestResult result = junit.textui.TestRunner.run(suite);
233 >            if (!result.wasSuccessful())
234 >                System.exit(1);
235              System.gc();
236              System.runFinalization();
237          }
177        System.exit(0);
238      }
239  
240      public static TestSuite newTestSuite(Object... suiteOrClasses) {
# Line 205 | Line 265 | public class JSR166TestCase extends Test
265      }
266  
267      public static final double JAVA_CLASS_VERSION;
268 +    public static final String JAVA_SPECIFICATION_VERSION;
269      static {
270          try {
271              JAVA_CLASS_VERSION = java.security.AccessController.doPrivileged(
272                  new java.security.PrivilegedAction<Double>() {
273                  public Double run() {
274                      return Double.valueOf(System.getProperty("java.class.version"));}});
275 +            JAVA_SPECIFICATION_VERSION = java.security.AccessController.doPrivileged(
276 +                new java.security.PrivilegedAction<String>() {
277 +                public String run() {
278 +                    return System.getProperty("java.specification.version");}});
279          } catch (Throwable t) {
280              throw new Error(t);
281          }
# Line 219 | Line 284 | public class JSR166TestCase extends Test
284      public static boolean atLeastJava6() { return JAVA_CLASS_VERSION >= 50.0; }
285      public static boolean atLeastJava7() { return JAVA_CLASS_VERSION >= 51.0; }
286      public static boolean atLeastJava8() { return JAVA_CLASS_VERSION >= 52.0; }
287 +    public static boolean atLeastJava9() {
288 +        return JAVA_CLASS_VERSION >= 53.0
289 +            // As of 2015-09, java9 still uses 52.0 class file version
290 +            || JAVA_SPECIFICATION_VERSION.matches("^(1\\.)?(9|[0-9][0-9])$");
291 +    }
292 +    public static boolean atLeastJava10() {
293 +        return JAVA_CLASS_VERSION >= 54.0
294 +            || JAVA_SPECIFICATION_VERSION.matches("^(1\\.)?[0-9][0-9]$");
295 +    }
296  
297      /**
298       * Collects all JSR166 unit tests as one suite.
# Line 294 | Line 368 | public class JSR166TestCase extends Test
368          // Java8+ test classes
369          if (atLeastJava8()) {
370              String[] java8TestClassNames = {
371 +                "Atomic8Test",
372                  "CompletableFutureTest",
373                  "ConcurrentHashMap8Test",
374                  "CountedCompleterTest",
375                  "DoubleAccumulatorTest",
376                  "DoubleAdderTest",
377                  "ForkJoinPool8Test",
378 +                "ForkJoinTask8Test",
379                  "LongAccumulatorTest",
380                  "LongAdderTest",
381                  "SplittableRandomTest",
382                  "StampedLockTest",
383 +                "SubmissionPublisherTest",
384 +                "ThreadLocalRandom8Test",
385              };
386              addNamedTestClasses(suite, java8TestClassNames);
387          }
388  
389 +        // Java9+ test classes
390 +        if (atLeastJava9()) {
391 +            String[] java9TestClassNames = {
392 +                // Currently empty, but expecting varhandle tests
393 +            };
394 +            addNamedTestClasses(suite, java9TestClassNames);
395 +        }
396 +
397          return suite;
398      }
399  
400 +    /** Returns list of junit-style test method names in given class. */
401 +    public static ArrayList<String> testMethodNames(Class<?> testClass) {
402 +        Method[] methods = testClass.getDeclaredMethods();
403 +        ArrayList<String> names = new ArrayList<String>(methods.length);
404 +        for (Method method : methods) {
405 +            if (method.getName().startsWith("test")
406 +                && Modifier.isPublic(method.getModifiers())
407 +                // method.getParameterCount() requires jdk8+
408 +                && method.getParameterTypes().length == 0) {
409 +                names.add(method.getName());
410 +            }
411 +        }
412 +        return names;
413 +    }
414 +
415 +    /**
416 +     * Returns junit-style testSuite for the given test class, but
417 +     * parameterized by passing extra data to each test.
418 +     */
419 +    public static <ExtraData> Test parameterizedTestSuite
420 +        (Class<? extends JSR166TestCase> testClass,
421 +         Class<ExtraData> dataClass,
422 +         ExtraData data) {
423 +        try {
424 +            TestSuite suite = new TestSuite();
425 +            Constructor c =
426 +                testClass.getDeclaredConstructor(dataClass, String.class);
427 +            for (String methodName : testMethodNames(testClass))
428 +                suite.addTest((Test) c.newInstance(data, methodName));
429 +            return suite;
430 +        } catch (Exception e) {
431 +            throw new Error(e);
432 +        }
433 +    }
434 +
435 +    /**
436 +     * Returns junit-style testSuite for the jdk8 extension of the
437 +     * given test class, but parameterized by passing extra data to
438 +     * each test.  Uses reflection to allow compilation in jdk7.
439 +     */
440 +    public static <ExtraData> Test jdk8ParameterizedTestSuite
441 +        (Class<? extends JSR166TestCase> testClass,
442 +         Class<ExtraData> dataClass,
443 +         ExtraData data) {
444 +        if (atLeastJava8()) {
445 +            String name = testClass.getName();
446 +            String name8 = name.replaceAll("Test$", "8Test");
447 +            if (name.equals(name8)) throw new Error(name);
448 +            try {
449 +                return (Test)
450 +                    Class.forName(name8)
451 +                    .getMethod("testSuite", new Class[] { dataClass })
452 +                    .invoke(null, data);
453 +            } catch (Exception e) {
454 +                throw new Error(e);
455 +            }
456 +        } else {
457 +            return new TestSuite();
458 +        }
459 +
460 +    }
461 +
462      // Delays for timing-dependent tests, in milliseconds.
463  
464      public static long SHORT_DELAY_MS;
# Line 345 | Line 493 | public class JSR166TestCase extends Test
493      }
494  
495      /**
496 <     * Returns a new Date instance representing a time delayMillis
497 <     * milliseconds in the future.
496 >     * Returns a new Date instance representing a time at least
497 >     * delayMillis milliseconds in the future.
498       */
499      Date delayedDate(long delayMillis) {
500 <        return new Date(System.currentTimeMillis() + delayMillis);
500 >        // Add 1 because currentTimeMillis is known to round into the past.
501 >        return new Date(System.currentTimeMillis() + delayMillis + 1);
502      }
503  
504      /**
# Line 405 | Line 554 | public class JSR166TestCase extends Test
554      }
555  
556      /**
557 <     * Find missing try { ... } finally { joinPool(e); }
557 >     * Finds missing try { ... } finally { joinPool(e); }
558       */
559      void checkForkJoinPoolThreadLeaks() throws InterruptedException {
560          Thread[] survivors = new Thread[5];
# Line 417 | Line 566 | public class JSR166TestCase extends Test
566                  // give thread some time to terminate
567                  thread.join(LONG_DELAY_MS);
568                  if (!thread.isAlive()) continue;
420                thread.stop();
569                  throw new AssertionFailedError
570                      (String.format("Found leaked ForkJoinPool thread test=%s thread=%s%n",
571                                     toString(), name));
# Line 503 | Line 651 | public class JSR166TestCase extends Test
651      public void threadAssertEquals(Object x, Object y) {
652          try {
653              assertEquals(x, y);
654 <        } catch (AssertionFailedError t) {
655 <            threadRecordFailure(t);
656 <            throw t;
657 <        } catch (Throwable t) {
658 <            threadUnexpectedException(t);
654 >        } catch (AssertionFailedError fail) {
655 >            threadRecordFailure(fail);
656 >            throw fail;
657 >        } catch (Throwable fail) {
658 >            threadUnexpectedException(fail);
659          }
660      }
661  
# Line 519 | Line 667 | public class JSR166TestCase extends Test
667      public void threadAssertSame(Object x, Object y) {
668          try {
669              assertSame(x, y);
670 <        } catch (AssertionFailedError t) {
671 <            threadRecordFailure(t);
672 <            throw t;
670 >        } catch (AssertionFailedError fail) {
671 >            threadRecordFailure(fail);
672 >            throw fail;
673          }
674      }
675  
# Line 583 | Line 731 | public class JSR166TestCase extends Test
731      /**
732       * Waits out termination of a thread pool or fails doing so.
733       */
734 <    void joinPool(ExecutorService exec) {
734 >    void joinPool(ExecutorService pool) {
735          try {
736 <            exec.shutdown();
737 <            assertTrue("ExecutorService did not terminate in a timely manner",
738 <                       exec.awaitTermination(2 * LONG_DELAY_MS, MILLISECONDS));
736 >            pool.shutdown();
737 >            if (!pool.awaitTermination(2 * LONG_DELAY_MS, MILLISECONDS))
738 >                fail("ExecutorService " + pool +
739 >                     " did not terminate in a timely manner");
740          } catch (SecurityException ok) {
741              // Allowed in case test doesn't have privs
742 <        } catch (InterruptedException ie) {
742 >        } catch (InterruptedException fail) {
743              fail("Unexpected InterruptedException");
744          }
745      }
746  
747 +    /** Like Runnable, but with the freedom to throw anything */
748 +    interface Action { public void run() throws Throwable; }
749 +
750 +    /**
751 +     * Runs all the given actions in parallel, failing if any fail.
752 +     * Useful for running multiple variants of tests that are
753 +     * necessarily individually slow because they must block.
754 +     */
755 +    void testInParallel(Action ... actions) {
756 +        ExecutorService pool = Executors.newCachedThreadPool();
757 +        try {
758 +            ArrayList<Future<?>> futures = new ArrayList<>(actions.length);
759 +            for (final Action action : actions)
760 +                futures.add(pool.submit(new CheckedRunnable() {
761 +                    public void realRun() throws Throwable { action.run();}}));
762 +            for (Future<?> future : futures)
763 +                try {
764 +                    assertNull(future.get(LONG_DELAY_MS, MILLISECONDS));
765 +                } catch (ExecutionException ex) {
766 +                    threadUnexpectedException(ex.getCause());
767 +                } catch (Exception ex) {
768 +                    threadUnexpectedException(ex);
769 +                }
770 +        } finally {
771 +            joinPool(pool);
772 +        }
773 +    }
774 +
775      /**
776       * A debugging tool to print all stack traces, as jstack does.
777       */
# Line 621 | Line 798 | public class JSR166TestCase extends Test
798              // No need to optimize the failing case via Thread.join.
799              delay(millis);
800              assertTrue(thread.isAlive());
801 <        } catch (InterruptedException ie) {
801 >        } catch (InterruptedException fail) {
802              fail("Unexpected InterruptedException");
803          }
804      }
# Line 643 | Line 820 | public class JSR166TestCase extends Test
820              delay(millis);
821              for (Thread thread : threads)
822                  assertTrue(thread.isAlive());
823 <        } catch (InterruptedException ie) {
823 >        } catch (InterruptedException fail) {
824              fail("Unexpected InterruptedException");
825          }
826      }
# Line 665 | Line 842 | public class JSR166TestCase extends Test
842              future.get(timeoutMillis, MILLISECONDS);
843              shouldThrow();
844          } catch (TimeoutException success) {
845 <        } catch (Exception e) {
846 <            threadUnexpectedException(e);
845 >        } catch (Exception fail) {
846 >            threadUnexpectedException(fail);
847          } finally { future.cancel(true); }
848          assertTrue(millisElapsedSince(startTime) >= timeoutMillis);
849      }
# Line 822 | Line 999 | public class JSR166TestCase extends Test
999      void sleep(long millis) {
1000          try {
1001              delay(millis);
1002 <        } catch (InterruptedException ie) {
1002 >        } catch (InterruptedException fail) {
1003              AssertionFailedError afe =
1004                  new AssertionFailedError("Unexpected InterruptedException");
1005 <            afe.initCause(ie);
1005 >            afe.initCause(fail);
1006              throw afe;
1007          }
1008      }
# Line 863 | Line 1040 | public class JSR166TestCase extends Test
1040      /**
1041       * Returns the number of milliseconds since time given by
1042       * startNanoTime, which must have been previously returned from a
1043 <     * call to {@link System.nanoTime()}.
1043 >     * call to {@link System#nanoTime()}.
1044       */
1045 <    long millisElapsedSince(long startNanoTime) {
1045 >    static long millisElapsedSince(long startNanoTime) {
1046          return NANOSECONDS.toMillis(System.nanoTime() - startNanoTime);
1047      }
1048  
1049 + //     void assertTerminatesPromptly(long timeoutMillis, Runnable r) {
1050 + //         long startTime = System.nanoTime();
1051 + //         try {
1052 + //             r.run();
1053 + //         } catch (Throwable fail) { threadUnexpectedException(fail); }
1054 + //         if (millisElapsedSince(startTime) > timeoutMillis/2)
1055 + //             throw new AssertionFailedError("did not return promptly");
1056 + //     }
1057 +
1058 + //     void assertTerminatesPromptly(Runnable r) {
1059 + //         assertTerminatesPromptly(LONG_DELAY_MS/2, r);
1060 + //     }
1061 +
1062 +    /**
1063 +     * Checks that timed f.get() returns the expected value, and does not
1064 +     * wait for the timeout to elapse before returning.
1065 +     */
1066 +    <T> void checkTimedGet(Future<T> f, T expectedValue, long timeoutMillis) {
1067 +        long startTime = System.nanoTime();
1068 +        try {
1069 +            assertEquals(expectedValue, f.get(timeoutMillis, MILLISECONDS));
1070 +        } catch (Throwable fail) { threadUnexpectedException(fail); }
1071 +        if (millisElapsedSince(startTime) > timeoutMillis/2)
1072 +            throw new AssertionFailedError("timed get did not return promptly");
1073 +    }
1074 +
1075 +    <T> void checkTimedGet(Future<T> f, T expectedValue) {
1076 +        checkTimedGet(f, expectedValue, LONG_DELAY_MS);
1077 +    }
1078 +
1079      /**
1080       * Returns a new started daemon Thread running the given runnable.
1081       */
# Line 887 | Line 1094 | public class JSR166TestCase extends Test
1094      void awaitTermination(Thread t, long timeoutMillis) {
1095          try {
1096              t.join(timeoutMillis);
1097 <        } catch (InterruptedException ie) {
1098 <            threadUnexpectedException(ie);
1097 >        } catch (InterruptedException fail) {
1098 >            threadUnexpectedException(fail);
1099          } finally {
1100              if (t.getState() != Thread.State.TERMINATED) {
1101                  t.interrupt();
# Line 914 | Line 1121 | public class JSR166TestCase extends Test
1121          public final void run() {
1122              try {
1123                  realRun();
1124 <            } catch (Throwable t) {
1125 <                threadUnexpectedException(t);
1124 >            } catch (Throwable fail) {
1125 >                threadUnexpectedException(fail);
1126              }
1127          }
1128      }
# Line 969 | Line 1176 | public class JSR166TestCase extends Test
1176                  threadShouldThrow("InterruptedException");
1177              } catch (InterruptedException success) {
1178                  threadAssertFalse(Thread.interrupted());
1179 <            } catch (Throwable t) {
1180 <                threadUnexpectedException(t);
1179 >            } catch (Throwable fail) {
1180 >                threadUnexpectedException(fail);
1181              }
1182          }
1183      }
# Line 981 | Line 1188 | public class JSR166TestCase extends Test
1188          public final T call() {
1189              try {
1190                  return realCall();
1191 <            } catch (Throwable t) {
1192 <                threadUnexpectedException(t);
1191 >            } catch (Throwable fail) {
1192 >                threadUnexpectedException(fail);
1193                  return null;
1194              }
1195          }
# Line 999 | Line 1206 | public class JSR166TestCase extends Test
1206                  return result;
1207              } catch (InterruptedException success) {
1208                  threadAssertFalse(Thread.interrupted());
1209 <            } catch (Throwable t) {
1210 <                threadUnexpectedException(t);
1209 >            } catch (Throwable fail) {
1210 >                threadUnexpectedException(fail);
1211              }
1212              return null;
1213          }
# Line 1017 | Line 1224 | public class JSR166TestCase extends Test
1224      public static final String TEST_STRING = "a test string";
1225  
1226      public static class StringTask implements Callable<String> {
1227 <        public String call() { return TEST_STRING; }
1227 >        final String value;
1228 >        public StringTask() { this(TEST_STRING); }
1229 >        public StringTask(String value) { this.value = value; }
1230 >        public String call() { return value; }
1231      }
1232  
1233      public Callable<String> latchAwaitingStringTask(final CountDownLatch latch) {
# Line 1040 | Line 1250 | public class JSR166TestCase extends Test
1250      public void await(CountDownLatch latch) {
1251          try {
1252              assertTrue(latch.await(LONG_DELAY_MS, MILLISECONDS));
1253 <        } catch (Throwable t) {
1254 <            threadUnexpectedException(t);
1253 >        } catch (Throwable fail) {
1254 >            threadUnexpectedException(fail);
1255          }
1256      }
1257  
1258      public void await(Semaphore semaphore) {
1259          try {
1260              assertTrue(semaphore.tryAcquire(LONG_DELAY_MS, MILLISECONDS));
1261 <        } catch (Throwable t) {
1262 <            threadUnexpectedException(t);
1261 >        } catch (Throwable fail) {
1262 >            threadUnexpectedException(fail);
1263          }
1264      }
1265  
# Line 1243 | Line 1453 | public class JSR166TestCase extends Test
1453          @Override protected final void compute() {
1454              try {
1455                  realCompute();
1456 <            } catch (Throwable t) {
1457 <                threadUnexpectedException(t);
1456 >            } catch (Throwable fail) {
1457 >                threadUnexpectedException(fail);
1458              }
1459          }
1460      }
# Line 1258 | Line 1468 | public class JSR166TestCase extends Test
1468          @Override protected final T compute() {
1469              try {
1470                  return realCompute();
1471 <            } catch (Throwable t) {
1472 <                threadUnexpectedException(t);
1471 >            } catch (Throwable fail) {
1472 >                threadUnexpectedException(fail);
1473                  return null;
1474              }
1475          }
# Line 1283 | Line 1493 | public class JSR166TestCase extends Test
1493          public int await() {
1494              try {
1495                  return super.await(2 * LONG_DELAY_MS, MILLISECONDS);
1496 <            } catch (TimeoutException e) {
1496 >            } catch (TimeoutException timedOut) {
1497                  throw new AssertionFailedError("timed out");
1498 <            } catch (Exception e) {
1498 >            } catch (Exception fail) {
1499                  AssertionFailedError afe =
1500 <                    new AssertionFailedError("Unexpected exception: " + e);
1501 <                afe.initCause(e);
1500 >                    new AssertionFailedError("Unexpected exception: " + fail);
1501 >                afe.initCause(fail);
1502                  throw afe;
1503              }
1504          }
# Line 1316 | Line 1526 | public class JSR166TestCase extends Test
1526                  q.remove();
1527                  shouldThrow();
1528              } catch (NoSuchElementException success) {}
1529 <        } catch (InterruptedException ie) {
1320 <            threadUnexpectedException(ie);
1321 <        }
1529 >        } catch (InterruptedException fail) { threadUnexpectedException(fail); }
1530      }
1531  
1532      void assertSerialEquals(Object x, Object y) {
# Line 1337 | Line 1545 | public class JSR166TestCase extends Test
1545              oos.flush();
1546              oos.close();
1547              return bos.toByteArray();
1548 <        } catch (Throwable t) {
1549 <            threadUnexpectedException(t);
1548 >        } catch (Throwable fail) {
1549 >            threadUnexpectedException(fail);
1550              return new byte[0];
1551          }
1552      }
# Line 1351 | Line 1559 | public class JSR166TestCase extends Test
1559              T clone = (T) ois.readObject();
1560              assertSame(o.getClass(), clone.getClass());
1561              return clone;
1562 <        } catch (Throwable t) {
1563 <            threadUnexpectedException(t);
1562 >        } catch (Throwable fail) {
1563 >            threadUnexpectedException(fail);
1564              return null;
1565          }
1566      }
# Line 1377 | Line 1585 | public class JSR166TestCase extends Test
1585                  shouldThrow(expectedExceptionClass.getName());
1586          }
1587      }
1588 +
1589 +    public void assertIteratorExhausted(Iterator<?> it) {
1590 +        try {
1591 +            it.next();
1592 +            shouldThrow();
1593 +        } catch (NoSuchElementException success) {}
1594 +        assertFalse(it.hasNext());
1595 +    }
1596   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines