1063 |
|
} |
1064 |
|
|
1065 |
|
/** |
1066 |
+ |
* Checks that thread eventually enters the expected blocked thread state. |
1067 |
+ |
*/ |
1068 |
+ |
void assertThreadBlocks(Thread thread, Thread.State expected) { |
1069 |
+ |
// always sleep at least 1 ms, avoiding transitional states |
1070 |
+ |
// with high probability |
1071 |
+ |
for (long retries = LONG_DELAY_MS * 3 / 4; retries-->0; ) { |
1072 |
+ |
try { delay(1); } |
1073 |
+ |
catch (InterruptedException fail) { |
1074 |
+ |
fail("Unexpected InterruptedException"); |
1075 |
+ |
} |
1076 |
+ |
Thread.State s = thread.getState(); |
1077 |
+ |
if (s == expected) |
1078 |
+ |
return; |
1079 |
+ |
else if (s == Thread.State.TERMINATED) |
1080 |
+ |
fail("Unexpected thread termination"); |
1081 |
+ |
} |
1082 |
+ |
fail("timed out waiting for thread to enter thread state " + expected); |
1083 |
+ |
} |
1084 |
+ |
|
1085 |
+ |
/** |
1086 |
|
* Checks that thread does not terminate within the default |
1087 |
|
* millisecond delay of {@code timeoutMillis()}. |
1088 |
|
*/ |
1104 |
|
} |
1105 |
|
|
1106 |
|
/** |
1087 |
– |
* Checks that the threads do not terminate within the default |
1088 |
– |
* millisecond delay of {@code timeoutMillis()}. |
1089 |
– |
*/ |
1090 |
– |
void assertThreadsStayAlive(Thread... threads) { |
1091 |
– |
assertThreadsStayAlive(timeoutMillis(), threads); |
1092 |
– |
} |
1093 |
– |
|
1094 |
– |
/** |
1095 |
– |
* Checks that the threads do not terminate within the given millisecond delay. |
1096 |
– |
*/ |
1097 |
– |
void assertThreadsStayAlive(long millis, Thread... threads) { |
1098 |
– |
try { |
1099 |
– |
// No need to optimize the failing case via Thread.join. |
1100 |
– |
delay(millis); |
1101 |
– |
for (Thread thread : threads) |
1102 |
– |
assertTrue(thread.isAlive()); |
1103 |
– |
} catch (InterruptedException fail) { |
1104 |
– |
threadFail("Unexpected InterruptedException"); |
1105 |
– |
} |
1106 |
– |
} |
1107 |
– |
|
1108 |
– |
/** |
1107 |
|
* Checks that future.get times out, with the default timeout of |
1108 |
|
* {@code timeoutMillis()}. |
1109 |
|
*/ |
1613 |
|
} catch (Throwable fail) { |
1614 |
|
threadUnexpectedException(fail); |
1615 |
|
} |
1616 |
+ |
} |
1617 |
+ |
|
1618 |
+ |
public void await(CyclicBarrier barrier) { |
1619 |
+ |
try { |
1620 |
+ |
barrier.await(LONG_DELAY_MS, MILLISECONDS); |
1621 |
+ |
} catch (Throwable fail) { |
1622 |
+ |
threadUnexpectedException(fail); |
1623 |
+ |
} |
1624 |
|
} |
1625 |
|
|
1626 |
|
// /** |