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 { |
548 |
|
/** |
549 |
|
* put(null) throws NPE |
550 |
|
*/ |
551 |
< |
public void testPutNull() throws InterruptedException { |
551 |
> |
public void testPutNull() throws InterruptedException { |
552 |
|
try { |
553 |
|
LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE); |
554 |
|
q.put(null); |
555 |
|
shouldThrow(); |
556 |
|
} catch (NullPointerException success) {} |
557 |
< |
} |
557 |
> |
} |
558 |
|
|
559 |
|
/** |
560 |
|
* all elements successfully put are contained |
561 |
|
*/ |
562 |
< |
public void testPut() throws InterruptedException { |
563 |
< |
LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE); |
564 |
< |
for (int i = 0; i < SIZE; ++i) { |
565 |
< |
Integer I = new Integer(i); |
566 |
< |
q.put(I); |
567 |
< |
assertTrue(q.contains(I)); |
568 |
< |
} |
569 |
< |
assertEquals(0, q.remainingCapacity()); |
562 |
> |
public void testPut() throws InterruptedException { |
563 |
> |
LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE); |
564 |
> |
for (int i = 0; i < SIZE; ++i) { |
565 |
> |
Integer I = new Integer(i); |
566 |
> |
q.put(I); |
567 |
> |
assertTrue(q.contains(I)); |
568 |
> |
} |
569 |
> |
assertEquals(0, q.remainingCapacity()); |
570 |
|
} |
571 |
|
|
572 |
|
/** |
600 |
|
*/ |
601 |
|
public void testPutWithTake() throws InterruptedException { |
602 |
|
final LinkedBlockingDeque q = new LinkedBlockingDeque(2); |
603 |
< |
Thread t = new Thread(new Runnable() { |
604 |
< |
public void run() { |
605 |
< |
int added = 0; |
606 |
< |
try { |
607 |
< |
q.put(new Object()); |
608 |
< |
++added; |
609 |
< |
q.put(new Object()); |
610 |
< |
++added; |
611 |
< |
q.put(new Object()); |
612 |
< |
++added; |
613 |
< |
q.put(new Object()); |
614 |
< |
++added; |
615 |
< |
threadShouldThrow(); |
616 |
< |
} catch (InterruptedException success) { |
617 |
< |
threadAssertTrue(added >= 2); |
618 |
< |
} |
603 |
> |
Thread t = new Thread(new CheckedRunnable() { |
604 |
> |
public void realRun() { |
605 |
> |
int added = 0; |
606 |
> |
try { |
607 |
> |
q.put(new Object()); |
608 |
> |
++added; |
609 |
> |
q.put(new Object()); |
610 |
> |
++added; |
611 |
> |
q.put(new Object()); |
612 |
> |
++added; |
613 |
> |
q.put(new Object()); |
614 |
> |
++added; |
615 |
> |
threadShouldThrow(); |
616 |
> |
} catch (InterruptedException success) { |
617 |
> |
threadAssertTrue(added >= 2); |
618 |
|
} |
619 |
< |
}); |
619 |
> |
}}); |
620 |
|
|
621 |
|
t.start(); |
622 |
|
Thread.sleep(SHORT_DELAY_MS); |
792 |
|
* putFirst blocks interruptibly if full |
793 |
|
*/ |
794 |
|
public void testBlockingPutFirst() throws InterruptedException { |
795 |
< |
Thread t = new Thread(new Runnable() { |
796 |
< |
public void run() { |
797 |
< |
int added = 0; |
798 |
< |
try { |
799 |
< |
LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE); |
800 |
< |
for (int i = 0; i < SIZE; ++i) { |
801 |
< |
q.putFirst(new Integer(i)); |
802 |
< |
++added; |
804 |
< |
} |
805 |
< |
q.putFirst(new Integer(SIZE)); |
806 |
< |
threadShouldThrow(); |
807 |
< |
} catch (InterruptedException success) { |
808 |
< |
threadAssertEquals(added, SIZE); |
795 |
> |
Thread t = new Thread(new CheckedRunnable() { |
796 |
> |
public void realRun() { |
797 |
> |
int added = 0; |
798 |
> |
try { |
799 |
> |
LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE); |
800 |
> |
for (int i = 0; i < SIZE; ++i) { |
801 |
> |
q.putFirst(new Integer(i)); |
802 |
> |
++added; |
803 |
|
} |
804 |
< |
}}); |
804 |
> |
q.putFirst(new Integer(SIZE)); |
805 |
> |
threadShouldThrow(); |
806 |
> |
} catch (InterruptedException success) { |
807 |
> |
threadAssertEquals(added, SIZE); |
808 |
> |
} |
809 |
> |
}}); |
810 |
|
|
811 |
|
t.start(); |
812 |
|
Thread.sleep(SHORT_DELAY_MS); |
819 |
|
*/ |
820 |
|
public void testPutFirstWithTake() throws InterruptedException { |
821 |
|
final LinkedBlockingDeque q = new LinkedBlockingDeque(2); |
822 |
< |
Thread t = new Thread(new Runnable() { |
823 |
< |
public void run() { |
824 |
< |
int added = 0; |
825 |
< |
try { |
826 |
< |
q.putFirst(new Object()); |
827 |
< |
++added; |
828 |
< |
q.putFirst(new Object()); |
829 |
< |
++added; |
830 |
< |
q.putFirst(new Object()); |
831 |
< |
++added; |
832 |
< |
q.putFirst(new Object()); |
833 |
< |
++added; |
834 |
< |
threadShouldThrow(); |
835 |
< |
} catch (InterruptedException success) { |
836 |
< |
threadAssertTrue(added >= 2); |
838 |
< |
} |
822 |
> |
Thread t = new Thread(new CheckedRunnable() { |
823 |
> |
public void realRun() { |
824 |
> |
int added = 0; |
825 |
> |
try { |
826 |
> |
q.putFirst(new Object()); |
827 |
> |
++added; |
828 |
> |
q.putFirst(new Object()); |
829 |
> |
++added; |
830 |
> |
q.putFirst(new Object()); |
831 |
> |
++added; |
832 |
> |
q.putFirst(new Object()); |
833 |
> |
++added; |
834 |
> |
threadShouldThrow(); |
835 |
> |
} catch (InterruptedException success) { |
836 |
> |
threadAssertTrue(added >= 2); |
837 |
|
} |
838 |
< |
}); |
838 |
> |
}}); |
839 |
|
|
840 |
|
t.start(); |
841 |
|
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); |
1557 |
|
try { |
1558 |
|
q.drainTo(q); |
1559 |
|
shouldThrow(); |
1560 |
< |
} catch (IllegalArgumentException success) { |
1563 |
< |
} |
1560 |
> |
} catch (IllegalArgumentException success) {} |
1561 |
|
} |
1562 |
|
|
1563 |
|
/** |