288 |
|
// Avoid spurious reports with enormous runsPerTest. |
289 |
|
// A single test case run should never take more than 1 second. |
290 |
|
// But let's cap it at the high end too ... |
291 |
< |
final int timeoutMinutes = |
292 |
< |
Math.min(15, Math.max(runsPerTest / 60, 1)); |
291 |
> |
final int timeoutMinutesMin = Math.max(runsPerTest / 60, 1) |
292 |
> |
* Math.max((int) delayFactor, 1); |
293 |
> |
final int timeoutMinutes = Math.min(15, timeoutMinutesMin); |
294 |
|
for (TestCase lastTestCase = currentTestCase;;) { |
295 |
|
try { MINUTES.sleep(timeoutMinutes); } |
296 |
|
catch (InterruptedException unexpected) { break; } |
461 |
|
public static boolean atLeastJava9() { return JAVA_CLASS_VERSION >= 53.0; } |
462 |
|
public static boolean atLeastJava10() { return JAVA_CLASS_VERSION >= 54.0; } |
463 |
|
public static boolean atLeastJava11() { return JAVA_CLASS_VERSION >= 55.0; } |
464 |
+ |
public static boolean atLeastJava12() { return JAVA_CLASS_VERSION >= 56.0; } |
465 |
+ |
public static boolean atLeastJava13() { return JAVA_CLASS_VERSION >= 57.0; } |
466 |
+ |
public static boolean atLeastJava14() { return JAVA_CLASS_VERSION >= 58.0; } |
467 |
+ |
public static boolean atLeastJava15() { return JAVA_CLASS_VERSION >= 59.0; } |
468 |
+ |
public static boolean atLeastJava16() { return JAVA_CLASS_VERSION >= 60.0; } |
469 |
+ |
public static boolean atLeastJava17() { return JAVA_CLASS_VERSION >= 61.0; } |
470 |
|
|
471 |
|
/** |
472 |
|
* Collects all JSR166 unit tests as one suite. |
518 |
|
ExecutorsTest.suite(), |
519 |
|
ExecutorCompletionServiceTest.suite(), |
520 |
|
FutureTaskTest.suite(), |
521 |
+ |
HashtableTest.suite(), |
522 |
|
LinkedBlockingDequeTest.suite(), |
523 |
|
LinkedBlockingQueueTest.suite(), |
524 |
|
LinkedListTest.suite(), |
558 |
|
"HashMapTest", |
559 |
|
"LinkedBlockingDeque8Test", |
560 |
|
"LinkedBlockingQueue8Test", |
561 |
+ |
"LinkedHashMapTest", |
562 |
|
"LongAccumulatorTest", |
563 |
|
"LongAdderTest", |
564 |
|
"SplittableRandomTest", |
685 |
|
static TimeUnit randomTimeUnit() { return RANDOM_TIMEUNIT; } |
686 |
|
|
687 |
|
/** |
688 |
+ |
* Returns a random boolean; a "coin flip". |
689 |
+ |
*/ |
690 |
+ |
static boolean randomBoolean() { |
691 |
+ |
return ThreadLocalRandom.current().nextBoolean(); |
692 |
+ |
} |
693 |
+ |
|
694 |
+ |
/** |
695 |
+ |
* Returns a random element from given choices. |
696 |
+ |
*/ |
697 |
+ |
<T> T chooseRandomly(T... choices) { |
698 |
+ |
return choices[ThreadLocalRandom.current().nextInt(choices.length)]; |
699 |
+ |
} |
700 |
+ |
|
701 |
+ |
/** |
702 |
|
* Returns the shortest timed delay. This can be scaled up for |
703 |
|
* slow machines using the jsr166.delay.factor system property, |
704 |
|
* or via jtreg's -timeoutFactor: flag. |
1381 |
|
} |
1382 |
|
|
1383 |
|
/** |
1384 |
+ |
* Spin-waits up to LONG_DELAY_MS milliseconds for the current thread to |
1385 |
+ |
* be interrupted. Clears the interrupt status before returning. |
1386 |
+ |
*/ |
1387 |
+ |
void awaitInterrupted() { |
1388 |
+ |
for (long startTime = 0L; !Thread.interrupted(); ) { |
1389 |
+ |
if (startTime == 0L) |
1390 |
+ |
startTime = System.nanoTime(); |
1391 |
+ |
else if (millisElapsedSince(startTime) > LONG_DELAY_MS) |
1392 |
+ |
fail("timed out waiting for thread interrupt"); |
1393 |
+ |
Thread.yield(); |
1394 |
+ |
} |
1395 |
+ |
} |
1396 |
+ |
|
1397 |
+ |
/** |
1398 |
|
* Returns the number of milliseconds since time given by |
1399 |
|
* startNanoTime, which must have been previously returned from a |
1400 |
|
* call to {@link System#nanoTime()}. |
1455 |
|
t.join(timeoutMillis); |
1456 |
|
} catch (InterruptedException fail) { |
1457 |
|
threadUnexpectedException(fail); |
1458 |
< |
} finally { |
1459 |
< |
if (t.getState() != Thread.State.TERMINATED) { |
1460 |
< |
t.interrupt(); |
1461 |
< |
threadFail("timed out waiting for thread to terminate"); |
1462 |
< |
} |
1458 |
> |
} |
1459 |
> |
Thread.State state; |
1460 |
> |
if ((state = t.getState()) != Thread.State.TERMINATED) { |
1461 |
> |
t.interrupt(); |
1462 |
> |
threadFail("timed out waiting for thread to terminate; " |
1463 |
> |
+ "state=" + state); |
1464 |
|
} |
1465 |
|
} |
1466 |
|
|
1781 |
|
} |
1782 |
|
} |
1783 |
|
|
1784 |
< |
void assertImmutable(final Object o) { |
1784 |
> |
void assertImmutable(Object o) { |
1785 |
|
if (o instanceof Collection) { |
1786 |
|
assertThrows( |
1787 |
|
UnsupportedOperationException.class, |
1788 |
< |
new Runnable() { public void run() { |
1751 |
< |
((Collection) o).add(null);}}); |
1788 |
> |
() -> ((Collection) o).add(null)); |
1789 |
|
} |
1790 |
|
} |
1791 |
|
|
1845 |
|
} |
1846 |
|
|
1847 |
|
public void assertThrows(Class<? extends Throwable> expectedExceptionClass, |
1848 |
< |
Runnable... throwingActions) { |
1849 |
< |
for (Runnable throwingAction : throwingActions) { |
1848 |
> |
Action... throwingActions) { |
1849 |
> |
for (Action throwingAction : throwingActions) { |
1850 |
|
boolean threw = false; |
1851 |
|
try { throwingAction.run(); } |
1852 |
|
catch (Throwable t) { |