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.12 by jsr166, Sat Nov 21 10:29:50 2009 UTC vs.
Revision 1.15 by jsr166, Sat Nov 21 21:12:55 2009 UTC

# Line 169 | Line 169 | public class LinkedBlockingDequeTest ext
169              q.getFirst();
170              shouldThrow();
171          } catch (NoSuchElementException success) {}
172 +        assertNull(q.peekFirst());
173      }
174  
175      /**
# Line 199 | Line 200 | public class LinkedBlockingDequeTest ext
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      /**
# Line 722 | Line 739 | public class LinkedBlockingDequeTest ext
739       * returning timeout status
740       */
741      public void testInterruptedTimedPoll() throws InterruptedException {
742 <        Thread t = new ThreadShouldThrow(InterruptedException.class) {
742 >        Thread t = new Thread(new CheckedRunnable() {
743              public void realRun() throws InterruptedException {
744                  LinkedBlockingDeque q = populatedDeque(SIZE);
745                  for (int i = 0; i < SIZE; ++i) {
746 <                    threadAssertEquals(i, ((Integer)q.poll(SHORT_DELAY_MS, MILLISECONDS)).intValue());
746 >                    assertEquals(i, ((Integer)q.poll(SHORT_DELAY_MS, MILLISECONDS)).intValue());
747                  }
748 <                q.poll(SMALL_DELAY_MS, MILLISECONDS);
749 <            }};
748 >                try {
749 >                    q.poll(SMALL_DELAY_MS, MILLISECONDS);
750 >                    shouldThrow();
751 >                } catch (InterruptedException success) {}
752 >            }});
753  
754          t.start();
755          Thread.sleep(SHORT_DELAY_MS);
# Line 743 | Line 763 | public class LinkedBlockingDequeTest ext
763       */
764      public void testTimedPollWithOffer() throws InterruptedException {
765          final LinkedBlockingDeque q = new LinkedBlockingDeque(2);
766 <        Thread t = new ThreadShouldThrow(InterruptedException.class) {
766 >        Thread t = new Thread(new CheckedRunnable() {
767              public void realRun() throws InterruptedException {
768 <                threadAssertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS));
769 <                q.poll(LONG_DELAY_MS, MILLISECONDS);
770 <                q.poll(LONG_DELAY_MS, MILLISECONDS);
771 <            }};
768 >                assertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS));
769 >                assertSame(zero, q.poll(LONG_DELAY_MS, MILLISECONDS));
770 >                try {
771 >                    q.poll(LONG_DELAY_MS, MILLISECONDS);
772 >                    shouldThrow();
773 >                } catch (InterruptedException success) {}
774 >            }});
775  
776          t.start();
777          Thread.sleep(SMALL_DELAY_MS);
# Line 930 | Line 953 | public class LinkedBlockingDequeTest ext
953       * returning timeout status
954       */
955      public void testInterruptedTimedPollFirst() throws InterruptedException {
956 <        Thread t = new ThreadShouldThrow(InterruptedException.class) {
956 >        Thread t = new Thread(new CheckedRunnable() {
957              public void realRun() throws InterruptedException {
958                  LinkedBlockingDeque q = populatedDeque(SIZE);
959                  for (int i = 0; i < SIZE; ++i) {
960 <                    threadAssertEquals(i, ((Integer)q.pollFirst(SHORT_DELAY_MS, MILLISECONDS)).intValue());
960 >                    assertEquals(i, ((Integer)q.pollFirst(SHORT_DELAY_MS, MILLISECONDS)).intValue());
961                  }
962 <                q.pollFirst(SMALL_DELAY_MS, MILLISECONDS);
963 <            }};
962 >                try {
963 >                    q.pollFirst(SMALL_DELAY_MS, MILLISECONDS);
964 >                    shouldThrow();
965 >                } catch (InterruptedException success) {}
966 >            }});
967  
968          t.start();
969          Thread.sleep(SHORT_DELAY_MS);
# Line 951 | Line 977 | public class LinkedBlockingDequeTest ext
977       */
978      public void testTimedPollFirstWithOfferFirst() throws InterruptedException {
979          final LinkedBlockingDeque q = new LinkedBlockingDeque(2);
980 <        Thread t = new ThreadShouldThrow(InterruptedException.class) {
980 >        Thread t = new Thread(new CheckedRunnable() {
981              public void realRun() throws InterruptedException {
982 <                threadAssertNull(q.pollFirst(SHORT_DELAY_MS, MILLISECONDS));
983 <                q.pollFirst(LONG_DELAY_MS, MILLISECONDS);
984 <                q.pollFirst(LONG_DELAY_MS, MILLISECONDS);
985 <            }};
982 >                assertNull(q.pollFirst(SHORT_DELAY_MS, MILLISECONDS));
983 >                assertSame(zero, q.pollFirst(LONG_DELAY_MS, MILLISECONDS));
984 >                try {
985 >                    q.pollFirst(LONG_DELAY_MS, MILLISECONDS);
986 >                    shouldThrow();
987 >                } catch (InterruptedException success) {}
988 >            }});
989  
990          t.start();
991          Thread.sleep(SMALL_DELAY_MS);
# Line 1137 | Line 1166 | public class LinkedBlockingDequeTest ext
1166       * returning timeout status
1167       */
1168      public void testInterruptedTimedPollLast() throws InterruptedException {
1169 <        Thread t = new ThreadShouldThrow(InterruptedException.class) {
1169 >        Thread t = new Thread(new CheckedRunnable() {
1170              public void realRun() throws InterruptedException {
1171                  LinkedBlockingDeque q = populatedDeque(SIZE);
1172                  for (int i = 0; i < SIZE; ++i) {
1173 <                    threadAssertEquals(SIZE-i-1, ((Integer)q.pollLast(SHORT_DELAY_MS, MILLISECONDS)).intValue());
1173 >                    assertEquals(SIZE-i-1, ((Integer)q.pollLast(SHORT_DELAY_MS, MILLISECONDS)).intValue());
1174                  }
1175 <                q.pollLast(SMALL_DELAY_MS, MILLISECONDS);
1176 <            }};
1175 >                try {
1176 >                    q.pollLast(SMALL_DELAY_MS, MILLISECONDS);
1177 >                    shouldThrow();
1178 >                } catch (InterruptedException success) {}
1179 >            }});
1180  
1181          t.start();
1182          Thread.sleep(SHORT_DELAY_MS);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines