276 |
|
} |
277 |
|
|
278 |
|
/** |
279 |
< |
* Constructor throws IAE if capacity argument nonpositive |
279 |
> |
* Constructor throws IAE if capacity argument nonpositive |
280 |
|
*/ |
281 |
|
public void testConstructor2() { |
282 |
|
try { |
323 |
|
* Deque contains all elements of collection used to initialize |
324 |
|
*/ |
325 |
|
public void testConstructor6() { |
326 |
< |
try { |
327 |
< |
Integer[] ints = new Integer[SIZE]; |
328 |
< |
for (int i = 0; i < SIZE; ++i) |
329 |
< |
ints[i] = new Integer(i); |
330 |
< |
LinkedBlockingDeque q = new LinkedBlockingDeque(Arrays.asList(ints)); |
331 |
< |
for (int i = 0; i < SIZE; ++i) |
332 |
< |
assertEquals(ints[i], q.poll()); |
333 |
< |
} |
334 |
< |
finally {} |
326 |
> |
Integer[] ints = new Integer[SIZE]; |
327 |
> |
for (int i = 0; i < SIZE; ++i) |
328 |
> |
ints[i] = new Integer(i); |
329 |
> |
LinkedBlockingDeque q = new LinkedBlockingDeque(Arrays.asList(ints)); |
330 |
> |
for (int i = 0; i < SIZE; ++i) |
331 |
> |
assertEquals(ints[i], q.poll()); |
332 |
|
} |
333 |
|
|
334 |
|
/** |
527 |
|
* Deque contains all elements, in traversal order, of successful addAll |
528 |
|
*/ |
529 |
|
public void testAddAll5() { |
530 |
< |
try { |
531 |
< |
Integer[] empty = new Integer[0]; |
532 |
< |
Integer[] ints = new Integer[SIZE]; |
533 |
< |
for (int i = 0; i < SIZE; ++i) |
534 |
< |
ints[i] = new Integer(i); |
535 |
< |
LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE); |
536 |
< |
assertFalse(q.addAll(Arrays.asList(empty))); |
537 |
< |
assertTrue(q.addAll(Arrays.asList(ints))); |
538 |
< |
for (int i = 0; i < SIZE; ++i) |
542 |
< |
assertEquals(ints[i], q.poll()); |
543 |
< |
} |
544 |
< |
finally {} |
530 |
> |
Integer[] empty = new Integer[0]; |
531 |
> |
Integer[] ints = new Integer[SIZE]; |
532 |
> |
for (int i = 0; i < SIZE; ++i) |
533 |
> |
ints[i] = new Integer(i); |
534 |
> |
LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE); |
535 |
> |
assertFalse(q.addAll(Arrays.asList(empty))); |
536 |
> |
assertTrue(q.addAll(Arrays.asList(ints))); |
537 |
> |
for (int i = 0; i < SIZE; ++i) |
538 |
> |
assertEquals(ints[i], q.poll()); |
539 |
|
} |
540 |
|
|
541 |
|
|
542 |
|
/** |
543 |
|
* put(null) throws NPE |
544 |
|
*/ |
545 |
< |
public void testPutNull() throws InterruptedException { |
545 |
> |
public void testPutNull() throws InterruptedException { |
546 |
|
try { |
547 |
|
LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE); |
548 |
|
q.put(null); |
549 |
|
shouldThrow(); |
550 |
|
} catch (NullPointerException success) {} |
551 |
< |
} |
551 |
> |
} |
552 |
|
|
553 |
|
/** |
554 |
|
* all elements successfully put are contained |
555 |
|
*/ |
556 |
< |
public void testPut() throws InterruptedException { |
557 |
< |
LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE); |
558 |
< |
for (int i = 0; i < SIZE; ++i) { |
559 |
< |
Integer I = new Integer(i); |
560 |
< |
q.put(I); |
561 |
< |
assertTrue(q.contains(I)); |
562 |
< |
} |
563 |
< |
assertEquals(0, q.remainingCapacity()); |
556 |
> |
public void testPut() throws InterruptedException { |
557 |
> |
LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE); |
558 |
> |
for (int i = 0; i < SIZE; ++i) { |
559 |
> |
Integer I = new Integer(i); |
560 |
> |
q.put(I); |
561 |
> |
assertTrue(q.contains(I)); |
562 |
> |
} |
563 |
> |
assertEquals(0, q.remainingCapacity()); |
564 |
|
} |
565 |
|
|
566 |
|
/** |
594 |
|
*/ |
595 |
|
public void testPutWithTake() throws InterruptedException { |
596 |
|
final LinkedBlockingDeque q = new LinkedBlockingDeque(2); |
597 |
< |
Thread t = new Thread(new Runnable() { |
598 |
< |
public void run() { |
599 |
< |
int added = 0; |
600 |
< |
try { |
601 |
< |
q.put(new Object()); |
602 |
< |
++added; |
603 |
< |
q.put(new Object()); |
604 |
< |
++added; |
605 |
< |
q.put(new Object()); |
606 |
< |
++added; |
607 |
< |
q.put(new Object()); |
608 |
< |
++added; |
609 |
< |
threadShouldThrow(); |
610 |
< |
} catch (InterruptedException success) { |
611 |
< |
threadAssertTrue(added >= 2); |
618 |
< |
} |
597 |
> |
Thread t = new Thread(new CheckedRunnable() { |
598 |
> |
public void realRun() { |
599 |
> |
int added = 0; |
600 |
> |
try { |
601 |
> |
q.put(new Object()); |
602 |
> |
++added; |
603 |
> |
q.put(new Object()); |
604 |
> |
++added; |
605 |
> |
q.put(new Object()); |
606 |
> |
++added; |
607 |
> |
q.put(new Object()); |
608 |
> |
++added; |
609 |
> |
threadShouldThrow(); |
610 |
> |
} catch (InterruptedException success) { |
611 |
> |
threadAssertTrue(added >= 2); |
612 |
|
} |
613 |
< |
}); |
613 |
> |
}}); |
614 |
|
|
615 |
|
t.start(); |
616 |
|
Thread.sleep(SHORT_DELAY_MS); |
722 |
|
* returning timeout status |
723 |
|
*/ |
724 |
|
public void testInterruptedTimedPoll() throws InterruptedException { |
725 |
< |
Thread t = new ThreadShouldThrow(InterruptedException.class) { |
725 |
> |
Thread t = new Thread(new CheckedRunnable() { |
726 |
|
public void realRun() throws InterruptedException { |
727 |
|
LinkedBlockingDeque q = populatedDeque(SIZE); |
728 |
|
for (int i = 0; i < SIZE; ++i) { |
729 |
< |
threadAssertEquals(i, ((Integer)q.poll(SHORT_DELAY_MS, MILLISECONDS)).intValue()); |
729 |
> |
assertEquals(i, ((Integer)q.poll(SHORT_DELAY_MS, MILLISECONDS)).intValue()); |
730 |
|
} |
731 |
< |
q.poll(SMALL_DELAY_MS, MILLISECONDS); |
732 |
< |
}}; |
731 |
> |
try { |
732 |
> |
q.poll(SMALL_DELAY_MS, MILLISECONDS); |
733 |
> |
shouldThrow(); |
734 |
> |
} catch (InterruptedException success) {} |
735 |
> |
}}); |
736 |
|
|
737 |
|
t.start(); |
738 |
|
Thread.sleep(SHORT_DELAY_MS); |
789 |
|
* putFirst blocks interruptibly if full |
790 |
|
*/ |
791 |
|
public void testBlockingPutFirst() throws InterruptedException { |
792 |
< |
Thread t = new Thread(new Runnable() { |
793 |
< |
public void run() { |
794 |
< |
int added = 0; |
795 |
< |
try { |
796 |
< |
LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE); |
797 |
< |
for (int i = 0; i < SIZE; ++i) { |
798 |
< |
q.putFirst(new Integer(i)); |
799 |
< |
++added; |
804 |
< |
} |
805 |
< |
q.putFirst(new Integer(SIZE)); |
806 |
< |
threadShouldThrow(); |
807 |
< |
} catch (InterruptedException success) { |
808 |
< |
threadAssertEquals(added, SIZE); |
792 |
> |
Thread t = new Thread(new CheckedRunnable() { |
793 |
> |
public void realRun() { |
794 |
> |
int added = 0; |
795 |
> |
try { |
796 |
> |
LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE); |
797 |
> |
for (int i = 0; i < SIZE; ++i) { |
798 |
> |
q.putFirst(new Integer(i)); |
799 |
> |
++added; |
800 |
|
} |
801 |
< |
}}); |
801 |
> |
q.putFirst(new Integer(SIZE)); |
802 |
> |
threadShouldThrow(); |
803 |
> |
} catch (InterruptedException success) { |
804 |
> |
threadAssertEquals(added, SIZE); |
805 |
> |
} |
806 |
> |
}}); |
807 |
|
|
808 |
|
t.start(); |
809 |
|
Thread.sleep(SHORT_DELAY_MS); |
816 |
|
*/ |
817 |
|
public void testPutFirstWithTake() throws InterruptedException { |
818 |
|
final LinkedBlockingDeque q = new LinkedBlockingDeque(2); |
819 |
< |
Thread t = new Thread(new Runnable() { |
820 |
< |
public void run() { |
821 |
< |
int added = 0; |
822 |
< |
try { |
823 |
< |
q.putFirst(new Object()); |
824 |
< |
++added; |
825 |
< |
q.putFirst(new Object()); |
826 |
< |
++added; |
827 |
< |
q.putFirst(new Object()); |
828 |
< |
++added; |
829 |
< |
q.putFirst(new Object()); |
830 |
< |
++added; |
831 |
< |
threadShouldThrow(); |
832 |
< |
} catch (InterruptedException success) { |
833 |
< |
threadAssertTrue(added >= 2); |
838 |
< |
} |
819 |
> |
Thread t = new Thread(new CheckedRunnable() { |
820 |
> |
public void realRun() { |
821 |
> |
int added = 0; |
822 |
> |
try { |
823 |
> |
q.putFirst(new Object()); |
824 |
> |
++added; |
825 |
> |
q.putFirst(new Object()); |
826 |
> |
++added; |
827 |
> |
q.putFirst(new Object()); |
828 |
> |
++added; |
829 |
> |
q.putFirst(new Object()); |
830 |
> |
++added; |
831 |
> |
threadShouldThrow(); |
832 |
> |
} catch (InterruptedException success) { |
833 |
> |
threadAssertTrue(added >= 2); |
834 |
|
} |
835 |
< |
}); |
835 |
> |
}}); |
836 |
|
|
837 |
|
t.start(); |
838 |
|
Thread.sleep(SHORT_DELAY_MS); |
933 |
|
* returning timeout status |
934 |
|
*/ |
935 |
|
public void testInterruptedTimedPollFirst() throws InterruptedException { |
936 |
< |
Thread t = new ThreadShouldThrow(InterruptedException.class) { |
936 |
> |
Thread t = new Thread(new CheckedRunnable() { |
937 |
|
public void realRun() throws InterruptedException { |
938 |
|
LinkedBlockingDeque q = populatedDeque(SIZE); |
939 |
|
for (int i = 0; i < SIZE; ++i) { |
940 |
< |
threadAssertEquals(i, ((Integer)q.pollFirst(SHORT_DELAY_MS, MILLISECONDS)).intValue()); |
940 |
> |
assertEquals(i, ((Integer)q.pollFirst(SHORT_DELAY_MS, MILLISECONDS)).intValue()); |
941 |
|
} |
942 |
< |
q.pollFirst(SMALL_DELAY_MS, MILLISECONDS); |
943 |
< |
}}; |
942 |
> |
try { |
943 |
> |
q.pollFirst(SMALL_DELAY_MS, MILLISECONDS); |
944 |
> |
shouldThrow(); |
945 |
> |
} catch (InterruptedException success) {} |
946 |
> |
}}); |
947 |
|
|
948 |
|
t.start(); |
949 |
|
Thread.sleep(SHORT_DELAY_MS); |
999 |
|
* putLast blocks interruptibly if full |
1000 |
|
*/ |
1001 |
|
public void testBlockingPutLast() throws InterruptedException { |
1002 |
< |
Thread t = new Thread(new Runnable() { |
1003 |
< |
public void run() { |
1004 |
< |
int added = 0; |
1005 |
< |
try { |
1006 |
< |
LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE); |
1007 |
< |
for (int i = 0; i < SIZE; ++i) { |
1008 |
< |
q.putLast(new Integer(i)); |
1009 |
< |
++added; |
1012 |
< |
} |
1013 |
< |
q.putLast(new Integer(SIZE)); |
1014 |
< |
threadShouldThrow(); |
1015 |
< |
} catch (InterruptedException success) { |
1016 |
< |
threadAssertEquals(added, SIZE); |
1002 |
> |
Thread t = new Thread(new CheckedRunnable() { |
1003 |
> |
public void realRun() { |
1004 |
> |
int added = 0; |
1005 |
> |
try { |
1006 |
> |
LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE); |
1007 |
> |
for (int i = 0; i < SIZE; ++i) { |
1008 |
> |
q.putLast(new Integer(i)); |
1009 |
> |
++added; |
1010 |
|
} |
1011 |
< |
}}); |
1011 |
> |
q.putLast(new Integer(SIZE)); |
1012 |
> |
threadShouldThrow(); |
1013 |
> |
} catch (InterruptedException success) { |
1014 |
> |
threadAssertEquals(added, SIZE); |
1015 |
> |
} |
1016 |
> |
}}); |
1017 |
> |
|
1018 |
|
t.start(); |
1019 |
|
Thread.sleep(SHORT_DELAY_MS); |
1020 |
|
t.interrupt(); |
1026 |
|
*/ |
1027 |
|
public void testPutLastWithTake() throws InterruptedException { |
1028 |
|
final LinkedBlockingDeque q = new LinkedBlockingDeque(2); |
1029 |
< |
Thread t = new Thread(new Runnable() { |
1030 |
< |
public void run() { |
1031 |
< |
int added = 0; |
1032 |
< |
try { |
1033 |
< |
q.putLast(new Object()); |
1034 |
< |
++added; |
1035 |
< |
q.putLast(new Object()); |
1036 |
< |
++added; |
1037 |
< |
q.putLast(new Object()); |
1038 |
< |
++added; |
1039 |
< |
q.putLast(new Object()); |
1040 |
< |
++added; |
1041 |
< |
threadShouldThrow(); |
1042 |
< |
} catch (InterruptedException success) { |
1043 |
< |
threadAssertTrue(added >= 2); |
1045 |
< |
} |
1029 |
> |
Thread t = new Thread(new CheckedRunnable() { |
1030 |
> |
public void realRun() { |
1031 |
> |
int added = 0; |
1032 |
> |
try { |
1033 |
> |
q.putLast(new Object()); |
1034 |
> |
++added; |
1035 |
> |
q.putLast(new Object()); |
1036 |
> |
++added; |
1037 |
> |
q.putLast(new Object()); |
1038 |
> |
++added; |
1039 |
> |
q.putLast(new Object()); |
1040 |
> |
++added; |
1041 |
> |
threadShouldThrow(); |
1042 |
> |
} catch (InterruptedException success) { |
1043 |
> |
threadAssertTrue(added >= 2); |
1044 |
|
} |
1045 |
< |
}); |
1045 |
> |
}}); |
1046 |
|
|
1047 |
|
t.start(); |
1048 |
|
Thread.sleep(SHORT_DELAY_MS); |
1143 |
|
* returning timeout status |
1144 |
|
*/ |
1145 |
|
public void testInterruptedTimedPollLast() throws InterruptedException { |
1146 |
< |
Thread t = new ThreadShouldThrow(InterruptedException.class) { |
1146 |
> |
Thread t = new Thread(new CheckedRunnable() { |
1147 |
|
public void realRun() throws InterruptedException { |
1148 |
|
LinkedBlockingDeque q = populatedDeque(SIZE); |
1149 |
|
for (int i = 0; i < SIZE; ++i) { |
1150 |
< |
threadAssertEquals(SIZE-i-1, ((Integer)q.pollLast(SHORT_DELAY_MS, MILLISECONDS)).intValue()); |
1150 |
> |
assertEquals(SIZE-i-1, ((Integer)q.pollLast(SHORT_DELAY_MS, MILLISECONDS)).intValue()); |
1151 |
|
} |
1152 |
< |
q.pollLast(SMALL_DELAY_MS, MILLISECONDS); |
1153 |
< |
}}; |
1152 |
> |
try { |
1153 |
> |
q.pollLast(SMALL_DELAY_MS, MILLISECONDS); |
1154 |
> |
shouldThrow(); |
1155 |
> |
} catch (InterruptedException success) {} |
1156 |
> |
}}); |
1157 |
|
|
1158 |
|
t.start(); |
1159 |
|
Thread.sleep(SHORT_DELAY_MS); |
1560 |
|
try { |
1561 |
|
q.drainTo(q); |
1562 |
|
shouldThrow(); |
1563 |
< |
} catch (IllegalArgumentException success) { |
1563 |
< |
} |
1563 |
> |
} catch (IllegalArgumentException success) {} |
1564 |
|
} |
1565 |
|
|
1566 |
|
/** |