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.178 by jsr166, Fri Oct 23 17:34:47 2015 UTC vs.
Revision 1.188 by jsr166, Mon Feb 22 23:16:06 2016 UTC

# Line 6 | Line 6
6   * Pat Fisher, Mike Judd.
7   */
8  
9 + /*
10 + * @test
11 + * @summary JSR-166 tck tests
12 + * @modules java.management
13 + * @build *
14 + * @run junit/othervm/timeout=1000 -Djsr166.testImplementationDetails=true JSR166TestCase
15 + */
16 +
17   import static java.util.concurrent.TimeUnit.MILLISECONDS;
18   import static java.util.concurrent.TimeUnit.MINUTES;
19   import static java.util.concurrent.TimeUnit.NANOSECONDS;
# Line 53 | Line 61 | import java.util.concurrent.Semaphore;
61   import java.util.concurrent.ThreadFactory;
62   import java.util.concurrent.ThreadPoolExecutor;
63   import java.util.concurrent.TimeoutException;
64 + import java.util.concurrent.atomic.AtomicBoolean;
65   import java.util.concurrent.atomic.AtomicReference;
66   import java.util.regex.Matcher;
67   import java.util.regex.Pattern;
# Line 112 | Line 121 | import junit.framework.TestSuite;
121   * methods as there are exceptions the method can throw. Sometimes
122   * there are multiple tests per JSR166 method when the different
123   * "normal" behaviors differ significantly. And sometimes testcases
124 < * cover multiple methods when they cannot be tested in
116 < * isolation.
124 > * cover multiple methods when they cannot be tested in isolation.
125   *
126   * <li>The documentation style for testcases is to provide as javadoc
127   * a simple sentence or two describing the property that the testcase
# Line 176 | Line 184 | public class JSR166TestCase extends Test
184      private static final int suiteRuns =
185          Integer.getInteger("jsr166.suiteRuns", 1);
186  
187 +    private static float systemPropertyValue(String name, float defaultValue) {
188 +        String floatString = System.getProperty(name);
189 +        if (floatString == null)
190 +            return defaultValue;
191 +        try {
192 +            return Float.parseFloat(floatString);
193 +        } catch (NumberFormatException ex) {
194 +            throw new IllegalArgumentException(
195 +                String.format("Bad float value in system property %s=%s",
196 +                              name, floatString));
197 +        }
198 +    }
199 +
200 +    /**
201 +     * The scaling factor to apply to standard delays used in tests.
202 +     */
203 +    private static final float delayFactor =
204 +        systemPropertyValue("jsr166.delay.factor", 1.0f);
205 +
206 +    /**
207 +     * The timeout factor as used in the jtreg test harness.
208 +     * See: http://openjdk.java.net/jtreg/tag-spec.html
209 +     */
210 +    private static final float jtregTestTimeoutFactor
211 +        = systemPropertyValue("test.timeout.factor", 1.0f);
212 +
213      public JSR166TestCase() { super(); }
214      public JSR166TestCase(String name) { super(name); }
215  
# Line 277 | Line 311 | public class JSR166TestCase extends Test
311          PithyResultPrinter(java.io.PrintStream writer) { super(writer); }
312          long runTime;
313          public void startTest(Test test) {}
314 <        protected void printHeader(long runTime) {
314 >        protected void printHeader(long runTime) {
315              this.runTime = runTime; // defer printing for later
316 <        }
317 <        protected void printFooter(TestResult result) {
316 >        }
317 >        protected void printFooter(TestResult result) {
318              if (result.wasSuccessful()) {
319                  getWriter().println("OK (" + result.runCount() + " tests)"
320                      + "  Time: " + elapsedTimeAsString(runTime));
# Line 549 | Line 583 | public class JSR166TestCase extends Test
583      public static long LONG_DELAY_MS;
584  
585      /**
586 <     * Returns the shortest timed delay. This could
587 <     * be reimplemented to use for example a Property.
586 >     * Returns the shortest timed delay. This can be scaled up for
587 >     * slow machines using the jsr166.delay.factor system property,
588 >     * or via jtreg's -timeoutFactor: flag.
589 >     * http://openjdk.java.net/jtreg/command-help.html
590       */
591      protected long getShortDelay() {
592 <        return 50;
592 >        return (long) (50 * delayFactor * jtregTestTimeoutFactor);
593      }
594  
595      /**
# Line 866 | Line 902 | public class JSR166TestCase extends Test
902          }};
903      }
904  
905 +    PoolCleaner cleaner(ExecutorService pool, AtomicBoolean flag) {
906 +        return new PoolCleanerWithReleaser(pool, releaser(flag));
907 +    }
908 +
909 +    Runnable releaser(final AtomicBoolean flag) {
910 +        return new Runnable() { public void run() { flag.set(true); }};
911 +    }
912 +
913      /**
914       * Waits out termination of a thread pool or fails doing so.
915       */
# Line 1422 | Line 1466 | public class JSR166TestCase extends Test
1466          return new LatchAwaiter(latch);
1467      }
1468  
1469 <    public void await(CountDownLatch latch) {
1469 >    public void await(CountDownLatch latch, long timeoutMillis) {
1470          try {
1471 <            if (!latch.await(LONG_DELAY_MS, MILLISECONDS))
1471 >            if (!latch.await(timeoutMillis, MILLISECONDS))
1472                  fail("timed out waiting for CountDownLatch for "
1473 <                     + (LONG_DELAY_MS/1000) + " sec");
1473 >                     + (timeoutMillis/1000) + " sec");
1474          } catch (Throwable fail) {
1475              threadUnexpectedException(fail);
1476          }
1477      }
1478  
1479 +    public void await(CountDownLatch latch) {
1480 +        await(latch, LONG_DELAY_MS);
1481 +    }
1482 +
1483      public void await(Semaphore semaphore) {
1484          try {
1485              if (!semaphore.tryAcquire(LONG_DELAY_MS, MILLISECONDS))

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines