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 |
1069 |
> |
// always sleep at least 1 ms, with high probability avoiding |
1070 |
> |
// transitory states |
1071 |
|
for (long retries = LONG_DELAY_MS * 3 / 4; retries-->0; ) { |
1072 |
|
try { delay(1); } |
1073 |
|
catch (InterruptedException fail) { |
1083 |
|
} |
1084 |
|
|
1085 |
|
/** |
1086 |
– |
* Checks that thread does not terminate within the default |
1087 |
– |
* millisecond delay of {@code timeoutMillis()}. |
1088 |
– |
*/ |
1089 |
– |
void assertThreadStaysAlive(Thread thread) { |
1090 |
– |
assertThreadStaysAlive(thread, timeoutMillis()); |
1091 |
– |
} |
1092 |
– |
|
1093 |
– |
/** |
1094 |
– |
* Checks that thread does not terminate within the given millisecond delay. |
1095 |
– |
*/ |
1096 |
– |
void assertThreadStaysAlive(Thread thread, long millis) { |
1097 |
– |
try { |
1098 |
– |
// No need to optimize the failing case via Thread.join. |
1099 |
– |
delay(millis); |
1100 |
– |
assertTrue(thread.isAlive()); |
1101 |
– |
} catch (InterruptedException fail) { |
1102 |
– |
threadFail("Unexpected InterruptedException"); |
1103 |
– |
} |
1104 |
– |
} |
1105 |
– |
|
1106 |
– |
/** |
1086 |
|
* Checks that future.get times out, with the default timeout of |
1087 |
|
* {@code timeoutMillis()}. |
1088 |
|
*/ |