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 |
|
*/ |
1635 |
|
} catch (Throwable fail) { |
1636 |
|
threadUnexpectedException(fail); |
1637 |
|
} |
1638 |
+ |
} |
1639 |
+ |
|
1640 |
+ |
public void await(CyclicBarrier barrier) { |
1641 |
+ |
try { |
1642 |
+ |
barrier.await(LONG_DELAY_MS, MILLISECONDS); |
1643 |
+ |
} catch (Throwable fail) { |
1644 |
+ |
threadUnexpectedException(fail); |
1645 |
+ |
} |
1646 |
|
} |
1647 |
|
|
1648 |
|
// /** |