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.3 by dl, Fri Sep 16 11:16:03 2005 UTC vs.
Revision 1.11 by jsr166, Sat Nov 21 10:25:05 2009 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() {
19 <        return new TestSuite(LinkedBlockingDequeTest.class);
19 >        return new TestSuite(LinkedBlockingDequeTest.class);
20      }
21  
22      /**
# Line 25 | Line 26 | public class LinkedBlockingDequeTest ext
26      private LinkedBlockingDeque populatedDeque(int n) {
27          LinkedBlockingDeque q = new LinkedBlockingDeque(n);
28          assertTrue(q.isEmpty());
29 <        for(int i = 0; i < n; i++)
30 <            assertTrue(q.offer(new Integer(i)));
29 >        for (int i = 0; i < n; i++)
30 >            assertTrue(q.offer(new Integer(i)));
31          assertFalse(q.isEmpty());
32          assertEquals(0, q.remainingCapacity());
33 <        assertEquals(n, q.size());
33 >        assertEquals(n, q.size());
34          return q;
35      }
36  
# Line 66 | Line 67 | public class LinkedBlockingDequeTest ext
67       * offer(null) throws NPE
68       */
69      public void testOfferFirstNull() {
70 <        try {
70 >        try {
71              LinkedBlockingDeque q = new LinkedBlockingDeque();
72              q.offerFirst(null);
73              shouldThrow();
74 <        } catch (NullPointerException success) {
74 <        }  
74 >        } catch (NullPointerException success) {}
75      }
76  
77      /**
78 <     * OfferFirst succeeds
78 >     * OfferFirst succeeds
79       */
80      public void testOfferFirst() {
81          LinkedBlockingDeque q = new LinkedBlockingDeque();
# Line 84 | Line 84 | public class LinkedBlockingDequeTest ext
84      }
85  
86      /**
87 <     * OfferLast succeeds
87 >     * OfferLast succeeds
88       */
89      public void testOfferLast() {
90          LinkedBlockingDeque q = new LinkedBlockingDeque();
# Line 100 | Line 100 | public class LinkedBlockingDequeTest ext
100          for (int i = 0; i < SIZE; ++i) {
101              assertEquals(i, ((Integer)q.pollFirst()).intValue());
102          }
103 <        assertNull(q.pollFirst());
103 >        assertNull(q.pollFirst());
104      }
105  
106      /**
# Line 111 | Line 111 | public class LinkedBlockingDequeTest ext
111          for (int i = SIZE-1; i >= 0; --i) {
112              assertEquals(i, ((Integer)q.pollLast()).intValue());
113          }
114 <        assertNull(q.pollLast());
114 >        assertNull(q.pollLast());
115      }
116  
117      /**
# Line 125 | Line 125 | public class LinkedBlockingDequeTest ext
125              assertTrue(q.peekFirst() == null ||
126                         i != ((Integer)q.peekFirst()).intValue());
127          }
128 <        assertNull(q.peekFirst());
128 >        assertNull(q.peekFirst());
129      }
130  
131      /**
# Line 139 | Line 139 | public class LinkedBlockingDequeTest ext
139              assertTrue(q.peek() == null ||
140                         i != ((Integer)q.peek()).intValue());
141          }
142 <        assertNull(q.peek());
142 >        assertNull(q.peek());
143      }
144  
145      /**
# Line 153 | Line 153 | public class LinkedBlockingDequeTest ext
153              assertTrue(q.peekLast() == null ||
154                         i != ((Integer)q.peekLast()).intValue());
155          }
156 <        assertNull(q.peekLast());
156 >        assertNull(q.peekLast());
157      }
158  
159      /**
# Line 168 | Line 168 | public class LinkedBlockingDequeTest ext
168          try {
169              q.getFirst();
170              shouldThrow();
171 <        }
172 <        catch (NoSuchElementException success) {}
171 >        } catch (NoSuchElementException success) {}
172      }
173  
174      /**
# Line 184 | Line 183 | public class LinkedBlockingDequeTest ext
183          try {
184              q.getLast();
185              shouldThrow();
186 <        }
187 <        catch (NoSuchElementException success) {}
189 <        assertNull(q.peekLast());
186 >        } catch (NoSuchElementException success) {}
187 >        assertNull(q.peekLast());
188      }
189  
190      /**
# Line 200 | Line 198 | public class LinkedBlockingDequeTest ext
198          try {
199              q.removeFirst();
200              shouldThrow();
201 <        } catch (NoSuchElementException success){
204 <        }  
201 >        } catch (NoSuchElementException success) {}
202      }
203  
204      /**
# Line 215 | Line 212 | public class LinkedBlockingDequeTest ext
212          try {
213              q.remove();
214              shouldThrow();
215 <        } catch (NoSuchElementException success){
219 <        }  
215 >        } catch (NoSuchElementException success) {}
216      }
217  
218      /**
# Line 255 | Line 251 | public class LinkedBlockingDequeTest ext
251      public void testAddFirst() {
252          LinkedBlockingDeque q = populatedDeque(3);
253          q.pollLast();
254 <        q.addFirst(four);
255 <        assertEquals(four,q.peekFirst());
256 <    }  
254 >        q.addFirst(four);
255 >        assertEquals(four,q.peekFirst());
256 >    }
257  
258      /**
259       * peekLast returns element inserted with addLast
# Line 265 | Line 261 | public class LinkedBlockingDequeTest ext
261      public void testAddLast() {
262          LinkedBlockingDeque q = populatedDeque(3);
263          q.pollLast();
264 <        q.addLast(four);
265 <        assertEquals(four,q.peekLast());
266 <    }  
264 >        q.addLast(four);
265 >        assertEquals(four,q.peekLast());
266 >    }
267  
268  
269      /**
# Line 280 | Line 276 | public class LinkedBlockingDequeTest ext
276      }
277  
278      /**
279 <     * Constructor throws IAE if  capacity argument nonpositive
279 >     * Constructor throws IAE if capacity argument nonpositive
280       */
281      public void testConstructor2() {
282          try {
283              LinkedBlockingDeque q = new LinkedBlockingDeque(0);
284              shouldThrow();
285 <        }
290 <        catch (IllegalArgumentException success) {}
285 >        } catch (IllegalArgumentException success) {}
286      }
287  
288      /**
# Line 297 | Line 292 | public class LinkedBlockingDequeTest ext
292          try {
293              LinkedBlockingDeque q = new LinkedBlockingDeque(null);
294              shouldThrow();
295 <        }
301 <        catch (NullPointerException success) {}
295 >        } catch (NullPointerException success) {}
296      }
297  
298      /**
# Line 309 | Line 303 | public class LinkedBlockingDequeTest ext
303              Integer[] ints = new Integer[SIZE];
304              LinkedBlockingDeque q = new LinkedBlockingDeque(Arrays.asList(ints));
305              shouldThrow();
306 <        }
313 <        catch (NullPointerException success) {}
306 >        } catch (NullPointerException success) {}
307      }
308  
309      /**
# Line 323 | Line 316 | public class LinkedBlockingDequeTest ext
316                  ints[i] = new Integer(i);
317              LinkedBlockingDeque q = new LinkedBlockingDeque(Arrays.asList(ints));
318              shouldThrow();
319 <        }
327 <        catch (NullPointerException success) {}
319 >        } catch (NullPointerException success) {}
320      }
321  
322      /**
# Line 378 | Line 370 | public class LinkedBlockingDequeTest ext
370       * offer(null) throws NPE
371       */
372      public void testOfferNull() {
373 <        try {
373 >        try {
374              LinkedBlockingDeque q = new LinkedBlockingDeque(1);
375              q.offer(null);
376              shouldThrow();
377 <        } catch (NullPointerException success) { }  
377 >        } catch (NullPointerException success) {}
378      }
379  
380      /**
381       * add(null) throws NPE
382       */
383      public void testAddNull() {
384 <        try {
384 >        try {
385              LinkedBlockingDeque q = new LinkedBlockingDeque(1);
386              q.add(null);
387              shouldThrow();
388 <        } catch (NullPointerException success) { }  
388 >        } catch (NullPointerException success) {}
389      }
390  
391      /**
392       * push(null) throws NPE
393       */
394      public void testPushNull() {
395 <        try {
395 >        try {
396              LinkedBlockingDeque q = new LinkedBlockingDeque(1);
397              q.push(null);
398              shouldThrow();
399 <        } catch (NullPointerException success) { }  
399 >        } catch (NullPointerException success) {}
400      }
401  
402      /**
403       * push succeeds if not full; throws ISE if full
404       */
405      public void testPush() {
406 <        try {
406 >        try {
407              LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
408              for (int i = 0; i < SIZE; ++i) {
409                  Integer I = new Integer(i);
# Line 420 | Line 412 | public class LinkedBlockingDequeTest ext
412              }
413              assertEquals(0, q.remainingCapacity());
414              q.push(new Integer(SIZE));
415 <        } catch (IllegalStateException success){
416 <        }  
415 >            shouldThrow();
416 >        } catch (IllegalStateException success) {}
417      }
418  
419      /**
# Line 430 | Line 422 | public class LinkedBlockingDequeTest ext
422      public void testPushWithPeek() {
423          LinkedBlockingDeque q = populatedDeque(3);
424          q.pollLast();
425 <        q.push(four);
426 <        assertEquals(four,q.peekFirst());
427 <    }  
425 >        q.push(four);
426 >        assertEquals(four,q.peekFirst());
427 >    }
428  
429  
430      /**
# Line 446 | Line 438 | public class LinkedBlockingDequeTest ext
438          try {
439              q.pop();
440              shouldThrow();
441 <        } catch (NoSuchElementException success){
450 <        }  
441 >        } catch (NoSuchElementException success) {}
442      }
443  
444  
# Line 464 | Line 455 | public class LinkedBlockingDequeTest ext
455       * add succeeds if not full; throws ISE if full
456       */
457      public void testAdd() {
458 <        try {
458 >        try {
459              LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
460              for (int i = 0; i < SIZE; ++i) {
461                  assertTrue(q.add(new Integer(i)));
462              }
463              assertEquals(0, q.remainingCapacity());
464              q.add(new Integer(SIZE));
465 <        } catch (IllegalStateException success){
466 <        }  
465 >            shouldThrow();
466 >        } catch (IllegalStateException success) {}
467      }
468  
469      /**
# Line 483 | Line 474 | public class LinkedBlockingDequeTest ext
474              LinkedBlockingDeque q = new LinkedBlockingDeque(1);
475              q.addAll(null);
476              shouldThrow();
477 <        }
487 <        catch (NullPointerException success) {}
477 >        } catch (NullPointerException success) {}
478      }
479  
480      /**
# Line 495 | Line 485 | public class LinkedBlockingDequeTest ext
485              LinkedBlockingDeque q = populatedDeque(SIZE);
486              q.addAll(q);
487              shouldThrow();
488 <        }
499 <        catch (IllegalArgumentException success) {}
488 >        } catch (IllegalArgumentException success) {}
489      }
490  
491      /**
# Line 508 | Line 497 | public class LinkedBlockingDequeTest ext
497              Integer[] ints = new Integer[SIZE];
498              q.addAll(Arrays.asList(ints));
499              shouldThrow();
500 <        }
512 <        catch (NullPointerException success) {}
500 >        } catch (NullPointerException success) {}
501      }
502      /**
503       * addAll of a collection with any null elements throws NPE after
# Line 523 | Line 511 | public class LinkedBlockingDequeTest ext
511                  ints[i] = new Integer(i);
512              q.addAll(Arrays.asList(ints));
513              shouldThrow();
514 <        }
527 <        catch (NullPointerException success) {}
514 >        } catch (NullPointerException success) {}
515      }
516      /**
517       * addAll throws ISE if not enough room
# Line 537 | Line 524 | public class LinkedBlockingDequeTest ext
524                  ints[i] = new Integer(i);
525              q.addAll(Arrays.asList(ints));
526              shouldThrow();
527 <        }
541 <        catch (IllegalStateException success) {}
527 >        } catch (IllegalStateException success) {}
528      }
529      /**
530       * Deque contains all elements, in traversal order, of successful addAll
# Line 562 | Line 548 | public class LinkedBlockingDequeTest ext
548      /**
549       * put(null) throws NPE
550       */
551 <     public void testPutNull() {
552 <        try {
551 >    public void testPutNull() throws InterruptedException {
552 >        try {
553              LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
554              q.put(null);
555              shouldThrow();
556 <        }
557 <        catch (NullPointerException success){
572 <        }  
573 <        catch (InterruptedException ie) {
574 <            unexpectedException();
575 <        }
576 <     }
556 >        } catch (NullPointerException success) {}
557 >    }
558  
559      /**
560       * all elements successfully put are contained
561       */
562 <     public void testPut() {
563 <         try {
564 <             LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
565 <             for (int i = 0; i < SIZE; ++i) {
566 <                 Integer I = new Integer(i);
567 <                 q.put(I);
587 <                 assertTrue(q.contains(I));
588 <             }
589 <             assertEquals(0, q.remainingCapacity());
590 <         }
591 <        catch (InterruptedException ie) {
592 <            unexpectedException();
562 >    public void testPut() throws InterruptedException {
563 >        LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
564 >        for (int i = 0; i < SIZE; ++i) {
565 >            Integer I = new Integer(i);
566 >            q.put(I);
567 >            assertTrue(q.contains(I));
568          }
569 +        assertEquals(0, q.remainingCapacity());
570      }
571  
572      /**
573       * put blocks interruptibly if full
574       */
575 <    public void testBlockingPut() {
576 <        Thread t = new Thread(new Runnable() {
577 <                public void run() {
578 <                    int added = 0;
579 <                    try {
580 <                        LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
581 <                        for (int i = 0; i < SIZE; ++i) {
582 <                            q.put(new Integer(i));
583 <                            ++added;
584 <                        }
585 <                        q.put(new Integer(SIZE));
586 <                        threadShouldThrow();
587 <                    } catch (InterruptedException ie){
588 <                        threadAssertEquals(added, SIZE);
589 <                    }  
590 <                }});
591 <        t.start();
592 <        try {
593 <           Thread.sleep(SHORT_DELAY_MS);
594 <           t.interrupt();
595 <           t.join();
620 <        }
621 <        catch (InterruptedException ie) {
622 <            unexpectedException();
623 <        }
575 >    public void testBlockingPut() throws InterruptedException {
576 >        Thread t = new Thread(new CheckedRunnable() {
577 >            public void realRun() {
578 >                int added = 0;
579 >                try {
580 >                    LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
581 >                    for (int i = 0; i < SIZE; ++i) {
582 >                        q.put(new Integer(i));
583 >                        ++added;
584 >                    }
585 >                    q.put(new Integer(SIZE));
586 >                    threadShouldThrow();
587 >                } catch (InterruptedException success) {
588 >                    threadAssertEquals(added, SIZE);
589 >                }
590 >            }});
591 >
592 >        t.start();
593 >        Thread.sleep(SHORT_DELAY_MS);
594 >        t.interrupt();
595 >        t.join();
596      }
597  
598      /**
599       * put blocks waiting for take when full
600       */
601 <    public void testPutWithTake() {
601 >    public void testPutWithTake() throws InterruptedException {
602          final LinkedBlockingDeque q = new LinkedBlockingDeque(2);
603 <        Thread t = new Thread(new Runnable() {
604 <                public void run() {
605 <                    int added = 0;
606 <                    try {
607 <                        q.put(new Object());
608 <                        ++added;
609 <                        q.put(new Object());
610 <                        ++added;
611 <                        q.put(new Object());
612 <                        ++added;
613 <                        q.put(new Object());
614 <                        ++added;
615 <                        threadShouldThrow();
616 <                    } catch (InterruptedException e){
617 <                        threadAssertTrue(added >= 2);
646 <                    }
603 >        Thread t = new Thread(new CheckedRunnable() {
604 >            public void realRun() {
605 >                int added = 0;
606 >                try {
607 >                    q.put(new Object());
608 >                    ++added;
609 >                    q.put(new Object());
610 >                    ++added;
611 >                    q.put(new Object());
612 >                    ++added;
613 >                    q.put(new Object());
614 >                    ++added;
615 >                    threadShouldThrow();
616 >                } catch (InterruptedException success) {
617 >                    threadAssertTrue(added >= 2);
618                  }
619 <            });
620 <        try {
621 <            t.start();
622 <            Thread.sleep(SHORT_DELAY_MS);
623 <            q.take();
624 <            t.interrupt();
625 <            t.join();
655 <        } catch (Exception e){
656 <            unexpectedException();
657 <        }
619 >            }});
620 >
621 >        t.start();
622 >        Thread.sleep(SHORT_DELAY_MS);
623 >        q.take();
624 >        t.interrupt();
625 >        t.join();
626      }
627  
628      /**
629       * timed offer times out if full and elements not taken
630       */
631 <    public void testTimedOffer() {
631 >    public void testTimedOffer() throws InterruptedException {
632          final LinkedBlockingDeque q = new LinkedBlockingDeque(2);
633 <        Thread t = new Thread(new Runnable() {
634 <                public void run() {
635 <                    try {
636 <                        q.put(new Object());
637 <                        q.put(new Object());
638 <                        threadAssertFalse(q.offer(new Object(), SHORT_DELAY_MS, TimeUnit.MILLISECONDS));
639 <                        q.offer(new Object(), LONG_DELAY_MS, TimeUnit.MILLISECONDS);
640 <                        threadShouldThrow();
641 <                    } catch (InterruptedException success){}
642 <                }
643 <            });
644 <        
677 <        try {
678 <            t.start();
679 <            Thread.sleep(SMALL_DELAY_MS);
680 <            t.interrupt();
681 <            t.join();
682 <        } catch (Exception e){
683 <            unexpectedException();
684 <        }
633 >        Thread t = new ThreadShouldThrow(InterruptedException.class) {
634 >            public void realRun() throws InterruptedException {
635 >                q.put(new Object());
636 >                q.put(new Object());
637 >                threadAssertFalse(q.offer(new Object(), SHORT_DELAY_MS, MILLISECONDS));
638 >                q.offer(new Object(), LONG_DELAY_MS, MILLISECONDS);
639 >            }};
640 >
641 >        t.start();
642 >        Thread.sleep(SMALL_DELAY_MS);
643 >        t.interrupt();
644 >        t.join();
645      }
646  
647      /**
648       * take retrieves elements in FIFO order
649       */
650 <    public void testTake() {
651 <        try {
652 <            LinkedBlockingDeque q = populatedDeque(SIZE);
653 <            for (int i = 0; i < SIZE; ++i) {
654 <                assertEquals(i, ((Integer)q.take()).intValue());
695 <            }
696 <        } catch (InterruptedException e){
697 <            unexpectedException();
698 <        }  
650 >    public void testTake() throws InterruptedException {
651 >        LinkedBlockingDeque q = populatedDeque(SIZE);
652 >        for (int i = 0; i < SIZE; ++i) {
653 >            assertEquals(i, ((Integer)q.take()).intValue());
654 >        }
655      }
656  
657      /**
658       * take blocks interruptibly when empty
659       */
660 <    public void testTakeFromEmpty() {
660 >    public void testTakeFromEmpty() throws InterruptedException {
661          final LinkedBlockingDeque q = new LinkedBlockingDeque(2);
662 <        Thread t = new Thread(new Runnable() {
663 <                public void run() {
664 <                    try {
665 <                        q.take();
666 <                        threadShouldThrow();
667 <                    } catch (InterruptedException success){ }                
668 <                }
669 <            });
670 <        try {
715 <            t.start();
716 <            Thread.sleep(SHORT_DELAY_MS);
717 <            t.interrupt();
718 <            t.join();
719 <        } catch (Exception e){
720 <            unexpectedException();
721 <        }
662 >        Thread t = new ThreadShouldThrow(InterruptedException.class) {
663 >            public void realRun() throws InterruptedException {
664 >                q.take();
665 >            }};
666 >
667 >        t.start();
668 >        Thread.sleep(SHORT_DELAY_MS);
669 >        t.interrupt();
670 >        t.join();
671      }
672  
673      /**
674       * Take removes existing elements until empty, then blocks interruptibly
675       */
676 <    public void testBlockingTake() {
677 <        Thread t = new Thread(new Runnable() {
678 <                public void run() {
679 <                    try {
680 <                        LinkedBlockingDeque q = populatedDeque(SIZE);
681 <                        for (int i = 0; i < SIZE; ++i) {
682 <                            assertEquals(i, ((Integer)q.take()).intValue());
683 <                        }
684 <                        q.take();
685 <                        threadShouldThrow();
686 <                    } catch (InterruptedException success){
687 <                    }  
688 <                }});
689 <        t.start();
741 <        try {
742 <           Thread.sleep(SHORT_DELAY_MS);
743 <           t.interrupt();
744 <           t.join();
745 <        }
746 <        catch (InterruptedException ie) {
747 <            unexpectedException();
748 <        }
676 >    public void testBlockingTake() throws InterruptedException {
677 >        Thread t = new ThreadShouldThrow(InterruptedException.class) {
678 >            public void realRun() throws InterruptedException {
679 >                LinkedBlockingDeque q = populatedDeque(SIZE);
680 >                for (int i = 0; i < SIZE; ++i) {
681 >                    assertEquals(i, ((Integer)q.take()).intValue());
682 >                }
683 >                q.take();
684 >            }};
685 >
686 >        t.start();
687 >        Thread.sleep(SHORT_DELAY_MS);
688 >        t.interrupt();
689 >        t.join();
690      }
691  
692  
# Line 757 | Line 698 | public class LinkedBlockingDequeTest ext
698          for (int i = 0; i < SIZE; ++i) {
699              assertEquals(i, ((Integer)q.poll()).intValue());
700          }
701 <        assertNull(q.poll());
701 >        assertNull(q.poll());
702      }
703  
704      /**
705       * timed poll with zero timeout succeeds when non-empty, else times out
706       */
707 <    public void testTimedPoll0() {
708 <        try {
709 <            LinkedBlockingDeque q = populatedDeque(SIZE);
710 <            for (int i = 0; i < SIZE; ++i) {
711 <                assertEquals(i, ((Integer)q.poll(0, TimeUnit.MILLISECONDS)).intValue());
712 <            }
772 <            assertNull(q.poll(0, TimeUnit.MILLISECONDS));
773 <        } catch (InterruptedException e){
774 <            unexpectedException();
775 <        }  
707 >    public void testTimedPoll0() throws InterruptedException {
708 >        LinkedBlockingDeque q = populatedDeque(SIZE);
709 >        for (int i = 0; i < SIZE; ++i) {
710 >            assertEquals(i, ((Integer)q.poll(0, MILLISECONDS)).intValue());
711 >        }
712 >        assertNull(q.poll(0, MILLISECONDS));
713      }
714  
715      /**
716       * timed poll with nonzero timeout succeeds when non-empty, else times out
717       */
718 <    public void testTimedPoll() {
719 <        try {
720 <            LinkedBlockingDeque q = populatedDeque(SIZE);
721 <            for (int i = 0; i < SIZE; ++i) {
722 <                assertEquals(i, ((Integer)q.poll(SHORT_DELAY_MS, TimeUnit.MILLISECONDS)).intValue());
723 <            }
787 <            assertNull(q.poll(SHORT_DELAY_MS, TimeUnit.MILLISECONDS));
788 <        } catch (InterruptedException e){
789 <            unexpectedException();
790 <        }  
718 >    public void testTimedPoll() throws InterruptedException {
719 >        LinkedBlockingDeque q = populatedDeque(SIZE);
720 >        for (int i = 0; i < SIZE; ++i) {
721 >            assertEquals(i, ((Integer)q.poll(SHORT_DELAY_MS, MILLISECONDS)).intValue());
722 >        }
723 >        assertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS));
724      }
725  
726      /**
727       * Interrupted timed poll throws InterruptedException instead of
728       * returning timeout status
729       */
730 <    public void testInterruptedTimedPoll() {
731 <        Thread t = new Thread(new Runnable() {
732 <                public void run() {
733 <                    try {
734 <                        LinkedBlockingDeque q = populatedDeque(SIZE);
735 <                        for (int i = 0; i < SIZE; ++i) {
736 <                            threadAssertEquals(i, ((Integer)q.poll(SHORT_DELAY_MS, TimeUnit.MILLISECONDS)).intValue());
737 <                        }
738 <                        threadAssertNull(q.poll(SHORT_DELAY_MS, TimeUnit.MILLISECONDS));
739 <                    } catch (InterruptedException success){
740 <                    }  
741 <                }});
742 <        t.start();
743 <        try {
811 <           Thread.sleep(SHORT_DELAY_MS);
812 <           t.interrupt();
813 <           t.join();
814 <        }
815 <        catch (InterruptedException ie) {
816 <            unexpectedException();
817 <        }
730 >    public void testInterruptedTimedPoll() throws InterruptedException {
731 >        Thread t = new ThreadShouldThrow(InterruptedException.class) {
732 >            public void realRun() throws InterruptedException {
733 >                LinkedBlockingDeque q = populatedDeque(SIZE);
734 >                for (int i = 0; i < SIZE; ++i) {
735 >                    threadAssertEquals(i, ((Integer)q.poll(SHORT_DELAY_MS, MILLISECONDS)).intValue());
736 >                }
737 >                q.poll(SMALL_DELAY_MS, MILLISECONDS);
738 >            }};
739 >
740 >        t.start();
741 >        Thread.sleep(SHORT_DELAY_MS);
742 >        t.interrupt();
743 >        t.join();
744      }
745  
746      /**
747       *  timed poll before a delayed offer fails; after offer succeeds;
748       *  on interruption throws
749       */
750 <    public void testTimedPollWithOffer() {
750 >    public void testTimedPollWithOffer() throws InterruptedException {
751          final LinkedBlockingDeque q = new LinkedBlockingDeque(2);
752 <        Thread t = new Thread(new Runnable() {
753 <                public void run() {
754 <                    try {
755 <                        threadAssertNull(q.poll(SHORT_DELAY_MS, TimeUnit.MILLISECONDS));
756 <                        q.poll(LONG_DELAY_MS, TimeUnit.MILLISECONDS);
757 <                        q.poll(LONG_DELAY_MS, TimeUnit.MILLISECONDS);
758 <                        threadShouldThrow();
759 <                    } catch (InterruptedException success) { }                
760 <                }
761 <            });
762 <        try {
763 <            t.start();
764 <            Thread.sleep(SMALL_DELAY_MS);
839 <            assertTrue(q.offer(zero, SHORT_DELAY_MS, TimeUnit.MILLISECONDS));
840 <            t.interrupt();
841 <            t.join();
842 <        } catch (Exception e){
843 <            unexpectedException();
844 <        }
845 <    }  
752 >        Thread t = new ThreadShouldThrow(InterruptedException.class) {
753 >            public void realRun() throws InterruptedException {
754 >                threadAssertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS));
755 >                q.poll(LONG_DELAY_MS, MILLISECONDS);
756 >                q.poll(LONG_DELAY_MS, MILLISECONDS);
757 >            }};
758 >
759 >        t.start();
760 >        Thread.sleep(SMALL_DELAY_MS);
761 >        assertTrue(q.offer(zero, SHORT_DELAY_MS, MILLISECONDS));
762 >        t.interrupt();
763 >        t.join();
764 >    }
765  
766  
767      /**
768       * putFirst(null) throws NPE
769       */
770 <     public void testPutFirstNull() {
771 <        try {
770 >     public void testPutFirstNull() throws InterruptedException {
771 >        try {
772              LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
773              q.putFirst(null);
774              shouldThrow();
775 <        }
857 <        catch (NullPointerException success){
858 <        }  
859 <        catch (InterruptedException ie) {
860 <            unexpectedException();
861 <        }
775 >        } catch (NullPointerException success) {}
776       }
777  
778      /**
779       * all elements successfully putFirst are contained
780       */
781 <     public void testPutFirst() {
782 <         try {
783 <             LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
784 <             for (int i = 0; i < SIZE; ++i) {
785 <                 Integer I = new Integer(i);
786 <                 q.putFirst(I);
873 <                 assertTrue(q.contains(I));
874 <             }
875 <             assertEquals(0, q.remainingCapacity());
781 >     public void testPutFirst() throws InterruptedException {
782 >         LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
783 >         for (int i = 0; i < SIZE; ++i) {
784 >             Integer I = new Integer(i);
785 >             q.putFirst(I);
786 >             assertTrue(q.contains(I));
787           }
788 <        catch (InterruptedException ie) {
878 <            unexpectedException();
879 <        }
788 >         assertEquals(0, q.remainingCapacity());
789      }
790  
791      /**
792       * putFirst blocks interruptibly if full
793       */
794 <    public void testBlockingPutFirst() {
795 <        Thread t = new Thread(new Runnable() {
796 <                public void run() {
797 <                    int added = 0;
798 <                    try {
799 <                        LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
800 <                        for (int i = 0; i < SIZE; ++i) {
801 <                            q.putFirst(new Integer(i));
802 <                            ++added;
803 <                        }
804 <                        q.putFirst(new Integer(SIZE));
805 <                        threadShouldThrow();
806 <                    } catch (InterruptedException ie){
807 <                        threadAssertEquals(added, SIZE);
808 <                    }  
809 <                }});
810 <        t.start();
811 <        try {
812 <           Thread.sleep(SHORT_DELAY_MS);
813 <           t.interrupt();
814 <           t.join();
906 <        }
907 <        catch (InterruptedException ie) {
908 <            unexpectedException();
909 <        }
794 >    public void testBlockingPutFirst() throws InterruptedException {
795 >        Thread t = new Thread(new CheckedRunnable() {
796 >            public void realRun() {
797 >                int added = 0;
798 >                try {
799 >                    LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
800 >                    for (int i = 0; i < SIZE; ++i) {
801 >                        q.putFirst(new Integer(i));
802 >                        ++added;
803 >                    }
804 >                    q.putFirst(new Integer(SIZE));
805 >                    threadShouldThrow();
806 >                } catch (InterruptedException success) {
807 >                    threadAssertEquals(added, SIZE);
808 >                }
809 >            }});
810 >
811 >        t.start();
812 >        Thread.sleep(SHORT_DELAY_MS);
813 >        t.interrupt();
814 >        t.join();
815      }
816  
817      /**
818       * putFirst blocks waiting for take when full
819       */
820 <    public void testPutFirstWithTake() {
820 >    public void testPutFirstWithTake() throws InterruptedException {
821          final LinkedBlockingDeque q = new LinkedBlockingDeque(2);
822 <        Thread t = new Thread(new Runnable() {
823 <                public void run() {
824 <                    int added = 0;
825 <                    try {
826 <                        q.putFirst(new Object());
827 <                        ++added;
828 <                        q.putFirst(new Object());
829 <                        ++added;
830 <                        q.putFirst(new Object());
831 <                        ++added;
832 <                        q.putFirst(new Object());
833 <                        ++added;
834 <                        threadShouldThrow();
835 <                    } catch (InterruptedException e){
836 <                        threadAssertTrue(added >= 2);
932 <                    }
822 >        Thread t = new Thread(new CheckedRunnable() {
823 >            public void realRun() {
824 >                int added = 0;
825 >                try {
826 >                    q.putFirst(new Object());
827 >                    ++added;
828 >                    q.putFirst(new Object());
829 >                    ++added;
830 >                    q.putFirst(new Object());
831 >                    ++added;
832 >                    q.putFirst(new Object());
833 >                    ++added;
834 >                    threadShouldThrow();
835 >                } catch (InterruptedException success) {
836 >                    threadAssertTrue(added >= 2);
837                  }
838 <            });
839 <        try {
840 <            t.start();
841 <            Thread.sleep(SHORT_DELAY_MS);
842 <            q.take();
843 <            t.interrupt();
844 <            t.join();
941 <        } catch (Exception e){
942 <            unexpectedException();
943 <        }
838 >            }});
839 >
840 >        t.start();
841 >        Thread.sleep(SHORT_DELAY_MS);
842 >        q.take();
843 >        t.interrupt();
844 >        t.join();
845      }
846  
847      /**
848       * timed offerFirst times out if full and elements not taken
849       */
850 <    public void testTimedOfferFirst() {
850 >    public void testTimedOfferFirst() throws InterruptedException {
851          final LinkedBlockingDeque q = new LinkedBlockingDeque(2);
852 <        Thread t = new Thread(new Runnable() {
853 <                public void run() {
854 <                    try {
855 <                        q.putFirst(new Object());
856 <                        q.putFirst(new Object());
857 <                        threadAssertFalse(q.offerFirst(new Object(), SHORT_DELAY_MS, TimeUnit.MILLISECONDS));
858 <                        q.offerFirst(new Object(), LONG_DELAY_MS, TimeUnit.MILLISECONDS);
859 <                        threadShouldThrow();
860 <                    } catch (InterruptedException success){}
861 <                }
862 <            });
863 <        
963 <        try {
964 <            t.start();
965 <            Thread.sleep(SMALL_DELAY_MS);
966 <            t.interrupt();
967 <            t.join();
968 <        } catch (Exception e){
969 <            unexpectedException();
970 <        }
852 >        Thread t = new ThreadShouldThrow(InterruptedException.class) {
853 >            public void realRun() throws InterruptedException {
854 >                q.putFirst(new Object());
855 >                q.putFirst(new Object());
856 >                threadAssertFalse(q.offerFirst(new Object(), SHORT_DELAY_MS, MILLISECONDS));
857 >                q.offerFirst(new Object(), LONG_DELAY_MS, MILLISECONDS);
858 >            }};
859 >
860 >        t.start();
861 >        Thread.sleep(SMALL_DELAY_MS);
862 >        t.interrupt();
863 >        t.join();
864      }
865  
866      /**
867       * take retrieves elements in FIFO order
868       */
869 <    public void testTakeFirst() {
870 <        try {
871 <            LinkedBlockingDeque q = populatedDeque(SIZE);
872 <            for (int i = 0; i < SIZE; ++i) {
873 <                assertEquals(i, ((Integer)q.takeFirst()).intValue());
981 <            }
982 <        } catch (InterruptedException e){
983 <            unexpectedException();
984 <        }  
869 >    public void testTakeFirst() throws InterruptedException {
870 >        LinkedBlockingDeque q = populatedDeque(SIZE);
871 >        for (int i = 0; i < SIZE; ++i) {
872 >            assertEquals(i, ((Integer)q.takeFirst()).intValue());
873 >        }
874      }
875  
876      /**
877       * takeFirst blocks interruptibly when empty
878       */
879 <    public void testTakeFirstFromEmpty() {
879 >    public void testTakeFirstFromEmpty() throws InterruptedException {
880          final LinkedBlockingDeque q = new LinkedBlockingDeque(2);
881 <        Thread t = new Thread(new Runnable() {
882 <                public void run() {
883 <                    try {
884 <                        q.takeFirst();
885 <                        threadShouldThrow();
886 <                    } catch (InterruptedException success){ }                
887 <                }
888 <            });
889 <        try {
1001 <            t.start();
1002 <            Thread.sleep(SHORT_DELAY_MS);
1003 <            t.interrupt();
1004 <            t.join();
1005 <        } catch (Exception e){
1006 <            unexpectedException();
1007 <        }
881 >        Thread t = new ThreadShouldThrow(InterruptedException.class) {
882 >            public void realRun() throws InterruptedException {
883 >                q.takeFirst();
884 >            }};
885 >
886 >        t.start();
887 >        Thread.sleep(SHORT_DELAY_MS);
888 >        t.interrupt();
889 >        t.join();
890      }
891  
892      /**
893       * TakeFirst removes existing elements until empty, then blocks interruptibly
894       */
895 <    public void testBlockingTakeFirst() {
896 <        Thread t = new Thread(new Runnable() {
897 <                public void run() {
898 <                    try {
899 <                        LinkedBlockingDeque q = populatedDeque(SIZE);
900 <                        for (int i = 0; i < SIZE; ++i) {
901 <                            assertEquals(i, ((Integer)q.takeFirst()).intValue());
902 <                        }
903 <                        q.takeFirst();
904 <                        threadShouldThrow();
905 <                    } catch (InterruptedException success){
906 <                    }  
907 <                }});
908 <        t.start();
1027 <        try {
1028 <           Thread.sleep(SHORT_DELAY_MS);
1029 <           t.interrupt();
1030 <           t.join();
1031 <        }
1032 <        catch (InterruptedException ie) {
1033 <            unexpectedException();
1034 <        }
895 >    public void testBlockingTakeFirst() throws InterruptedException {
896 >        Thread t = new ThreadShouldThrow(InterruptedException.class) {
897 >            public void realRun() throws InterruptedException {
898 >                LinkedBlockingDeque q = populatedDeque(SIZE);
899 >                for (int i = 0; i < SIZE; ++i) {
900 >                    assertEquals(i, ((Integer)q.takeFirst()).intValue());
901 >                }
902 >                q.takeFirst();
903 >            }};
904 >
905 >        t.start();
906 >        Thread.sleep(SHORT_DELAY_MS);
907 >        t.interrupt();
908 >        t.join();
909      }
910  
911  
912      /**
913       * timed pollFirst with zero timeout succeeds when non-empty, else times out
914       */
915 <    public void testTimedPollFirst0() {
916 <        try {
917 <            LinkedBlockingDeque q = populatedDeque(SIZE);
918 <            for (int i = 0; i < SIZE; ++i) {
919 <                assertEquals(i, ((Integer)q.pollFirst(0, TimeUnit.MILLISECONDS)).intValue());
920 <            }
1047 <            assertNull(q.pollFirst(0, TimeUnit.MILLISECONDS));
1048 <        } catch (InterruptedException e){
1049 <            unexpectedException();
1050 <        }  
915 >    public void testTimedPollFirst0() throws InterruptedException {
916 >        LinkedBlockingDeque q = populatedDeque(SIZE);
917 >        for (int i = 0; i < SIZE; ++i) {
918 >            assertEquals(i, ((Integer)q.pollFirst(0, MILLISECONDS)).intValue());
919 >        }
920 >        assertNull(q.pollFirst(0, MILLISECONDS));
921      }
922  
923      /**
924       * timed pollFirst with nonzero timeout succeeds when non-empty, else times out
925       */
926 <    public void testTimedPollFirst() {
927 <        try {
928 <            LinkedBlockingDeque q = populatedDeque(SIZE);
929 <            for (int i = 0; i < SIZE; ++i) {
930 <                assertEquals(i, ((Integer)q.pollFirst(SHORT_DELAY_MS, TimeUnit.MILLISECONDS)).intValue());
931 <            }
1062 <            assertNull(q.pollFirst(SHORT_DELAY_MS, TimeUnit.MILLISECONDS));
1063 <        } catch (InterruptedException e){
1064 <            unexpectedException();
1065 <        }  
926 >    public void testTimedPollFirst() throws InterruptedException {
927 >        LinkedBlockingDeque q = populatedDeque(SIZE);
928 >        for (int i = 0; i < SIZE; ++i) {
929 >            assertEquals(i, ((Integer)q.pollFirst(SHORT_DELAY_MS, MILLISECONDS)).intValue());
930 >        }
931 >        assertNull(q.pollFirst(SHORT_DELAY_MS, MILLISECONDS));
932      }
933  
934      /**
935       * Interrupted timed pollFirst throws InterruptedException instead of
936       * returning timeout status
937       */
938 <    public void testInterruptedTimedPollFirst() {
939 <        Thread t = new Thread(new Runnable() {
940 <                public void run() {
941 <                    try {
942 <                        LinkedBlockingDeque q = populatedDeque(SIZE);
943 <                        for (int i = 0; i < SIZE; ++i) {
944 <                            threadAssertEquals(i, ((Integer)q.pollFirst(SHORT_DELAY_MS, TimeUnit.MILLISECONDS)).intValue());
945 <                        }
946 <                        threadAssertNull(q.pollFirst(SHORT_DELAY_MS, TimeUnit.MILLISECONDS));
947 <                    } catch (InterruptedException success){
948 <                    }  
949 <                }});
950 <        t.start();
951 <        try {
1086 <           Thread.sleep(SHORT_DELAY_MS);
1087 <           t.interrupt();
1088 <           t.join();
1089 <        }
1090 <        catch (InterruptedException ie) {
1091 <            unexpectedException();
1092 <        }
938 >    public void testInterruptedTimedPollFirst() throws InterruptedException {
939 >        Thread t = new ThreadShouldThrow(InterruptedException.class) {
940 >            public void realRun() throws InterruptedException {
941 >                LinkedBlockingDeque q = populatedDeque(SIZE);
942 >                for (int i = 0; i < SIZE; ++i) {
943 >                    threadAssertEquals(i, ((Integer)q.pollFirst(SHORT_DELAY_MS, MILLISECONDS)).intValue());
944 >                }
945 >                q.pollFirst(SMALL_DELAY_MS, MILLISECONDS);
946 >            }};
947 >
948 >        t.start();
949 >        Thread.sleep(SHORT_DELAY_MS);
950 >        t.interrupt();
951 >        t.join();
952      }
953  
954      /**
955       *  timed pollFirst before a delayed offerFirst fails; after offerFirst succeeds;
956       *  on interruption throws
957       */
958 <    public void testTimedPollFirstWithOfferFirst() {
958 >    public void testTimedPollFirstWithOfferFirst() throws InterruptedException {
959          final LinkedBlockingDeque q = new LinkedBlockingDeque(2);
960 <        Thread t = new Thread(new Runnable() {
961 <                public void run() {
962 <                    try {
963 <                        threadAssertNull(q.pollFirst(SHORT_DELAY_MS, TimeUnit.MILLISECONDS));
964 <                        q.pollFirst(LONG_DELAY_MS, TimeUnit.MILLISECONDS);
965 <                        q.pollFirst(LONG_DELAY_MS, TimeUnit.MILLISECONDS);
966 <                        threadShouldThrow();
967 <                    } catch (InterruptedException success) { }                
968 <                }
969 <            });
970 <        try {
971 <            t.start();
972 <            Thread.sleep(SMALL_DELAY_MS);
1114 <            assertTrue(q.offerFirst(zero, SHORT_DELAY_MS, TimeUnit.MILLISECONDS));
1115 <            t.interrupt();
1116 <            t.join();
1117 <        } catch (Exception e){
1118 <            unexpectedException();
1119 <        }
1120 <    }  
960 >        Thread t = new ThreadShouldThrow(InterruptedException.class) {
961 >            public void realRun() throws InterruptedException {
962 >                threadAssertNull(q.pollFirst(SHORT_DELAY_MS, MILLISECONDS));
963 >                q.pollFirst(LONG_DELAY_MS, MILLISECONDS);
964 >                q.pollFirst(LONG_DELAY_MS, MILLISECONDS);
965 >            }};
966 >
967 >        t.start();
968 >        Thread.sleep(SMALL_DELAY_MS);
969 >        assertTrue(q.offerFirst(zero, SHORT_DELAY_MS, MILLISECONDS));
970 >        t.interrupt();
971 >        t.join();
972 >    }
973  
974      /**
975       * putLast(null) throws NPE
976       */
977 <     public void testPutLastNull() {
978 <        try {
977 >     public void testPutLastNull() throws InterruptedException {
978 >        try {
979              LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
980              q.putLast(null);
981              shouldThrow();
982 <        }
1131 <        catch (NullPointerException success){
1132 <        }  
1133 <        catch (InterruptedException ie) {
1134 <            unexpectedException();
1135 <        }
982 >        } catch (NullPointerException success) {}
983       }
984  
985      /**
986       * all elements successfully putLast are contained
987       */
988 <     public void testPutLast() {
989 <         try {
990 <             LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
991 <             for (int i = 0; i < SIZE; ++i) {
992 <                 Integer I = new Integer(i);
993 <                 q.putLast(I);
1147 <                 assertTrue(q.contains(I));
1148 <             }
1149 <             assertEquals(0, q.remainingCapacity());
988 >     public void testPutLast() throws InterruptedException {
989 >         LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
990 >         for (int i = 0; i < SIZE; ++i) {
991 >             Integer I = new Integer(i);
992 >             q.putLast(I);
993 >             assertTrue(q.contains(I));
994           }
995 <        catch (InterruptedException ie) {
1152 <            unexpectedException();
1153 <        }
995 >         assertEquals(0, q.remainingCapacity());
996      }
997  
998      /**
999       * putLast blocks interruptibly if full
1000       */
1001 <    public void testBlockingPutLast() {
1002 <        Thread t = new Thread(new Runnable() {
1003 <                public void run() {
1004 <                    int added = 0;
1005 <                    try {
1006 <                        LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
1007 <                        for (int i = 0; i < SIZE; ++i) {
1008 <                            q.putLast(new Integer(i));
1009 <                            ++added;
1010 <                        }
1011 <                        q.putLast(new Integer(SIZE));
1012 <                        threadShouldThrow();
1013 <                    } catch (InterruptedException ie){
1014 <                        threadAssertEquals(added, SIZE);
1015 <                    }  
1016 <                }});
1017 <        t.start();
1018 <        try {
1019 <           Thread.sleep(SHORT_DELAY_MS);
1020 <           t.interrupt();
1021 <           t.join();
1180 <        }
1181 <        catch (InterruptedException ie) {
1182 <            unexpectedException();
1183 <        }
1001 >    public void testBlockingPutLast() throws InterruptedException {
1002 >        Thread t = new Thread(new CheckedRunnable() {
1003 >            public void realRun() {
1004 >                int added = 0;
1005 >                try {
1006 >                    LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
1007 >                    for (int i = 0; i < SIZE; ++i) {
1008 >                        q.putLast(new Integer(i));
1009 >                        ++added;
1010 >                    }
1011 >                    q.putLast(new Integer(SIZE));
1012 >                    threadShouldThrow();
1013 >                } catch (InterruptedException success) {
1014 >                    threadAssertEquals(added, SIZE);
1015 >                }
1016 >            }});
1017 >
1018 >        t.start();
1019 >        Thread.sleep(SHORT_DELAY_MS);
1020 >        t.interrupt();
1021 >        t.join();
1022      }
1023  
1024      /**
1025       * putLast blocks waiting for take when full
1026       */
1027 <    public void testPutLastWithTake() {
1027 >    public void testPutLastWithTake() throws InterruptedException {
1028          final LinkedBlockingDeque q = new LinkedBlockingDeque(2);
1029 <        Thread t = new Thread(new Runnable() {
1030 <                public void run() {
1031 <                    int added = 0;
1032 <                    try {
1033 <                        q.putLast(new Object());
1034 <                        ++added;
1035 <                        q.putLast(new Object());
1036 <                        ++added;
1037 <                        q.putLast(new Object());
1038 <                        ++added;
1039 <                        q.putLast(new Object());
1040 <                        ++added;
1041 <                        threadShouldThrow();
1042 <                    } catch (InterruptedException e){
1043 <                        threadAssertTrue(added >= 2);
1206 <                    }
1029 >        Thread t = new Thread(new CheckedRunnable() {
1030 >            public void realRun() {
1031 >                int added = 0;
1032 >                try {
1033 >                    q.putLast(new Object());
1034 >                    ++added;
1035 >                    q.putLast(new Object());
1036 >                    ++added;
1037 >                    q.putLast(new Object());
1038 >                    ++added;
1039 >                    q.putLast(new Object());
1040 >                    ++added;
1041 >                    threadShouldThrow();
1042 >                } catch (InterruptedException success) {
1043 >                    threadAssertTrue(added >= 2);
1044                  }
1045 <            });
1046 <        try {
1047 <            t.start();
1048 <            Thread.sleep(SHORT_DELAY_MS);
1049 <            q.take();
1050 <            t.interrupt();
1051 <            t.join();
1215 <        } catch (Exception e){
1216 <            unexpectedException();
1217 <        }
1045 >            }});
1046 >
1047 >        t.start();
1048 >        Thread.sleep(SHORT_DELAY_MS);
1049 >        q.take();
1050 >        t.interrupt();
1051 >        t.join();
1052      }
1053  
1054      /**
1055       * timed offerLast times out if full and elements not taken
1056       */
1057 <    public void testTimedOfferLast() {
1057 >    public void testTimedOfferLast() throws InterruptedException {
1058          final LinkedBlockingDeque q = new LinkedBlockingDeque(2);
1059 <        Thread t = new Thread(new Runnable() {
1060 <                public void run() {
1061 <                    try {
1062 <                        q.putLast(new Object());
1063 <                        q.putLast(new Object());
1064 <                        threadAssertFalse(q.offerLast(new Object(), SHORT_DELAY_MS, TimeUnit.MILLISECONDS));
1065 <                        q.offerLast(new Object(), LONG_DELAY_MS, TimeUnit.MILLISECONDS);
1066 <                        threadShouldThrow();
1067 <                    } catch (InterruptedException success){}
1068 <                }
1069 <            });
1070 <        
1237 <        try {
1238 <            t.start();
1239 <            Thread.sleep(SMALL_DELAY_MS);
1240 <            t.interrupt();
1241 <            t.join();
1242 <        } catch (Exception e){
1243 <            unexpectedException();
1244 <        }
1059 >        Thread t = new ThreadShouldThrow(InterruptedException.class) {
1060 >            public void realRun() throws InterruptedException {
1061 >                q.putLast(new Object());
1062 >                q.putLast(new Object());
1063 >                threadAssertFalse(q.offerLast(new Object(), SHORT_DELAY_MS, MILLISECONDS));
1064 >                q.offerLast(new Object(), LONG_DELAY_MS, MILLISECONDS);
1065 >            }};
1066 >
1067 >        t.start();
1068 >        Thread.sleep(SMALL_DELAY_MS);
1069 >        t.interrupt();
1070 >        t.join();
1071      }
1072  
1073      /**
1074       * takeLast retrieves elements in FIFO order
1075       */
1076 <    public void testTakeLast() {
1077 <        try {
1078 <            LinkedBlockingDeque q = populatedDeque(SIZE);
1079 <            for (int i = 0; i < SIZE; ++i) {
1080 <                assertEquals(SIZE-i-1, ((Integer)q.takeLast()).intValue());
1255 <            }
1256 <        } catch (InterruptedException e){
1257 <            unexpectedException();
1258 <        }  
1076 >    public void testTakeLast() throws InterruptedException {
1077 >        LinkedBlockingDeque q = populatedDeque(SIZE);
1078 >        for (int i = 0; i < SIZE; ++i) {
1079 >            assertEquals(SIZE-i-1, ((Integer)q.takeLast()).intValue());
1080 >        }
1081      }
1082  
1083      /**
1084       * takeLast blocks interruptibly when empty
1085       */
1086 <    public void testTakeLastFromEmpty() {
1086 >    public void testTakeLastFromEmpty() throws InterruptedException {
1087          final LinkedBlockingDeque q = new LinkedBlockingDeque(2);
1088 <        Thread t = new Thread(new Runnable() {
1089 <                public void run() {
1090 <                    try {
1091 <                        q.takeLast();
1092 <                        threadShouldThrow();
1093 <                    } catch (InterruptedException success){ }                
1094 <                }
1095 <            });
1096 <        try {
1275 <            t.start();
1276 <            Thread.sleep(SHORT_DELAY_MS);
1277 <            t.interrupt();
1278 <            t.join();
1279 <        } catch (Exception e){
1280 <            unexpectedException();
1281 <        }
1088 >        Thread t = new ThreadShouldThrow(InterruptedException.class) {
1089 >            public void realRun() throws InterruptedException {
1090 >                q.takeLast();
1091 >            }};
1092 >
1093 >        t.start();
1094 >        Thread.sleep(SHORT_DELAY_MS);
1095 >        t.interrupt();
1096 >        t.join();
1097      }
1098  
1099      /**
1100       * TakeLast removes existing elements until empty, then blocks interruptibly
1101       */
1102 <    public void testBlockingTakeLast() {
1103 <        Thread t = new Thread(new Runnable() {
1104 <                public void run() {
1105 <                    try {
1106 <                        LinkedBlockingDeque q = populatedDeque(SIZE);
1107 <                        for (int i = 0; i < SIZE; ++i) {
1108 <                            assertEquals(SIZE-i-1, ((Integer)q.takeLast()).intValue());
1109 <                        }
1110 <                        q.takeLast();
1111 <                        threadShouldThrow();
1112 <                    } catch (InterruptedException success){
1113 <                    }  
1114 <                }});
1115 <        t.start();
1301 <        try {
1302 <           Thread.sleep(SHORT_DELAY_MS);
1303 <           t.interrupt();
1304 <           t.join();
1305 <        }
1306 <        catch (InterruptedException ie) {
1307 <            unexpectedException();
1308 <        }
1102 >    public void testBlockingTakeLast() throws InterruptedException {
1103 >        Thread t = new ThreadShouldThrow(InterruptedException.class) {
1104 >            public void realRun() throws InterruptedException {
1105 >                LinkedBlockingDeque q = populatedDeque(SIZE);
1106 >                for (int i = 0; i < SIZE; ++i) {
1107 >                    assertEquals(SIZE-i-1, ((Integer)q.takeLast()).intValue());
1108 >                }
1109 >                q.takeLast();
1110 >            }};
1111 >
1112 >        t.start();
1113 >        Thread.sleep(SHORT_DELAY_MS);
1114 >        t.interrupt();
1115 >        t.join();
1116      }
1117  
1118  
1119      /**
1120       * timed pollLast with zero timeout succeeds when non-empty, else times out
1121       */
1122 <    public void testTimedPollLast0() {
1123 <        try {
1124 <            LinkedBlockingDeque q = populatedDeque(SIZE);
1125 <            for (int i = 0; i < SIZE; ++i) {
1126 <                assertEquals(SIZE-i-1, ((Integer)q.pollLast(0, TimeUnit.MILLISECONDS)).intValue());
1127 <            }
1321 <            assertNull(q.pollLast(0, TimeUnit.MILLISECONDS));
1322 <        } catch (InterruptedException e){
1323 <            unexpectedException();
1324 <        }  
1122 >    public void testTimedPollLast0() throws InterruptedException {
1123 >        LinkedBlockingDeque q = populatedDeque(SIZE);
1124 >        for (int i = 0; i < SIZE; ++i) {
1125 >            assertEquals(SIZE-i-1, ((Integer)q.pollLast(0, MILLISECONDS)).intValue());
1126 >        }
1127 >        assertNull(q.pollLast(0, MILLISECONDS));
1128      }
1129  
1130      /**
1131       * timed pollLast with nonzero timeout succeeds when non-empty, else times out
1132       */
1133 <    public void testTimedPollLast() {
1134 <        try {
1135 <            LinkedBlockingDeque q = populatedDeque(SIZE);
1136 <            for (int i = 0; i < SIZE; ++i) {
1137 <                assertEquals(SIZE-i-1, ((Integer)q.pollLast(SHORT_DELAY_MS, TimeUnit.MILLISECONDS)).intValue());
1138 <            }
1336 <            assertNull(q.pollLast(SHORT_DELAY_MS, TimeUnit.MILLISECONDS));
1337 <        } catch (InterruptedException e){
1338 <            unexpectedException();
1339 <        }  
1133 >    public void testTimedPollLast() throws InterruptedException {
1134 >        LinkedBlockingDeque q = populatedDeque(SIZE);
1135 >        for (int i = 0; i < SIZE; ++i) {
1136 >            assertEquals(SIZE-i-1, ((Integer)q.pollLast(SHORT_DELAY_MS, MILLISECONDS)).intValue());
1137 >        }
1138 >        assertNull(q.pollLast(SHORT_DELAY_MS, MILLISECONDS));
1139      }
1140  
1141      /**
1142       * Interrupted timed pollLast throws InterruptedException instead of
1143       * returning timeout status
1144       */
1145 <    public void testInterruptedTimedPollLast() {
1146 <        Thread t = new Thread(new Runnable() {
1147 <                public void run() {
1148 <                    try {
1149 <                        LinkedBlockingDeque q = populatedDeque(SIZE);
1150 <                        for (int i = 0; i < SIZE; ++i) {
1151 <                            threadAssertEquals(SIZE-i-1, ((Integer)q.pollLast(SHORT_DELAY_MS, TimeUnit.MILLISECONDS)).intValue());
1152 <                        }
1153 <                        threadAssertNull(q.pollLast(SHORT_DELAY_MS, TimeUnit.MILLISECONDS));
1154 <                    } catch (InterruptedException success){
1155 <                    }  
1156 <                }});
1157 <        t.start();
1158 <        try {
1360 <           Thread.sleep(SHORT_DELAY_MS);
1361 <           t.interrupt();
1362 <           t.join();
1363 <        }
1364 <        catch (InterruptedException ie) {
1365 <            unexpectedException();
1366 <        }
1145 >    public void testInterruptedTimedPollLast() throws InterruptedException {
1146 >        Thread t = new ThreadShouldThrow(InterruptedException.class) {
1147 >            public void realRun() throws InterruptedException {
1148 >                LinkedBlockingDeque q = populatedDeque(SIZE);
1149 >                for (int i = 0; i < SIZE; ++i) {
1150 >                    threadAssertEquals(SIZE-i-1, ((Integer)q.pollLast(SHORT_DELAY_MS, MILLISECONDS)).intValue());
1151 >                }
1152 >                q.pollLast(SMALL_DELAY_MS, MILLISECONDS);
1153 >            }};
1154 >
1155 >        t.start();
1156 >        Thread.sleep(SHORT_DELAY_MS);
1157 >        t.interrupt();
1158 >        t.join();
1159      }
1160  
1161      /**
1162       *  timed poll before a delayed offerLast fails; after offerLast succeeds;
1163       *  on interruption throws
1164       */
1165 <    public void testTimedPollWithOfferLast() {
1165 >    public void testTimedPollWithOfferLast() throws InterruptedException {
1166          final LinkedBlockingDeque q = new LinkedBlockingDeque(2);
1167 <        Thread t = new Thread(new Runnable() {
1168 <                public void run() {
1169 <                    try {
1170 <                        threadAssertNull(q.poll(SHORT_DELAY_MS, TimeUnit.MILLISECONDS));
1171 <                        q.poll(LONG_DELAY_MS, TimeUnit.MILLISECONDS);
1172 <                        q.poll(LONG_DELAY_MS, TimeUnit.MILLISECONDS);
1173 <                        threadShouldThrow();
1174 <                    } catch (InterruptedException success) { }                
1175 <                }
1176 <            });
1177 <        try {
1178 <            t.start();
1179 <            Thread.sleep(SMALL_DELAY_MS);
1180 <            assertTrue(q.offerLast(zero, SHORT_DELAY_MS, TimeUnit.MILLISECONDS));
1181 <            t.interrupt();
1182 <            t.join();
1391 <        } catch (Exception e){
1392 <            unexpectedException();
1393 <        }
1394 <    }  
1167 >        Thread t = new Thread(new CheckedRunnable() {
1168 >            public void realRun() throws InterruptedException {
1169 >                assertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS));
1170 >                assertSame(zero, q.poll(LONG_DELAY_MS, MILLISECONDS));
1171 >                try {
1172 >                    q.poll(LONG_DELAY_MS, MILLISECONDS);
1173 >                    shouldThrow();
1174 >                } catch (InterruptedException success) {}
1175 >            }});
1176 >
1177 >        t.start();
1178 >        Thread.sleep(SMALL_DELAY_MS);
1179 >        assertTrue(q.offerLast(zero, SHORT_DELAY_MS, MILLISECONDS));
1180 >        t.interrupt();
1181 >        t.join();
1182 >    }
1183  
1184  
1185      /**
# Line 1406 | Line 1194 | public class LinkedBlockingDequeTest ext
1194          try {
1195              q.element();
1196              shouldThrow();
1197 <        }
1410 <        catch (NoSuchElementException success) {}
1197 >        } catch (NoSuchElementException success) {}
1198      }
1199  
1200      /**
# Line 1424 | Line 1211 | public class LinkedBlockingDequeTest ext
1211          }
1212          assertTrue(q.isEmpty());
1213      }
1214 <        
1214 >
1215      /**
1216       * contains(x) reports true when elements added but not yet removed
1217       */
# Line 1505 | Line 1292 | public class LinkedBlockingDequeTest ext
1292      /**
1293       * toArray contains all elements
1294       */
1295 <    public void testToArray() {
1295 >    public void testToArray() throws InterruptedException{
1296          LinkedBlockingDeque q = populatedDeque(SIZE);
1297 <        Object[] o = q.toArray();
1298 <        try {
1299 <        for(int i = 0; i < o.length; i++)
1513 <            assertEquals(o[i], q.take());
1514 <        } catch (InterruptedException e){
1515 <            unexpectedException();
1516 <        }    
1297 >        Object[] o = q.toArray();
1298 >        for (int i = 0; i < o.length; i++)
1299 >            assertEquals(o[i], q.take());
1300      }
1301  
1302      /**
1303       * toArray(a) contains all elements
1304       */
1305 <    public void testToArray2() {
1305 >    public void testToArray2() throws InterruptedException {
1306          LinkedBlockingDeque q = populatedDeque(SIZE);
1307 <        Integer[] ints = new Integer[SIZE];
1308 <        ints = (Integer[])q.toArray(ints);
1309 <        try {
1310 <            for(int i = 0; i < ints.length; i++)
1528 <                assertEquals(ints[i], q.take());
1529 <        } catch (InterruptedException e){
1530 <            unexpectedException();
1531 <        }    
1307 >        Integer[] ints = new Integer[SIZE];
1308 >        ints = (Integer[])q.toArray(ints);
1309 >        for (int i = 0; i < ints.length; i++)
1310 >            assertEquals(ints[i], q.take());
1311      }
1312  
1313      /**
1314       * toArray(null) throws NPE
1315       */
1316      public void testToArray_BadArg() {
1317 <        try {
1317 >        try {
1318              LinkedBlockingDeque q = populatedDeque(SIZE);
1319 <            Object o[] = q.toArray(null);
1320 <            shouldThrow();
1321 <        } catch(NullPointerException success){}
1319 >            Object o[] = q.toArray(null);
1320 >            shouldThrow();
1321 >        } catch (NullPointerException success) {}
1322      }
1323  
1324      /**
1325       * toArray with incompatible array type throws CCE
1326       */
1327      public void testToArray1_BadArg() {
1328 <        try {
1328 >        try {
1329              LinkedBlockingDeque q = populatedDeque(SIZE);
1330 <            Object o[] = q.toArray(new String[10] );
1331 <            shouldThrow();
1332 <        } catch(ArrayStoreException  success){}
1330 >            Object o[] = q.toArray(new String[10] );
1331 >            shouldThrow();
1332 >        } catch (ArrayStoreException success) {}
1333      }
1334  
1335 <    
1335 >
1336      /**
1337       * iterator iterates through all elements
1338       */
1339 <    public void testIterator() {
1339 >    public void testIterator() throws InterruptedException {
1340          LinkedBlockingDeque q = populatedDeque(SIZE);
1341 <        Iterator it = q.iterator();
1342 <        try {
1343 <            while(it.hasNext()){
1344 <                assertEquals(it.next(), q.take());
1566 <            }
1567 <        } catch (InterruptedException e){
1568 <            unexpectedException();
1569 <        }    
1341 >        Iterator it = q.iterator();
1342 >        while (it.hasNext()) {
1343 >            assertEquals(it.next(), q.take());
1344 >        }
1345      }
1346  
1347      /**
# Line 1581 | Line 1356 | public class LinkedBlockingDequeTest ext
1356          Iterator it = q.iterator();
1357          it.next();
1358          it.remove();
1359 <        
1359 >
1360          it = q.iterator();
1361          assertEquals(it.next(), one);
1362          assertEquals(it.next(), three);
# Line 1614 | Line 1389 | public class LinkedBlockingDequeTest ext
1389          q.add(one);
1390          q.add(two);
1391          q.add(three);
1392 <        try {
1393 <            for (Iterator it = q.iterator(); it.hasNext();) {
1394 <                q.remove();
1620 <                it.next();
1621 <            }
1622 <        }
1623 <        catch (ConcurrentModificationException e) {
1624 <            unexpectedException();
1392 >        for (Iterator it = q.iterator(); it.hasNext();) {
1393 >            q.remove();
1394 >            it.next();
1395          }
1396          assertEquals(0, q.size());
1397      }
# Line 1633 | Line 1403 | public class LinkedBlockingDequeTest ext
1403      public void testDescendingIterator() {
1404          LinkedBlockingDeque q = populatedDeque(SIZE);
1405          int i = 0;
1406 <        Iterator it = q.descendingIterator();
1407 <        while(it.hasNext()) {
1406 >        Iterator it = q.descendingIterator();
1407 >        while (it.hasNext()) {
1408              assertTrue(q.contains(it.next()));
1409              ++i;
1410          }
# Line 1642 | Line 1412 | public class LinkedBlockingDequeTest ext
1412          assertFalse(it.hasNext());
1413          try {
1414              it.next();
1415 <        } catch(NoSuchElementException success) {
1416 <        }
1415 >            shouldThrow();
1416 >        } catch (NoSuchElementException success) {}
1417      }
1418  
1419      /**
# Line 1660 | Line 1430 | public class LinkedBlockingDequeTest ext
1430                  int i = ((Integer)(it.next())).intValue();
1431                  assertEquals(++k, i);
1432              }
1433 <            
1433 >
1434              assertEquals(3, k);
1435              q.remove();
1436              q.remove();
# Line 1700 | Line 1470 | public class LinkedBlockingDequeTest ext
1470          for (int i = 0; i < SIZE; ++i) {
1471              assertTrue(s.indexOf(String.valueOf(i)) >= 0);
1472          }
1473 <    }        
1473 >    }
1474  
1475  
1476      /**
# Line 1711 | Line 1481 | public class LinkedBlockingDequeTest ext
1481          q.add(one);
1482          q.add(two);
1483          ExecutorService executor = Executors.newFixedThreadPool(2);
1484 <        executor.execute(new Runnable() {
1485 <            public void run() {
1484 >        executor.execute(new CheckedRunnable() {
1485 >            public void realRun() throws InterruptedException {
1486                  threadAssertFalse(q.offer(three));
1487 <                try {
1488 <                    threadAssertTrue(q.offer(three, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS));
1489 <                    threadAssertEquals(0, q.remainingCapacity());
1490 <                }
1491 <                catch (InterruptedException e) {
1492 <                    threadUnexpectedException();
1493 <                }
1494 <            }
1495 <        });
1487 >                threadAssertTrue(q.offer(three, MEDIUM_DELAY_MS, MILLISECONDS));
1488 >                threadAssertEquals(0, q.remainingCapacity());
1489 >            }});
1490 >
1491 >        executor.execute(new CheckedRunnable() {
1492 >            public void realRun() throws InterruptedException {
1493 >                Thread.sleep(SMALL_DELAY_MS);
1494 >                threadAssertEquals(one, q.take());
1495 >            }});
1496  
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        });
1738        
1497          joinPool(executor);
1498      }
1499  
# Line 1745 | Line 1503 | public class LinkedBlockingDequeTest ext
1503      public void testPollInExecutor() {
1504          final LinkedBlockingDeque q = new LinkedBlockingDeque(2);
1505          ExecutorService executor = Executors.newFixedThreadPool(2);
1506 <        executor.execute(new Runnable() {
1507 <            public void run() {
1506 >        executor.execute(new CheckedRunnable() {
1507 >            public void realRun() throws InterruptedException {
1508                  threadAssertNull(q.poll());
1509 <                try {
1510 <                    threadAssertTrue(null != q.poll(MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS));
1511 <                    threadAssertTrue(q.isEmpty());
1512 <                }
1513 <                catch (InterruptedException e) {
1514 <                    threadUnexpectedException();
1515 <                }
1516 <            }
1517 <        });
1509 >                threadAssertTrue(null != q.poll(MEDIUM_DELAY_MS, MILLISECONDS));
1510 >                threadAssertTrue(q.isEmpty());
1511 >            }});
1512 >
1513 >        executor.execute(new CheckedRunnable() {
1514 >            public void realRun() throws InterruptedException {
1515 >                Thread.sleep(SMALL_DELAY_MS);
1516 >                q.put(one);
1517 >            }});
1518  
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        });
1772        
1519          joinPool(executor);
1520      }
1521  
1522      /**
1523       * A deserialized serialized deque has same elements in same order
1524       */
1525 <    public void testSerialization() {
1525 >    public void testSerialization() throws Exception {
1526          LinkedBlockingDeque q = populatedDeque(SIZE);
1527  
1528 <        try {
1529 <            ByteArrayOutputStream bout = new ByteArrayOutputStream(10000);
1530 <            ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout));
1531 <            out.writeObject(q);
1532 <            out.close();
1533 <
1534 <            ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
1535 <            ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin));
1536 <            LinkedBlockingDeque r = (LinkedBlockingDeque)in.readObject();
1537 <            assertEquals(q.size(), r.size());
1538 <            while (!q.isEmpty())
1793 <                assertEquals(q.remove(), r.remove());
1794 <        } catch(Exception e){
1795 <            unexpectedException();
1796 <        }
1528 >        ByteArrayOutputStream bout = new ByteArrayOutputStream(10000);
1529 >        ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout));
1530 >        out.writeObject(q);
1531 >        out.close();
1532 >
1533 >        ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
1534 >        ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin));
1535 >        LinkedBlockingDeque r = (LinkedBlockingDeque)in.readObject();
1536 >        assertEquals(q.size(), r.size());
1537 >        while (!q.isEmpty())
1538 >            assertEquals(q.remove(), r.remove());
1539      }
1540  
1541      /**
1542       * drainTo(null) throws NPE
1543 <     */
1543 >     */
1544      public void testDrainToNull() {
1545          LinkedBlockingDeque q = populatedDeque(SIZE);
1546          try {
1547              q.drainTo(null);
1548              shouldThrow();
1549 <        } catch(NullPointerException success) {
1808 <        }
1549 >        } catch (NullPointerException success) {}
1550      }
1551  
1552      /**
1553       * drainTo(this) throws IAE
1554 <     */
1554 >     */
1555      public void testDrainToSelf() {
1556          LinkedBlockingDeque q = populatedDeque(SIZE);
1557          try {
1558              q.drainTo(q);
1559              shouldThrow();
1560 <        } catch(IllegalArgumentException success) {
1820 <        }
1560 >        } catch (IllegalArgumentException success) {}
1561      }
1562  
1563      /**
1564       * drainTo(c) empties deque into another collection c
1565 <     */
1565 >     */
1566      public void testDrainTo() {
1567          LinkedBlockingDeque q = populatedDeque(SIZE);
1568          ArrayList l = new ArrayList();
1569          q.drainTo(l);
1570          assertEquals(q.size(), 0);
1571          assertEquals(l.size(), SIZE);
1572 <        for (int i = 0; i < SIZE; ++i)
1572 >        for (int i = 0; i < SIZE; ++i)
1573              assertEquals(l.get(i), new Integer(i));
1574          q.add(zero);
1575          q.add(one);
# Line 1840 | Line 1580 | public class LinkedBlockingDequeTest ext
1580          q.drainTo(l);
1581          assertEquals(q.size(), 0);
1582          assertEquals(l.size(), 2);
1583 <        for (int i = 0; i < 2; ++i)
1583 >        for (int i = 0; i < 2; ++i)
1584              assertEquals(l.get(i), new Integer(i));
1585      }
1586  
1587      /**
1588       * drainTo empties full deque, unblocking a waiting put.
1589 <     */
1590 <    public void testDrainToWithActivePut() {
1589 >     */
1590 >    public void testDrainToWithActivePut() throws InterruptedException {
1591          final LinkedBlockingDeque q = populatedDeque(SIZE);
1592 <        Thread t = new Thread(new Runnable() {
1593 <                public void run() {
1594 <                    try {
1595 <                        q.put(new Integer(SIZE+1));
1596 <                    } catch (InterruptedException ie){
1597 <                        threadUnexpectedException();
1598 <                    }
1599 <                }
1600 <            });
1601 <        try {
1602 <            t.start();
1603 <            ArrayList l = new ArrayList();
1604 <            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 <        }
1592 >        Thread t = new Thread(new CheckedRunnable() {
1593 >            public void realRun() throws InterruptedException {
1594 >                q.put(new Integer(SIZE+1));
1595 >            }});
1596 >
1597 >        t.start();
1598 >        ArrayList l = new ArrayList();
1599 >        q.drainTo(l);
1600 >        assertTrue(l.size() >= SIZE);
1601 >        for (int i = 0; i < SIZE; ++i)
1602 >            assertEquals(l.get(i), new Integer(i));
1603 >        t.join();
1604 >        assertTrue(q.size() + l.size() >= SIZE);
1605      }
1606  
1607      /**
1608       * drainTo(null, n) throws NPE
1609 <     */
1609 >     */
1610      public void testDrainToNullN() {
1611          LinkedBlockingDeque q = populatedDeque(SIZE);
1612          try {
1613              q.drainTo(null, 0);
1614              shouldThrow();
1615 <        } catch(NullPointerException success) {
1884 <        }
1615 >        } catch (NullPointerException success) {}
1616      }
1617  
1618      /**
1619       * drainTo(this, n) throws IAE
1620 <     */
1620 >     */
1621      public void testDrainToSelfN() {
1622          LinkedBlockingDeque q = populatedDeque(SIZE);
1623          try {
1624              q.drainTo(q, 0);
1625              shouldThrow();
1626 <        } catch(IllegalArgumentException success) {
1896 <        }
1626 >        } catch (IllegalArgumentException success) {}
1627      }
1628  
1629      /**
1630       * drainTo(c, n) empties first max {n, size} elements of deque into c
1631 <     */
1631 >     */
1632      public void testDrainToN() {
1633          LinkedBlockingDeque q = new LinkedBlockingDeque();
1634          for (int i = 0; i < SIZE + 2; ++i) {
1635 <            for(int j = 0; j < SIZE; j++)
1635 >            for (int j = 0; j < SIZE; j++)
1636                  assertTrue(q.offer(new Integer(j)));
1637              ArrayList l = new ArrayList();
1638              q.drainTo(l, i);
1639              int k = (i < SIZE)? i : SIZE;
1640              assertEquals(l.size(), k);
1641              assertEquals(q.size(), SIZE-k);
1642 <            for (int j = 0; j < k; ++j)
1642 >            for (int j = 0; j < k; ++j)
1643                  assertEquals(l.get(j), new Integer(j));
1644              while (q.poll() != null) ;
1645          }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines