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()); |
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); |
646 |
|
assertEquals(0, q.take()); |
647 |
|
|
648 |
|
await(pleaseInterrupt); |
649 |
< |
assertThreadStaysAlive(t); |
649 |
> |
assertThreadBlocks(t, Thread.State.WAITING); |
650 |
|
t.interrupt(); |
651 |
|
awaitTermination(t); |
652 |
|
assertEquals(0, q.remainingCapacity()); |
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); |
677 |
< |
assertThreadStaysAlive(t); |
677 |
> |
assertThreadBlocks(t, Thread.State.TIMED_WAITING); |
678 |
|
t.interrupt(); |
679 |
|
awaitTermination(t); |
680 |
|
} |
697 |
|
final CountDownLatch pleaseInterrupt = new CountDownLatch(1); |
698 |
|
Thread t = newStartedThread(new CheckedRunnable() { |
699 |
|
public void realRun() throws InterruptedException { |
700 |
< |
for (int i = 0; i < SIZE; ++i) { |
693 |
< |
assertEquals(i, q.take()); |
694 |
< |
} |
700 |
> |
for (int i = 0; i < SIZE; i++) assertEquals(i, q.take()); |
701 |
|
|
702 |
|
Thread.currentThread().interrupt(); |
703 |
|
try { |
715 |
|
}}); |
716 |
|
|
717 |
|
await(pleaseInterrupt); |
718 |
< |
assertThreadStaysAlive(t); |
718 |
> |
assertThreadBlocks(t, Thread.State.WAITING); |
719 |
|
t.interrupt(); |
720 |
|
awaitTermination(t); |
721 |
|
} |
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 |
> |
assertFalse(Thread.interrupted()); |
780 |
> |
|
781 |
> |
pleaseInterrupt.countDown(); |
782 |
|
try { |
783 |
|
q.poll(LONG_DELAY_MS, MILLISECONDS); |
784 |
|
shouldThrow(); |
785 |
< |
} catch (InterruptedException success) { |
786 |
< |
assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS); |
787 |
< |
} |
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); |
848 |
|
}}); |
849 |
|
|
850 |
|
await(pleaseInterrupt); |
851 |
< |
assertThreadStaysAlive(t); |
851 |
> |
assertThreadBlocks(t, Thread.State.WAITING); |
852 |
|
t.interrupt(); |
853 |
|
awaitTermination(t); |
854 |
|
assertEquals(SIZE, q.size()); |
883 |
|
assertEquals(capacity - 1, q.take()); |
884 |
|
|
885 |
|
await(pleaseInterrupt); |
886 |
< |
assertThreadStaysAlive(t); |
886 |
> |
assertThreadBlocks(t, Thread.State.WAITING); |
887 |
|
t.interrupt(); |
888 |
|
awaitTermination(t); |
889 |
|
assertEquals(0, q.remainingCapacity()); |
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); |
914 |
< |
assertThreadStaysAlive(t); |
914 |
> |
assertThreadBlocks(t, Thread.State.TIMED_WAITING); |
915 |
|
t.interrupt(); |
916 |
|
awaitTermination(t); |
917 |
|
} |
943 |
|
}}); |
944 |
|
|
945 |
|
await(threadStarted); |
946 |
< |
assertThreadStaysAlive(t); |
946 |
> |
assertThreadBlocks(t, Thread.State.WAITING); |
947 |
|
t.interrupt(); |
948 |
|
awaitTermination(t); |
949 |
|
} |
984 |
|
}}); |
985 |
|
|
986 |
|
await(threadStarted); |
987 |
< |
assertThreadStaysAlive(t); |
987 |
> |
assertThreadBlocks(t, Thread.State.WAITING); |
988 |
|
t.interrupt(); |
989 |
|
awaitTermination(t); |
990 |
|
} |
1016 |
|
final CountDownLatch pleaseInterrupt = new CountDownLatch(1); |
1017 |
|
Thread t = newStartedThread(new CheckedRunnable() { |
1018 |
|
public void realRun() throws InterruptedException { |
1019 |
< |
for (int i = 0; i < SIZE; ++i) { |
1005 |
< |
assertEquals(i, q.takeFirst()); |
1006 |
< |
} |
1019 |
> |
for (int i = 0; i < SIZE; i++) assertEquals(i, q.takeFirst()); |
1020 |
|
|
1021 |
|
Thread.currentThread().interrupt(); |
1022 |
|
try { |
1034 |
|
}}); |
1035 |
|
|
1036 |
|
await(pleaseInterrupt); |
1037 |
< |
assertThreadStaysAlive(t); |
1037 |
> |
assertThreadBlocks(t, Thread.State.WAITING); |
1038 |
|
t.interrupt(); |
1039 |
|
awaitTermination(t); |
1040 |
|
} |
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)); |
1068 |
– |
} |
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 |
|
} |
1197 |
|
}}); |
1198 |
|
|
1199 |
|
await(pleaseInterrupt); |
1200 |
< |
assertThreadStaysAlive(t); |
1200 |
> |
assertThreadBlocks(t, Thread.State.WAITING); |
1201 |
|
t.interrupt(); |
1202 |
|
awaitTermination(t); |
1203 |
|
assertEquals(SIZE, q.size()); |
1232 |
|
assertEquals(0, q.take()); |
1233 |
|
|
1234 |
|
await(pleaseInterrupt); |
1235 |
< |
assertThreadStaysAlive(t); |
1235 |
> |
assertThreadBlocks(t, Thread.State.WAITING); |
1236 |
|
t.interrupt(); |
1237 |
|
awaitTermination(t); |
1238 |
|
assertEquals(0, q.remainingCapacity()); |
1259 |
|
}}); |
1260 |
|
|
1261 |
|
await(pleaseInterrupt); |
1262 |
< |
assertThreadStaysAlive(t); |
1262 |
> |
assertThreadBlocks(t, Thread.State.TIMED_WAITING); |
1263 |
|
t.interrupt(); |
1264 |
|
awaitTermination(t); |
1265 |
|
} |
1282 |
|
final CountDownLatch pleaseInterrupt = new CountDownLatch(1); |
1283 |
|
Thread t = newStartedThread(new CheckedRunnable() { |
1284 |
|
public void realRun() throws InterruptedException { |
1285 |
< |
for (int i = 0; i < SIZE; ++i) { |
1285 |
> |
for (int i = 0; i < SIZE; i++) |
1286 |
|
assertEquals(SIZE - i - 1, q.takeLast()); |
1273 |
– |
} |
1287 |
|
|
1288 |
|
Thread.currentThread().interrupt(); |
1289 |
|
try { |
1301 |
|
}}); |
1302 |
|
|
1303 |
|
await(pleaseInterrupt); |
1304 |
< |
assertThreadStaysAlive(t); |
1304 |
> |
assertThreadBlocks(t, Thread.State.WAITING); |
1305 |
|
t.interrupt(); |
1306 |
|
awaitTermination(t); |
1307 |
|
} |
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)); |
1336 |
– |
} |
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); |
1411 |
|
assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS); |
1412 |
|
|
1413 |
|
barrier.await(); |
1414 |
< |
assertThreadStaysAlive(t); |
1414 |
> |
assertThreadBlocks(t, Thread.State.TIMED_WAITING); |
1415 |
|
t.interrupt(); |
1416 |
|
awaitTermination(t); |
1417 |
|
} |