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", |
657 |
|
public static long MEDIUM_DELAY_MS; |
658 |
|
public static long LONG_DELAY_MS; |
659 |
|
|
660 |
+ |
/** |
661 |
+ |
* A delay significantly longer than LONG_DELAY_MS. |
662 |
+ |
* Use this in a thread that is waited for via awaitTermination(Thread). |
663 |
+ |
*/ |
664 |
+ |
public static long LONGER_DELAY_MS; |
665 |
+ |
|
666 |
|
private static final long RANDOM_TIMEOUT; |
667 |
|
private static final long RANDOM_EXPIRED_TIMEOUT; |
668 |
|
private static final TimeUnit RANDOM_TIMEUNIT; |
691 |
|
static TimeUnit randomTimeUnit() { return RANDOM_TIMEUNIT; } |
692 |
|
|
693 |
|
/** |
694 |
+ |
* Returns a random boolean; a "coin flip". |
695 |
+ |
*/ |
696 |
+ |
static boolean randomBoolean() { |
697 |
+ |
return ThreadLocalRandom.current().nextBoolean(); |
698 |
+ |
} |
699 |
+ |
|
700 |
+ |
/** |
701 |
+ |
* Returns a random element from given choices. |
702 |
+ |
*/ |
703 |
+ |
<T> T chooseRandomly(T... choices) { |
704 |
+ |
return choices[ThreadLocalRandom.current().nextInt(choices.length)]; |
705 |
+ |
} |
706 |
+ |
|
707 |
+ |
/** |
708 |
|
* Returns the shortest timed delay. This can be scaled up for |
709 |
|
* slow machines using the jsr166.delay.factor system property, |
710 |
|
* or via jtreg's -timeoutFactor: flag. |
722 |
|
SMALL_DELAY_MS = SHORT_DELAY_MS * 5; |
723 |
|
MEDIUM_DELAY_MS = SHORT_DELAY_MS * 10; |
724 |
|
LONG_DELAY_MS = SHORT_DELAY_MS * 200; |
725 |
+ |
LONGER_DELAY_MS = 2 * LONG_DELAY_MS; |
726 |
|
} |
727 |
|
|
728 |
|
private static final long TIMEOUT_DELAY_MS |
761 |
|
*/ |
762 |
|
public void threadRecordFailure(Throwable t) { |
763 |
|
System.err.println(t); |
764 |
< |
dumpTestThreads(); |
765 |
< |
threadFailure.compareAndSet(null, t); |
764 |
> |
if (threadFailure.compareAndSet(null, t)) |
765 |
> |
dumpTestThreads(); |
766 |
|
} |
767 |
|
|
768 |
|
public void setUp() { |
1388 |
|
} |
1389 |
|
|
1390 |
|
/** |
1391 |
+ |
* Spin-waits up to LONG_DELAY_MS milliseconds for the current thread to |
1392 |
+ |
* be interrupted. Clears the interrupt status before returning. |
1393 |
+ |
*/ |
1394 |
+ |
void awaitInterrupted() { |
1395 |
+ |
for (long startTime = 0L; !Thread.interrupted(); ) { |
1396 |
+ |
if (startTime == 0L) |
1397 |
+ |
startTime = System.nanoTime(); |
1398 |
+ |
else if (millisElapsedSince(startTime) > LONG_DELAY_MS) |
1399 |
+ |
fail("timed out waiting for thread interrupt"); |
1400 |
+ |
Thread.yield(); |
1401 |
+ |
} |
1402 |
+ |
} |
1403 |
+ |
|
1404 |
+ |
/** |
1405 |
|
* Returns the number of milliseconds since time given by |
1406 |
|
* startNanoTime, which must have been previously returned from a |
1407 |
|
* call to {@link System#nanoTime()}. |
1457 |
|
* to terminate (using {@link Thread#join(long)}), else interrupts |
1458 |
|
* the thread (in the hope that it may terminate later) and fails. |
1459 |
|
*/ |
1460 |
< |
void awaitTermination(Thread t, long timeoutMillis) { |
1460 |
> |
void awaitTermination(Thread thread, long timeoutMillis) { |
1461 |
|
try { |
1462 |
< |
t.join(timeoutMillis); |
1462 |
> |
thread.join(timeoutMillis); |
1463 |
|
} catch (InterruptedException fail) { |
1464 |
|
threadUnexpectedException(fail); |
1465 |
< |
} finally { |
1466 |
< |
if (t.getState() != Thread.State.TERMINATED) { |
1467 |
< |
t.interrupt(); |
1468 |
< |
threadFail("timed out waiting for thread to terminate"); |
1465 |
> |
} |
1466 |
> |
if (thread.getState() != Thread.State.TERMINATED) { |
1467 |
> |
String detail = String.format( |
1468 |
> |
"timed out waiting for thread to terminate, thread=%s, state=%s" , |
1469 |
> |
thread, thread.getState()); |
1470 |
> |
try { |
1471 |
> |
threadFail(detail); |
1472 |
> |
} finally { |
1473 |
> |
// Interrupt thread __after__ having reported its stack trace |
1474 |
> |
thread.interrupt(); |
1475 |
|
} |
1476 |
|
} |
1477 |
|
} |
1793 |
|
} |
1794 |
|
} |
1795 |
|
|
1796 |
< |
void assertImmutable(final Object o) { |
1796 |
> |
void assertImmutable(Object o) { |
1797 |
|
if (o instanceof Collection) { |
1798 |
|
assertThrows( |
1799 |
|
UnsupportedOperationException.class, |
1800 |
< |
new Runnable() { public void run() { |
1751 |
< |
((Collection) o).add(null);}}); |
1800 |
> |
() -> ((Collection) o).add(null)); |
1801 |
|
} |
1802 |
|
} |
1803 |
|
|
1857 |
|
} |
1858 |
|
|
1859 |
|
public void assertThrows(Class<? extends Throwable> expectedExceptionClass, |
1860 |
< |
Runnable... throwingActions) { |
1861 |
< |
for (Runnable throwingAction : throwingActions) { |
1860 |
> |
Action... throwingActions) { |
1861 |
> |
for (Action throwingAction : throwingActions) { |
1862 |
|
boolean threw = false; |
1863 |
|
try { throwingAction.run(); } |
1864 |
|
catch (Throwable t) { |