617 |
|
}}); |
618 |
|
|
619 |
|
t.start(); |
620 |
< |
Thread.sleep(SHORT_DELAY_MS); |
620 |
> |
delay(SHORT_DELAY_MS); |
621 |
|
t.interrupt(); |
622 |
|
t.join(); |
623 |
|
assertEquals(SIZE, q.size()); |
641 |
|
}}); |
642 |
|
|
643 |
|
t.start(); |
644 |
< |
Thread.sleep(SHORT_DELAY_MS); |
644 |
> |
delay(SHORT_DELAY_MS); |
645 |
|
assertEquals(q.remainingCapacity(), 0); |
646 |
|
assertEquals(0, q.take()); |
647 |
< |
Thread.sleep(SHORT_DELAY_MS); |
647 |
> |
delay(SHORT_DELAY_MS); |
648 |
|
t.interrupt(); |
649 |
|
t.join(); |
650 |
|
assertEquals(q.remainingCapacity(), 0); |
655 |
|
*/ |
656 |
|
public void testTimedOffer() throws InterruptedException { |
657 |
|
final LinkedBlockingDeque q = new LinkedBlockingDeque(2); |
658 |
< |
Thread t = new Thread(new CheckedRunnable() { |
658 |
> |
final CountDownLatch pleaseInterrupt = new CountDownLatch(1); |
659 |
> |
Thread t = newStartedThread(new CheckedRunnable() { |
660 |
|
public void realRun() throws InterruptedException { |
661 |
|
q.put(new Object()); |
662 |
|
q.put(new Object()); |
663 |
< |
assertFalse(q.offer(new Object(), SHORT_DELAY_MS, MILLISECONDS)); |
663 |
> |
long startTime = System.nanoTime(); |
664 |
> |
assertFalse(q.offer(new Object(), timeoutMillis(), MILLISECONDS)); |
665 |
> |
assertTrue(millisElapsedSince(startTime) >= timeoutMillis()); |
666 |
> |
pleaseInterrupt.countDown(); |
667 |
|
try { |
668 |
< |
q.offer(new Object(), LONG_DELAY_MS, MILLISECONDS); |
668 |
> |
q.offer(new Object(), 2 * LONG_DELAY_MS, MILLISECONDS); |
669 |
|
shouldThrow(); |
670 |
|
} catch (InterruptedException success) {} |
671 |
|
}}); |
672 |
|
|
673 |
< |
t.start(); |
670 |
< |
Thread.sleep(SMALL_DELAY_MS); |
673 |
> |
await(pleaseInterrupt); |
674 |
|
t.interrupt(); |
675 |
< |
t.join(); |
675 |
> |
awaitTermination(t); |
676 |
|
} |
677 |
|
|
678 |
|
/** |
702 |
|
}}); |
703 |
|
|
704 |
|
t.start(); |
705 |
< |
Thread.sleep(SHORT_DELAY_MS); |
705 |
> |
delay(SHORT_DELAY_MS); |
706 |
|
t.interrupt(); |
707 |
|
t.join(); |
708 |
|
} |
814 |
|
}}); |
815 |
|
|
816 |
|
t.start(); |
817 |
< |
Thread.sleep(SHORT_DELAY_MS); |
817 |
> |
delay(SHORT_DELAY_MS); |
818 |
|
t.interrupt(); |
819 |
|
t.join(); |
820 |
|
assertEquals(SIZE, q.size()); |
838 |
|
}}); |
839 |
|
|
840 |
|
t.start(); |
841 |
< |
Thread.sleep(SHORT_DELAY_MS); |
841 |
> |
delay(SHORT_DELAY_MS); |
842 |
|
assertEquals(q.remainingCapacity(), 0); |
843 |
|
assertEquals(capacity - 1, q.take()); |
844 |
< |
Thread.sleep(SHORT_DELAY_MS); |
844 |
> |
delay(SHORT_DELAY_MS); |
845 |
|
t.interrupt(); |
846 |
|
t.join(); |
847 |
|
assertEquals(q.remainingCapacity(), 0); |
852 |
|
*/ |
853 |
|
public void testTimedOfferFirst() throws InterruptedException { |
854 |
|
final LinkedBlockingDeque q = new LinkedBlockingDeque(2); |
855 |
< |
Thread t = new Thread(new CheckedRunnable() { |
855 |
> |
final CountDownLatch pleaseInterrupt = new CountDownLatch(1); |
856 |
> |
Thread t = newStartedThread(new CheckedRunnable() { |
857 |
|
public void realRun() throws InterruptedException { |
858 |
|
q.putFirst(new Object()); |
859 |
|
q.putFirst(new Object()); |
860 |
< |
assertFalse(q.offerFirst(new Object(), SHORT_DELAY_MS, MILLISECONDS)); |
860 |
> |
long startTime = System.nanoTime(); |
861 |
> |
assertFalse(q.offerFirst(new Object(), timeoutMillis(), MILLISECONDS)); |
862 |
> |
assertTrue(millisElapsedSince(startTime) >= timeoutMillis()); |
863 |
> |
pleaseInterrupt.countDown(); |
864 |
|
try { |
865 |
< |
q.offerFirst(new Object(), LONG_DELAY_MS, MILLISECONDS); |
865 |
> |
q.offerFirst(new Object(), 2 * LONG_DELAY_MS, MILLISECONDS); |
866 |
|
shouldThrow(); |
867 |
|
} catch (InterruptedException success) {} |
868 |
|
}}); |
869 |
|
|
870 |
< |
t.start(); |
864 |
< |
Thread.sleep(SMALL_DELAY_MS); |
870 |
> |
await(pleaseInterrupt); |
871 |
|
t.interrupt(); |
872 |
< |
t.join(); |
872 |
> |
awaitTermination(t); |
873 |
|
} |
874 |
|
|
875 |
|
/** |
893 |
|
}}; |
894 |
|
|
895 |
|
t.start(); |
896 |
< |
Thread.sleep(SHORT_DELAY_MS); |
896 |
> |
delay(SHORT_DELAY_MS); |
897 |
|
t.interrupt(); |
898 |
|
t.join(); |
899 |
|
} |
914 |
|
}}); |
915 |
|
|
916 |
|
t.start(); |
917 |
< |
Thread.sleep(SHORT_DELAY_MS); |
917 |
> |
delay(SHORT_DELAY_MS); |
918 |
|
t.interrupt(); |
919 |
|
t.join(); |
920 |
|
} |
960 |
|
}}); |
961 |
|
|
962 |
|
t.start(); |
963 |
< |
Thread.sleep(SHORT_DELAY_MS); |
963 |
> |
delay(SHORT_DELAY_MS); |
964 |
|
t.interrupt(); |
965 |
|
t.join(); |
966 |
|
} |
982 |
|
}}); |
983 |
|
|
984 |
|
t.start(); |
985 |
< |
Thread.sleep(SMALL_DELAY_MS); |
985 |
> |
delay(SMALL_DELAY_MS); |
986 |
|
assertTrue(q.offerFirst(zero, SHORT_DELAY_MS, MILLISECONDS)); |
987 |
|
t.interrupt(); |
988 |
|
t.join(); |
1030 |
|
}}); |
1031 |
|
|
1032 |
|
t.start(); |
1033 |
< |
Thread.sleep(SHORT_DELAY_MS); |
1033 |
> |
delay(SHORT_DELAY_MS); |
1034 |
|
t.interrupt(); |
1035 |
|
t.join(); |
1036 |
|
assertEquals(SIZE, q.size()); |
1054 |
|
}}); |
1055 |
|
|
1056 |
|
t.start(); |
1057 |
< |
Thread.sleep(SHORT_DELAY_MS); |
1057 |
> |
delay(SHORT_DELAY_MS); |
1058 |
|
assertEquals(q.remainingCapacity(), 0); |
1059 |
|
assertEquals(0, q.take()); |
1060 |
< |
Thread.sleep(SHORT_DELAY_MS); |
1060 |
> |
delay(SHORT_DELAY_MS); |
1061 |
|
t.interrupt(); |
1062 |
|
t.join(); |
1063 |
|
assertEquals(q.remainingCapacity(), 0); |
1068 |
|
*/ |
1069 |
|
public void testTimedOfferLast() throws InterruptedException { |
1070 |
|
final LinkedBlockingDeque q = new LinkedBlockingDeque(2); |
1071 |
< |
Thread t = new Thread(new CheckedRunnable() { |
1071 |
> |
final CountDownLatch pleaseInterrupt = new CountDownLatch(1); |
1072 |
> |
Thread t = newStartedThread(new CheckedRunnable() { |
1073 |
|
public void realRun() throws InterruptedException { |
1074 |
|
q.putLast(new Object()); |
1075 |
|
q.putLast(new Object()); |
1076 |
< |
assertFalse(q.offerLast(new Object(), SHORT_DELAY_MS, MILLISECONDS)); |
1076 |
> |
long startTime = System.nanoTime(); |
1077 |
> |
assertFalse(q.offerLast(new Object(), timeoutMillis(), MILLISECONDS)); |
1078 |
> |
assertTrue(millisElapsedSince(startTime) >= timeoutMillis()); |
1079 |
> |
pleaseInterrupt.countDown(); |
1080 |
|
try { |
1081 |
< |
q.offerLast(new Object(), LONG_DELAY_MS, MILLISECONDS); |
1081 |
> |
q.offerLast(new Object(), 2 * LONG_DELAY_MS, MILLISECONDS); |
1082 |
|
shouldThrow(); |
1083 |
|
} catch (InterruptedException success) {} |
1084 |
|
}}); |
1085 |
|
|
1086 |
< |
t.start(); |
1077 |
< |
Thread.sleep(SMALL_DELAY_MS); |
1086 |
> |
await(pleaseInterrupt); |
1087 |
|
t.interrupt(); |
1088 |
< |
t.join(); |
1088 |
> |
awaitTermination(t); |
1089 |
|
} |
1090 |
|
|
1091 |
|
/** |
1109 |
|
}}; |
1110 |
|
|
1111 |
|
t.start(); |
1112 |
< |
Thread.sleep(SHORT_DELAY_MS); |
1112 |
> |
delay(SHORT_DELAY_MS); |
1113 |
|
t.interrupt(); |
1114 |
|
t.join(); |
1115 |
|
} |
1130 |
|
}}); |
1131 |
|
|
1132 |
|
t.start(); |
1133 |
< |
Thread.sleep(SHORT_DELAY_MS); |
1133 |
> |
delay(SHORT_DELAY_MS); |
1134 |
|
t.interrupt(); |
1135 |
|
t.join(); |
1136 |
|
} |
1175 |
|
}}); |
1176 |
|
|
1177 |
|
t.start(); |
1178 |
< |
Thread.sleep(SHORT_DELAY_MS); |
1178 |
> |
delay(SHORT_DELAY_MS); |
1179 |
|
t.interrupt(); |
1180 |
|
t.join(); |
1181 |
|
} |
1197 |
|
}}); |
1198 |
|
|
1199 |
|
t.start(); |
1200 |
< |
Thread.sleep(SMALL_DELAY_MS); |
1200 |
> |
delay(SMALL_DELAY_MS); |
1201 |
|
assertTrue(q.offerLast(zero, SHORT_DELAY_MS, MILLISECONDS)); |
1202 |
|
t.interrupt(); |
1203 |
|
t.join(); |
1517 |
|
|
1518 |
|
executor.execute(new CheckedRunnable() { |
1519 |
|
public void realRun() throws InterruptedException { |
1520 |
< |
Thread.sleep(SMALL_DELAY_MS); |
1520 |
> |
delay(SMALL_DELAY_MS); |
1521 |
|
assertSame(one, q.take()); |
1522 |
|
}}); |
1523 |
|
|
1539 |
|
|
1540 |
|
executor.execute(new CheckedRunnable() { |
1541 |
|
public void realRun() throws InterruptedException { |
1542 |
< |
Thread.sleep(SMALL_DELAY_MS); |
1542 |
> |
delay(SMALL_DELAY_MS); |
1543 |
|
q.put(one); |
1544 |
|
}}); |
1545 |
|
|