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.99 by jsr166, Tue Feb 5 03:39:34 2013 UTC vs.
Revision 1.113 by dl, Sun Sep 8 23:00:36 2013 UTC

# Line 128 | Line 128 | public class JSR166TestCase extends Test
128      private static final long profileThreshold =
129          Long.getLong("jsr166.profileThreshold", 100);
130  
131 +    /**
132 +     * The number of repetitions per test (for tickling rare bugs).
133 +     */
134 +    private static final int runsPerTest =
135 +        Integer.getInteger("jsr166.runsPerTest", 1);
136 +
137      protected void runTest() throws Throwable {
138 <        if (profileTests)
139 <            runTestProfiled();
140 <        else
141 <            super.runTest();
138 >        for (int i = 0; i < runsPerTest; i++) {
139 >            if (profileTests)
140 >                runTestProfiled();
141 >            else
142 >                super.runTest();
143 >        }
144      }
145  
146      protected void runTestProfiled() throws Throwable {
# Line 286 | Line 294 | public class JSR166TestCase extends Test
294          // Java8+ test classes
295          if (atLeastJava8()) {
296              String[] java8TestClassNames = {
297 <                "StampedLockTest",
297 >                "Atomic8Test",
298 >                "CompletableFutureTest",
299 >                "ConcurrentHashMap8Test",
300 >                "CountedCompleterTest",
301 >                "DoubleAccumulatorTest",
302 >                "DoubleAdderTest",
303                  "ForkJoinPool8Test",
304 +                "ForkJoinTask8Test",
305 +                "LongAccumulatorTest",
306 +                "LongAdderTest",
307 +                "SplittableRandomTest",
308 +                "StampedLockTest",
309 +                "ThreadLocalRandom8Test",
310              };
311              addNamedTestClasses(suite, java8TestClassNames);
312          }
# Line 295 | Line 314 | public class JSR166TestCase extends Test
314          return suite;
315      }
316  
317 +    // Delays for timing-dependent tests, in milliseconds.
318  
319      public static long SHORT_DELAY_MS;
320      public static long SMALL_DELAY_MS;
321      public static long MEDIUM_DELAY_MS;
322      public static long LONG_DELAY_MS;
323  
304
324      /**
325       * Returns the shortest timed delay. This could
326       * be reimplemented to use for example a Property.
# Line 384 | Line 403 | public class JSR166TestCase extends Test
403  
404          if (Thread.interrupted())
405              throw new AssertionFailedError("interrupt status set in main thread");
406 +
407 +        checkForkJoinPoolThreadLeaks();
408 +    }
409 +
410 +    /**
411 +     * Find missing try { ... } finally { joinPool(e); }
412 +     */
413 +    void checkForkJoinPoolThreadLeaks() throws InterruptedException {
414 +        Thread[] survivors = new Thread[5];
415 +        int count = Thread.enumerate(survivors);
416 +        for (int i = 0; i < count; i++) {
417 +            Thread thread = survivors[i];
418 +            String name = thread.getName();
419 +            if (name.startsWith("ForkJoinPool-")) {
420 +                // give thread some time to terminate
421 +                thread.join(LONG_DELAY_MS);
422 +                if (!thread.isAlive()) continue;
423 +                thread.stop();
424 +                throw new AssertionFailedError
425 +                    (String.format("Found leaked ForkJoinPool thread test=%s thread=%s%n",
426 +                                   toString(), name));
427 +            }
428 +        }
429      }
430  
431      /**
# Line 671 | Line 713 | public class JSR166TestCase extends Test
713      public static final Integer m6  = new Integer(-6);
714      public static final Integer m10 = new Integer(-10);
715  
674
716      /**
717       * Runs Runnable r with a security policy that permits precisely
718       * the specified permissions.  If there is no current security
# Line 1202 | Line 1243 | public class JSR166TestCase extends Test
1243      public abstract class CheckedRecursiveAction extends RecursiveAction {
1244          protected abstract void realCompute() throws Throwable;
1245  
1246 <        public final void compute() {
1246 >        @Override protected final void compute() {
1247              try {
1248                  realCompute();
1249              } catch (Throwable t) {
# Line 1217 | Line 1258 | public class JSR166TestCase extends Test
1258      public abstract class CheckedRecursiveTask<T> extends RecursiveTask<T> {
1259          protected abstract T realCompute() throws Throwable;
1260  
1261 <        public final T compute() {
1261 >        @Override protected final T compute() {
1262              try {
1263                  return realCompute();
1264              } catch (Throwable t) {
# Line 1318 | Line 1359 | public class JSR166TestCase extends Test
1359              return null;
1360          }
1361      }
1362 +
1363 +    public void assertThrows(Class<? extends Throwable> expectedExceptionClass,
1364 +                             Runnable... throwingActions) {
1365 +        for (Runnable throwingAction : throwingActions) {
1366 +            boolean threw = false;
1367 +            try { throwingAction.run(); }
1368 +            catch (Throwable t) {
1369 +                threw = true;
1370 +                if (!expectedExceptionClass.isInstance(t)) {
1371 +                    AssertionFailedError afe =
1372 +                        new AssertionFailedError
1373 +                        ("Expected " + expectedExceptionClass.getName() +
1374 +                         ", got " + t.getClass().getName());
1375 +                    afe.initCause(t);
1376 +                    threadUnexpectedException(afe);
1377 +                }
1378 +            }
1379 +            if (!threw)
1380 +                shouldThrow(expectedExceptionClass.getName());
1381 +        }
1382 +    }
1383   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines