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.97 by jsr166, Fri Feb 1 19:07:36 2013 UTC vs.
Revision 1.101 by jsr166, Wed Feb 6 16:57:21 2013 UTC

# Line 182 | Line 182 | public class JSR166TestCase extends Test
182          return suite;
183      }
184  
185 <    static void addTestReflectively(TestSuite suite, String testClassName) {
186 <        try {
187 <            Class klazz = Class.forName(testClassName);
188 <            Method m = klazz.getDeclaredMethod("suite", new Class<?>[0]);
189 <            suite.addTest(newTestSuite((Test)m.invoke(null)));
190 <        } catch (Exception e) {
191 <            throw new Error(e);
185 >    public static void addNamedTestClasses(TestSuite suite,
186 >                                           String... testClassNames) {
187 >        for (String testClassName : testClassNames) {
188 >            try {
189 >                Class<?> testClass = Class.forName(testClassName);
190 >                Method m = testClass.getDeclaredMethod("suite",
191 >                                                       new Class<?>[0]);
192 >                suite.addTest(newTestSuite((Test)m.invoke(null)));
193 >            } catch (Exception e) {
194 >                throw new Error("Missing test class", e);
195 >            }
196          }
197      }
198  
# Line 204 | Line 208 | public class JSR166TestCase extends Test
208          }
209      }
210  
211 <    public static boolean isAtLeastJdk6() { return JAVA_CLASS_VERSION >= 50.0; }
212 <    public static boolean isAtLeastJdk7() { return JAVA_CLASS_VERSION >= 51.0; }
213 <    public static boolean isAtLeastJdk8() { return JAVA_CLASS_VERSION >= 52.0; }
211 >    public static boolean atLeastJava6() { return JAVA_CLASS_VERSION >= 50.0; }
212 >    public static boolean atLeastJava7() { return JAVA_CLASS_VERSION >= 51.0; }
213 >    public static boolean atLeastJava8() { return JAVA_CLASS_VERSION >= 52.0; }
214  
215      /**
216       * Collects all JSR166 unit tests as one suite.
217       */
218      public static Test suite() {
219 +        // Java7+ test classes
220          TestSuite suite = newTestSuite(
221              ForkJoinPoolTest.suite(),
222              ForkJoinTaskTest.suite(),
# Line 277 | Line 282 | public class JSR166TestCase extends Test
282              TreeSetTest.suite(),
283              TreeSubMapTest.suite(),
284              TreeSubSetTest.suite());
285 <        if (isAtLeastJdk8()) {
286 <            addTestReflectively(suite, "StampedLockTest");
285 >
286 >        // Java8+ test classes
287 >        if (atLeastJava8()) {
288 >            String[] java8TestClassNames = {
289 >                "StampedLockTest",
290 >                "ForkJoinPool8Test",
291 >            };
292 >            addNamedTestClasses(suite, java8TestClassNames);
293          }
294 +
295          return suite;
296      }
297  
# Line 372 | Line 384 | public class JSR166TestCase extends Test
384  
385          if (Thread.interrupted())
386              throw new AssertionFailedError("interrupt status set in main thread");
387 +
388 +        checkForkJoinPoolThreadLeaks();
389 +    }
390 +
391 +    /**
392 +     * Find missing try { ... } finally { joinPool(e); }
393 +     */
394 +    void checkForkJoinPoolThreadLeaks() throws InterruptedException {
395 +        Thread[] survivors = new Thread[5];
396 +        int count = Thread.enumerate(survivors);
397 +        for (int i = 0; i < count; i++) {
398 +            Thread thread = survivors[i];
399 +            String name = thread.getName();
400 +            if (name.startsWith("ForkJoinPool-")) {
401 +                // give thread some time to terminate
402 +                thread.join(LONG_DELAY_MS);
403 +                if (!thread.isAlive()) continue;
404 +                thread.stop();
405 +                throw new AssertionFailedError
406 +                    (String.format("Found leaked ForkJoinPool thread test=%s thread=%s%n",
407 +                                   toString(), name));
408 +            }
409 +        }
410      }
411  
412      /**

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines