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.181 by jsr166, Mon Nov 9 06:06:54 2015 UTC vs.
Revision 1.193 by jsr166, Mon May 23 18:19:48 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 50 | Line 58 | import java.util.concurrent.RecursiveAct
58   import java.util.concurrent.RecursiveTask;
59   import java.util.concurrent.RejectedExecutionHandler;
60   import java.util.concurrent.Semaphore;
61 + import java.util.concurrent.SynchronousQueue;
62   import java.util.concurrent.ThreadFactory;
63   import java.util.concurrent.ThreadPoolExecutor;
64   import java.util.concurrent.TimeoutException;
65 + import java.util.concurrent.atomic.AtomicBoolean;
66   import java.util.concurrent.atomic.AtomicReference;
67   import java.util.regex.Matcher;
68   import java.util.regex.Pattern;
# Line 176 | Line 186 | public class JSR166TestCase extends Test
186          Integer.getInteger("jsr166.suiteRuns", 1);
187  
188      /**
189 <     * The scaling factor to apply to standard delays used in tests.
189 >     * Returns the value of the system property, or NaN if not defined.
190       */
191 <    private static final int delayFactor =
192 <        Integer.getInteger("jsr166.delay.factor", 1);
191 >    private static float systemPropertyValue(String name) {
192 >        String floatString = System.getProperty(name);
193 >        if (floatString == null)
194 >            return Float.NaN;
195 >        try {
196 >            return Float.parseFloat(floatString);
197 >        } catch (NumberFormatException ex) {
198 >            throw new IllegalArgumentException(
199 >                String.format("Bad float value in system property %s=%s",
200 >                              name, floatString));
201 >        }
202 >    }
203 >
204 >    /**
205 >     * The scaling factor to apply to standard delays used in tests.
206 >     * May be initialized from any of:
207 >     * - the "jsr166.delay.factor" system property
208 >     * - the "test.timeout.factor" system property (as used by jtreg)
209 >     *   See: http://openjdk.java.net/jtreg/tag-spec.html
210 >     * - hard-coded fuzz factor when using a known slowpoke VM
211 >     */
212 >    private static final float delayFactor = delayFactor();
213 >
214 >    private static float delayFactor() {
215 >        float x;
216 >        if (!Float.isNaN(x = systemPropertyValue("jsr166.delay.factor")))
217 >            return x;
218 >        if (!Float.isNaN(x = systemPropertyValue("test.timeout.factor")))
219 >            return x;
220 >        String prop = System.getProperty("java.vm.version");
221 >        if (prop != null && prop.matches(".*debug.*"))
222 >            return 4.0f; // How much slower is fastdebug than product?!
223 >        return 1.0f;
224 >    }
225  
226      public JSR166TestCase() { super(); }
227      public JSR166TestCase(String name) { super(name); }
# Line 470 | Line 512 | public class JSR166TestCase extends Test
512                  "StampedLockTest",
513                  "SubmissionPublisherTest",
514                  "ThreadLocalRandom8Test",
515 +                "TimeUnit8Test",
516              };
517              addNamedTestClasses(suite, java8TestClassNames);
518          }
# Line 477 | Line 520 | public class JSR166TestCase extends Test
520          // Java9+ test classes
521          if (atLeastJava9()) {
522              String[] java9TestClassNames = {
523 <                // Currently empty, but expecting varhandle tests
523 >                "ExecutorCompletionService9Test",
524              };
525              addNamedTestClasses(suite, java9TestClassNames);
526          }
# Line 555 | Line 598 | public class JSR166TestCase extends Test
598  
599      /**
600       * Returns the shortest timed delay. This can be scaled up for
601 <     * slow machines using the jsr166.delay.factor system property.
601 >     * slow machines using the jsr166.delay.factor system property,
602 >     * or via jtreg's -timeoutFactor: flag.
603 >     * http://openjdk.java.net/jtreg/command-help.html
604       */
605      protected long getShortDelay() {
606 <        return 50 * delayFactor;
606 >        return (long) (50 * delayFactor);
607      }
608  
609      /**
# Line 871 | Line 916 | public class JSR166TestCase extends Test
916          }};
917      }
918  
919 +    PoolCleaner cleaner(ExecutorService pool, AtomicBoolean flag) {
920 +        return new PoolCleanerWithReleaser(pool, releaser(flag));
921 +    }
922 +
923 +    Runnable releaser(final AtomicBoolean flag) {
924 +        return new Runnable() { public void run() { flag.set(true); }};
925 +    }
926 +
927      /**
928       * Waits out termination of a thread pool or fails doing so.
929       */
# Line 1427 | Line 1480 | public class JSR166TestCase extends Test
1480          return new LatchAwaiter(latch);
1481      }
1482  
1483 <    public void await(CountDownLatch latch) {
1483 >    public void await(CountDownLatch latch, long timeoutMillis) {
1484          try {
1485 <            if (!latch.await(LONG_DELAY_MS, MILLISECONDS))
1485 >            if (!latch.await(timeoutMillis, MILLISECONDS))
1486                  fail("timed out waiting for CountDownLatch for "
1487 <                     + (LONG_DELAY_MS/1000) + " sec");
1487 >                     + (timeoutMillis/1000) + " sec");
1488          } catch (Throwable fail) {
1489              threadUnexpectedException(fail);
1490          }
1491      }
1492  
1493 +    public void await(CountDownLatch latch) {
1494 +        await(latch, LONG_DELAY_MS);
1495 +    }
1496 +
1497      public void await(Semaphore semaphore) {
1498          try {
1499              if (!semaphore.tryAcquire(LONG_DELAY_MS, MILLISECONDS))
# Line 1777 | Line 1834 | public class JSR166TestCase extends Test
1834          } catch (NoSuchElementException success) {}
1835          assertFalse(it.hasNext());
1836      }
1837 +
1838 +    public <T> Callable<T> callableThrowing(final Exception ex) {
1839 +        return new Callable<T>() { public T call() throws Exception { throw ex; }};
1840 +    }
1841 +
1842 +    public Runnable runnableThrowing(final RuntimeException ex) {
1843 +        return new Runnable() { public void run() { throw ex; }};
1844 +    }
1845 +
1846 +    /** A reusable thread pool to be shared by tests. */
1847 +    static final ExecutorService cachedThreadPool =
1848 +        new ThreadPoolExecutor(0, Integer.MAX_VALUE,
1849 +                               1000L, MILLISECONDS,
1850 +                               new SynchronousQueue<Runnable>());
1851 +
1852   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines