19 |
|
* @summary JSR-166 tck tests (whitebox tests allowed) |
20 |
|
* @build * |
21 |
|
* @modules java.base/java.util.concurrent:open |
22 |
+ |
* java.base/java.lang:open |
23 |
|
* java.management |
24 |
|
* @run junit/othervm/timeout=1000 |
25 |
|
* -Djsr166.testImplementationDetails=true |
33 |
|
* -Djava.util.concurrent.ForkJoinPool.common.parallelism=1 |
34 |
|
* -Djava.util.secureRandomSeed=true |
35 |
|
* JSR166TestCase |
36 |
+ |
* @run junit/othervm/timeout=1000/policy=tck.policy |
37 |
+ |
* -Djsr166.testImplementationDetails=true |
38 |
+ |
* JSR166TestCase |
39 |
|
*/ |
40 |
|
|
41 |
|
import static java.util.concurrent.TimeUnit.MILLISECONDS; |
561 |
|
"AtomicReference9Test", |
562 |
|
"AtomicReferenceArray9Test", |
563 |
|
"ExecutorCompletionService9Test", |
564 |
+ |
"ForkJoinPool9Test", |
565 |
|
}; |
566 |
|
addNamedTestClasses(suite, java9TestClassNames); |
567 |
|
} |
572 |
|
/** Returns list of junit-style test method names in given class. */ |
573 |
|
public static ArrayList<String> testMethodNames(Class<?> testClass) { |
574 |
|
Method[] methods = testClass.getDeclaredMethods(); |
575 |
< |
ArrayList<String> names = new ArrayList<String>(methods.length); |
575 |
> |
ArrayList<String> names = new ArrayList<>(methods.length); |
576 |
|
for (Method method : methods) { |
577 |
|
if (method.getName().startsWith("test") |
578 |
|
&& Modifier.isPublic(method.getModifiers()) |
678 |
|
* The first exception encountered if any threadAssertXXX method fails. |
679 |
|
*/ |
680 |
|
private final AtomicReference<Throwable> threadFailure |
681 |
< |
= new AtomicReference<Throwable>(null); |
681 |
> |
= new AtomicReference<>(null); |
682 |
|
|
683 |
|
/** |
684 |
|
* Records an exception so that it can be rethrown later in the test |
1240 |
|
} |
1241 |
|
public void refresh() {} |
1242 |
|
public String toString() { |
1243 |
< |
List<Permission> ps = new ArrayList<Permission>(); |
1243 |
> |
List<Permission> ps = new ArrayList<>(); |
1244 |
|
for (Enumeration<Permission> e = perms.elements(); e.hasMoreElements();) |
1245 |
|
ps.add(e.nextElement()); |
1246 |
|
return "AdjustablePolicy with permissions " + ps; |
1299 |
|
startTime = System.nanoTime(); |
1300 |
|
else if (millisElapsedSince(startTime) > timeoutMillis) { |
1301 |
|
threadAssertTrue(thread.isAlive()); |
1302 |
< |
return; |
1302 |
> |
fail("timed out waiting for thread to enter wait state"); |
1303 |
|
} |
1304 |
|
Thread.yield(); |
1305 |
|
} |
1306 |
|
} |
1307 |
|
|
1308 |
|
/** |
1309 |
< |
* Waits up to LONG_DELAY_MS for the given thread to enter a wait |
1310 |
< |
* state: BLOCKED, WAITING, or TIMED_WAITING. |
1309 |
> |
* Spin-waits up to the specified number of milliseconds for the given |
1310 |
> |
* thread to enter a wait state: BLOCKED, WAITING, or TIMED_WAITING, |
1311 |
> |
* and additionally satisfy the given condition. |
1312 |
> |
*/ |
1313 |
> |
void waitForThreadToEnterWaitState( |
1314 |
> |
Thread thread, long timeoutMillis, Callable<Boolean> waitingForGodot) { |
1315 |
> |
long startTime = 0L; |
1316 |
> |
for (;;) { |
1317 |
> |
Thread.State s = thread.getState(); |
1318 |
> |
if (s == Thread.State.BLOCKED || |
1319 |
> |
s == Thread.State.WAITING || |
1320 |
> |
s == Thread.State.TIMED_WAITING) { |
1321 |
> |
try { |
1322 |
> |
if (waitingForGodot.call()) |
1323 |
> |
return; |
1324 |
> |
} catch (Throwable fail) { threadUnexpectedException(fail); } |
1325 |
> |
} |
1326 |
> |
else if (s == Thread.State.TERMINATED) |
1327 |
> |
fail("Unexpected thread termination"); |
1328 |
> |
else if (startTime == 0L) |
1329 |
> |
startTime = System.nanoTime(); |
1330 |
> |
else if (millisElapsedSince(startTime) > timeoutMillis) { |
1331 |
> |
threadAssertTrue(thread.isAlive()); |
1332 |
> |
fail("timed out waiting for thread to enter wait state"); |
1333 |
> |
} |
1334 |
> |
Thread.yield(); |
1335 |
> |
} |
1336 |
> |
} |
1337 |
> |
|
1338 |
> |
/** |
1339 |
> |
* Spin-waits up to LONG_DELAY_MS milliseconds for the given thread to |
1340 |
> |
* enter a wait state: BLOCKED, WAITING, or TIMED_WAITING. |
1341 |
|
*/ |
1342 |
|
void waitForThreadToEnterWaitState(Thread thread) { |
1343 |
|
waitForThreadToEnterWaitState(thread, LONG_DELAY_MS); |
1344 |
|
} |
1345 |
|
|
1346 |
|
/** |
1347 |
+ |
* Spin-waits up to LONG_DELAY_MS milliseconds for the given thread to |
1348 |
+ |
* enter a wait state: BLOCKED, WAITING, or TIMED_WAITING, |
1349 |
+ |
* and additionally satisfy the given condition. |
1350 |
+ |
*/ |
1351 |
+ |
void waitForThreadToEnterWaitState( |
1352 |
+ |
Thread thread, Callable<Boolean> waitingForGodot) { |
1353 |
+ |
waitForThreadToEnterWaitState(thread, LONG_DELAY_MS, waitingForGodot); |
1354 |
+ |
} |
1355 |
+ |
|
1356 |
+ |
/** |
1357 |
|
* Returns the number of milliseconds since time given by |
1358 |
|
* startNanoTime, which must have been previously returned from a |
1359 |
|
* call to {@link System#nanoTime()}. |