ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/tck/LinkedBlockingDequeTest.java
(Generate patch)

Comparing jsr166/src/test/tck/LinkedBlockingDequeTest.java (file contents):
Revision 1.16 by jsr166, Sat Nov 21 22:00:46 2009 UTC vs.
Revision 1.23 by dl, Wed Sep 29 12:33:48 2010 UTC

# Line 12 | Line 12 | import java.io.*;
12  
13   public class LinkedBlockingDequeTest extends JSR166TestCase {
14      public static void main(String[] args) {
15 <        junit.textui.TestRunner.run (suite());
15 >        junit.textui.TestRunner.run(suite());
16      }
17  
18      public static Test suite() {
# Line 98 | Line 98 | public class LinkedBlockingDequeTest ext
98      public void testPollFirst() {
99          LinkedBlockingDeque q = populatedDeque(SIZE);
100          for (int i = 0; i < SIZE; ++i) {
101 <            assertEquals(i, ((Integer)q.pollFirst()).intValue());
101 >            assertEquals(i, q.pollFirst());
102          }
103          assertNull(q.pollFirst());
104      }
# Line 109 | Line 109 | public class LinkedBlockingDequeTest ext
109      public void testPollLast() {
110          LinkedBlockingDeque q = populatedDeque(SIZE);
111          for (int i = SIZE-1; i >= 0; --i) {
112 <            assertEquals(i, ((Integer)q.pollLast()).intValue());
112 >            assertEquals(i, q.pollLast());
113          }
114          assertNull(q.pollLast());
115      }
# Line 120 | Line 120 | public class LinkedBlockingDequeTest ext
120      public void testPeekFirst() {
121          LinkedBlockingDeque q = populatedDeque(SIZE);
122          for (int i = 0; i < SIZE; ++i) {
123 <            assertEquals(i, ((Integer)q.peekFirst()).intValue());
124 <            q.pollFirst();
123 >            assertEquals(i, q.peekFirst());
124 >            assertEquals(i, q.pollFirst());
125              assertTrue(q.peekFirst() == null ||
126 <                       i != ((Integer)q.peekFirst()).intValue());
126 >                       !q.peekFirst().equals(i));
127          }
128          assertNull(q.peekFirst());
129      }
# Line 134 | Line 134 | public class LinkedBlockingDequeTest ext
134      public void testPeek() {
135          LinkedBlockingDeque q = populatedDeque(SIZE);
136          for (int i = 0; i < SIZE; ++i) {
137 <            assertEquals(i, ((Integer)q.peek()).intValue());
138 <            q.pollFirst();
137 >            assertEquals(i, q.peek());
138 >            assertEquals(i, q.pollFirst());
139              assertTrue(q.peek() == null ||
140 <                       i != ((Integer)q.peek()).intValue());
140 >                       !q.peek().equals(i));
141          }
142          assertNull(q.peek());
143      }
# Line 148 | Line 148 | public class LinkedBlockingDequeTest ext
148      public void testPeekLast() {
149          LinkedBlockingDeque q = populatedDeque(SIZE);
150          for (int i = SIZE-1; i >= 0; --i) {
151 <            assertEquals(i, ((Integer)q.peekLast()).intValue());
152 <            q.pollLast();
151 >            assertEquals(i, q.peekLast());
152 >            assertEquals(i, q.pollLast());
153              assertTrue(q.peekLast() == null ||
154 <                       i != ((Integer)q.peekLast()).intValue());
154 >                       !q.peekLast().equals(i));
155          }
156          assertNull(q.peekLast());
157      }
158  
159      /**
160 <     * getFirst returns next getFirst, or throws NSEE if empty
160 >     * getFirst() returns first element, or throws NSEE if empty
161       */
162      public void testFirstElement() {
163          LinkedBlockingDeque q = populatedDeque(SIZE);
164          for (int i = 0; i < SIZE; ++i) {
165 <            assertEquals(i, ((Integer)q.getFirst()).intValue());
166 <            q.pollFirst();
165 >            assertEquals(i, q.getFirst());
166 >            assertEquals(i, q.pollFirst());
167          }
168          try {
169              q.getFirst();
# Line 173 | Line 173 | public class LinkedBlockingDequeTest ext
173      }
174  
175      /**
176 <     *  getLast returns next element, or throws NSEE if empty
176 >     *  getLast() returns last element, or throws NSEE if empty
177       */
178      public void testLastElement() {
179          LinkedBlockingDeque q = populatedDeque(SIZE);
180          for (int i = SIZE-1; i >= 0; --i) {
181 <            assertEquals(i, ((Integer)q.getLast()).intValue());
182 <            q.pollLast();
181 >            assertEquals(i, q.getLast());
182 >            assertEquals(i, q.pollLast());
183          }
184          try {
185              q.getLast();
# Line 189 | Line 189 | public class LinkedBlockingDequeTest ext
189      }
190  
191      /**
192 <     *  removeFirst removes next element, or throws NSEE if empty
192 >     * removeFirst() removes first element, or throws NSEE if empty
193       */
194      public void testRemoveFirst() {
195          LinkedBlockingDeque q = populatedDeque(SIZE);
196          for (int i = 0; i < SIZE; ++i) {
197 <            assertEquals(i, ((Integer)q.removeFirst()).intValue());
197 >            assertEquals(i, q.removeFirst());
198          }
199          try {
200              q.removeFirst();
# Line 204 | Line 204 | public class LinkedBlockingDequeTest ext
204      }
205  
206      /**
207 <     *  removeLast removes last element, or throws NSEE if empty
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());
212 >            assertEquals(i, q.removeLast());
213          }
214          try {
215              q.removeLast();
# Line 224 | Line 224 | public class LinkedBlockingDequeTest ext
224      public void testRemove() {
225          LinkedBlockingDeque q = populatedDeque(SIZE);
226          for (int i = 0; i < SIZE; ++i) {
227 <            assertEquals(i, ((Integer)q.remove()).intValue());
227 >            assertEquals(i, q.remove());
228          }
229          try {
230              q.remove();
# Line 269 | Line 269 | public class LinkedBlockingDequeTest ext
269          LinkedBlockingDeque q = populatedDeque(3);
270          q.pollLast();
271          q.addFirst(four);
272 <        assertEquals(four,q.peekFirst());
272 >        assertSame(four, q.peekFirst());
273      }
274  
275      /**
# Line 279 | Line 279 | public class LinkedBlockingDequeTest ext
279          LinkedBlockingDeque q = populatedDeque(3);
280          q.pollLast();
281          q.addLast(four);
282 <        assertEquals(four,q.peekLast());
282 >        assertSame(four, q.peekLast());
283      }
284  
285  
# Line 437 | Line 437 | public class LinkedBlockingDequeTest ext
437          LinkedBlockingDeque q = populatedDeque(3);
438          q.pollLast();
439          q.push(four);
440 <        assertEquals(four,q.peekFirst());
440 >        assertSame(four, q.peekFirst());
441      }
442  
443  
# Line 447 | Line 447 | public class LinkedBlockingDequeTest ext
447      public void testPop() {
448          LinkedBlockingDeque q = populatedDeque(SIZE);
449          for (int i = 0; i < SIZE; ++i) {
450 <            assertEquals(i, ((Integer)q.pop()).intValue());
450 >            assertEquals(i, q.pop());
451          }
452          try {
453              q.pop();
# Line 513 | Line 513 | public class LinkedBlockingDequeTest ext
513              shouldThrow();
514          } catch (NullPointerException success) {}
515      }
516 +
517      /**
518       * addAll of a collection with any null elements throws NPE after
519       * possibly adding some elements
# Line 527 | Line 528 | public class LinkedBlockingDequeTest ext
528              shouldThrow();
529          } catch (NullPointerException success) {}
530      }
531 +
532      /**
533       * addAll throws ISE if not enough room
534       */
# Line 585 | Line 587 | public class LinkedBlockingDequeTest ext
587       * put blocks interruptibly if full
588       */
589      public void testBlockingPut() throws InterruptedException {
590 +        final LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
591          Thread t = new Thread(new CheckedRunnable() {
592 <            public void realRun() {
593 <                int added = 0;
592 >            public void realRun() throws InterruptedException {
593 >                for (int i = 0; i < SIZE; ++i)
594 >                    q.put(i);
595 >                assertEquals(SIZE, q.size());
596 >                assertEquals(0, q.remainingCapacity());
597                  try {
598 <                    LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
599 <                    for (int i = 0; i < SIZE; ++i) {
600 <                        q.put(new Integer(i));
595 <                        ++added;
596 <                    }
597 <                    q.put(new Integer(SIZE));
598 <                    threadShouldThrow();
599 <                } catch (InterruptedException success) {
600 <                    threadAssertEquals(added, SIZE);
601 <                }
598 >                    q.put(99);
599 >                    shouldThrow();
600 >                } catch (InterruptedException success) {}
601              }});
602  
603          t.start();
604          Thread.sleep(SHORT_DELAY_MS);
605          t.interrupt();
606          t.join();
607 +        assertEquals(SIZE, q.size());
608 +        assertEquals(0, q.remainingCapacity());
609      }
610  
611      /**
612       * put blocks waiting for take when full
613       */
614      public void testPutWithTake() throws InterruptedException {
615 <        final LinkedBlockingDeque q = new LinkedBlockingDeque(2);
615 >        final int capacity = 2;
616 >        final LinkedBlockingDeque q = new LinkedBlockingDeque(capacity);
617          Thread t = new Thread(new CheckedRunnable() {
618 <            public void realRun() {
619 <                int added = 0;
618 >            public void realRun() throws InterruptedException {
619 >                for (int i = 0; i < capacity + 1; i++)
620 >                    q.put(i);
621                  try {
622 <                    q.put(new Object());
623 <                    ++added;
624 <                    q.put(new Object());
622 <                    ++added;
623 <                    q.put(new Object());
624 <                    ++added;
625 <                    q.put(new Object());
626 <                    ++added;
627 <                    threadShouldThrow();
628 <                } catch (InterruptedException success) {
629 <                    threadAssertTrue(added >= 2);
630 <                }
622 >                    q.put(99);
623 >                    shouldThrow();
624 >                } catch (InterruptedException success) {}
625              }});
626  
627          t.start();
628          Thread.sleep(SHORT_DELAY_MS);
629 <        q.take();
629 >        assertEquals(q.remainingCapacity(), 0);
630 >        assertEquals(0, q.take());
631 >        Thread.sleep(SHORT_DELAY_MS);
632          t.interrupt();
633          t.join();
634 +        assertEquals(q.remainingCapacity(), 0);
635      }
636  
637      /**
# Line 665 | Line 662 | public class LinkedBlockingDequeTest ext
662      public void testTake() throws InterruptedException {
663          LinkedBlockingDeque q = populatedDeque(SIZE);
664          for (int i = 0; i < SIZE; ++i) {
665 <            assertEquals(i, ((Integer)q.take()).intValue());
665 >            assertEquals(i, q.take());
666          }
667      }
668  
# Line 689 | Line 686 | public class LinkedBlockingDequeTest ext
686       * Take removes existing elements until empty, then blocks interruptibly
687       */
688      public void testBlockingTake() throws InterruptedException {
689 <        Thread t = new ThreadShouldThrow(InterruptedException.class) {
689 >        final LinkedBlockingDeque q = populatedDeque(SIZE);
690 >        Thread t = new Thread(new CheckedRunnable() {
691              public void realRun() throws InterruptedException {
694                LinkedBlockingDeque q = populatedDeque(SIZE);
692                  for (int i = 0; i < SIZE; ++i) {
693 <                    assertEquals(i, ((Integer)q.take()).intValue());
693 >                    assertEquals(i, q.take());
694                  }
695 <                q.take();
696 <            }};
695 >                try {
696 >                    q.take();
697 >                    shouldThrow();
698 >                } catch (InterruptedException success) {}
699 >            }});
700  
701          t.start();
702          Thread.sleep(SHORT_DELAY_MS);
# Line 711 | Line 711 | public class LinkedBlockingDequeTest ext
711      public void testPoll() {
712          LinkedBlockingDeque q = populatedDeque(SIZE);
713          for (int i = 0; i < SIZE; ++i) {
714 <            assertEquals(i, ((Integer)q.poll()).intValue());
714 >            assertEquals(i, q.poll());
715          }
716          assertNull(q.poll());
717      }
# Line 722 | Line 722 | public class LinkedBlockingDequeTest ext
722      public void testTimedPoll0() throws InterruptedException {
723          LinkedBlockingDeque q = populatedDeque(SIZE);
724          for (int i = 0; i < SIZE; ++i) {
725 <            assertEquals(i, ((Integer)q.poll(0, MILLISECONDS)).intValue());
725 >            assertEquals(i, q.poll(0, MILLISECONDS));
726          }
727          assertNull(q.poll(0, MILLISECONDS));
728      }
# Line 733 | Line 733 | public class LinkedBlockingDequeTest ext
733      public void testTimedPoll() throws InterruptedException {
734          LinkedBlockingDeque q = populatedDeque(SIZE);
735          for (int i = 0; i < SIZE; ++i) {
736 <            assertEquals(i, ((Integer)q.poll(SHORT_DELAY_MS, MILLISECONDS)).intValue());
736 >            assertEquals(i, q.poll(SHORT_DELAY_MS, MILLISECONDS));
737          }
738          assertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS));
739      }
# Line 747 | Line 747 | public class LinkedBlockingDequeTest ext
747              public void realRun() throws InterruptedException {
748                  LinkedBlockingDeque q = populatedDeque(SIZE);
749                  for (int i = 0; i < SIZE; ++i) {
750 <                    assertEquals(i, ((Integer)q.poll(SHORT_DELAY_MS, MILLISECONDS)).intValue());
750 >                    assertEquals(i, q.poll(SHORT_DELAY_MS, MILLISECONDS));
751                  }
752                  try {
753                      q.poll(SMALL_DELAY_MS, MILLISECONDS);
# Line 769 | Line 769 | public class LinkedBlockingDequeTest ext
769          final LinkedBlockingDeque q = new LinkedBlockingDeque(2);
770          Thread t = new Thread(new CheckedRunnable() {
771              public void realRun() throws InterruptedException {
772                assertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS));
773                assertSame(zero, q.poll(LONG_DELAY_MS, MILLISECONDS));
772                  try {
773 +                    assertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS));
774 +                    assertSame(zero, q.poll(LONG_DELAY_MS, MILLISECONDS));
775                      q.poll(LONG_DELAY_MS, MILLISECONDS);
776                      shouldThrow();
777                  } catch (InterruptedException success) {}
# Line 813 | Line 813 | public class LinkedBlockingDequeTest ext
813       * putFirst blocks interruptibly if full
814       */
815      public void testBlockingPutFirst() throws InterruptedException {
816 +        final LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
817          Thread t = new Thread(new CheckedRunnable() {
818 <            public void realRun() {
819 <                int added = 0;
818 >            public void realRun() throws InterruptedException {
819 >                for (int i = 0; i < SIZE; ++i)
820 >                    q.putFirst(i);
821 >                assertEquals(SIZE, q.size());
822 >                assertEquals(0, q.remainingCapacity());
823                  try {
824 <                    LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
825 <                    for (int i = 0; i < SIZE; ++i) {
826 <                        q.putFirst(new Integer(i));
823 <                        ++added;
824 <                    }
825 <                    q.putFirst(new Integer(SIZE));
826 <                    threadShouldThrow();
827 <                } catch (InterruptedException success) {
828 <                    threadAssertEquals(added, SIZE);
829 <                }
824 >                    q.putFirst(99);
825 >                    shouldThrow();
826 >                } catch (InterruptedException success) {}
827              }});
828  
829          t.start();
830          Thread.sleep(SHORT_DELAY_MS);
831          t.interrupt();
832          t.join();
833 +        assertEquals(SIZE, q.size());
834 +        assertEquals(0, q.remainingCapacity());
835      }
836  
837      /**
838       * putFirst blocks waiting for take when full
839       */
840      public void testPutFirstWithTake() throws InterruptedException {
841 <        final LinkedBlockingDeque q = new LinkedBlockingDeque(2);
841 >        final int capacity = 2;
842 >        final LinkedBlockingDeque q = new LinkedBlockingDeque(capacity);
843          Thread t = new Thread(new CheckedRunnable() {
844 <            public void realRun() {
845 <                int added = 0;
844 >            public void realRun() throws InterruptedException {
845 >                for (int i = 0; i < capacity + 1; i++)
846 >                    q.putFirst(i);
847                  try {
848 <                    q.putFirst(new Object());
849 <                    ++added;
850 <                    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 <                }
848 >                    q.putFirst(99);
849 >                    shouldThrow();
850 >                } catch (InterruptedException success) {}
851              }});
852  
853          t.start();
854          Thread.sleep(SHORT_DELAY_MS);
855 <        q.take();
855 >        assertEquals(q.remainingCapacity(), 0);
856 >        assertEquals(capacity - 1, q.take());
857 >        Thread.sleep(SHORT_DELAY_MS);
858          t.interrupt();
859          t.join();
860 +        assertEquals(q.remainingCapacity(), 0);
861      }
862  
863      /**
# Line 893 | Line 888 | public class LinkedBlockingDequeTest ext
888      public void testTakeFirst() throws InterruptedException {
889          LinkedBlockingDeque q = populatedDeque(SIZE);
890          for (int i = 0; i < SIZE; ++i) {
891 <            assertEquals(i, ((Integer)q.takeFirst()).intValue());
891 >            assertEquals(i, q.takeFirst());
892          }
893      }
894  
# Line 917 | Line 912 | public class LinkedBlockingDequeTest ext
912       * TakeFirst removes existing elements until empty, then blocks interruptibly
913       */
914      public void testBlockingTakeFirst() throws InterruptedException {
915 <        Thread t = new ThreadShouldThrow(InterruptedException.class) {
915 >        final LinkedBlockingDeque q = populatedDeque(SIZE);
916 >        Thread t = new Thread(new CheckedRunnable() {
917              public void realRun() throws InterruptedException {
918 <                LinkedBlockingDeque q = populatedDeque(SIZE);
919 <                for (int i = 0; i < SIZE; ++i) {
920 <                    assertEquals(i, ((Integer)q.takeFirst()).intValue());
921 <                }
922 <                q.takeFirst();
923 <            }};
918 >                for (int i = 0; i < SIZE; ++i)
919 >                    assertEquals(i, q.takeFirst());
920 >                try {
921 >                    q.takeFirst();
922 >                    shouldThrow();
923 >                } catch (InterruptedException success) {}
924 >            }});
925  
926          t.start();
927          Thread.sleep(SHORT_DELAY_MS);
# Line 939 | Line 936 | public class LinkedBlockingDequeTest ext
936      public void testTimedPollFirst0() throws InterruptedException {
937          LinkedBlockingDeque q = populatedDeque(SIZE);
938          for (int i = 0; i < SIZE; ++i) {
939 <            assertEquals(i, ((Integer)q.pollFirst(0, MILLISECONDS)).intValue());
939 >            assertEquals(i, q.pollFirst(0, MILLISECONDS));
940          }
941          assertNull(q.pollFirst(0, MILLISECONDS));
942      }
# Line 950 | Line 947 | public class LinkedBlockingDequeTest ext
947      public void testTimedPollFirst() throws InterruptedException {
948          LinkedBlockingDeque q = populatedDeque(SIZE);
949          for (int i = 0; i < SIZE; ++i) {
950 <            assertEquals(i, ((Integer)q.pollFirst(SHORT_DELAY_MS, MILLISECONDS)).intValue());
950 >            assertEquals(i, q.pollFirst(SHORT_DELAY_MS, MILLISECONDS));
951          }
952          assertNull(q.pollFirst(SHORT_DELAY_MS, MILLISECONDS));
953      }
# Line 964 | Line 961 | public class LinkedBlockingDequeTest ext
961              public void realRun() throws InterruptedException {
962                  LinkedBlockingDeque q = populatedDeque(SIZE);
963                  for (int i = 0; i < SIZE; ++i) {
964 <                    assertEquals(i, ((Integer)q.pollFirst(SHORT_DELAY_MS, MILLISECONDS)).intValue());
964 >                    assertEquals(i, q.pollFirst(SHORT_DELAY_MS, MILLISECONDS));
965                  }
966                  try {
967                      q.pollFirst(SMALL_DELAY_MS, MILLISECONDS);
# Line 1029 | Line 1026 | public class LinkedBlockingDequeTest ext
1026       * putLast blocks interruptibly if full
1027       */
1028      public void testBlockingPutLast() throws InterruptedException {
1029 +        final LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
1030          Thread t = new Thread(new CheckedRunnable() {
1031 <            public void realRun() {
1032 <                int added = 0;
1031 >            public void realRun() throws InterruptedException {
1032 >                for (int i = 0; i < SIZE; ++i)
1033 >                    q.putLast(i);
1034 >                assertEquals(SIZE, q.size());
1035 >                assertEquals(0, q.remainingCapacity());
1036                  try {
1037 <                    LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
1038 <                    for (int i = 0; i < SIZE; ++i) {
1039 <                        q.putLast(new Integer(i));
1039 <                        ++added;
1040 <                    }
1041 <                    q.putLast(new Integer(SIZE));
1042 <                    threadShouldThrow();
1043 <                } catch (InterruptedException success) {
1044 <                    threadAssertEquals(added, SIZE);
1045 <                }
1037 >                    q.putLast(99);
1038 >                    shouldThrow();
1039 >                } catch (InterruptedException success) {}
1040              }});
1041  
1042          t.start();
1043          Thread.sleep(SHORT_DELAY_MS);
1044          t.interrupt();
1045          t.join();
1046 +        assertEquals(SIZE, q.size());
1047 +        assertEquals(0, q.remainingCapacity());
1048      }
1049  
1050      /**
1051       * putLast blocks waiting for take when full
1052       */
1053      public void testPutLastWithTake() throws InterruptedException {
1054 <        final LinkedBlockingDeque q = new LinkedBlockingDeque(2);
1054 >        final int capacity = 2;
1055 >        final LinkedBlockingDeque q = new LinkedBlockingDeque(capacity);
1056          Thread t = new Thread(new CheckedRunnable() {
1057 <            public void realRun() {
1058 <                int added = 0;
1057 >            public void realRun() throws InterruptedException {
1058 >                for (int i = 0; i < capacity + 1; i++)
1059 >                    q.putLast(i);
1060                  try {
1061 <                    q.putLast(new Object());
1062 <                    ++added;
1063 <                    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 <                }
1061 >                    q.putLast(99);
1062 >                    shouldThrow();
1063 >                } catch (InterruptedException success) {}
1064              }});
1065  
1066          t.start();
1067          Thread.sleep(SHORT_DELAY_MS);
1068 <        q.take();
1068 >        assertEquals(q.remainingCapacity(), 0);
1069 >        assertEquals(0, q.take());
1070 >        Thread.sleep(SHORT_DELAY_MS);
1071          t.interrupt();
1072          t.join();
1073 +        assertEquals(q.remainingCapacity(), 0);
1074      }
1075  
1076      /**
# Line 1109 | Line 1101 | public class LinkedBlockingDequeTest ext
1101      public void testTakeLast() throws InterruptedException {
1102          LinkedBlockingDeque q = populatedDeque(SIZE);
1103          for (int i = 0; i < SIZE; ++i) {
1104 <            assertEquals(SIZE-i-1, ((Integer)q.takeLast()).intValue());
1104 >            assertEquals(SIZE-i-1, q.takeLast());
1105          }
1106      }
1107  
# Line 1133 | Line 1125 | public class LinkedBlockingDequeTest ext
1125       * TakeLast removes existing elements until empty, then blocks interruptibly
1126       */
1127      public void testBlockingTakeLast() throws InterruptedException {
1128 <        Thread t = new ThreadShouldThrow(InterruptedException.class) {
1128 >        final LinkedBlockingDeque q = populatedDeque(SIZE);
1129 >        Thread t = new Thread(new CheckedRunnable() {
1130              public void realRun() throws InterruptedException {
1131 <                LinkedBlockingDeque q = populatedDeque(SIZE);
1132 <                for (int i = 0; i < SIZE; ++i) {
1133 <                    assertEquals(SIZE-i-1, ((Integer)q.takeLast()).intValue());
1134 <                }
1135 <                q.takeLast();
1136 <            }};
1131 >                for (int i = 0; i < SIZE; ++i)
1132 >                    assertEquals(SIZE - 1 - i, q.takeLast());
1133 >                try {
1134 >                    q.takeLast();
1135 >                    shouldThrow();
1136 >                } catch (InterruptedException success) {}
1137 >            }});
1138  
1139          t.start();
1140          Thread.sleep(SHORT_DELAY_MS);
# Line 1148 | Line 1142 | public class LinkedBlockingDequeTest ext
1142          t.join();
1143      }
1144  
1151
1145      /**
1146       * timed pollLast with zero timeout succeeds when non-empty, else times out
1147       */
1148      public void testTimedPollLast0() throws InterruptedException {
1149          LinkedBlockingDeque q = populatedDeque(SIZE);
1150          for (int i = 0; i < SIZE; ++i) {
1151 <            assertEquals(SIZE-i-1, ((Integer)q.pollLast(0, MILLISECONDS)).intValue());
1151 >            assertEquals(SIZE-i-1, q.pollLast(0, MILLISECONDS));
1152          }
1153          assertNull(q.pollLast(0, MILLISECONDS));
1154      }
# Line 1166 | Line 1159 | public class LinkedBlockingDequeTest ext
1159      public void testTimedPollLast() throws InterruptedException {
1160          LinkedBlockingDeque q = populatedDeque(SIZE);
1161          for (int i = 0; i < SIZE; ++i) {
1162 <            assertEquals(SIZE-i-1, ((Integer)q.pollLast(SHORT_DELAY_MS, MILLISECONDS)).intValue());
1162 >            assertEquals(SIZE-i-1, q.pollLast(SHORT_DELAY_MS, MILLISECONDS));
1163          }
1164          assertNull(q.pollLast(SHORT_DELAY_MS, MILLISECONDS));
1165      }
# Line 1180 | Line 1173 | public class LinkedBlockingDequeTest ext
1173              public void realRun() throws InterruptedException {
1174                  LinkedBlockingDeque q = populatedDeque(SIZE);
1175                  for (int i = 0; i < SIZE; ++i) {
1176 <                    assertEquals(SIZE-i-1, ((Integer)q.pollLast(SHORT_DELAY_MS, MILLISECONDS)).intValue());
1176 >                    assertEquals(SIZE-i-1, q.pollLast(SHORT_DELAY_MS, MILLISECONDS));
1177                  }
1178                  try {
1179                      q.pollLast(SMALL_DELAY_MS, MILLISECONDS);
# Line 1224 | Line 1217 | public class LinkedBlockingDequeTest ext
1217      public void testElement() {
1218          LinkedBlockingDeque q = populatedDeque(SIZE);
1219          for (int i = 0; i < SIZE; ++i) {
1220 <            assertEquals(i, ((Integer)q.element()).intValue());
1220 >            assertEquals(i, q.element());
1221              q.poll();
1222          }
1223          try {
# Line 1350 | Line 1343 | public class LinkedBlockingDequeTest ext
1343       * toArray(null) throws NPE
1344       */
1345      public void testToArray_BadArg() {
1346 +        LinkedBlockingDeque q = populatedDeque(SIZE);
1347          try {
1354            LinkedBlockingDeque q = populatedDeque(SIZE);
1348              Object o[] = q.toArray(null);
1349              shouldThrow();
1350          } catch (NullPointerException success) {}
# Line 1361 | Line 1354 | public class LinkedBlockingDequeTest ext
1354       * toArray with incompatible array type throws CCE
1355       */
1356      public void testToArray1_BadArg() {
1357 +        LinkedBlockingDeque q = populatedDeque(SIZE);
1358          try {
1359 <            LinkedBlockingDeque q = populatedDeque(SIZE);
1366 <            Object o[] = q.toArray(new String[10] );
1359 >            Object o[] = q.toArray(new String[10]);
1360              shouldThrow();
1361          } catch (ArrayStoreException success) {}
1362      }
# Line 1383 | Line 1376 | public class LinkedBlockingDequeTest ext
1376      /**
1377       * iterator.remove removes current element
1378       */
1379 <    public void testIteratorRemove () {
1379 >    public void testIteratorRemove() {
1380          final LinkedBlockingDeque q = new LinkedBlockingDeque(3);
1381          q.add(two);
1382          q.add(one);
# Line 1394 | Line 1387 | public class LinkedBlockingDequeTest ext
1387          it.remove();
1388  
1389          it = q.iterator();
1390 <        assertEquals(it.next(), one);
1391 <        assertEquals(it.next(), three);
1390 >        assertSame(it.next(), one);
1391 >        assertSame(it.next(), three);
1392          assertFalse(it.hasNext());
1393      }
1394  
# Line 1411 | Line 1404 | public class LinkedBlockingDequeTest ext
1404          assertEquals(0, q.remainingCapacity());
1405          int k = 0;
1406          for (Iterator it = q.iterator(); it.hasNext();) {
1407 <            int i = ((Integer)(it.next())).intValue();
1415 <            assertEquals(++k, i);
1407 >            assertEquals(++k, it.next());
1408          }
1409          assertEquals(3, k);
1410      }
# Line 1420 | Line 1412 | public class LinkedBlockingDequeTest ext
1412      /**
1413       * Modifications do not cause iterators to fail
1414       */
1415 <    public void testWeaklyConsistentIteration () {
1415 >    public void testWeaklyConsistentIteration() {
1416          final LinkedBlockingDeque q = new LinkedBlockingDeque(3);
1417          q.add(one);
1418          q.add(two);
# Line 1463 | Line 1455 | public class LinkedBlockingDequeTest ext
1455              q.add(new Integer(1));
1456              int k = 0;
1457              for (Iterator it = q.descendingIterator(); it.hasNext();) {
1458 <                int i = ((Integer)(it.next())).intValue();
1467 <                assertEquals(++k, i);
1458 >                assertEquals(++k, it.next());
1459              }
1460  
1461              assertEquals(3, k);
# Line 1477 | Line 1468 | public class LinkedBlockingDequeTest ext
1468      /**
1469       * descendingIterator.remove removes current element
1470       */
1471 <    public void testDescendingIteratorRemove () {
1471 >    public void testDescendingIteratorRemove() {
1472          final LinkedBlockingDeque q = new LinkedBlockingDeque();
1473          for (int iters = 0; iters < 100; ++iters) {
1474              q.add(new Integer(3));
# Line 1519 | Line 1510 | public class LinkedBlockingDequeTest ext
1510          ExecutorService executor = Executors.newFixedThreadPool(2);
1511          executor.execute(new CheckedRunnable() {
1512              public void realRun() throws InterruptedException {
1513 <                threadAssertFalse(q.offer(three));
1514 <                threadAssertTrue(q.offer(three, MEDIUM_DELAY_MS, MILLISECONDS));
1515 <                threadAssertEquals(0, q.remainingCapacity());
1513 >                assertFalse(q.offer(three));
1514 >                assertTrue(q.offer(three, MEDIUM_DELAY_MS, MILLISECONDS));
1515 >                assertEquals(0, q.remainingCapacity());
1516              }});
1517  
1518          executor.execute(new CheckedRunnable() {
1519              public void realRun() throws InterruptedException {
1520                  Thread.sleep(SMALL_DELAY_MS);
1521 <                threadAssertEquals(one, q.take());
1521 >                assertSame(one, q.take());
1522              }});
1523  
1524          joinPool(executor);
# Line 1541 | Line 1532 | public class LinkedBlockingDequeTest ext
1532          ExecutorService executor = Executors.newFixedThreadPool(2);
1533          executor.execute(new CheckedRunnable() {
1534              public void realRun() throws InterruptedException {
1535 <                threadAssertNull(q.poll());
1536 <                threadAssertTrue(null != q.poll(MEDIUM_DELAY_MS, MILLISECONDS));
1537 <                threadAssertTrue(q.isEmpty());
1535 >                assertNull(q.poll());
1536 >                assertSame(one, q.poll(MEDIUM_DELAY_MS, MILLISECONDS));
1537 >                assertTrue(q.isEmpty());
1538              }});
1539  
1540          executor.execute(new CheckedRunnable() {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines