12 |
|
* @modules java.management |
13 |
|
* @build * |
14 |
|
* @run junit/othervm/timeout=1000 -Djsr166.testImplementationDetails=true JSR166TestCase |
15 |
+ |
* @run junit/othervm/timeout=1000 -Djava.util.concurrent.ForkJoinPool.common.parallelism=0 -Djsr166.testImplementationDetails=true JSR166TestCase |
16 |
|
*/ |
17 |
|
|
18 |
|
import static java.util.concurrent.TimeUnit.MILLISECONDS; |
59 |
|
import java.util.concurrent.RecursiveTask; |
60 |
|
import java.util.concurrent.RejectedExecutionHandler; |
61 |
|
import java.util.concurrent.Semaphore; |
62 |
+ |
import java.util.concurrent.SynchronousQueue; |
63 |
|
import java.util.concurrent.ThreadFactory; |
64 |
|
import java.util.concurrent.ThreadPoolExecutor; |
65 |
|
import java.util.concurrent.TimeoutException; |
186 |
|
private static final int suiteRuns = |
187 |
|
Integer.getInteger("jsr166.suiteRuns", 1); |
188 |
|
|
189 |
< |
private static float systemPropertyValue(String name, float defaultValue) { |
189 |
> |
/** |
190 |
> |
* Returns the value of the system property, or NaN if not defined. |
191 |
> |
*/ |
192 |
> |
private static float systemPropertyValue(String name) { |
193 |
|
String floatString = System.getProperty(name); |
194 |
|
if (floatString == null) |
195 |
< |
return defaultValue; |
195 |
> |
return Float.NaN; |
196 |
|
try { |
197 |
|
return Float.parseFloat(floatString); |
198 |
|
} catch (NumberFormatException ex) { |
204 |
|
|
205 |
|
/** |
206 |
|
* The scaling factor to apply to standard delays used in tests. |
207 |
< |
*/ |
208 |
< |
private static final float delayFactor = |
209 |
< |
systemPropertyValue("jsr166.delay.factor", 1.0f); |
210 |
< |
|
211 |
< |
/** |
212 |
< |
* The timeout factor as used in the jtreg test harness. |
213 |
< |
* See: http://openjdk.java.net/jtreg/tag-spec.html |
214 |
< |
*/ |
215 |
< |
private static final float jtregTestTimeoutFactor |
216 |
< |
= systemPropertyValue("test.timeout.factor", 1.0f); |
207 |
> |
* May be initialized from any of: |
208 |
> |
* - the "jsr166.delay.factor" system property |
209 |
> |
* - the "test.timeout.factor" system property (as used by jtreg) |
210 |
> |
* See: http://openjdk.java.net/jtreg/tag-spec.html |
211 |
> |
* - hard-coded fuzz factor when using a known slowpoke VM |
212 |
> |
*/ |
213 |
> |
private static final float delayFactor = delayFactor(); |
214 |
> |
|
215 |
> |
private static float delayFactor() { |
216 |
> |
float x; |
217 |
> |
if (!Float.isNaN(x = systemPropertyValue("jsr166.delay.factor"))) |
218 |
> |
return x; |
219 |
> |
if (!Float.isNaN(x = systemPropertyValue("test.timeout.factor"))) |
220 |
> |
return x; |
221 |
> |
String prop = System.getProperty("java.vm.version"); |
222 |
> |
if (prop != null && prop.matches(".*debug.*")) |
223 |
> |
return 4.0f; // How much slower is fastdebug than product?! |
224 |
> |
return 1.0f; |
225 |
> |
} |
226 |
|
|
227 |
|
public JSR166TestCase() { super(); } |
228 |
|
public JSR166TestCase(String name) { super(name); } |
513 |
|
"StampedLockTest", |
514 |
|
"SubmissionPublisherTest", |
515 |
|
"ThreadLocalRandom8Test", |
516 |
+ |
"TimeUnit8Test", |
517 |
|
}; |
518 |
|
addNamedTestClasses(suite, java8TestClassNames); |
519 |
|
} |
521 |
|
// Java9+ test classes |
522 |
|
if (atLeastJava9()) { |
523 |
|
String[] java9TestClassNames = { |
524 |
< |
// Currently empty, but expecting varhandle tests |
524 |
> |
"ExecutorCompletionService9Test", |
525 |
|
}; |
526 |
|
addNamedTestClasses(suite, java9TestClassNames); |
527 |
|
} |
604 |
|
* http://openjdk.java.net/jtreg/command-help.html |
605 |
|
*/ |
606 |
|
protected long getShortDelay() { |
607 |
< |
return (long) (50 * delayFactor * jtregTestTimeoutFactor); |
607 |
> |
return (long) (50 * delayFactor); |
608 |
|
} |
609 |
|
|
610 |
|
/** |
979 |
|
* Uninteresting threads are filtered out. |
980 |
|
*/ |
981 |
|
static void dumpTestThreads() { |
982 |
+ |
SecurityManager sm = System.getSecurityManager(); |
983 |
+ |
if (sm != null) { |
984 |
+ |
try { |
985 |
+ |
System.setSecurityManager(null); |
986 |
+ |
} catch (SecurityException giveUp) { |
987 |
+ |
return; |
988 |
+ |
} |
989 |
+ |
} |
990 |
+ |
|
991 |
|
ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean(); |
992 |
|
System.err.println("------ stacktrace dump start ------"); |
993 |
|
for (ThreadInfo info : threadMXBean.dumpAllThreads(true, true)) { |
1005 |
|
System.err.print(info); |
1006 |
|
} |
1007 |
|
System.err.println("------ stacktrace dump end ------"); |
1008 |
+ |
|
1009 |
+ |
if (sm != null) System.setSecurityManager(sm); |
1010 |
|
} |
1011 |
|
|
1012 |
|
/** |
1492 |
|
return new LatchAwaiter(latch); |
1493 |
|
} |
1494 |
|
|
1495 |
< |
public void await(CountDownLatch latch) { |
1495 |
> |
public void await(CountDownLatch latch, long timeoutMillis) { |
1496 |
|
try { |
1497 |
< |
if (!latch.await(LONG_DELAY_MS, MILLISECONDS)) |
1497 |
> |
if (!latch.await(timeoutMillis, MILLISECONDS)) |
1498 |
|
fail("timed out waiting for CountDownLatch for " |
1499 |
< |
+ (LONG_DELAY_MS/1000) + " sec"); |
1499 |
> |
+ (timeoutMillis/1000) + " sec"); |
1500 |
|
} catch (Throwable fail) { |
1501 |
|
threadUnexpectedException(fail); |
1502 |
|
} |
1503 |
|
} |
1504 |
|
|
1505 |
+ |
public void await(CountDownLatch latch) { |
1506 |
+ |
await(latch, LONG_DELAY_MS); |
1507 |
+ |
} |
1508 |
+ |
|
1509 |
|
public void await(Semaphore semaphore) { |
1510 |
|
try { |
1511 |
|
if (!semaphore.tryAcquire(LONG_DELAY_MS, MILLISECONDS)) |
1846 |
|
} catch (NoSuchElementException success) {} |
1847 |
|
assertFalse(it.hasNext()); |
1848 |
|
} |
1849 |
+ |
|
1850 |
+ |
public <T> Callable<T> callableThrowing(final Exception ex) { |
1851 |
+ |
return new Callable<T>() { public T call() throws Exception { throw ex; }}; |
1852 |
+ |
} |
1853 |
+ |
|
1854 |
+ |
public Runnable runnableThrowing(final RuntimeException ex) { |
1855 |
+ |
return new Runnable() { public void run() { throw ex; }}; |
1856 |
+ |
} |
1857 |
+ |
|
1858 |
+ |
/** A reusable thread pool to be shared by tests. */ |
1859 |
+ |
static final ExecutorService cachedThreadPool = |
1860 |
+ |
new ThreadPoolExecutor(0, Integer.MAX_VALUE, |
1861 |
+ |
1000L, MILLISECONDS, |
1862 |
+ |
new SynchronousQueue<Runnable>()); |
1863 |
+ |
|
1864 |
|
} |