--- jsr166/src/test/tck/JSR166TestCase.java 2016/02/22 20:41:59 1.187 +++ jsr166/src/test/tck/JSR166TestCase.java 2016/05/21 22:29:45 1.191 @@ -184,10 +184,13 @@ public class JSR166TestCase extends Test private static final int suiteRuns = Integer.getInteger("jsr166.suiteRuns", 1); - private static float systemPropertyValue(String name, float defaultValue) { + /** + * Returns the value of the system property, or NaN if not defined. + */ + private static float systemPropertyValue(String name) { String floatString = System.getProperty(name); if (floatString == null) - return defaultValue; + return Float.NaN; try { return Float.parseFloat(floatString); } catch (NumberFormatException ex) { @@ -199,16 +202,25 @@ public class JSR166TestCase extends Test /** * The scaling factor to apply to standard delays used in tests. - */ - private static final float delayFactor = - systemPropertyValue("jsr166.delay.factor", 1.0f); - - /** - * The timeout factor as used in the jtreg test harness. - * See: http://openjdk.java.net/jtreg/tag-spec.html - */ - private static final float jtregTestTimeoutFactor - = systemPropertyValue("test.timeout.factor", 1.0f); + * May be initialized from any of: + * - the "jsr166.delay.factor" system property + * - the "test.timeout.factor" system property (as used by jtreg) + * See: http://openjdk.java.net/jtreg/tag-spec.html + * - hard-coded fuzz factor when using a known slowpoke VM + */ + private static final float delayFactor = delayFactor(); + + private static float delayFactor() { + float x; + if (!Float.isNaN(x = systemPropertyValue("jsr166.delay.factor"))) + return x; + if (!Float.isNaN(x = systemPropertyValue("test.timeout.factor"))) + return x; + String prop = System.getProperty("java.vm.version"); + if (prop != null && prop.matches(".*debug.*")) + return 4.0f; // How much slower is fastdebug than product?! + return 1.0f; + } public JSR166TestCase() { super(); } public JSR166TestCase(String name) { super(name); } @@ -499,6 +511,7 @@ public class JSR166TestCase extends Test "StampedLockTest", "SubmissionPublisherTest", "ThreadLocalRandom8Test", + "TimeUnit8Test", }; addNamedTestClasses(suite, java8TestClassNames); } @@ -589,7 +602,7 @@ public class JSR166TestCase extends Test * http://openjdk.java.net/jtreg/command-help.html */ protected long getShortDelay() { - return (long) (50 * delayFactor * jtregTestTimeoutFactor); + return (long) (50 * delayFactor); } /** @@ -1466,16 +1479,20 @@ public class JSR166TestCase extends Test return new LatchAwaiter(latch); } - public void await(CountDownLatch latch) { + public void await(CountDownLatch latch, long timeoutMillis) { try { - if (!latch.await(LONG_DELAY_MS, MILLISECONDS)) + if (!latch.await(timeoutMillis, MILLISECONDS)) fail("timed out waiting for CountDownLatch for " - + (LONG_DELAY_MS/1000) + " sec"); + + (timeoutMillis/1000) + " sec"); } catch (Throwable fail) { threadUnexpectedException(fail); } } + public void await(CountDownLatch latch) { + await(latch, LONG_DELAY_MS); + } + public void await(Semaphore semaphore) { try { if (!semaphore.tryAcquire(LONG_DELAY_MS, MILLISECONDS)) @@ -1816,4 +1833,12 @@ public class JSR166TestCase extends Test } catch (NoSuchElementException success) {} assertFalse(it.hasNext()); } + + public Callable callableThrowing(final Exception ex) { + return new Callable() { public T call() throws Exception { throw ex; }}; + } + + public Runnable runnableThrowing(final RuntimeException ex) { + return new Runnable() { public void run() { throw ex; }}; + } }