169 |
|
q.getFirst(); |
170 |
|
shouldThrow(); |
171 |
|
} catch (NoSuchElementException success) {} |
172 |
+ |
assertNull(q.peekFirst()); |
173 |
|
} |
174 |
|
|
175 |
|
/** |
200 |
|
q.removeFirst(); |
201 |
|
shouldThrow(); |
202 |
|
} catch (NoSuchElementException success) {} |
203 |
+ |
assertNull(q.peekFirst()); |
204 |
+ |
} |
205 |
+ |
|
206 |
+ |
/** |
207 |
+ |
* removeLast removes last element, or throws NSEE if empty |
208 |
+ |
*/ |
209 |
+ |
public void testRemoveLast() { |
210 |
+ |
LinkedBlockingDeque q = populatedDeque(SIZE); |
211 |
+ |
for (int i = SIZE - 1; i >= 0; --i) { |
212 |
+ |
assertEquals(i, ((Integer)q.removeLast()).intValue()); |
213 |
+ |
} |
214 |
+ |
try { |
215 |
+ |
q.removeLast(); |
216 |
+ |
shouldThrow(); |
217 |
+ |
} catch (NoSuchElementException success) {} |
218 |
+ |
assertNull(q.peekLast()); |
219 |
|
} |
220 |
|
|
221 |
|
/** |
293 |
|
} |
294 |
|
|
295 |
|
/** |
296 |
< |
* Constructor throws IAE if capacity argument nonpositive |
296 |
> |
* Constructor throws IAE if capacity argument nonpositive |
297 |
|
*/ |
298 |
|
public void testConstructor2() { |
299 |
|
try { |
340 |
|
* Deque contains all elements of collection used to initialize |
341 |
|
*/ |
342 |
|
public void testConstructor6() { |
343 |
< |
try { |
344 |
< |
Integer[] ints = new Integer[SIZE]; |
345 |
< |
for (int i = 0; i < SIZE; ++i) |
346 |
< |
ints[i] = new Integer(i); |
347 |
< |
LinkedBlockingDeque q = new LinkedBlockingDeque(Arrays.asList(ints)); |
348 |
< |
for (int i = 0; i < SIZE; ++i) |
332 |
< |
assertEquals(ints[i], q.poll()); |
333 |
< |
} |
334 |
< |
finally {} |
343 |
> |
Integer[] ints = new Integer[SIZE]; |
344 |
> |
for (int i = 0; i < SIZE; ++i) |
345 |
> |
ints[i] = new Integer(i); |
346 |
> |
LinkedBlockingDeque q = new LinkedBlockingDeque(Arrays.asList(ints)); |
347 |
> |
for (int i = 0; i < SIZE; ++i) |
348 |
> |
assertEquals(ints[i], q.poll()); |
349 |
|
} |
350 |
|
|
351 |
|
/** |
540 |
|
shouldThrow(); |
541 |
|
} catch (IllegalStateException success) {} |
542 |
|
} |
543 |
+ |
|
544 |
|
/** |
545 |
|
* Deque contains all elements, in traversal order, of successful addAll |
546 |
|
*/ |
547 |
|
public void testAddAll5() { |
548 |
< |
try { |
549 |
< |
Integer[] empty = new Integer[0]; |
550 |
< |
Integer[] ints = new Integer[SIZE]; |
551 |
< |
for (int i = 0; i < SIZE; ++i) |
552 |
< |
ints[i] = new Integer(i); |
553 |
< |
LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE); |
554 |
< |
assertFalse(q.addAll(Arrays.asList(empty))); |
555 |
< |
assertTrue(q.addAll(Arrays.asList(ints))); |
556 |
< |
for (int i = 0; i < SIZE; ++i) |
542 |
< |
assertEquals(ints[i], q.poll()); |
543 |
< |
} |
544 |
< |
finally {} |
548 |
> |
Integer[] empty = new Integer[0]; |
549 |
> |
Integer[] ints = new Integer[SIZE]; |
550 |
> |
for (int i = 0; i < SIZE; ++i) |
551 |
> |
ints[i] = new Integer(i); |
552 |
> |
LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE); |
553 |
> |
assertFalse(q.addAll(Arrays.asList(empty))); |
554 |
> |
assertTrue(q.addAll(Arrays.asList(ints))); |
555 |
> |
for (int i = 0; i < SIZE; ++i) |
556 |
> |
assertEquals(ints[i], q.poll()); |
557 |
|
} |
558 |
|
|
559 |
|
|
642 |
|
*/ |
643 |
|
public void testTimedOffer() throws InterruptedException { |
644 |
|
final LinkedBlockingDeque q = new LinkedBlockingDeque(2); |
645 |
< |
Thread t = new ThreadShouldThrow(InterruptedException.class) { |
645 |
> |
Thread t = new Thread(new CheckedRunnable() { |
646 |
|
public void realRun() throws InterruptedException { |
647 |
|
q.put(new Object()); |
648 |
|
q.put(new Object()); |
649 |
< |
threadAssertFalse(q.offer(new Object(), SHORT_DELAY_MS, MILLISECONDS)); |
650 |
< |
q.offer(new Object(), LONG_DELAY_MS, MILLISECONDS); |
651 |
< |
}}; |
649 |
> |
assertFalse(q.offer(new Object(), SHORT_DELAY_MS, MILLISECONDS)); |
650 |
> |
try { |
651 |
> |
q.offer(new Object(), LONG_DELAY_MS, MILLISECONDS); |
652 |
> |
shouldThrow(); |
653 |
> |
} catch (InterruptedException success) {} |
654 |
> |
}}); |
655 |
|
|
656 |
|
t.start(); |
657 |
|
Thread.sleep(SMALL_DELAY_MS); |
743 |
|
* returning timeout status |
744 |
|
*/ |
745 |
|
public void testInterruptedTimedPoll() throws InterruptedException { |
746 |
< |
Thread t = new ThreadShouldThrow(InterruptedException.class) { |
746 |
> |
Thread t = new Thread(new CheckedRunnable() { |
747 |
|
public void realRun() throws InterruptedException { |
748 |
|
LinkedBlockingDeque q = populatedDeque(SIZE); |
749 |
|
for (int i = 0; i < SIZE; ++i) { |
750 |
< |
threadAssertEquals(i, ((Integer)q.poll(SHORT_DELAY_MS, MILLISECONDS)).intValue()); |
750 |
> |
assertEquals(i, ((Integer)q.poll(SHORT_DELAY_MS, MILLISECONDS)).intValue()); |
751 |
|
} |
752 |
< |
q.poll(SMALL_DELAY_MS, MILLISECONDS); |
753 |
< |
}}; |
752 |
> |
try { |
753 |
> |
q.poll(SMALL_DELAY_MS, MILLISECONDS); |
754 |
> |
shouldThrow(); |
755 |
> |
} catch (InterruptedException success) {} |
756 |
> |
}}); |
757 |
|
|
758 |
|
t.start(); |
759 |
|
Thread.sleep(SHORT_DELAY_MS); |
767 |
|
*/ |
768 |
|
public void testTimedPollWithOffer() throws InterruptedException { |
769 |
|
final LinkedBlockingDeque q = new LinkedBlockingDeque(2); |
770 |
< |
Thread t = new ThreadShouldThrow(InterruptedException.class) { |
770 |
> |
Thread t = new Thread(new CheckedRunnable() { |
771 |
|
public void realRun() throws InterruptedException { |
772 |
< |
threadAssertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS)); |
773 |
< |
q.poll(LONG_DELAY_MS, MILLISECONDS); |
774 |
< |
q.poll(LONG_DELAY_MS, MILLISECONDS); |
775 |
< |
}}; |
772 |
> |
assertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS)); |
773 |
> |
assertSame(zero, q.poll(LONG_DELAY_MS, MILLISECONDS)); |
774 |
> |
try { |
775 |
> |
q.poll(LONG_DELAY_MS, MILLISECONDS); |
776 |
> |
shouldThrow(); |
777 |
> |
} catch (InterruptedException success) {} |
778 |
> |
}}); |
779 |
|
|
780 |
|
t.start(); |
781 |
|
Thread.sleep(SMALL_DELAY_MS); |
813 |
|
* putFirst blocks interruptibly if full |
814 |
|
*/ |
815 |
|
public void testBlockingPutFirst() throws InterruptedException { |
816 |
< |
Thread t = new Thread(new Runnable() { |
817 |
< |
public void run() { |
818 |
< |
int added = 0; |
819 |
< |
try { |
820 |
< |
LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE); |
821 |
< |
for (int i = 0; i < SIZE; ++i) { |
822 |
< |
q.putFirst(new Integer(i)); |
823 |
< |
++added; |
803 |
< |
} |
804 |
< |
q.putFirst(new Integer(SIZE)); |
805 |
< |
threadShouldThrow(); |
806 |
< |
} catch (InterruptedException success) { |
807 |
< |
threadAssertEquals(added, SIZE); |
816 |
> |
Thread t = new Thread(new CheckedRunnable() { |
817 |
> |
public void realRun() { |
818 |
> |
int added = 0; |
819 |
> |
try { |
820 |
> |
LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE); |
821 |
> |
for (int i = 0; i < SIZE; ++i) { |
822 |
> |
q.putFirst(new Integer(i)); |
823 |
> |
++added; |
824 |
|
} |
825 |
< |
}}); |
825 |
> |
q.putFirst(new Integer(SIZE)); |
826 |
> |
threadShouldThrow(); |
827 |
> |
} catch (InterruptedException success) { |
828 |
> |
threadAssertEquals(added, SIZE); |
829 |
> |
} |
830 |
> |
}}); |
831 |
|
|
832 |
|
t.start(); |
833 |
|
Thread.sleep(SHORT_DELAY_MS); |
840 |
|
*/ |
841 |
|
public void testPutFirstWithTake() throws InterruptedException { |
842 |
|
final LinkedBlockingDeque q = new LinkedBlockingDeque(2); |
843 |
< |
Thread t = new Thread(new Runnable() { |
844 |
< |
public void run() { |
845 |
< |
int added = 0; |
846 |
< |
try { |
847 |
< |
q.putFirst(new Object()); |
848 |
< |
++added; |
849 |
< |
q.putFirst(new Object()); |
850 |
< |
++added; |
851 |
< |
q.putFirst(new Object()); |
852 |
< |
++added; |
853 |
< |
q.putFirst(new Object()); |
854 |
< |
++added; |
855 |
< |
threadShouldThrow(); |
856 |
< |
} catch (InterruptedException success) { |
857 |
< |
threadAssertTrue(added >= 2); |
837 |
< |
} |
843 |
> |
Thread t = new Thread(new CheckedRunnable() { |
844 |
> |
public void realRun() { |
845 |
> |
int added = 0; |
846 |
> |
try { |
847 |
> |
q.putFirst(new Object()); |
848 |
> |
++added; |
849 |
> |
q.putFirst(new Object()); |
850 |
> |
++added; |
851 |
> |
q.putFirst(new Object()); |
852 |
> |
++added; |
853 |
> |
q.putFirst(new Object()); |
854 |
> |
++added; |
855 |
> |
threadShouldThrow(); |
856 |
> |
} catch (InterruptedException success) { |
857 |
> |
threadAssertTrue(added >= 2); |
858 |
|
} |
859 |
< |
}); |
859 |
> |
}}); |
860 |
|
|
861 |
|
t.start(); |
862 |
|
Thread.sleep(SHORT_DELAY_MS); |
870 |
|
*/ |
871 |
|
public void testTimedOfferFirst() throws InterruptedException { |
872 |
|
final LinkedBlockingDeque q = new LinkedBlockingDeque(2); |
873 |
< |
Thread t = new ThreadShouldThrow(InterruptedException.class) { |
873 |
> |
Thread t = new Thread(new CheckedRunnable() { |
874 |
|
public void realRun() throws InterruptedException { |
875 |
|
q.putFirst(new Object()); |
876 |
|
q.putFirst(new Object()); |
877 |
< |
threadAssertFalse(q.offerFirst(new Object(), SHORT_DELAY_MS, MILLISECONDS)); |
878 |
< |
q.offerFirst(new Object(), LONG_DELAY_MS, MILLISECONDS); |
879 |
< |
}}; |
877 |
> |
assertFalse(q.offerFirst(new Object(), SHORT_DELAY_MS, MILLISECONDS)); |
878 |
> |
try { |
879 |
> |
q.offerFirst(new Object(), LONG_DELAY_MS, MILLISECONDS); |
880 |
> |
shouldThrow(); |
881 |
> |
} catch (InterruptedException success) {} |
882 |
> |
}}); |
883 |
|
|
884 |
|
t.start(); |
885 |
|
Thread.sleep(SMALL_DELAY_MS); |
960 |
|
* returning timeout status |
961 |
|
*/ |
962 |
|
public void testInterruptedTimedPollFirst() throws InterruptedException { |
963 |
< |
Thread t = new ThreadShouldThrow(InterruptedException.class) { |
963 |
> |
Thread t = new Thread(new CheckedRunnable() { |
964 |
|
public void realRun() throws InterruptedException { |
965 |
|
LinkedBlockingDeque q = populatedDeque(SIZE); |
966 |
|
for (int i = 0; i < SIZE; ++i) { |
967 |
< |
threadAssertEquals(i, ((Integer)q.pollFirst(SHORT_DELAY_MS, MILLISECONDS)).intValue()); |
967 |
> |
assertEquals(i, ((Integer)q.pollFirst(SHORT_DELAY_MS, MILLISECONDS)).intValue()); |
968 |
|
} |
969 |
< |
q.pollFirst(SMALL_DELAY_MS, MILLISECONDS); |
970 |
< |
}}; |
969 |
> |
try { |
970 |
> |
q.pollFirst(SMALL_DELAY_MS, MILLISECONDS); |
971 |
> |
shouldThrow(); |
972 |
> |
} catch (InterruptedException success) {} |
973 |
> |
}}); |
974 |
|
|
975 |
|
t.start(); |
976 |
|
Thread.sleep(SHORT_DELAY_MS); |
984 |
|
*/ |
985 |
|
public void testTimedPollFirstWithOfferFirst() throws InterruptedException { |
986 |
|
final LinkedBlockingDeque q = new LinkedBlockingDeque(2); |
987 |
< |
Thread t = new ThreadShouldThrow(InterruptedException.class) { |
987 |
> |
Thread t = new Thread(new CheckedRunnable() { |
988 |
|
public void realRun() throws InterruptedException { |
989 |
< |
threadAssertNull(q.pollFirst(SHORT_DELAY_MS, MILLISECONDS)); |
990 |
< |
q.pollFirst(LONG_DELAY_MS, MILLISECONDS); |
991 |
< |
q.pollFirst(LONG_DELAY_MS, MILLISECONDS); |
992 |
< |
}}; |
989 |
> |
assertNull(q.pollFirst(SHORT_DELAY_MS, MILLISECONDS)); |
990 |
> |
assertSame(zero, q.pollFirst(LONG_DELAY_MS, MILLISECONDS)); |
991 |
> |
try { |
992 |
> |
q.pollFirst(LONG_DELAY_MS, MILLISECONDS); |
993 |
> |
shouldThrow(); |
994 |
> |
} catch (InterruptedException success) {} |
995 |
> |
}}); |
996 |
|
|
997 |
|
t.start(); |
998 |
|
Thread.sleep(SMALL_DELAY_MS); |
1029 |
|
* putLast blocks interruptibly if full |
1030 |
|
*/ |
1031 |
|
public void testBlockingPutLast() throws InterruptedException { |
1032 |
< |
Thread t = new Thread(new Runnable() { |
1033 |
< |
public void run() { |
1034 |
< |
int added = 0; |
1035 |
< |
try { |
1036 |
< |
LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE); |
1037 |
< |
for (int i = 0; i < SIZE; ++i) { |
1038 |
< |
q.putLast(new Integer(i)); |
1039 |
< |
++added; |
1011 |
< |
} |
1012 |
< |
q.putLast(new Integer(SIZE)); |
1013 |
< |
threadShouldThrow(); |
1014 |
< |
} catch (InterruptedException success) { |
1015 |
< |
threadAssertEquals(added, SIZE); |
1032 |
> |
Thread t = new Thread(new CheckedRunnable() { |
1033 |
> |
public void realRun() { |
1034 |
> |
int added = 0; |
1035 |
> |
try { |
1036 |
> |
LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE); |
1037 |
> |
for (int i = 0; i < SIZE; ++i) { |
1038 |
> |
q.putLast(new Integer(i)); |
1039 |
> |
++added; |
1040 |
|
} |
1041 |
< |
}}); |
1041 |
> |
q.putLast(new Integer(SIZE)); |
1042 |
> |
threadShouldThrow(); |
1043 |
> |
} catch (InterruptedException success) { |
1044 |
> |
threadAssertEquals(added, SIZE); |
1045 |
> |
} |
1046 |
> |
}}); |
1047 |
> |
|
1048 |
|
t.start(); |
1049 |
|
Thread.sleep(SHORT_DELAY_MS); |
1050 |
|
t.interrupt(); |
1056 |
|
*/ |
1057 |
|
public void testPutLastWithTake() throws InterruptedException { |
1058 |
|
final LinkedBlockingDeque q = new LinkedBlockingDeque(2); |
1059 |
< |
Thread t = new Thread(new Runnable() { |
1060 |
< |
public void run() { |
1061 |
< |
int added = 0; |
1062 |
< |
try { |
1063 |
< |
q.putLast(new Object()); |
1064 |
< |
++added; |
1065 |
< |
q.putLast(new Object()); |
1066 |
< |
++added; |
1067 |
< |
q.putLast(new Object()); |
1068 |
< |
++added; |
1069 |
< |
q.putLast(new Object()); |
1070 |
< |
++added; |
1071 |
< |
threadShouldThrow(); |
1072 |
< |
} catch (InterruptedException success) { |
1073 |
< |
threadAssertTrue(added >= 2); |
1044 |
< |
} |
1059 |
> |
Thread t = new Thread(new CheckedRunnable() { |
1060 |
> |
public void realRun() { |
1061 |
> |
int added = 0; |
1062 |
> |
try { |
1063 |
> |
q.putLast(new Object()); |
1064 |
> |
++added; |
1065 |
> |
q.putLast(new Object()); |
1066 |
> |
++added; |
1067 |
> |
q.putLast(new Object()); |
1068 |
> |
++added; |
1069 |
> |
q.putLast(new Object()); |
1070 |
> |
++added; |
1071 |
> |
threadShouldThrow(); |
1072 |
> |
} catch (InterruptedException success) { |
1073 |
> |
threadAssertTrue(added >= 2); |
1074 |
|
} |
1075 |
< |
}); |
1075 |
> |
}}); |
1076 |
|
|
1077 |
|
t.start(); |
1078 |
|
Thread.sleep(SHORT_DELAY_MS); |
1086 |
|
*/ |
1087 |
|
public void testTimedOfferLast() throws InterruptedException { |
1088 |
|
final LinkedBlockingDeque q = new LinkedBlockingDeque(2); |
1089 |
< |
Thread t = new ThreadShouldThrow(InterruptedException.class) { |
1089 |
> |
Thread t = new Thread(new CheckedRunnable() { |
1090 |
|
public void realRun() throws InterruptedException { |
1091 |
|
q.putLast(new Object()); |
1092 |
|
q.putLast(new Object()); |
1093 |
< |
threadAssertFalse(q.offerLast(new Object(), SHORT_DELAY_MS, MILLISECONDS)); |
1094 |
< |
q.offerLast(new Object(), LONG_DELAY_MS, MILLISECONDS); |
1095 |
< |
}}; |
1093 |
> |
assertFalse(q.offerLast(new Object(), SHORT_DELAY_MS, MILLISECONDS)); |
1094 |
> |
try { |
1095 |
> |
q.offerLast(new Object(), LONG_DELAY_MS, MILLISECONDS); |
1096 |
> |
shouldThrow(); |
1097 |
> |
} catch (InterruptedException success) {} |
1098 |
> |
}}); |
1099 |
|
|
1100 |
|
t.start(); |
1101 |
|
Thread.sleep(SMALL_DELAY_MS); |
1176 |
|
* returning timeout status |
1177 |
|
*/ |
1178 |
|
public void testInterruptedTimedPollLast() throws InterruptedException { |
1179 |
< |
Thread t = new ThreadShouldThrow(InterruptedException.class) { |
1179 |
> |
Thread t = new Thread(new CheckedRunnable() { |
1180 |
|
public void realRun() throws InterruptedException { |
1181 |
|
LinkedBlockingDeque q = populatedDeque(SIZE); |
1182 |
|
for (int i = 0; i < SIZE; ++i) { |
1183 |
< |
threadAssertEquals(SIZE-i-1, ((Integer)q.pollLast(SHORT_DELAY_MS, MILLISECONDS)).intValue()); |
1183 |
> |
assertEquals(SIZE-i-1, ((Integer)q.pollLast(SHORT_DELAY_MS, MILLISECONDS)).intValue()); |
1184 |
|
} |
1185 |
< |
q.pollLast(SMALL_DELAY_MS, MILLISECONDS); |
1186 |
< |
}}; |
1185 |
> |
try { |
1186 |
> |
q.pollLast(SMALL_DELAY_MS, MILLISECONDS); |
1187 |
> |
shouldThrow(); |
1188 |
> |
} catch (InterruptedException success) {} |
1189 |
> |
}}); |
1190 |
|
|
1191 |
|
t.start(); |
1192 |
|
Thread.sleep(SHORT_DELAY_MS); |