235 |
|
* default timeout duration). |
236 |
|
*/ |
237 |
|
void assertAwaitTimesOut(ConditionObject c, AwaitMethod awaitMethod) { |
238 |
< |
long timeoutMillis = timeoutMillis(); |
239 |
< |
long startTime; |
238 |
> |
final long timeoutMillis = timeoutMillis(); |
239 |
> |
final long startTime; |
240 |
|
try { |
241 |
|
switch (awaitMethod) { |
242 |
|
case awaitTimed: |
255 |
|
case awaitUntil: |
256 |
|
// We shouldn't assume that nanoTime and currentTimeMillis |
257 |
|
// use the same time source, so don't use nanoTime here. |
258 |
< |
java.util.Date delayedDate = delayedDate(timeoutMillis()); |
258 |
> |
java.util.Date delayedDate = delayedDate(timeoutMillis); |
259 |
|
assertFalse(c.awaitUntil(delayedDate(timeoutMillis))); |
260 |
|
assertTrue(new java.util.Date().getTime() >= delayedDate.getTime()); |
261 |
|
break; |
965 |
|
*/ |
966 |
|
public void testAwaitUninterruptibly() { |
967 |
|
final Mutex sync = new Mutex(); |
968 |
< |
final ConditionObject c = sync.newCondition(); |
968 |
> |
final ConditionObject condition = sync.newCondition(); |
969 |
|
final BooleanLatch pleaseInterrupt = new BooleanLatch(); |
970 |
|
Thread t = newStartedThread(new CheckedRunnable() { |
971 |
|
public void realRun() { |
972 |
|
sync.acquire(); |
973 |
|
assertTrue(pleaseInterrupt.releaseShared(0)); |
974 |
< |
c.awaitUninterruptibly(); |
974 |
> |
condition.awaitUninterruptibly(); |
975 |
|
assertTrue(Thread.interrupted()); |
976 |
< |
assertHasWaitersLocked(sync, c, NO_THREADS); |
976 |
> |
assertHasWaitersLocked(sync, condition, NO_THREADS); |
977 |
|
sync.release(); |
978 |
|
}}); |
979 |
|
|
980 |
|
pleaseInterrupt.acquireShared(0); |
981 |
|
sync.acquire(); |
982 |
< |
assertHasWaitersLocked(sync, c, t); |
982 |
> |
assertHasWaitersLocked(sync, condition, t); |
983 |
|
sync.release(); |
984 |
|
t.interrupt(); |
985 |
< |
assertHasWaitersUnlocked(sync, c, t); |
986 |
< |
assertThreadStaysAlive(t); |
985 |
> |
assertHasWaitersUnlocked(sync, condition, t); |
986 |
> |
assertThreadBlocks(t, Thread.State.WAITING); |
987 |
|
sync.acquire(); |
988 |
< |
assertHasWaitersLocked(sync, c, t); |
988 |
> |
assertHasWaitersLocked(sync, condition, t); |
989 |
|
assertHasExclusiveQueuedThreads(sync, NO_THREADS); |
990 |
< |
c.signal(); |
991 |
< |
assertHasWaitersLocked(sync, c, NO_THREADS); |
990 |
> |
condition.signal(); |
991 |
> |
assertHasWaitersLocked(sync, condition, NO_THREADS); |
992 |
|
assertHasExclusiveQueuedThreads(sync, t); |
993 |
|
sync.release(); |
994 |
|
awaitTermination(t); |