58 |
|
* Returns a new deque of given size containing consecutive |
59 |
|
* Integers 0 ... n - 1. |
60 |
|
*/ |
61 |
< |
private LinkedBlockingDeque<Integer> populatedDeque(int n) { |
61 |
> |
private static LinkedBlockingDeque<Integer> populatedDeque(int n) { |
62 |
|
LinkedBlockingDeque<Integer> q = |
63 |
|
new LinkedBlockingDeque<Integer>(n); |
64 |
|
assertTrue(q.isEmpty()); |
604 |
|
}}); |
605 |
|
|
606 |
|
await(pleaseInterrupt); |
607 |
< |
assertThreadStaysAlive(t); |
607 |
> |
assertThreadBlocks(t, Thread.State.WAITING); |
608 |
|
t.interrupt(); |
609 |
|
awaitTermination(t); |
610 |
|
assertEquals(SIZE, q.size()); |
639 |
|
assertEquals(0, q.take()); |
640 |
|
|
641 |
|
await(pleaseInterrupt); |
642 |
< |
assertThreadStaysAlive(t); |
642 |
> |
assertThreadBlocks(t, Thread.State.WAITING); |
643 |
|
t.interrupt(); |
644 |
|
awaitTermination(t); |
645 |
|
assertEquals(0, q.remainingCapacity()); |
663 |
|
q.offer(new Object(), 2 * LONG_DELAY_MS, MILLISECONDS); |
664 |
|
shouldThrow(); |
665 |
|
} catch (InterruptedException success) {} |
666 |
+ |
assertFalse(Thread.interrupted()); |
667 |
|
}}); |
668 |
|
|
669 |
|
await(pleaseInterrupt); |
670 |
< |
assertThreadStaysAlive(t); |
670 |
> |
assertThreadBlocks(t, Thread.State.TIMED_WAITING); |
671 |
|
t.interrupt(); |
672 |
|
awaitTermination(t); |
673 |
|
} |
690 |
|
final CountDownLatch pleaseInterrupt = new CountDownLatch(1); |
691 |
|
Thread t = newStartedThread(new CheckedRunnable() { |
692 |
|
public void realRun() throws InterruptedException { |
693 |
< |
for (int i = 0; i < SIZE; ++i) { |
693 |
< |
assertEquals(i, q.take()); |
694 |
< |
} |
693 |
> |
for (int i = 0; i < SIZE; i++) assertEquals(i, q.take()); |
694 |
|
|
695 |
|
Thread.currentThread().interrupt(); |
696 |
|
try { |
708 |
|
}}); |
709 |
|
|
710 |
|
await(pleaseInterrupt); |
711 |
< |
assertThreadStaysAlive(t); |
711 |
> |
assertThreadBlocks(t, Thread.State.WAITING); |
712 |
|
t.interrupt(); |
713 |
|
awaitTermination(t); |
714 |
|
} |
757 |
|
*/ |
758 |
|
public void testInterruptedTimedPoll() throws InterruptedException { |
759 |
|
final BlockingQueue<Integer> q = populatedDeque(SIZE); |
760 |
< |
final CountDownLatch aboutToWait = new CountDownLatch(1); |
760 |
> |
final CountDownLatch pleaseInterrupt = new CountDownLatch(1); |
761 |
|
Thread t = newStartedThread(new CheckedRunnable() { |
762 |
|
public void realRun() throws InterruptedException { |
763 |
|
long startTime = System.nanoTime(); |
764 |
< |
for (int i = 0; i < SIZE; ++i) { |
764 |
> |
for (int i = 0; i < SIZE; i++) |
765 |
|
assertEquals(i, (int) q.poll(LONG_DELAY_MS, MILLISECONDS)); |
766 |
< |
} |
767 |
< |
aboutToWait.countDown(); |
766 |
> |
|
767 |
> |
Thread.currentThread().interrupt(); |
768 |
|
try { |
769 |
|
q.poll(LONG_DELAY_MS, MILLISECONDS); |
770 |
|
shouldThrow(); |
771 |
< |
} catch (InterruptedException success) { |
772 |
< |
assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS); |
773 |
< |
} |
771 |
> |
} catch (InterruptedException success) {} |
772 |
> |
assertFalse(Thread.interrupted()); |
773 |
> |
|
774 |
> |
pleaseInterrupt.countDown(); |
775 |
> |
try { |
776 |
> |
q.poll(LONG_DELAY_MS, MILLISECONDS); |
777 |
> |
shouldThrow(); |
778 |
> |
} catch (InterruptedException success) {} |
779 |
> |
assertFalse(Thread.interrupted()); |
780 |
> |
|
781 |
> |
assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS); |
782 |
|
}}); |
783 |
|
|
784 |
< |
aboutToWait.await(); |
785 |
< |
waitForThreadToEnterWaitState(t); |
784 |
> |
await(pleaseInterrupt); |
785 |
> |
assertThreadBlocks(t, Thread.State.TIMED_WAITING); |
786 |
|
t.interrupt(); |
787 |
|
awaitTermination(t); |
788 |
|
checkEmpty(q); |
841 |
|
}}); |
842 |
|
|
843 |
|
await(pleaseInterrupt); |
844 |
< |
assertThreadStaysAlive(t); |
844 |
> |
assertThreadBlocks(t, Thread.State.WAITING); |
845 |
|
t.interrupt(); |
846 |
|
awaitTermination(t); |
847 |
|
assertEquals(SIZE, q.size()); |
876 |
|
assertEquals(capacity - 1, q.take()); |
877 |
|
|
878 |
|
await(pleaseInterrupt); |
879 |
< |
assertThreadStaysAlive(t); |
879 |
> |
assertThreadBlocks(t, Thread.State.WAITING); |
880 |
|
t.interrupt(); |
881 |
|
awaitTermination(t); |
882 |
|
assertEquals(0, q.remainingCapacity()); |
900 |
|
q.offerFirst(new Object(), 2 * LONG_DELAY_MS, MILLISECONDS); |
901 |
|
shouldThrow(); |
902 |
|
} catch (InterruptedException success) {} |
903 |
+ |
assertFalse(Thread.interrupted()); |
904 |
|
}}); |
905 |
|
|
906 |
|
await(pleaseInterrupt); |
907 |
< |
assertThreadStaysAlive(t); |
907 |
> |
assertThreadBlocks(t, Thread.State.TIMED_WAITING); |
908 |
|
t.interrupt(); |
909 |
|
awaitTermination(t); |
910 |
|
} |
936 |
|
}}); |
937 |
|
|
938 |
|
await(threadStarted); |
939 |
< |
assertThreadStaysAlive(t); |
939 |
> |
assertThreadBlocks(t, Thread.State.WAITING); |
940 |
|
t.interrupt(); |
941 |
|
awaitTermination(t); |
942 |
|
} |
977 |
|
}}); |
978 |
|
|
979 |
|
await(threadStarted); |
980 |
< |
assertThreadStaysAlive(t); |
980 |
> |
assertThreadBlocks(t, Thread.State.WAITING); |
981 |
|
t.interrupt(); |
982 |
|
awaitTermination(t); |
983 |
|
} |
1009 |
|
final CountDownLatch pleaseInterrupt = new CountDownLatch(1); |
1010 |
|
Thread t = newStartedThread(new CheckedRunnable() { |
1011 |
|
public void realRun() throws InterruptedException { |
1012 |
< |
for (int i = 0; i < SIZE; ++i) { |
1005 |
< |
assertEquals(i, q.takeFirst()); |
1006 |
< |
} |
1012 |
> |
for (int i = 0; i < SIZE; i++) assertEquals(i, q.takeFirst()); |
1013 |
|
|
1014 |
|
Thread.currentThread().interrupt(); |
1015 |
|
try { |
1027 |
|
}}); |
1028 |
|
|
1029 |
|
await(pleaseInterrupt); |
1030 |
< |
assertThreadStaysAlive(t); |
1030 |
> |
assertThreadBlocks(t, Thread.State.WAITING); |
1031 |
|
t.interrupt(); |
1032 |
|
awaitTermination(t); |
1033 |
|
} |
1069 |
|
Thread t = newStartedThread(new CheckedRunnable() { |
1070 |
|
public void realRun() throws InterruptedException { |
1071 |
|
long startTime = System.nanoTime(); |
1072 |
< |
for (int i = 0; i < SIZE; ++i) { |
1072 |
> |
for (int i = 0; i < SIZE; i++) |
1073 |
|
assertEquals(i, q.pollFirst(LONG_DELAY_MS, MILLISECONDS)); |
1068 |
– |
} |
1074 |
|
|
1075 |
|
Thread.currentThread().interrupt(); |
1076 |
|
try { |
1085 |
|
shouldThrow(); |
1086 |
|
} catch (InterruptedException success) {} |
1087 |
|
assertFalse(Thread.interrupted()); |
1088 |
+ |
|
1089 |
|
assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS); |
1090 |
|
}}); |
1091 |
|
|
1092 |
|
await(pleaseInterrupt); |
1093 |
< |
assertThreadStaysAlive(t); |
1093 |
> |
assertThreadBlocks(t, Thread.State.TIMED_WAITING); |
1094 |
|
t.interrupt(); |
1095 |
|
awaitTermination(t); |
1096 |
|
} |
1123 |
|
q.pollFirst(LONG_DELAY_MS, MILLISECONDS); |
1124 |
|
shouldThrow(); |
1125 |
|
} catch (InterruptedException success) {} |
1126 |
+ |
assertFalse(Thread.interrupted()); |
1127 |
|
assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS); |
1128 |
|
}}); |
1129 |
|
|
1132 |
|
assertTrue(q.offerFirst(zero, LONG_DELAY_MS, MILLISECONDS)); |
1133 |
|
assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS); |
1134 |
|
barrier.await(); |
1135 |
< |
assertThreadStaysAlive(t); |
1135 |
> |
assertThreadBlocks(t, Thread.State.TIMED_WAITING); |
1136 |
|
t.interrupt(); |
1137 |
|
awaitTermination(t); |
1138 |
|
} |
1190 |
|
}}); |
1191 |
|
|
1192 |
|
await(pleaseInterrupt); |
1193 |
< |
assertThreadStaysAlive(t); |
1193 |
> |
assertThreadBlocks(t, Thread.State.WAITING); |
1194 |
|
t.interrupt(); |
1195 |
|
awaitTermination(t); |
1196 |
|
assertEquals(SIZE, q.size()); |
1225 |
|
assertEquals(0, q.take()); |
1226 |
|
|
1227 |
|
await(pleaseInterrupt); |
1228 |
< |
assertThreadStaysAlive(t); |
1228 |
> |
assertThreadBlocks(t, Thread.State.WAITING); |
1229 |
|
t.interrupt(); |
1230 |
|
awaitTermination(t); |
1231 |
|
assertEquals(0, q.remainingCapacity()); |
1252 |
|
}}); |
1253 |
|
|
1254 |
|
await(pleaseInterrupt); |
1255 |
< |
assertThreadStaysAlive(t); |
1255 |
> |
assertThreadBlocks(t, Thread.State.TIMED_WAITING); |
1256 |
|
t.interrupt(); |
1257 |
|
awaitTermination(t); |
1258 |
|
} |
1275 |
|
final CountDownLatch pleaseInterrupt = new CountDownLatch(1); |
1276 |
|
Thread t = newStartedThread(new CheckedRunnable() { |
1277 |
|
public void realRun() throws InterruptedException { |
1278 |
< |
for (int i = 0; i < SIZE; ++i) { |
1278 |
> |
for (int i = 0; i < SIZE; i++) |
1279 |
|
assertEquals(SIZE - i - 1, q.takeLast()); |
1273 |
– |
} |
1280 |
|
|
1281 |
|
Thread.currentThread().interrupt(); |
1282 |
|
try { |
1294 |
|
}}); |
1295 |
|
|
1296 |
|
await(pleaseInterrupt); |
1297 |
< |
assertThreadStaysAlive(t); |
1297 |
> |
assertThreadBlocks(t, Thread.State.WAITING); |
1298 |
|
t.interrupt(); |
1299 |
|
awaitTermination(t); |
1300 |
|
} |
1336 |
|
Thread t = newStartedThread(new CheckedRunnable() { |
1337 |
|
public void realRun() throws InterruptedException { |
1338 |
|
long startTime = System.nanoTime(); |
1339 |
< |
for (int i = 0; i < SIZE; ++i) { |
1339 |
> |
for (int i = 0; i < SIZE; i++) |
1340 |
|
assertEquals(SIZE - i - 1, |
1341 |
|
q.pollLast(LONG_DELAY_MS, MILLISECONDS)); |
1336 |
– |
} |
1342 |
|
|
1343 |
|
Thread.currentThread().interrupt(); |
1344 |
|
try { |
1358 |
|
}}); |
1359 |
|
|
1360 |
|
await(pleaseInterrupt); |
1361 |
< |
assertThreadStaysAlive(t); |
1361 |
> |
assertThreadBlocks(t, Thread.State.TIMED_WAITING); |
1362 |
|
t.interrupt(); |
1363 |
|
awaitTermination(t); |
1364 |
|
checkEmpty(q); |
1404 |
|
assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS); |
1405 |
|
|
1406 |
|
barrier.await(); |
1407 |
< |
assertThreadStaysAlive(t); |
1407 |
> |
assertThreadBlocks(t, Thread.State.TIMED_WAITING); |
1408 |
|
t.interrupt(); |
1409 |
|
awaitTermination(t); |
1410 |
|
} |