626 |
|
pleaseTake.countDown(); |
627 |
|
q.put(86); |
628 |
|
|
629 |
+ |
Thread.currentThread().interrupt(); |
630 |
+ |
try { |
631 |
+ |
q.put(99); |
632 |
+ |
shouldThrow(); |
633 |
+ |
} catch (InterruptedException success) {} |
634 |
+ |
assertFalse(Thread.interrupted()); |
635 |
+ |
|
636 |
|
pleaseInterrupt.countDown(); |
637 |
|
try { |
638 |
|
q.put(99); |
670 |
|
q.offer(new Object(), 2 * LONG_DELAY_MS, MILLISECONDS); |
671 |
|
shouldThrow(); |
672 |
|
} catch (InterruptedException success) {} |
673 |
+ |
assertFalse(Thread.interrupted()); |
674 |
|
}}); |
675 |
|
|
676 |
|
await(pleaseInterrupt); |
764 |
|
*/ |
765 |
|
public void testInterruptedTimedPoll() throws InterruptedException { |
766 |
|
final BlockingQueue<Integer> q = populatedDeque(SIZE); |
767 |
< |
final CountDownLatch aboutToWait = new CountDownLatch(1); |
767 |
> |
final CountDownLatch pleaseInterrupt = new CountDownLatch(1); |
768 |
|
Thread t = newStartedThread(new CheckedRunnable() { |
769 |
|
public void realRun() throws InterruptedException { |
770 |
|
long startTime = System.nanoTime(); |
771 |
< |
for (int i = 0; i < SIZE; ++i) { |
771 |
> |
for (int i = 0; i < SIZE; i++) |
772 |
|
assertEquals(i, (int) q.poll(LONG_DELAY_MS, MILLISECONDS)); |
773 |
< |
} |
774 |
< |
aboutToWait.countDown(); |
773 |
> |
|
774 |
> |
Thread.currentThread().interrupt(); |
775 |
|
try { |
776 |
|
q.poll(LONG_DELAY_MS, MILLISECONDS); |
777 |
|
shouldThrow(); |
778 |
< |
} catch (InterruptedException success) { |
779 |
< |
assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS); |
780 |
< |
} |
778 |
> |
} catch (InterruptedException success) {} |
779 |
> |
assertFalse(Thread.interrupted()); |
780 |
> |
|
781 |
> |
pleaseInterrupt.countDown(); |
782 |
> |
try { |
783 |
> |
q.poll(LONG_DELAY_MS, MILLISECONDS); |
784 |
> |
shouldThrow(); |
785 |
> |
} catch (InterruptedException success) {} |
786 |
> |
assertFalse(Thread.interrupted()); |
787 |
> |
|
788 |
> |
assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS); |
789 |
|
}}); |
790 |
|
|
791 |
< |
await(aboutToWait); |
792 |
< |
waitForThreadToEnterWaitState(t); |
791 |
> |
await(pleaseInterrupt); |
792 |
> |
assertThreadBlocks(t, Thread.State.TIMED_WAITING); |
793 |
|
t.interrupt(); |
794 |
|
awaitTermination(t); |
795 |
|
checkEmpty(q); |
907 |
|
q.offerFirst(new Object(), 2 * LONG_DELAY_MS, MILLISECONDS); |
908 |
|
shouldThrow(); |
909 |
|
} catch (InterruptedException success) {} |
910 |
+ |
assertFalse(Thread.interrupted()); |
911 |
|
}}); |
912 |
|
|
913 |
|
await(pleaseInterrupt); |
1076 |
|
Thread t = newStartedThread(new CheckedRunnable() { |
1077 |
|
public void realRun() throws InterruptedException { |
1078 |
|
long startTime = System.nanoTime(); |
1079 |
< |
for (int i = 0; i < SIZE; ++i) { |
1079 |
> |
for (int i = 0; i < SIZE; i++) |
1080 |
|
assertEquals(i, q.pollFirst(LONG_DELAY_MS, MILLISECONDS)); |
1064 |
– |
} |
1081 |
|
|
1082 |
|
Thread.currentThread().interrupt(); |
1083 |
|
try { |
1092 |
|
shouldThrow(); |
1093 |
|
} catch (InterruptedException success) {} |
1094 |
|
assertFalse(Thread.interrupted()); |
1095 |
+ |
|
1096 |
|
assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS); |
1097 |
|
}}); |
1098 |
|
|
1099 |
|
await(pleaseInterrupt); |
1100 |
< |
assertThreadStaysAlive(t); |
1100 |
> |
assertThreadBlocks(t, Thread.State.TIMED_WAITING); |
1101 |
|
t.interrupt(); |
1102 |
|
awaitTermination(t); |
1103 |
|
} |
1130 |
|
q.pollFirst(LONG_DELAY_MS, MILLISECONDS); |
1131 |
|
shouldThrow(); |
1132 |
|
} catch (InterruptedException success) {} |
1133 |
+ |
assertFalse(Thread.interrupted()); |
1134 |
|
assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS); |
1135 |
|
}}); |
1136 |
|
|
1139 |
|
assertTrue(q.offerFirst(zero, LONG_DELAY_MS, MILLISECONDS)); |
1140 |
|
assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS); |
1141 |
|
barrier.await(); |
1142 |
< |
assertThreadStaysAlive(t); |
1142 |
> |
assertThreadBlocks(t, Thread.State.TIMED_WAITING); |
1143 |
|
t.interrupt(); |
1144 |
|
awaitTermination(t); |
1145 |
|
} |
1343 |
|
Thread t = newStartedThread(new CheckedRunnable() { |
1344 |
|
public void realRun() throws InterruptedException { |
1345 |
|
long startTime = System.nanoTime(); |
1346 |
< |
for (int i = 0; i < SIZE; ++i) { |
1346 |
> |
for (int i = 0; i < SIZE; i++) |
1347 |
|
assertEquals(SIZE - i - 1, |
1348 |
|
q.pollLast(LONG_DELAY_MS, MILLISECONDS)); |
1331 |
– |
} |
1349 |
|
|
1350 |
|
Thread.currentThread().interrupt(); |
1351 |
|
try { |
1365 |
|
}}); |
1366 |
|
|
1367 |
|
await(pleaseInterrupt); |
1368 |
< |
assertThreadStaysAlive(t); |
1368 |
> |
assertThreadBlocks(t, Thread.State.TIMED_WAITING); |
1369 |
|
t.interrupt(); |
1370 |
|
awaitTermination(t); |
1371 |
|
checkEmpty(q); |