751 |
|
final CountDownLatch aboutToWait = new CountDownLatch(1); |
752 |
|
Thread t = newStartedThread(new CheckedRunnable() { |
753 |
|
public void realRun() throws InterruptedException { |
754 |
+ |
long startTime = System.nanoTime(); |
755 |
|
for (int i = 0; i < SIZE; ++i) { |
755 |
– |
long t0 = System.nanoTime(); |
756 |
|
assertEquals(i, (int) q.poll(LONG_DELAY_MS, MILLISECONDS)); |
757 |
– |
assertTrue(millisElapsedSince(t0) < SMALL_DELAY_MS); |
757 |
|
} |
759 |
– |
long t0 = System.nanoTime(); |
758 |
|
aboutToWait.countDown(); |
759 |
|
try { |
760 |
< |
q.poll(MEDIUM_DELAY_MS, MILLISECONDS); |
760 |
> |
q.poll(LONG_DELAY_MS, MILLISECONDS); |
761 |
|
shouldThrow(); |
762 |
|
} catch (InterruptedException success) { |
763 |
< |
assertTrue(millisElapsedSince(t0) < MEDIUM_DELAY_MS); |
763 |
> |
assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS); |
764 |
|
} |
765 |
|
}}); |
766 |
|
|
767 |
|
aboutToWait.await(); |
768 |
< |
waitForThreadToEnterWaitState(t, SMALL_DELAY_MS); |
768 |
> |
waitForThreadToEnterWaitState(t, LONG_DELAY_MS); |
769 |
|
t.interrupt(); |
770 |
< |
awaitTermination(t, MEDIUM_DELAY_MS); |
770 |
> |
awaitTermination(t); |
771 |
|
checkEmpty(q); |
772 |
|
} |
773 |
|
|
1048 |
|
* returning timeout status |
1049 |
|
*/ |
1050 |
|
public void testInterruptedTimedPollFirst() throws InterruptedException { |
1051 |
+ |
final LinkedBlockingDeque q = populatedDeque(SIZE); |
1052 |
|
final CountDownLatch pleaseInterrupt = new CountDownLatch(1); |
1053 |
|
Thread t = newStartedThread(new CheckedRunnable() { |
1054 |
|
public void realRun() throws InterruptedException { |
1055 |
< |
LinkedBlockingDeque q = populatedDeque(SIZE); |
1055 |
> |
long startTime = System.nanoTime(); |
1056 |
|
for (int i = 0; i < SIZE; ++i) { |
1057 |
|
assertEquals(i, q.pollFirst(LONG_DELAY_MS, MILLISECONDS)); |
1058 |
|
} |
1059 |
|
|
1060 |
|
Thread.currentThread().interrupt(); |
1061 |
|
try { |
1062 |
< |
q.pollFirst(SMALL_DELAY_MS, MILLISECONDS); |
1062 |
> |
q.pollFirst(LONG_DELAY_MS, MILLISECONDS); |
1063 |
|
shouldThrow(); |
1064 |
|
} catch (InterruptedException success) {} |
1065 |
|
assertFalse(Thread.interrupted()); |
1070 |
|
shouldThrow(); |
1071 |
|
} catch (InterruptedException success) {} |
1072 |
|
assertFalse(Thread.interrupted()); |
1073 |
+ |
assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS); |
1074 |
|
}}); |
1075 |
|
|
1076 |
|
await(pleaseInterrupt); |
1315 |
|
* returning timeout status |
1316 |
|
*/ |
1317 |
|
public void testInterruptedTimedPollLast() throws InterruptedException { |
1318 |
+ |
final LinkedBlockingDeque q = populatedDeque(SIZE); |
1319 |
|
final CountDownLatch pleaseInterrupt = new CountDownLatch(1); |
1320 |
|
Thread t = newStartedThread(new CheckedRunnable() { |
1321 |
|
public void realRun() throws InterruptedException { |
1322 |
< |
LinkedBlockingDeque q = populatedDeque(SIZE); |
1322 |
> |
long startTime = System.nanoTime(); |
1323 |
|
for (int i = 0; i < SIZE; ++i) { |
1324 |
|
assertEquals(SIZE - i - 1, |
1325 |
|
q.pollLast(LONG_DELAY_MS, MILLISECONDS)); |
1338 |
|
shouldThrow(); |
1339 |
|
} catch (InterruptedException success) {} |
1340 |
|
assertFalse(Thread.interrupted()); |
1341 |
+ |
|
1342 |
+ |
assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS); |
1343 |
|
}}); |
1344 |
|
|
1345 |
|
await(pleaseInterrupt); |
1346 |
|
assertThreadStaysAlive(t); |
1347 |
|
t.interrupt(); |
1348 |
|
awaitTermination(t); |
1349 |
+ |
checkEmpty(q); |
1350 |
|
} |
1351 |
|
|
1352 |
|
/** |