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.7 by jsr166, Sat Nov 21 02:07:26 2009 UTC vs.
Revision 1.21 by jsr166, Wed Aug 25 00:07:03 2010 UTC

# Line 7 | Line 7
7   import junit.framework.*;
8   import java.util.*;
9   import java.util.concurrent.*;
10 + import static java.util.concurrent.TimeUnit.MILLISECONDS;
11   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 70 | Line 71 | public class LinkedBlockingDequeTest ext
71              LinkedBlockingDeque q = new LinkedBlockingDeque();
72              q.offerFirst(null);
73              shouldThrow();
74 <        } catch (NullPointerException success) {
74 <        }
74 >        } catch (NullPointerException success) {}
75      }
76  
77      /**
# 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      }
# Line 162 | Line 162 | public class LinkedBlockingDequeTest ext
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();
170              shouldThrow();
171 <        }
172 <        catch (NoSuchElementException success) {}
171 >        } catch (NoSuchElementException success) {}
172 >        assertNull(q.peekFirst());
173      }
174  
175      /**
# Line 178 | Line 178 | public class LinkedBlockingDequeTest ext
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();
186              shouldThrow();
187 <        }
188 <        catch (NoSuchElementException success) {}
187 >        } catch (NoSuchElementException success) {}
188          assertNull(q.peekLast());
189      }
190  
# Line 195 | Line 194 | public class LinkedBlockingDequeTest ext
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();
201              shouldThrow();
202 <        } catch (NoSuchElementException success) {
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, q.removeLast());
213          }
214 +        try {
215 +            q.removeLast();
216 +            shouldThrow();
217 +        } catch (NoSuchElementException success) {}
218 +        assertNull(q.peekLast());
219      }
220  
221      /**
# Line 210 | 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();
231              shouldThrow();
232 <        } catch (NoSuchElementException success) {
219 <        }
232 >        } catch (NoSuchElementException success) {}
233      }
234  
235      /**
# Line 256 | 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 266 | 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 280 | Line 293 | public class LinkedBlockingDequeTest ext
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 {
300              LinkedBlockingDeque q = new LinkedBlockingDeque(0);
301              shouldThrow();
302 <        }
290 <        catch (IllegalArgumentException success) {}
302 >        } catch (IllegalArgumentException success) {}
303      }
304  
305      /**
# Line 297 | Line 309 | public class LinkedBlockingDequeTest ext
309          try {
310              LinkedBlockingDeque q = new LinkedBlockingDeque(null);
311              shouldThrow();
312 <        }
301 <        catch (NullPointerException success) {}
312 >        } catch (NullPointerException success) {}
313      }
314  
315      /**
# Line 309 | Line 320 | public class LinkedBlockingDequeTest ext
320              Integer[] ints = new Integer[SIZE];
321              LinkedBlockingDeque q = new LinkedBlockingDeque(Arrays.asList(ints));
322              shouldThrow();
323 <        }
313 <        catch (NullPointerException success) {}
323 >        } catch (NullPointerException success) {}
324      }
325  
326      /**
# Line 323 | Line 333 | public class LinkedBlockingDequeTest ext
333                  ints[i] = new Integer(i);
334              LinkedBlockingDeque q = new LinkedBlockingDeque(Arrays.asList(ints));
335              shouldThrow();
336 <        }
327 <        catch (NullPointerException success) {}
336 >        } catch (NullPointerException success) {}
337      }
338  
339      /**
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)
340 <                assertEquals(ints[i], q.poll());
341 <        }
342 <        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      /**
# Line 382 | Line 388 | public class LinkedBlockingDequeTest ext
388              LinkedBlockingDeque q = new LinkedBlockingDeque(1);
389              q.offer(null);
390              shouldThrow();
391 <        } catch (NullPointerException success) { }
391 >        } catch (NullPointerException success) {}
392      }
393  
394      /**
# Line 393 | Line 399 | public class LinkedBlockingDequeTest ext
399              LinkedBlockingDeque q = new LinkedBlockingDeque(1);
400              q.add(null);
401              shouldThrow();
402 <        } catch (NullPointerException success) { }
402 >        } catch (NullPointerException success) {}
403      }
404  
405      /**
# Line 404 | Line 410 | public class LinkedBlockingDequeTest ext
410              LinkedBlockingDeque q = new LinkedBlockingDeque(1);
411              q.push(null);
412              shouldThrow();
413 <        } catch (NullPointerException success) { }
413 >        } catch (NullPointerException success) {}
414      }
415  
416      /**
# Line 420 | Line 426 | public class LinkedBlockingDequeTest ext
426              }
427              assertEquals(0, q.remainingCapacity());
428              q.push(new Integer(SIZE));
429 <        } catch (IllegalStateException success) {
430 <        }
429 >            shouldThrow();
430 >        } catch (IllegalStateException success) {}
431      }
432  
433      /**
# Line 431 | 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 441 | 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();
454              shouldThrow();
455 <        } catch (NoSuchElementException success) {
450 <        }
455 >        } catch (NoSuchElementException success) {}
456      }
457  
458  
# Line 471 | Line 476 | public class LinkedBlockingDequeTest ext
476              }
477              assertEquals(0, q.remainingCapacity());
478              q.add(new Integer(SIZE));
479 <        } catch (IllegalStateException success) {
480 <        }
479 >            shouldThrow();
480 >        } catch (IllegalStateException success) {}
481      }
482  
483      /**
# Line 483 | Line 488 | public class LinkedBlockingDequeTest ext
488              LinkedBlockingDeque q = new LinkedBlockingDeque(1);
489              q.addAll(null);
490              shouldThrow();
491 <        }
487 <        catch (NullPointerException success) {}
491 >        } catch (NullPointerException success) {}
492      }
493  
494      /**
# Line 495 | Line 499 | public class LinkedBlockingDequeTest ext
499              LinkedBlockingDeque q = populatedDeque(SIZE);
500              q.addAll(q);
501              shouldThrow();
502 <        }
499 <        catch (IllegalArgumentException success) {}
502 >        } catch (IllegalArgumentException success) {}
503      }
504  
505      /**
# Line 508 | Line 511 | public class LinkedBlockingDequeTest ext
511              Integer[] ints = new Integer[SIZE];
512              q.addAll(Arrays.asList(ints));
513              shouldThrow();
514 <        }
512 <        catch (NullPointerException success) {}
514 >        } catch (NullPointerException success) {}
515      }
516      /**
517       * addAll of a collection with any null elements throws NPE after
# Line 523 | Line 525 | public class LinkedBlockingDequeTest ext
525                  ints[i] = new Integer(i);
526              q.addAll(Arrays.asList(ints));
527              shouldThrow();
528 <        }
527 <        catch (NullPointerException success) {}
528 >        } catch (NullPointerException success) {}
529      }
530      /**
531       * addAll throws ISE if not enough room
# Line 537 | Line 538 | public class LinkedBlockingDequeTest ext
538                  ints[i] = new Integer(i);
539              q.addAll(Arrays.asList(ints));
540              shouldThrow();
541 <        }
541 <        catch (IllegalStateException success) {}
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)
556 <                assertEquals(ints[i], q.poll());
557 <        }
558 <        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  
560      /**
561       * put(null) throws NPE
562       */
563 <     public void testPutNull() {
563 >    public void testPutNull() throws InterruptedException {
564          try {
565              LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
566              q.put(null);
567              shouldThrow();
568 <        }
569 <        catch (NullPointerException success) {
572 <        }
573 <        catch (InterruptedException ie) {
574 <            unexpectedException();
575 <        }
576 <     }
568 >        } catch (NullPointerException success) {}
569 >    }
570  
571      /**
572       * all elements successfully put are contained
573       */
574 <     public void testPut() {
575 <         try {
576 <             LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
577 <             for (int i = 0; i < SIZE; ++i) {
578 <                 Integer I = new Integer(i);
579 <                 q.put(I);
587 <                 assertTrue(q.contains(I));
588 <             }
589 <             assertEquals(0, q.remainingCapacity());
590 <         }
591 <        catch (InterruptedException ie) {
592 <            unexpectedException();
574 >    public void testPut() throws InterruptedException {
575 >        LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
576 >        for (int i = 0; i < SIZE; ++i) {
577 >            Integer I = new Integer(i);
578 >            q.put(I);
579 >            assertTrue(q.contains(I));
580          }
581 +        assertEquals(0, q.remainingCapacity());
582      }
583  
584      /**
585       * put blocks interruptibly if full
586       */
587 <    public void testBlockingPut() {
588 <        Thread t = new Thread(new Runnable() {
589 <                public void run() {
590 <                    int added = 0;
591 <                    try {
592 <                        LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
593 <                        for (int i = 0; i < SIZE; ++i) {
594 <                            q.put(new Integer(i));
595 <                            ++added;
596 <                        }
597 <                        q.put(new Integer(SIZE));
598 <                        threadShouldThrow();
599 <                    } catch (InterruptedException ie) {
600 <                        threadAssertEquals(added, SIZE);
601 <                    }
602 <                }});
603 <        t.start();
604 <        try {
605 <           Thread.sleep(SHORT_DELAY_MS);
606 <           t.interrupt();
619 <           t.join();
620 <        }
621 <        catch (InterruptedException ie) {
622 <            unexpectedException();
623 <        }
587 >    public void testBlockingPut() throws InterruptedException {
588 >        final LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
589 >        Thread t = new Thread(new CheckedRunnable() {
590 >            public void realRun() throws InterruptedException {
591 >                for (int i = 0; i < SIZE; ++i)
592 >                    q.put(i);
593 >                assertEquals(SIZE, q.size());
594 >                assertEquals(0, q.remainingCapacity());
595 >                try {
596 >                    q.put(99);
597 >                    shouldThrow();
598 >                } catch (InterruptedException success) {}
599 >            }});
600 >
601 >        t.start();
602 >        Thread.sleep(SHORT_DELAY_MS);
603 >        t.interrupt();
604 >        t.join();
605 >        assertEquals(SIZE, q.size());
606 >        assertEquals(0, q.remainingCapacity());
607      }
608  
609      /**
610       * put blocks waiting for take when full
611       */
612 <    public void testPutWithTake() {
613 <        final LinkedBlockingDeque q = new LinkedBlockingDeque(2);
614 <        Thread t = new Thread(new Runnable() {
615 <                public void run() {
616 <                    int added = 0;
617 <                    try {
618 <                        q.put(new Object());
619 <                        ++added;
620 <                        q.put(new Object());
621 <                        ++added;
622 <                        q.put(new Object());
623 <                        ++added;
624 <                        q.put(new Object());
625 <                        ++added;
626 <                        threadShouldThrow();
627 <                    } catch (InterruptedException e) {
628 <                        threadAssertTrue(added >= 2);
629 <                    }
630 <                }
631 <            });
632 <        try {
650 <            t.start();
651 <            Thread.sleep(SHORT_DELAY_MS);
652 <            q.take();
653 <            t.interrupt();
654 <            t.join();
655 <        } catch (Exception e) {
656 <            unexpectedException();
657 <        }
612 >    public void testPutWithTake() throws InterruptedException {
613 >        final int capacity = 2;
614 >        final LinkedBlockingDeque q = new LinkedBlockingDeque(capacity);
615 >        Thread t = new Thread(new CheckedRunnable() {
616 >            public void realRun() throws InterruptedException {
617 >                for (int i = 0; i < capacity + 1; i++)
618 >                    q.put(i);
619 >                try {
620 >                    q.put(99);
621 >                    shouldThrow();
622 >                } catch (InterruptedException success) {}
623 >            }});
624 >
625 >        t.start();
626 >        Thread.sleep(SHORT_DELAY_MS);
627 >        assertEquals(q.remainingCapacity(), 0);
628 >        assertEquals(0, q.take());
629 >        Thread.sleep(SHORT_DELAY_MS);
630 >        t.interrupt();
631 >        t.join();
632 >        assertEquals(q.remainingCapacity(), 0);
633      }
634  
635      /**
636       * timed offer times out if full and elements not taken
637       */
638 <    public void testTimedOffer() {
638 >    public void testTimedOffer() throws InterruptedException {
639          final LinkedBlockingDeque q = new LinkedBlockingDeque(2);
640 <        Thread t = new Thread(new Runnable() {
641 <                public void run() {
642 <                    try {
643 <                        q.put(new Object());
644 <                        q.put(new Object());
645 <                        threadAssertFalse(q.offer(new Object(), SHORT_DELAY_MS, TimeUnit.MILLISECONDS));
646 <                        q.offer(new Object(), LONG_DELAY_MS, TimeUnit.MILLISECONDS);
647 <                        threadShouldThrow();
648 <                    } catch (InterruptedException success) {}
649 <                }
675 <            });
640 >        Thread t = new Thread(new CheckedRunnable() {
641 >            public void realRun() throws InterruptedException {
642 >                q.put(new Object());
643 >                q.put(new Object());
644 >                assertFalse(q.offer(new Object(), SHORT_DELAY_MS, MILLISECONDS));
645 >                try {
646 >                    q.offer(new Object(), LONG_DELAY_MS, MILLISECONDS);
647 >                    shouldThrow();
648 >                } catch (InterruptedException success) {}
649 >            }});
650  
651 <        try {
652 <            t.start();
653 <            Thread.sleep(SMALL_DELAY_MS);
654 <            t.interrupt();
681 <            t.join();
682 <        } catch (Exception e) {
683 <            unexpectedException();
684 <        }
651 >        t.start();
652 >        Thread.sleep(SMALL_DELAY_MS);
653 >        t.interrupt();
654 >        t.join();
655      }
656  
657      /**
658       * take retrieves elements in FIFO order
659       */
660 <    public void testTake() {
661 <        try {
662 <            LinkedBlockingDeque q = populatedDeque(SIZE);
663 <            for (int i = 0; i < SIZE; ++i) {
694 <                assertEquals(i, ((Integer)q.take()).intValue());
695 <            }
696 <        } catch (InterruptedException e) {
697 <            unexpectedException();
660 >    public void testTake() throws InterruptedException {
661 >        LinkedBlockingDeque q = populatedDeque(SIZE);
662 >        for (int i = 0; i < SIZE; ++i) {
663 >            assertEquals(i, q.take());
664          }
665      }
666  
667      /**
668       * take blocks interruptibly when empty
669       */
670 <    public void testTakeFromEmpty() {
670 >    public void testTakeFromEmpty() throws InterruptedException {
671          final LinkedBlockingDeque q = new LinkedBlockingDeque(2);
672 <        Thread t = new Thread(new Runnable() {
673 <                public void run() {
674 <                    try {
675 <                        q.take();
676 <                        threadShouldThrow();
677 <                    } catch (InterruptedException success) { }
678 <                }
679 <            });
680 <        try {
715 <            t.start();
716 <            Thread.sleep(SHORT_DELAY_MS);
717 <            t.interrupt();
718 <            t.join();
719 <        } catch (Exception e) {
720 <            unexpectedException();
721 <        }
672 >        Thread t = new ThreadShouldThrow(InterruptedException.class) {
673 >            public void realRun() throws InterruptedException {
674 >                q.take();
675 >            }};
676 >
677 >        t.start();
678 >        Thread.sleep(SHORT_DELAY_MS);
679 >        t.interrupt();
680 >        t.join();
681      }
682  
683      /**
684       * Take removes existing elements until empty, then blocks interruptibly
685       */
686 <    public void testBlockingTake() {
687 <        Thread t = new Thread(new Runnable() {
688 <                public void run() {
689 <                    try {
690 <                        LinkedBlockingDeque q = populatedDeque(SIZE);
691 <                        for (int i = 0; i < SIZE; ++i) {
692 <                            assertEquals(i, ((Integer)q.take()).intValue());
693 <                        }
694 <                        q.take();
695 <                        threadShouldThrow();
696 <                    } catch (InterruptedException success) {
697 <                    }
698 <                }});
699 <        t.start();
700 <        try {
701 <           Thread.sleep(SHORT_DELAY_MS);
702 <           t.interrupt();
744 <           t.join();
745 <        }
746 <        catch (InterruptedException ie) {
747 <            unexpectedException();
748 <        }
686 >    public void testBlockingTake() throws InterruptedException {
687 >        final LinkedBlockingDeque q = populatedDeque(SIZE);
688 >        Thread t = new Thread(new CheckedRunnable() {
689 >            public void realRun() throws InterruptedException {
690 >                for (int i = 0; i < SIZE; ++i) {
691 >                    assertEquals(i, q.take());
692 >                }
693 >                try {
694 >                    q.take();
695 >                    shouldThrow();
696 >                } catch (InterruptedException success) {}
697 >            }});
698 >
699 >        t.start();
700 >        Thread.sleep(SHORT_DELAY_MS);
701 >        t.interrupt();
702 >        t.join();
703      }
704  
705  
# Line 755 | Line 709 | public class LinkedBlockingDequeTest ext
709      public void testPoll() {
710          LinkedBlockingDeque q = populatedDeque(SIZE);
711          for (int i = 0; i < SIZE; ++i) {
712 <            assertEquals(i, ((Integer)q.poll()).intValue());
712 >            assertEquals(i, q.poll());
713          }
714          assertNull(q.poll());
715      }
# Line 763 | Line 717 | public class LinkedBlockingDequeTest ext
717      /**
718       * timed poll with zero timeout succeeds when non-empty, else times out
719       */
720 <    public void testTimedPoll0() {
721 <        try {
722 <            LinkedBlockingDeque q = populatedDeque(SIZE);
723 <            for (int i = 0; i < SIZE; ++i) {
770 <                assertEquals(i, ((Integer)q.poll(0, TimeUnit.MILLISECONDS)).intValue());
771 <            }
772 <            assertNull(q.poll(0, TimeUnit.MILLISECONDS));
773 <        } catch (InterruptedException e) {
774 <            unexpectedException();
720 >    public void testTimedPoll0() throws InterruptedException {
721 >        LinkedBlockingDeque q = populatedDeque(SIZE);
722 >        for (int i = 0; i < SIZE; ++i) {
723 >            assertEquals(i, q.poll(0, MILLISECONDS));
724          }
725 +        assertNull(q.poll(0, MILLISECONDS));
726      }
727  
728      /**
729       * timed poll with nonzero timeout succeeds when non-empty, else times out
730       */
731 <    public void testTimedPoll() {
732 <        try {
733 <            LinkedBlockingDeque q = populatedDeque(SIZE);
734 <            for (int i = 0; i < SIZE; ++i) {
785 <                assertEquals(i, ((Integer)q.poll(SHORT_DELAY_MS, TimeUnit.MILLISECONDS)).intValue());
786 <            }
787 <            assertNull(q.poll(SHORT_DELAY_MS, TimeUnit.MILLISECONDS));
788 <        } catch (InterruptedException e) {
789 <            unexpectedException();
731 >    public void testTimedPoll() throws InterruptedException {
732 >        LinkedBlockingDeque q = populatedDeque(SIZE);
733 >        for (int i = 0; i < SIZE; ++i) {
734 >            assertEquals(i, q.poll(SHORT_DELAY_MS, MILLISECONDS));
735          }
736 +        assertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS));
737      }
738  
739      /**
740       * Interrupted timed poll throws InterruptedException instead of
741       * returning timeout status
742       */
743 <    public void testInterruptedTimedPoll() {
744 <        Thread t = new Thread(new Runnable() {
745 <                public void run() {
746 <                    try {
747 <                        LinkedBlockingDeque q = populatedDeque(SIZE);
748 <                        for (int i = 0; i < SIZE; ++i) {
749 <                            threadAssertEquals(i, ((Integer)q.poll(SHORT_DELAY_MS, TimeUnit.MILLISECONDS)).intValue());
750 <                        }
751 <                        threadAssertNull(q.poll(SHORT_DELAY_MS, TimeUnit.MILLISECONDS));
752 <                    } catch (InterruptedException success) {
753 <                    }
754 <                }});
755 <        t.start();
756 <        try {
757 <           Thread.sleep(SHORT_DELAY_MS);
758 <           t.interrupt();
759 <           t.join();
814 <        }
815 <        catch (InterruptedException ie) {
816 <            unexpectedException();
817 <        }
743 >    public void testInterruptedTimedPoll() throws InterruptedException {
744 >        Thread t = new Thread(new CheckedRunnable() {
745 >            public void realRun() throws InterruptedException {
746 >                LinkedBlockingDeque q = populatedDeque(SIZE);
747 >                for (int i = 0; i < SIZE; ++i) {
748 >                    assertEquals(i, q.poll(SHORT_DELAY_MS, MILLISECONDS));
749 >                }
750 >                try {
751 >                    q.poll(SMALL_DELAY_MS, MILLISECONDS);
752 >                    shouldThrow();
753 >                } catch (InterruptedException success) {}
754 >            }});
755 >
756 >        t.start();
757 >        Thread.sleep(SHORT_DELAY_MS);
758 >        t.interrupt();
759 >        t.join();
760      }
761  
762      /**
763       *  timed poll before a delayed offer fails; after offer succeeds;
764       *  on interruption throws
765       */
766 <    public void testTimedPollWithOffer() {
766 >    public void testTimedPollWithOffer() throws InterruptedException {
767          final LinkedBlockingDeque q = new LinkedBlockingDeque(2);
768 <        Thread t = new Thread(new Runnable() {
769 <                public void run() {
770 <                    try {
771 <                        threadAssertNull(q.poll(SHORT_DELAY_MS, TimeUnit.MILLISECONDS));
772 <                        q.poll(LONG_DELAY_MS, TimeUnit.MILLISECONDS);
773 <                        q.poll(LONG_DELAY_MS, TimeUnit.MILLISECONDS);
774 <                        threadShouldThrow();
775 <                    } catch (InterruptedException success) { }
776 <                }
777 <            });
778 <        try {
779 <            t.start();
780 <            Thread.sleep(SMALL_DELAY_MS);
781 <            assertTrue(q.offer(zero, SHORT_DELAY_MS, TimeUnit.MILLISECONDS));
782 <            t.interrupt();
841 <            t.join();
842 <        } catch (Exception e) {
843 <            unexpectedException();
844 <        }
768 >        Thread t = new Thread(new CheckedRunnable() {
769 >            public void realRun() throws InterruptedException {
770 >                assertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS));
771 >                assertSame(zero, q.poll(LONG_DELAY_MS, MILLISECONDS));
772 >                try {
773 >                    q.poll(LONG_DELAY_MS, MILLISECONDS);
774 >                    shouldThrow();
775 >                } catch (InterruptedException success) {}
776 >            }});
777 >
778 >        t.start();
779 >        Thread.sleep(SMALL_DELAY_MS);
780 >        assertTrue(q.offer(zero, SHORT_DELAY_MS, MILLISECONDS));
781 >        t.interrupt();
782 >        t.join();
783      }
784  
785  
786      /**
787       * putFirst(null) throws NPE
788       */
789 <     public void testPutFirstNull() {
789 >     public void testPutFirstNull() throws InterruptedException {
790          try {
791              LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
792              q.putFirst(null);
793              shouldThrow();
794 <        }
857 <        catch (NullPointerException success) {
858 <        }
859 <        catch (InterruptedException ie) {
860 <            unexpectedException();
861 <        }
794 >        } catch (NullPointerException success) {}
795       }
796  
797      /**
798       * all elements successfully putFirst are contained
799       */
800 <     public void testPutFirst() {
801 <         try {
802 <             LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
803 <             for (int i = 0; i < SIZE; ++i) {
804 <                 Integer I = new Integer(i);
805 <                 q.putFirst(I);
873 <                 assertTrue(q.contains(I));
874 <             }
875 <             assertEquals(0, q.remainingCapacity());
800 >     public void testPutFirst() throws InterruptedException {
801 >         LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
802 >         for (int i = 0; i < SIZE; ++i) {
803 >             Integer I = new Integer(i);
804 >             q.putFirst(I);
805 >             assertTrue(q.contains(I));
806           }
807 <        catch (InterruptedException ie) {
878 <            unexpectedException();
879 <        }
807 >         assertEquals(0, q.remainingCapacity());
808      }
809  
810      /**
811       * putFirst blocks interruptibly if full
812       */
813 <    public void testBlockingPutFirst() {
814 <        Thread t = new Thread(new Runnable() {
815 <                public void run() {
816 <                    int added = 0;
817 <                    try {
818 <                        LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
819 <                        for (int i = 0; i < SIZE; ++i) {
820 <                            q.putFirst(new Integer(i));
821 <                            ++added;
822 <                        }
823 <                        q.putFirst(new Integer(SIZE));
824 <                        threadShouldThrow();
825 <                    } catch (InterruptedException ie) {
826 <                        threadAssertEquals(added, SIZE);
827 <                    }
828 <                }});
829 <        t.start();
830 <        try {
831 <           Thread.sleep(SHORT_DELAY_MS);
832 <           t.interrupt();
905 <           t.join();
906 <        }
907 <        catch (InterruptedException ie) {
908 <            unexpectedException();
909 <        }
813 >    public void testBlockingPutFirst() throws InterruptedException {
814 >        final LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
815 >        Thread t = new Thread(new CheckedRunnable() {
816 >            public void realRun() throws InterruptedException {
817 >                for (int i = 0; i < SIZE; ++i)
818 >                    q.putFirst(i);
819 >                assertEquals(SIZE, q.size());
820 >                assertEquals(0, q.remainingCapacity());
821 >                try {
822 >                    q.putFirst(99);
823 >                    shouldThrow();
824 >                } catch (InterruptedException success) {}
825 >            }});
826 >
827 >        t.start();
828 >        Thread.sleep(SHORT_DELAY_MS);
829 >        t.interrupt();
830 >        t.join();
831 >        assertEquals(SIZE, q.size());
832 >        assertEquals(0, q.remainingCapacity());
833      }
834  
835      /**
836       * putFirst blocks waiting for take when full
837       */
838 <    public void testPutFirstWithTake() {
839 <        final LinkedBlockingDeque q = new LinkedBlockingDeque(2);
840 <        Thread t = new Thread(new Runnable() {
841 <                public void run() {
842 <                    int added = 0;
843 <                    try {
844 <                        q.putFirst(new Object());
845 <                        ++added;
846 <                        q.putFirst(new Object());
847 <                        ++added;
848 <                        q.putFirst(new Object());
849 <                        ++added;
850 <                        q.putFirst(new Object());
851 <                        ++added;
852 <                        threadShouldThrow();
853 <                    } catch (InterruptedException e) {
854 <                        threadAssertTrue(added >= 2);
855 <                    }
856 <                }
857 <            });
858 <        try {
936 <            t.start();
937 <            Thread.sleep(SHORT_DELAY_MS);
938 <            q.take();
939 <            t.interrupt();
940 <            t.join();
941 <        } catch (Exception e) {
942 <            unexpectedException();
943 <        }
838 >    public void testPutFirstWithTake() throws InterruptedException {
839 >        final int capacity = 2;
840 >        final LinkedBlockingDeque q = new LinkedBlockingDeque(capacity);
841 >        Thread t = new Thread(new CheckedRunnable() {
842 >            public void realRun() throws InterruptedException {
843 >                for (int i = 0; i < capacity + 1; i++)
844 >                    q.putFirst(i);
845 >                try {
846 >                    q.putFirst(99);
847 >                    shouldThrow();
848 >                } catch (InterruptedException success) {}
849 >            }});
850 >
851 >        t.start();
852 >        Thread.sleep(SHORT_DELAY_MS);
853 >        assertEquals(q.remainingCapacity(), 0);
854 >        assertEquals(capacity - 1, q.take());
855 >        Thread.sleep(SHORT_DELAY_MS);
856 >        t.interrupt();
857 >        t.join();
858 >        assertEquals(q.remainingCapacity(), 0);
859      }
860  
861      /**
862       * timed offerFirst times out if full and elements not taken
863       */
864 <    public void testTimedOfferFirst() {
864 >    public void testTimedOfferFirst() throws InterruptedException {
865          final LinkedBlockingDeque q = new LinkedBlockingDeque(2);
866 <        Thread t = new Thread(new Runnable() {
867 <                public void run() {
868 <                    try {
869 <                        q.putFirst(new Object());
870 <                        q.putFirst(new Object());
871 <                        threadAssertFalse(q.offerFirst(new Object(), SHORT_DELAY_MS, TimeUnit.MILLISECONDS));
872 <                        q.offerFirst(new Object(), LONG_DELAY_MS, TimeUnit.MILLISECONDS);
873 <                        threadShouldThrow();
874 <                    } catch (InterruptedException success) {}
875 <                }
961 <            });
866 >        Thread t = new Thread(new CheckedRunnable() {
867 >            public void realRun() throws InterruptedException {
868 >                q.putFirst(new Object());
869 >                q.putFirst(new Object());
870 >                assertFalse(q.offerFirst(new Object(), SHORT_DELAY_MS, MILLISECONDS));
871 >                try {
872 >                    q.offerFirst(new Object(), LONG_DELAY_MS, MILLISECONDS);
873 >                    shouldThrow();
874 >                } catch (InterruptedException success) {}
875 >            }});
876  
877 <        try {
878 <            t.start();
879 <            Thread.sleep(SMALL_DELAY_MS);
880 <            t.interrupt();
967 <            t.join();
968 <        } catch (Exception e) {
969 <            unexpectedException();
970 <        }
877 >        t.start();
878 >        Thread.sleep(SMALL_DELAY_MS);
879 >        t.interrupt();
880 >        t.join();
881      }
882  
883      /**
884       * take retrieves elements in FIFO order
885       */
886 <    public void testTakeFirst() {
887 <        try {
888 <            LinkedBlockingDeque q = populatedDeque(SIZE);
889 <            for (int i = 0; i < SIZE; ++i) {
980 <                assertEquals(i, ((Integer)q.takeFirst()).intValue());
981 <            }
982 <        } catch (InterruptedException e) {
983 <            unexpectedException();
886 >    public void testTakeFirst() throws InterruptedException {
887 >        LinkedBlockingDeque q = populatedDeque(SIZE);
888 >        for (int i = 0; i < SIZE; ++i) {
889 >            assertEquals(i, q.takeFirst());
890          }
891      }
892  
893      /**
894       * takeFirst blocks interruptibly when empty
895       */
896 <    public void testTakeFirstFromEmpty() {
896 >    public void testTakeFirstFromEmpty() throws InterruptedException {
897          final LinkedBlockingDeque q = new LinkedBlockingDeque(2);
898 <        Thread t = new Thread(new Runnable() {
899 <                public void run() {
900 <                    try {
901 <                        q.takeFirst();
902 <                        threadShouldThrow();
903 <                    } catch (InterruptedException success) { }
904 <                }
905 <            });
906 <        try {
1001 <            t.start();
1002 <            Thread.sleep(SHORT_DELAY_MS);
1003 <            t.interrupt();
1004 <            t.join();
1005 <        } catch (Exception e) {
1006 <            unexpectedException();
1007 <        }
898 >        Thread t = new ThreadShouldThrow(InterruptedException.class) {
899 >            public void realRun() throws InterruptedException {
900 >                q.takeFirst();
901 >            }};
902 >
903 >        t.start();
904 >        Thread.sleep(SHORT_DELAY_MS);
905 >        t.interrupt();
906 >        t.join();
907      }
908  
909      /**
910       * TakeFirst removes existing elements until empty, then blocks interruptibly
911       */
912 <    public void testBlockingTakeFirst() {
913 <        Thread t = new Thread(new Runnable() {
914 <                public void run() {
915 <                    try {
916 <                        LinkedBlockingDeque q = populatedDeque(SIZE);
917 <                        for (int i = 0; i < SIZE; ++i) {
918 <                            assertEquals(i, ((Integer)q.takeFirst()).intValue());
919 <                        }
920 <                        q.takeFirst();
921 <                        threadShouldThrow();
922 <                    } catch (InterruptedException success) {
923 <                    }
924 <                }});
925 <        t.start();
926 <        try {
927 <           Thread.sleep(SHORT_DELAY_MS);
1029 <           t.interrupt();
1030 <           t.join();
1031 <        }
1032 <        catch (InterruptedException ie) {
1033 <            unexpectedException();
1034 <        }
912 >    public void testBlockingTakeFirst() throws InterruptedException {
913 >        final LinkedBlockingDeque q = populatedDeque(SIZE);
914 >        Thread t = new Thread(new CheckedRunnable() {
915 >            public void realRun() throws InterruptedException {
916 >                for (int i = 0; i < SIZE; ++i)
917 >                    assertEquals(i, q.takeFirst());
918 >                try {
919 >                    q.takeFirst();
920 >                    shouldThrow();
921 >                } catch (InterruptedException success) {}
922 >            }});
923 >
924 >        t.start();
925 >        Thread.sleep(SHORT_DELAY_MS);
926 >        t.interrupt();
927 >        t.join();
928      }
929  
930  
931      /**
932       * timed pollFirst with zero timeout succeeds when non-empty, else times out
933       */
934 <    public void testTimedPollFirst0() {
935 <        try {
936 <            LinkedBlockingDeque q = populatedDeque(SIZE);
937 <            for (int i = 0; i < SIZE; ++i) {
1045 <                assertEquals(i, ((Integer)q.pollFirst(0, TimeUnit.MILLISECONDS)).intValue());
1046 <            }
1047 <            assertNull(q.pollFirst(0, TimeUnit.MILLISECONDS));
1048 <        } catch (InterruptedException e) {
1049 <            unexpectedException();
934 >    public void testTimedPollFirst0() throws InterruptedException {
935 >        LinkedBlockingDeque q = populatedDeque(SIZE);
936 >        for (int i = 0; i < SIZE; ++i) {
937 >            assertEquals(i, q.pollFirst(0, MILLISECONDS));
938          }
939 +        assertNull(q.pollFirst(0, MILLISECONDS));
940      }
941  
942      /**
943       * timed pollFirst with nonzero timeout succeeds when non-empty, else times out
944       */
945 <    public void testTimedPollFirst() {
946 <        try {
947 <            LinkedBlockingDeque q = populatedDeque(SIZE);
948 <            for (int i = 0; i < SIZE; ++i) {
1060 <                assertEquals(i, ((Integer)q.pollFirst(SHORT_DELAY_MS, TimeUnit.MILLISECONDS)).intValue());
1061 <            }
1062 <            assertNull(q.pollFirst(SHORT_DELAY_MS, TimeUnit.MILLISECONDS));
1063 <        } catch (InterruptedException e) {
1064 <            unexpectedException();
945 >    public void testTimedPollFirst() throws InterruptedException {
946 >        LinkedBlockingDeque q = populatedDeque(SIZE);
947 >        for (int i = 0; i < SIZE; ++i) {
948 >            assertEquals(i, q.pollFirst(SHORT_DELAY_MS, MILLISECONDS));
949          }
950 +        assertNull(q.pollFirst(SHORT_DELAY_MS, MILLISECONDS));
951      }
952  
953      /**
954       * Interrupted timed pollFirst throws InterruptedException instead of
955       * returning timeout status
956       */
957 <    public void testInterruptedTimedPollFirst() {
958 <        Thread t = new Thread(new Runnable() {
959 <                public void run() {
960 <                    try {
961 <                        LinkedBlockingDeque q = populatedDeque(SIZE);
962 <                        for (int i = 0; i < SIZE; ++i) {
963 <                            threadAssertEquals(i, ((Integer)q.pollFirst(SHORT_DELAY_MS, TimeUnit.MILLISECONDS)).intValue());
964 <                        }
965 <                        threadAssertNull(q.pollFirst(SHORT_DELAY_MS, TimeUnit.MILLISECONDS));
966 <                    } catch (InterruptedException success) {
967 <                    }
968 <                }});
969 <        t.start();
970 <        try {
971 <           Thread.sleep(SHORT_DELAY_MS);
972 <           t.interrupt();
973 <           t.join();
1089 <        }
1090 <        catch (InterruptedException ie) {
1091 <            unexpectedException();
1092 <        }
957 >    public void testInterruptedTimedPollFirst() throws InterruptedException {
958 >        Thread t = new Thread(new CheckedRunnable() {
959 >            public void realRun() throws InterruptedException {
960 >                LinkedBlockingDeque q = populatedDeque(SIZE);
961 >                for (int i = 0; i < SIZE; ++i) {
962 >                    assertEquals(i, q.pollFirst(SHORT_DELAY_MS, MILLISECONDS));
963 >                }
964 >                try {
965 >                    q.pollFirst(SMALL_DELAY_MS, MILLISECONDS);
966 >                    shouldThrow();
967 >                } catch (InterruptedException success) {}
968 >            }});
969 >
970 >        t.start();
971 >        Thread.sleep(SHORT_DELAY_MS);
972 >        t.interrupt();
973 >        t.join();
974      }
975  
976      /**
977       *  timed pollFirst before a delayed offerFirst fails; after offerFirst succeeds;
978       *  on interruption throws
979       */
980 <    public void testTimedPollFirstWithOfferFirst() {
980 >    public void testTimedPollFirstWithOfferFirst() throws InterruptedException {
981          final LinkedBlockingDeque q = new LinkedBlockingDeque(2);
982 <        Thread t = new Thread(new Runnable() {
983 <                public void run() {
984 <                    try {
985 <                        threadAssertNull(q.pollFirst(SHORT_DELAY_MS, TimeUnit.MILLISECONDS));
986 <                        q.pollFirst(LONG_DELAY_MS, TimeUnit.MILLISECONDS);
987 <                        q.pollFirst(LONG_DELAY_MS, TimeUnit.MILLISECONDS);
988 <                        threadShouldThrow();
989 <                    } catch (InterruptedException success) { }
990 <                }
991 <            });
992 <        try {
993 <            t.start();
994 <            Thread.sleep(SMALL_DELAY_MS);
995 <            assertTrue(q.offerFirst(zero, SHORT_DELAY_MS, TimeUnit.MILLISECONDS));
996 <            t.interrupt();
1116 <            t.join();
1117 <        } catch (Exception e) {
1118 <            unexpectedException();
1119 <        }
982 >        Thread t = new Thread(new CheckedRunnable() {
983 >            public void realRun() throws InterruptedException {
984 >                assertNull(q.pollFirst(SHORT_DELAY_MS, MILLISECONDS));
985 >                assertSame(zero, q.pollFirst(LONG_DELAY_MS, MILLISECONDS));
986 >                try {
987 >                    q.pollFirst(LONG_DELAY_MS, MILLISECONDS);
988 >                    shouldThrow();
989 >                } catch (InterruptedException success) {}
990 >            }});
991 >
992 >        t.start();
993 >        Thread.sleep(SMALL_DELAY_MS);
994 >        assertTrue(q.offerFirst(zero, SHORT_DELAY_MS, MILLISECONDS));
995 >        t.interrupt();
996 >        t.join();
997      }
998  
999      /**
1000       * putLast(null) throws NPE
1001       */
1002 <     public void testPutLastNull() {
1002 >     public void testPutLastNull() throws InterruptedException {
1003          try {
1004              LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
1005              q.putLast(null);
1006              shouldThrow();
1007 <        }
1131 <        catch (NullPointerException success) {
1132 <        }
1133 <        catch (InterruptedException ie) {
1134 <            unexpectedException();
1135 <        }
1007 >        } catch (NullPointerException success) {}
1008       }
1009  
1010      /**
1011       * all elements successfully putLast are contained
1012       */
1013 <     public void testPutLast() {
1014 <         try {
1015 <             LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
1016 <             for (int i = 0; i < SIZE; ++i) {
1017 <                 Integer I = new Integer(i);
1018 <                 q.putLast(I);
1147 <                 assertTrue(q.contains(I));
1148 <             }
1149 <             assertEquals(0, q.remainingCapacity());
1013 >     public void testPutLast() throws InterruptedException {
1014 >         LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
1015 >         for (int i = 0; i < SIZE; ++i) {
1016 >             Integer I = new Integer(i);
1017 >             q.putLast(I);
1018 >             assertTrue(q.contains(I));
1019           }
1020 <        catch (InterruptedException ie) {
1152 <            unexpectedException();
1153 <        }
1020 >         assertEquals(0, q.remainingCapacity());
1021      }
1022  
1023      /**
1024       * putLast blocks interruptibly if full
1025       */
1026 <    public void testBlockingPutLast() {
1027 <        Thread t = new Thread(new Runnable() {
1028 <                public void run() {
1029 <                    int added = 0;
1030 <                    try {
1031 <                        LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
1032 <                        for (int i = 0; i < SIZE; ++i) {
1033 <                            q.putLast(new Integer(i));
1034 <                            ++added;
1035 <                        }
1036 <                        q.putLast(new Integer(SIZE));
1037 <                        threadShouldThrow();
1038 <                    } catch (InterruptedException ie) {
1039 <                        threadAssertEquals(added, SIZE);
1040 <                    }
1041 <                }});
1042 <        t.start();
1043 <        try {
1044 <           Thread.sleep(SHORT_DELAY_MS);
1045 <           t.interrupt();
1179 <           t.join();
1180 <        }
1181 <        catch (InterruptedException ie) {
1182 <            unexpectedException();
1183 <        }
1026 >    public void testBlockingPutLast() throws InterruptedException {
1027 >        final LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
1028 >        Thread t = new Thread(new CheckedRunnable() {
1029 >            public void realRun() throws InterruptedException {
1030 >                for (int i = 0; i < SIZE; ++i)
1031 >                    q.putLast(i);
1032 >                assertEquals(SIZE, q.size());
1033 >                assertEquals(0, q.remainingCapacity());
1034 >                try {
1035 >                    q.putLast(99);
1036 >                    shouldThrow();
1037 >                } catch (InterruptedException success) {}
1038 >            }});
1039 >
1040 >        t.start();
1041 >        Thread.sleep(SHORT_DELAY_MS);
1042 >        t.interrupt();
1043 >        t.join();
1044 >        assertEquals(SIZE, q.size());
1045 >        assertEquals(0, q.remainingCapacity());
1046      }
1047  
1048      /**
1049       * putLast blocks waiting for take when full
1050       */
1051 <    public void testPutLastWithTake() {
1052 <        final LinkedBlockingDeque q = new LinkedBlockingDeque(2);
1053 <        Thread t = new Thread(new Runnable() {
1054 <                public void run() {
1055 <                    int added = 0;
1056 <                    try {
1057 <                        q.putLast(new Object());
1058 <                        ++added;
1059 <                        q.putLast(new Object());
1060 <                        ++added;
1061 <                        q.putLast(new Object());
1062 <                        ++added;
1063 <                        q.putLast(new Object());
1064 <                        ++added;
1065 <                        threadShouldThrow();
1066 <                    } catch (InterruptedException e) {
1067 <                        threadAssertTrue(added >= 2);
1068 <                    }
1069 <                }
1070 <            });
1071 <        try {
1210 <            t.start();
1211 <            Thread.sleep(SHORT_DELAY_MS);
1212 <            q.take();
1213 <            t.interrupt();
1214 <            t.join();
1215 <        } catch (Exception e) {
1216 <            unexpectedException();
1217 <        }
1051 >    public void testPutLastWithTake() throws InterruptedException {
1052 >        final int capacity = 2;
1053 >        final LinkedBlockingDeque q = new LinkedBlockingDeque(capacity);
1054 >        Thread t = new Thread(new CheckedRunnable() {
1055 >            public void realRun() throws InterruptedException {
1056 >                for (int i = 0; i < capacity + 1; i++)
1057 >                    q.putLast(i);
1058 >                try {
1059 >                    q.putLast(99);
1060 >                    shouldThrow();
1061 >                } catch (InterruptedException success) {}
1062 >            }});
1063 >
1064 >        t.start();
1065 >        Thread.sleep(SHORT_DELAY_MS);
1066 >        assertEquals(q.remainingCapacity(), 0);
1067 >        assertEquals(0, q.take());
1068 >        Thread.sleep(SHORT_DELAY_MS);
1069 >        t.interrupt();
1070 >        t.join();
1071 >        assertEquals(q.remainingCapacity(), 0);
1072      }
1073  
1074      /**
1075       * timed offerLast times out if full and elements not taken
1076       */
1077 <    public void testTimedOfferLast() {
1077 >    public void testTimedOfferLast() throws InterruptedException {
1078          final LinkedBlockingDeque q = new LinkedBlockingDeque(2);
1079 <        Thread t = new Thread(new Runnable() {
1080 <                public void run() {
1081 <                    try {
1082 <                        q.putLast(new Object());
1083 <                        q.putLast(new Object());
1084 <                        threadAssertFalse(q.offerLast(new Object(), SHORT_DELAY_MS, TimeUnit.MILLISECONDS));
1085 <                        q.offerLast(new Object(), LONG_DELAY_MS, TimeUnit.MILLISECONDS);
1086 <                        threadShouldThrow();
1087 <                    } catch (InterruptedException success) {}
1088 <                }
1235 <            });
1079 >        Thread t = new Thread(new CheckedRunnable() {
1080 >            public void realRun() throws InterruptedException {
1081 >                q.putLast(new Object());
1082 >                q.putLast(new Object());
1083 >                assertFalse(q.offerLast(new Object(), SHORT_DELAY_MS, MILLISECONDS));
1084 >                try {
1085 >                    q.offerLast(new Object(), LONG_DELAY_MS, MILLISECONDS);
1086 >                    shouldThrow();
1087 >                } catch (InterruptedException success) {}
1088 >            }});
1089  
1090 <        try {
1091 <            t.start();
1092 <            Thread.sleep(SMALL_DELAY_MS);
1093 <            t.interrupt();
1241 <            t.join();
1242 <        } catch (Exception e) {
1243 <            unexpectedException();
1244 <        }
1090 >        t.start();
1091 >        Thread.sleep(SMALL_DELAY_MS);
1092 >        t.interrupt();
1093 >        t.join();
1094      }
1095  
1096      /**
1097       * takeLast retrieves elements in FIFO order
1098       */
1099 <    public void testTakeLast() {
1100 <        try {
1101 <            LinkedBlockingDeque q = populatedDeque(SIZE);
1102 <            for (int i = 0; i < SIZE; ++i) {
1254 <                assertEquals(SIZE-i-1, ((Integer)q.takeLast()).intValue());
1255 <            }
1256 <        } catch (InterruptedException e) {
1257 <            unexpectedException();
1099 >    public void testTakeLast() throws InterruptedException {
1100 >        LinkedBlockingDeque q = populatedDeque(SIZE);
1101 >        for (int i = 0; i < SIZE; ++i) {
1102 >            assertEquals(SIZE-i-1, q.takeLast());
1103          }
1104      }
1105  
1106      /**
1107       * takeLast blocks interruptibly when empty
1108       */
1109 <    public void testTakeLastFromEmpty() {
1109 >    public void testTakeLastFromEmpty() throws InterruptedException {
1110          final LinkedBlockingDeque q = new LinkedBlockingDeque(2);
1111 <        Thread t = new Thread(new Runnable() {
1112 <                public void run() {
1113 <                    try {
1114 <                        q.takeLast();
1115 <                        threadShouldThrow();
1116 <                    } catch (InterruptedException success) { }
1117 <                }
1118 <            });
1119 <        try {
1275 <            t.start();
1276 <            Thread.sleep(SHORT_DELAY_MS);
1277 <            t.interrupt();
1278 <            t.join();
1279 <        } catch (Exception e) {
1280 <            unexpectedException();
1281 <        }
1111 >        Thread t = new ThreadShouldThrow(InterruptedException.class) {
1112 >            public void realRun() throws InterruptedException {
1113 >                q.takeLast();
1114 >            }};
1115 >
1116 >        t.start();
1117 >        Thread.sleep(SHORT_DELAY_MS);
1118 >        t.interrupt();
1119 >        t.join();
1120      }
1121  
1122      /**
1123       * TakeLast removes existing elements until empty, then blocks interruptibly
1124       */
1125 <    public void testBlockingTakeLast() {
1126 <        Thread t = new Thread(new Runnable() {
1127 <                public void run() {
1128 <                    try {
1129 <                        LinkedBlockingDeque q = populatedDeque(SIZE);
1130 <                        for (int i = 0; i < SIZE; ++i) {
1131 <                            assertEquals(SIZE-i-1, ((Integer)q.takeLast()).intValue());
1132 <                        }
1133 <                        q.takeLast();
1134 <                        threadShouldThrow();
1135 <                    } catch (InterruptedException success) {
1298 <                    }
1299 <                }});
1300 <        t.start();
1301 <        try {
1302 <           Thread.sleep(SHORT_DELAY_MS);
1303 <           t.interrupt();
1304 <           t.join();
1305 <        }
1306 <        catch (InterruptedException ie) {
1307 <            unexpectedException();
1308 <        }
1309 <    }
1125 >    public void testBlockingTakeLast() throws InterruptedException {
1126 >        final LinkedBlockingDeque q = populatedDeque(SIZE);
1127 >        Thread t = new Thread(new CheckedRunnable() {
1128 >            public void realRun() throws InterruptedException {
1129 >                for (int i = 0; i < SIZE; ++i)
1130 >                    assertEquals(SIZE - 1 - i, q.takeLast());
1131 >                try {
1132 >                    q.takeLast();
1133 >                    shouldThrow();
1134 >                } catch (InterruptedException success) {}
1135 >            }});
1136  
1137 +        t.start();
1138 +        Thread.sleep(SHORT_DELAY_MS);
1139 +        t.interrupt();
1140 +        t.join();
1141 +    }
1142  
1143      /**
1144       * timed pollLast with zero timeout succeeds when non-empty, else times out
1145       */
1146 <    public void testTimedPollLast0() {
1147 <        try {
1148 <            LinkedBlockingDeque q = populatedDeque(SIZE);
1149 <            for (int i = 0; i < SIZE; ++i) {
1319 <                assertEquals(SIZE-i-1, ((Integer)q.pollLast(0, TimeUnit.MILLISECONDS)).intValue());
1320 <            }
1321 <            assertNull(q.pollLast(0, TimeUnit.MILLISECONDS));
1322 <        } catch (InterruptedException e) {
1323 <            unexpectedException();
1146 >    public void testTimedPollLast0() throws InterruptedException {
1147 >        LinkedBlockingDeque q = populatedDeque(SIZE);
1148 >        for (int i = 0; i < SIZE; ++i) {
1149 >            assertEquals(SIZE-i-1, q.pollLast(0, MILLISECONDS));
1150          }
1151 +        assertNull(q.pollLast(0, MILLISECONDS));
1152      }
1153  
1154      /**
1155       * timed pollLast with nonzero timeout succeeds when non-empty, else times out
1156       */
1157 <    public void testTimedPollLast() {
1158 <        try {
1159 <            LinkedBlockingDeque q = populatedDeque(SIZE);
1160 <            for (int i = 0; i < SIZE; ++i) {
1334 <                assertEquals(SIZE-i-1, ((Integer)q.pollLast(SHORT_DELAY_MS, TimeUnit.MILLISECONDS)).intValue());
1335 <            }
1336 <            assertNull(q.pollLast(SHORT_DELAY_MS, TimeUnit.MILLISECONDS));
1337 <        } catch (InterruptedException e) {
1338 <            unexpectedException();
1157 >    public void testTimedPollLast() throws InterruptedException {
1158 >        LinkedBlockingDeque q = populatedDeque(SIZE);
1159 >        for (int i = 0; i < SIZE; ++i) {
1160 >            assertEquals(SIZE-i-1, q.pollLast(SHORT_DELAY_MS, MILLISECONDS));
1161          }
1162 +        assertNull(q.pollLast(SHORT_DELAY_MS, MILLISECONDS));
1163      }
1164  
1165      /**
1166       * Interrupted timed pollLast throws InterruptedException instead of
1167       * returning timeout status
1168       */
1169 <    public void testInterruptedTimedPollLast() {
1170 <        Thread t = new Thread(new Runnable() {
1171 <                public void run() {
1172 <                    try {
1173 <                        LinkedBlockingDeque q = populatedDeque(SIZE);
1174 <                        for (int i = 0; i < SIZE; ++i) {
1175 <                            threadAssertEquals(SIZE-i-1, ((Integer)q.pollLast(SHORT_DELAY_MS, TimeUnit.MILLISECONDS)).intValue());
1176 <                        }
1177 <                        threadAssertNull(q.pollLast(SHORT_DELAY_MS, TimeUnit.MILLISECONDS));
1178 <                    } catch (InterruptedException success) {
1179 <                    }
1180 <                }});
1181 <        t.start();
1182 <        try {
1183 <           Thread.sleep(SHORT_DELAY_MS);
1184 <           t.interrupt();
1185 <           t.join();
1363 <        }
1364 <        catch (InterruptedException ie) {
1365 <            unexpectedException();
1366 <        }
1169 >    public void testInterruptedTimedPollLast() throws InterruptedException {
1170 >        Thread t = new Thread(new CheckedRunnable() {
1171 >            public void realRun() throws InterruptedException {
1172 >                LinkedBlockingDeque q = populatedDeque(SIZE);
1173 >                for (int i = 0; i < SIZE; ++i) {
1174 >                    assertEquals(SIZE-i-1, q.pollLast(SHORT_DELAY_MS, MILLISECONDS));
1175 >                }
1176 >                try {
1177 >                    q.pollLast(SMALL_DELAY_MS, MILLISECONDS);
1178 >                    shouldThrow();
1179 >                } catch (InterruptedException success) {}
1180 >            }});
1181 >
1182 >        t.start();
1183 >        Thread.sleep(SHORT_DELAY_MS);
1184 >        t.interrupt();
1185 >        t.join();
1186      }
1187  
1188      /**
1189       *  timed poll before a delayed offerLast fails; after offerLast succeeds;
1190       *  on interruption throws
1191       */
1192 <    public void testTimedPollWithOfferLast() {
1192 >    public void testTimedPollWithOfferLast() throws InterruptedException {
1193          final LinkedBlockingDeque q = new LinkedBlockingDeque(2);
1194 <        Thread t = new Thread(new Runnable() {
1195 <                public void run() {
1196 <                    try {
1197 <                        threadAssertNull(q.poll(SHORT_DELAY_MS, TimeUnit.MILLISECONDS));
1198 <                        q.poll(LONG_DELAY_MS, TimeUnit.MILLISECONDS);
1199 <                        q.poll(LONG_DELAY_MS, TimeUnit.MILLISECONDS);
1200 <                        threadShouldThrow();
1201 <                    } catch (InterruptedException success) { }
1202 <                }
1203 <            });
1204 <        try {
1205 <            t.start();
1206 <            Thread.sleep(SMALL_DELAY_MS);
1207 <            assertTrue(q.offerLast(zero, SHORT_DELAY_MS, TimeUnit.MILLISECONDS));
1208 <            t.interrupt();
1390 <            t.join();
1391 <        } catch (Exception e) {
1392 <            unexpectedException();
1393 <        }
1194 >        Thread t = new Thread(new CheckedRunnable() {
1195 >            public void realRun() throws InterruptedException {
1196 >                assertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS));
1197 >                assertSame(zero, q.poll(LONG_DELAY_MS, MILLISECONDS));
1198 >                try {
1199 >                    q.poll(LONG_DELAY_MS, MILLISECONDS);
1200 >                    shouldThrow();
1201 >                } catch (InterruptedException success) {}
1202 >            }});
1203 >
1204 >        t.start();
1205 >        Thread.sleep(SMALL_DELAY_MS);
1206 >        assertTrue(q.offerLast(zero, SHORT_DELAY_MS, MILLISECONDS));
1207 >        t.interrupt();
1208 >        t.join();
1209      }
1210  
1211  
# Line 1400 | Line 1215 | public class LinkedBlockingDequeTest ext
1215      public void testElement() {
1216          LinkedBlockingDeque q = populatedDeque(SIZE);
1217          for (int i = 0; i < SIZE; ++i) {
1218 <            assertEquals(i, ((Integer)q.element()).intValue());
1218 >            assertEquals(i, q.element());
1219              q.poll();
1220          }
1221          try {
1222              q.element();
1223              shouldThrow();
1224 <        }
1410 <        catch (NoSuchElementException success) {}
1224 >        } catch (NoSuchElementException success) {}
1225      }
1226  
1227      /**
# Line 1505 | Line 1319 | public class LinkedBlockingDequeTest ext
1319      /**
1320       * toArray contains all elements
1321       */
1322 <    public void testToArray() {
1322 >    public void testToArray() throws InterruptedException{
1323          LinkedBlockingDeque q = populatedDeque(SIZE);
1324          Object[] o = q.toArray();
1511        try {
1325          for (int i = 0; i < o.length; i++)
1326              assertEquals(o[i], q.take());
1514        } catch (InterruptedException e) {
1515            unexpectedException();
1516        }
1327      }
1328  
1329      /**
1330       * toArray(a) contains all elements
1331       */
1332 <    public void testToArray2() {
1332 >    public void testToArray2() throws InterruptedException {
1333          LinkedBlockingDeque q = populatedDeque(SIZE);
1334          Integer[] ints = new Integer[SIZE];
1335          ints = (Integer[])q.toArray(ints);
1336 <        try {
1337 <            for (int i = 0; i < ints.length; i++)
1528 <                assertEquals(ints[i], q.take());
1529 <        } catch (InterruptedException e) {
1530 <            unexpectedException();
1531 <        }
1336 >        for (int i = 0; i < ints.length; i++)
1337 >            assertEquals(ints[i], q.take());
1338      }
1339  
1340      /**
1341       * toArray(null) throws NPE
1342       */
1343      public void testToArray_BadArg() {
1344 +        LinkedBlockingDeque q = populatedDeque(SIZE);
1345          try {
1539            LinkedBlockingDeque q = populatedDeque(SIZE);
1346              Object o[] = q.toArray(null);
1347              shouldThrow();
1348          } catch (NullPointerException success) {}
# Line 1546 | Line 1352 | public class LinkedBlockingDequeTest ext
1352       * toArray with incompatible array type throws CCE
1353       */
1354      public void testToArray1_BadArg() {
1355 +        LinkedBlockingDeque q = populatedDeque(SIZE);
1356          try {
1357 <            LinkedBlockingDeque q = populatedDeque(SIZE);
1551 <            Object o[] = q.toArray(new String[10] );
1357 >            Object o[] = q.toArray(new String[10]);
1358              shouldThrow();
1359 <        } catch (ArrayStoreException  success) {}
1359 >        } catch (ArrayStoreException success) {}
1360      }
1361  
1362  
1363      /**
1364       * iterator iterates through all elements
1365       */
1366 <    public void testIterator() {
1366 >    public void testIterator() throws InterruptedException {
1367          LinkedBlockingDeque q = populatedDeque(SIZE);
1368          Iterator it = q.iterator();
1369 <        try {
1370 <            while (it.hasNext()) {
1565 <                assertEquals(it.next(), q.take());
1566 <            }
1567 <        } catch (InterruptedException e) {
1568 <            unexpectedException();
1369 >        while (it.hasNext()) {
1370 >            assertEquals(it.next(), q.take());
1371          }
1372      }
1373  
1374      /**
1375       * iterator.remove removes current element
1376       */
1377 <    public void testIteratorRemove () {
1377 >    public void testIteratorRemove() {
1378          final LinkedBlockingDeque q = new LinkedBlockingDeque(3);
1379          q.add(two);
1380          q.add(one);
# Line 1583 | Line 1385 | public class LinkedBlockingDequeTest ext
1385          it.remove();
1386  
1387          it = q.iterator();
1388 <        assertEquals(it.next(), one);
1389 <        assertEquals(it.next(), three);
1388 >        assertSame(it.next(), one);
1389 >        assertSame(it.next(), three);
1390          assertFalse(it.hasNext());
1391      }
1392  
# Line 1600 | Line 1402 | public class LinkedBlockingDequeTest ext
1402          assertEquals(0, q.remainingCapacity());
1403          int k = 0;
1404          for (Iterator it = q.iterator(); it.hasNext();) {
1405 <            int i = ((Integer)(it.next())).intValue();
1604 <            assertEquals(++k, i);
1405 >            assertEquals(++k, it.next());
1406          }
1407          assertEquals(3, k);
1408      }
# Line 1609 | Line 1410 | public class LinkedBlockingDequeTest ext
1410      /**
1411       * Modifications do not cause iterators to fail
1412       */
1413 <    public void testWeaklyConsistentIteration () {
1413 >    public void testWeaklyConsistentIteration() {
1414          final LinkedBlockingDeque q = new LinkedBlockingDeque(3);
1415          q.add(one);
1416          q.add(two);
1417          q.add(three);
1418 <        try {
1419 <            for (Iterator it = q.iterator(); it.hasNext();) {
1420 <                q.remove();
1620 <                it.next();
1621 <            }
1622 <        }
1623 <        catch (ConcurrentModificationException e) {
1624 <            unexpectedException();
1418 >        for (Iterator it = q.iterator(); it.hasNext();) {
1419 >            q.remove();
1420 >            it.next();
1421          }
1422          assertEquals(0, q.size());
1423      }
# Line 1642 | Line 1438 | public class LinkedBlockingDequeTest ext
1438          assertFalse(it.hasNext());
1439          try {
1440              it.next();
1441 <        } catch (NoSuchElementException success) {
1442 <        }
1441 >            shouldThrow();
1442 >        } catch (NoSuchElementException success) {}
1443      }
1444  
1445      /**
# Line 1657 | Line 1453 | public class LinkedBlockingDequeTest ext
1453              q.add(new Integer(1));
1454              int k = 0;
1455              for (Iterator it = q.descendingIterator(); it.hasNext();) {
1456 <                int i = ((Integer)(it.next())).intValue();
1661 <                assertEquals(++k, i);
1456 >                assertEquals(++k, it.next());
1457              }
1458  
1459              assertEquals(3, k);
# Line 1671 | Line 1466 | public class LinkedBlockingDequeTest ext
1466      /**
1467       * descendingIterator.remove removes current element
1468       */
1469 <    public void testDescendingIteratorRemove () {
1469 >    public void testDescendingIteratorRemove() {
1470          final LinkedBlockingDeque q = new LinkedBlockingDeque();
1471          for (int iters = 0; iters < 100; ++iters) {
1472              q.add(new Integer(3));
# Line 1711 | Line 1506 | public class LinkedBlockingDequeTest ext
1506          q.add(one);
1507          q.add(two);
1508          ExecutorService executor = Executors.newFixedThreadPool(2);
1509 <        executor.execute(new Runnable() {
1510 <            public void run() {
1511 <                threadAssertFalse(q.offer(three));
1512 <                try {
1513 <                    threadAssertTrue(q.offer(three, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS));
1514 <                    threadAssertEquals(0, q.remainingCapacity());
1515 <                }
1516 <                catch (InterruptedException e) {
1517 <                    threadUnexpectedException();
1518 <                }
1519 <            }
1520 <        });
1726 <
1727 <        executor.execute(new Runnable() {
1728 <            public void run() {
1729 <                try {
1730 <                    Thread.sleep(SMALL_DELAY_MS);
1731 <                    threadAssertEquals(one, q.take());
1732 <                }
1733 <                catch (InterruptedException e) {
1734 <                    threadUnexpectedException();
1735 <                }
1736 <            }
1737 <        });
1509 >        executor.execute(new CheckedRunnable() {
1510 >            public void realRun() throws InterruptedException {
1511 >                assertFalse(q.offer(three));
1512 >                assertTrue(q.offer(three, MEDIUM_DELAY_MS, MILLISECONDS));
1513 >                assertEquals(0, q.remainingCapacity());
1514 >            }});
1515 >
1516 >        executor.execute(new CheckedRunnable() {
1517 >            public void realRun() throws InterruptedException {
1518 >                Thread.sleep(SMALL_DELAY_MS);
1519 >                assertSame(one, q.take());
1520 >            }});
1521  
1522          joinPool(executor);
1523      }
# Line 1745 | Line 1528 | public class LinkedBlockingDequeTest ext
1528      public void testPollInExecutor() {
1529          final LinkedBlockingDeque q = new LinkedBlockingDeque(2);
1530          ExecutorService executor = Executors.newFixedThreadPool(2);
1531 <        executor.execute(new Runnable() {
1532 <            public void run() {
1533 <                threadAssertNull(q.poll());
1534 <                try {
1535 <                    threadAssertTrue(null != q.poll(MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS));
1536 <                    threadAssertTrue(q.isEmpty());
1537 <                }
1538 <                catch (InterruptedException e) {
1539 <                    threadUnexpectedException();
1540 <                }
1541 <            }
1542 <        });
1760 <
1761 <        executor.execute(new Runnable() {
1762 <            public void run() {
1763 <                try {
1764 <                    Thread.sleep(SMALL_DELAY_MS);
1765 <                    q.put(one);
1766 <                }
1767 <                catch (InterruptedException e) {
1768 <                    threadUnexpectedException();
1769 <                }
1770 <            }
1771 <        });
1531 >        executor.execute(new CheckedRunnable() {
1532 >            public void realRun() throws InterruptedException {
1533 >                assertNull(q.poll());
1534 >                assertSame(one, q.poll(MEDIUM_DELAY_MS, MILLISECONDS));
1535 >                assertTrue(q.isEmpty());
1536 >            }});
1537 >
1538 >        executor.execute(new CheckedRunnable() {
1539 >            public void realRun() throws InterruptedException {
1540 >                Thread.sleep(SMALL_DELAY_MS);
1541 >                q.put(one);
1542 >            }});
1543  
1544          joinPool(executor);
1545      }
# Line 1776 | Line 1547 | public class LinkedBlockingDequeTest ext
1547      /**
1548       * A deserialized serialized deque has same elements in same order
1549       */
1550 <    public void testSerialization() {
1550 >    public void testSerialization() throws Exception {
1551          LinkedBlockingDeque q = populatedDeque(SIZE);
1552  
1553 <        try {
1554 <            ByteArrayOutputStream bout = new ByteArrayOutputStream(10000);
1555 <            ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout));
1556 <            out.writeObject(q);
1557 <            out.close();
1558 <
1559 <            ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
1560 <            ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin));
1561 <            LinkedBlockingDeque r = (LinkedBlockingDeque)in.readObject();
1562 <            assertEquals(q.size(), r.size());
1563 <            while (!q.isEmpty())
1793 <                assertEquals(q.remove(), r.remove());
1794 <        } catch (Exception e) {
1795 <            unexpectedException();
1796 <        }
1553 >        ByteArrayOutputStream bout = new ByteArrayOutputStream(10000);
1554 >        ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout));
1555 >        out.writeObject(q);
1556 >        out.close();
1557 >
1558 >        ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
1559 >        ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin));
1560 >        LinkedBlockingDeque r = (LinkedBlockingDeque)in.readObject();
1561 >        assertEquals(q.size(), r.size());
1562 >        while (!q.isEmpty())
1563 >            assertEquals(q.remove(), r.remove());
1564      }
1565  
1566      /**
# Line 1804 | Line 1571 | public class LinkedBlockingDequeTest ext
1571          try {
1572              q.drainTo(null);
1573              shouldThrow();
1574 <        } catch (NullPointerException success) {
1808 <        }
1574 >        } catch (NullPointerException success) {}
1575      }
1576  
1577      /**
# Line 1816 | Line 1582 | public class LinkedBlockingDequeTest ext
1582          try {
1583              q.drainTo(q);
1584              shouldThrow();
1585 <        } catch (IllegalArgumentException success) {
1820 <        }
1585 >        } catch (IllegalArgumentException success) {}
1586      }
1587  
1588      /**
# Line 1847 | Line 1612 | public class LinkedBlockingDequeTest ext
1612      /**
1613       * drainTo empties full deque, unblocking a waiting put.
1614       */
1615 <    public void testDrainToWithActivePut() {
1615 >    public void testDrainToWithActivePut() throws InterruptedException {
1616          final LinkedBlockingDeque q = populatedDeque(SIZE);
1617 <        Thread t = new Thread(new Runnable() {
1618 <                public void run() {
1619 <                    try {
1620 <                        q.put(new Integer(SIZE+1));
1621 <                    } catch (InterruptedException ie) {
1622 <                        threadUnexpectedException();
1623 <                    }
1624 <                }
1625 <            });
1626 <        try {
1627 <            t.start();
1628 <            ArrayList l = new ArrayList();
1629 <            q.drainTo(l);
1865 <            assertTrue(l.size() >= SIZE);
1866 <            for (int i = 0; i < SIZE; ++i)
1867 <                assertEquals(l.get(i), new Integer(i));
1868 <            t.join();
1869 <            assertTrue(q.size() + l.size() >= SIZE);
1870 <        } catch (Exception e) {
1871 <            unexpectedException();
1872 <        }
1617 >        Thread t = new Thread(new CheckedRunnable() {
1618 >            public void realRun() throws InterruptedException {
1619 >                q.put(new Integer(SIZE+1));
1620 >            }});
1621 >
1622 >        t.start();
1623 >        ArrayList l = new ArrayList();
1624 >        q.drainTo(l);
1625 >        assertTrue(l.size() >= SIZE);
1626 >        for (int i = 0; i < SIZE; ++i)
1627 >            assertEquals(l.get(i), new Integer(i));
1628 >        t.join();
1629 >        assertTrue(q.size() + l.size() >= SIZE);
1630      }
1631  
1632      /**
# Line 1880 | Line 1637 | public class LinkedBlockingDequeTest ext
1637          try {
1638              q.drainTo(null, 0);
1639              shouldThrow();
1640 <        } catch (NullPointerException success) {
1884 <        }
1640 >        } catch (NullPointerException success) {}
1641      }
1642  
1643      /**
# Line 1892 | Line 1648 | public class LinkedBlockingDequeTest ext
1648          try {
1649              q.drainTo(q, 0);
1650              shouldThrow();
1651 <        } catch (IllegalArgumentException success) {
1896 <        }
1651 >        } catch (IllegalArgumentException success) {}
1652      }
1653  
1654      /**

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines