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.104 by dl, Thu Mar 21 00:26:43 2013 UTC vs.
Revision 1.114 by jsr166, Tue Sep 17 06:38:36 2013 UTC

# Line 26 | Line 26 | import java.util.concurrent.atomic.Atomi
26   import java.util.concurrent.atomic.AtomicReference;
27   import static java.util.concurrent.TimeUnit.MILLISECONDS;
28   import static java.util.concurrent.TimeUnit.NANOSECONDS;
29 + import java.util.regex.Pattern;
30   import java.security.CodeSource;
31   import java.security.Permission;
32   import java.security.PermissionCollection;
# Line 128 | Line 129 | public class JSR166TestCase extends Test
129      private static final long profileThreshold =
130          Long.getLong("jsr166.profileThreshold", 100);
131  
132 +    /**
133 +     * The number of repetitions per test (for tickling rare bugs).
134 +     */
135 +    private static final int runsPerTest =
136 +        Integer.getInteger("jsr166.runsPerTest", 1);
137 +
138 +    /**
139 +     * A filter for tests to run, matching strings of the form
140 +     * methodName(className), e.g. "testInvokeAll5(ForkJoinPoolTest)"
141 +     * Usefully combined with jsr166.runsPerTest.
142 +     */
143 +    private static final Pattern methodFilter = methodFilter();
144 +
145 +    private static Pattern methodFilter() {
146 +        String regex = System.getProperty("jsr166.methodFilter");
147 +        return (regex == null) ? null : Pattern.compile(regex);
148 +    }
149 +
150      protected void runTest() throws Throwable {
151 <        if (profileTests)
152 <            runTestProfiled();
153 <        else
154 <            super.runTest();
151 >        if (methodFilter == null
152 >            || methodFilter.matcher(toString()).find()) {
153 >            for (int i = 0; i < runsPerTest; i++) {
154 >                if (profileTests)
155 >                    runTestProfiled();
156 >                else
157 >                    super.runTest();
158 >            }
159 >        }
160      }
161  
162      protected void runTestProfiled() throws Throwable {
# Line 286 | Line 310 | public class JSR166TestCase extends Test
310          // Java8+ test classes
311          if (atLeastJava8()) {
312              String[] java8TestClassNames = {
313 +                "Atomic8Test",
314                  "CompletableFutureTest",
315 +                "ConcurrentHashMap8Test",
316                  "CountedCompleterTest",
317                  "DoubleAccumulatorTest",
318                  "DoubleAdderTest",
319                  "ForkJoinPool8Test",
320 +                "ForkJoinTask8Test",
321                  "LongAccumulatorTest",
322                  "LongAdderTest",
323 +                "SplittableRandomTest",
324                  "StampedLockTest",
325 +                "ThreadLocalRandom8Test",
326              };
327              addNamedTestClasses(suite, java8TestClassNames);
328          }
# Line 301 | Line 330 | public class JSR166TestCase extends Test
330          return suite;
331      }
332  
333 +    // Delays for timing-dependent tests, in milliseconds.
334  
335      public static long SHORT_DELAY_MS;
336      public static long SMALL_DELAY_MS;
337      public static long MEDIUM_DELAY_MS;
338      public static long LONG_DELAY_MS;
339  
310
340      /**
341       * Returns the shortest timed delay. This could
342       * be reimplemented to use for example a Property.
# Line 700 | Line 729 | public class JSR166TestCase extends Test
729      public static final Integer m6  = new Integer(-6);
730      public static final Integer m10 = new Integer(-10);
731  
703
732      /**
733       * Runs Runnable r with a security policy that permits precisely
734       * the specified permissions.  If there is no current security
# Line 1231 | Line 1259 | public class JSR166TestCase extends Test
1259      public abstract class CheckedRecursiveAction extends RecursiveAction {
1260          protected abstract void realCompute() throws Throwable;
1261  
1262 <        public final void compute() {
1262 >        @Override protected final void compute() {
1263              try {
1264                  realCompute();
1265              } catch (Throwable t) {
# Line 1246 | Line 1274 | public class JSR166TestCase extends Test
1274      public abstract class CheckedRecursiveTask<T> extends RecursiveTask<T> {
1275          protected abstract T realCompute() throws Throwable;
1276  
1277 <        public final T compute() {
1277 >        @Override protected final T compute() {
1278              try {
1279                  return realCompute();
1280              } catch (Throwable t) {
# Line 1347 | Line 1375 | public class JSR166TestCase extends Test
1375              return null;
1376          }
1377      }
1378 +
1379 +    public void assertThrows(Class<? extends Throwable> expectedExceptionClass,
1380 +                             Runnable... throwingActions) {
1381 +        for (Runnable throwingAction : throwingActions) {
1382 +            boolean threw = false;
1383 +            try { throwingAction.run(); }
1384 +            catch (Throwable t) {
1385 +                threw = true;
1386 +                if (!expectedExceptionClass.isInstance(t)) {
1387 +                    AssertionFailedError afe =
1388 +                        new AssertionFailedError
1389 +                        ("Expected " + expectedExceptionClass.getName() +
1390 +                         ", got " + t.getClass().getName());
1391 +                    afe.initCause(t);
1392 +                    threadUnexpectedException(afe);
1393 +                }
1394 +            }
1395 +            if (!threw)
1396 +                shouldThrow(expectedExceptionClass.getName());
1397 +        }
1398 +    }
1399   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines