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.8 by jsr166, Sat Nov 21 02:33:20 2009 UTC vs.
Revision 1.10 by jsr166, Sat Nov 21 09:28:16 2009 UTC

# Line 71 | Line 71 | public class LinkedBlockingDequeTest ext
71              LinkedBlockingDeque q = new LinkedBlockingDeque();
72              q.offerFirst(null);
73              shouldThrow();
74 <        } catch (NullPointerException success) {
75 <        }
74 >        } catch (NullPointerException success) {}
75      }
76  
77      /**
# Line 169 | Line 168 | public class LinkedBlockingDequeTest ext
168          try {
169              q.getFirst();
170              shouldThrow();
171 <        }
173 <        catch (NoSuchElementException success) {}
171 >        } catch (NoSuchElementException success) {}
172      }
173  
174      /**
# Line 185 | Line 183 | public class LinkedBlockingDequeTest ext
183          try {
184              q.getLast();
185              shouldThrow();
186 <        }
189 <        catch (NoSuchElementException success) {}
186 >        } catch (NoSuchElementException success) {}
187          assertNull(q.peekLast());
188      }
189  
# Line 201 | Line 198 | public class LinkedBlockingDequeTest ext
198          try {
199              q.removeFirst();
200              shouldThrow();
201 <        } catch (NoSuchElementException success) {
205 <        }
201 >        } catch (NoSuchElementException success) {}
202      }
203  
204      /**
# Line 216 | Line 212 | public class LinkedBlockingDequeTest ext
212          try {
213              q.remove();
214              shouldThrow();
215 <        } catch (NoSuchElementException success) {
220 <        }
215 >        } catch (NoSuchElementException success) {}
216      }
217  
218      /**
# Line 287 | Line 282 | public class LinkedBlockingDequeTest ext
282          try {
283              LinkedBlockingDeque q = new LinkedBlockingDeque(0);
284              shouldThrow();
285 <        }
291 <        catch (IllegalArgumentException success) {}
285 >        } catch (IllegalArgumentException success) {}
286      }
287  
288      /**
# Line 298 | Line 292 | public class LinkedBlockingDequeTest ext
292          try {
293              LinkedBlockingDeque q = new LinkedBlockingDeque(null);
294              shouldThrow();
295 <        }
302 <        catch (NullPointerException success) {}
295 >        } catch (NullPointerException success) {}
296      }
297  
298      /**
# Line 310 | Line 303 | public class LinkedBlockingDequeTest ext
303              Integer[] ints = new Integer[SIZE];
304              LinkedBlockingDeque q = new LinkedBlockingDeque(Arrays.asList(ints));
305              shouldThrow();
306 <        }
314 <        catch (NullPointerException success) {}
306 >        } catch (NullPointerException success) {}
307      }
308  
309      /**
# Line 324 | Line 316 | public class LinkedBlockingDequeTest ext
316                  ints[i] = new Integer(i);
317              LinkedBlockingDeque q = new LinkedBlockingDeque(Arrays.asList(ints));
318              shouldThrow();
319 <        }
328 <        catch (NullPointerException success) {}
319 >        } catch (NullPointerException success) {}
320      }
321  
322      /**
# Line 383 | Line 374 | public class LinkedBlockingDequeTest ext
374              LinkedBlockingDeque q = new LinkedBlockingDeque(1);
375              q.offer(null);
376              shouldThrow();
377 <        } catch (NullPointerException success) { }
377 >        } catch (NullPointerException success) {}
378      }
379  
380      /**
# Line 394 | Line 385 | public class LinkedBlockingDequeTest ext
385              LinkedBlockingDeque q = new LinkedBlockingDeque(1);
386              q.add(null);
387              shouldThrow();
388 <        } catch (NullPointerException success) { }
388 >        } catch (NullPointerException success) {}
389      }
390  
391      /**
# Line 405 | Line 396 | public class LinkedBlockingDequeTest ext
396              LinkedBlockingDeque q = new LinkedBlockingDeque(1);
397              q.push(null);
398              shouldThrow();
399 <        } catch (NullPointerException success) { }
399 >        } catch (NullPointerException success) {}
400      }
401  
402      /**
# Line 421 | 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 447 | Line 438 | public class LinkedBlockingDequeTest ext
438          try {
439              q.pop();
440              shouldThrow();
441 <        } catch (NoSuchElementException success) {
451 <        }
441 >        } catch (NoSuchElementException success) {}
442      }
443  
444  
# Line 472 | Line 462 | public class LinkedBlockingDequeTest ext
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 484 | Line 474 | public class LinkedBlockingDequeTest ext
474              LinkedBlockingDeque q = new LinkedBlockingDeque(1);
475              q.addAll(null);
476              shouldThrow();
477 <        }
488 <        catch (NullPointerException success) {}
477 >        } catch (NullPointerException success) {}
478      }
479  
480      /**
# Line 496 | Line 485 | public class LinkedBlockingDequeTest ext
485              LinkedBlockingDeque q = populatedDeque(SIZE);
486              q.addAll(q);
487              shouldThrow();
488 <        }
500 <        catch (IllegalArgumentException success) {}
488 >        } catch (IllegalArgumentException success) {}
489      }
490  
491      /**
# Line 509 | Line 497 | public class LinkedBlockingDequeTest ext
497              Integer[] ints = new Integer[SIZE];
498              q.addAll(Arrays.asList(ints));
499              shouldThrow();
500 <        }
513 <        catch (NullPointerException success) {}
500 >        } catch (NullPointerException success) {}
501      }
502      /**
503       * addAll of a collection with any null elements throws NPE after
# Line 524 | Line 511 | public class LinkedBlockingDequeTest ext
511                  ints[i] = new Integer(i);
512              q.addAll(Arrays.asList(ints));
513              shouldThrow();
514 <        }
528 <        catch (NullPointerException success) {}
514 >        } catch (NullPointerException success) {}
515      }
516      /**
517       * addAll throws ISE if not enough room
# Line 538 | Line 524 | public class LinkedBlockingDequeTest ext
524                  ints[i] = new Integer(i);
525              q.addAll(Arrays.asList(ints));
526              shouldThrow();
527 <        }
542 <        catch (IllegalStateException success) {}
527 >        } catch (IllegalStateException success) {}
528      }
529      /**
530       * Deque contains all elements, in traversal order, of successful addAll
# Line 563 | Line 548 | public class LinkedBlockingDequeTest ext
548      /**
549       * put(null) throws NPE
550       */
551 <     public void testPutNull() {
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) {
573 <        }
574 <        catch (InterruptedException ie) {
575 <            unexpectedException();
576 <        }
577 <     }
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);
588 <                 assertTrue(q.contains(I));
589 <             }
590 <             assertEquals(0, q.remainingCapacity());
591 <         }
592 <        catch (InterruptedException ie) {
593 <            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;
609 <                        }
610 <                        q.put(new Integer(SIZE));
611 <                        threadShouldThrow();
612 <                    } catch (InterruptedException ie) {
613 <                        threadAssertEquals(added, SIZE);
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 <                }});
585 >                    q.put(new Integer(SIZE));
586 >                    threadShouldThrow();
587 >                } catch (InterruptedException success) {
588 >                    threadAssertEquals(added, SIZE);
589 >                }
590 >            }});
591 >
592          t.start();
593 <        try {
594 <           Thread.sleep(SHORT_DELAY_MS);
595 <           t.interrupt();
620 <           t.join();
621 <        }
622 <        catch (InterruptedException ie) {
623 <            unexpectedException();
624 <        }
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);
647 <                    }
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();
656 <        } catch (Exception e) {
657 <            unexpectedException();
658 <        }
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, MILLISECONDS));
639 <                        q.offer(new Object(), LONG_DELAY_MS, MILLISECONDS);
673 <                        threadShouldThrow();
674 <                    } catch (InterruptedException success) {}
675 <                }
676 <            });
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 <        try {
642 <            t.start();
643 <            Thread.sleep(SMALL_DELAY_MS);
644 <            t.interrupt();
682 <            t.join();
683 <        } catch (Exception e) {
684 <            unexpectedException();
685 <        }
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) {
695 <                assertEquals(i, ((Integer)q.take()).intValue());
696 <            }
697 <        } catch (InterruptedException e) {
698 <            unexpectedException();
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 {
716 <            t.start();
717 <            Thread.sleep(SHORT_DELAY_MS);
718 <            t.interrupt();
719 <            t.join();
720 <        } catch (Exception e) {
721 <            unexpectedException();
722 <        }
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();
738 <                    } catch (InterruptedException success) {
739 <                    }
740 <                }});
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 <        try {
688 <           Thread.sleep(SHORT_DELAY_MS);
689 <           t.interrupt();
745 <           t.join();
746 <        }
747 <        catch (InterruptedException ie) {
748 <            unexpectedException();
749 <        }
687 >        Thread.sleep(SHORT_DELAY_MS);
688 >        t.interrupt();
689 >        t.join();
690      }
691  
692  
# Line 764 | Line 704 | public class LinkedBlockingDequeTest ext
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) {
771 <                assertEquals(i, ((Integer)q.poll(0, MILLISECONDS)).intValue());
772 <            }
773 <            assertNull(q.poll(0, MILLISECONDS));
774 <        } catch (InterruptedException e) {
775 <            unexpectedException();
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) {
786 <                assertEquals(i, ((Integer)q.poll(SHORT_DELAY_MS, MILLISECONDS)).intValue());
787 <            }
788 <            assertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS));
789 <        } catch (InterruptedException e) {
790 <            unexpectedException();
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, MILLISECONDS)).intValue());
737 <                        }
738 <                        threadAssertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS));
739 <                    } catch (InterruptedException success) {
808 <                    }
809 <                }});
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 <        try {
742 <           Thread.sleep(SHORT_DELAY_MS);
743 <           t.interrupt();
814 <           t.join();
815 <        }
816 <        catch (InterruptedException ie) {
817 <            unexpectedException();
818 <        }
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, MILLISECONDS));
756 <                        q.poll(LONG_DELAY_MS, MILLISECONDS);
757 <                        q.poll(LONG_DELAY_MS, MILLISECONDS);
758 <                        threadShouldThrow();
759 <                    } catch (InterruptedException success) { }
760 <                }
761 <            });
762 <        try {
763 <            t.start();
839 <            Thread.sleep(SMALL_DELAY_MS);
840 <            assertTrue(q.offer(zero, SHORT_DELAY_MS, MILLISECONDS));
841 <            t.interrupt();
842 <            t.join();
843 <        } catch (Exception e) {
844 <            unexpectedException();
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() {
770 >     public void testPutFirstNull() throws InterruptedException {
771          try {
772              LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
773              q.putFirst(null);
774              shouldThrow();
775 <        }
858 <        catch (NullPointerException success) {
859 <        }
860 <        catch (InterruptedException ie) {
861 <            unexpectedException();
862 <        }
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);
874 <                 assertTrue(q.contains(I));
875 <             }
876 <             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) {
879 <            unexpectedException();
880 <        }
788 >         assertEquals(0, q.remainingCapacity());
789      }
790  
791      /**
792       * putFirst blocks interruptibly if full
793       */
794 <    public void testBlockingPutFirst() {
794 >    public void testBlockingPutFirst() throws InterruptedException {
795          Thread t = new Thread(new Runnable() {
796                  public void run() {
797                      int added = 0;
# Line 895 | Line 803 | public class LinkedBlockingDequeTest ext
803                          }
804                          q.putFirst(new Integer(SIZE));
805                          threadShouldThrow();
806 <                    } catch (InterruptedException ie) {
806 >                    } catch (InterruptedException success) {
807                          threadAssertEquals(added, SIZE);
808                      }
809                  }});
810 +
811          t.start();
812 <        try {
813 <           Thread.sleep(SHORT_DELAY_MS);
814 <           t.interrupt();
906 <           t.join();
907 <        }
908 <        catch (InterruptedException ie) {
909 <            unexpectedException();
910 <        }
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() {
# Line 928 | Line 832 | public class LinkedBlockingDequeTest ext
832                          q.putFirst(new Object());
833                          ++added;
834                          threadShouldThrow();
835 <                    } catch (InterruptedException e) {
835 >                    } catch (InterruptedException success) {
836                          threadAssertTrue(added >= 2);
837                      }
838                  }
839              });
840 <        try {
841 <            t.start();
842 <            Thread.sleep(SHORT_DELAY_MS);
843 <            q.take();
844 <            t.interrupt();
845 <            t.join();
942 <        } catch (Exception e) {
943 <            unexpectedException();
944 <        }
840 >
841 >        t.start();
842 >        Thread.sleep(SHORT_DELAY_MS);
843 >        q.take();
844 >        t.interrupt();
845 >        t.join();
846      }
847  
848      /**
849       * timed offerFirst times out if full and elements not taken
850       */
851 <    public void testTimedOfferFirst() {
851 >    public void testTimedOfferFirst() throws InterruptedException {
852          final LinkedBlockingDeque q = new LinkedBlockingDeque(2);
853 <        Thread t = new Thread(new Runnable() {
854 <                public void run() {
855 <                    try {
856 <                        q.putFirst(new Object());
857 <                        q.putFirst(new Object());
858 <                        threadAssertFalse(q.offerFirst(new Object(), SHORT_DELAY_MS, MILLISECONDS));
859 <                        q.offerFirst(new Object(), LONG_DELAY_MS, MILLISECONDS);
959 <                        threadShouldThrow();
960 <                    } catch (InterruptedException success) {}
961 <                }
962 <            });
853 >        Thread t = new ThreadShouldThrow(InterruptedException.class) {
854 >            public void realRun() throws InterruptedException {
855 >                q.putFirst(new Object());
856 >                q.putFirst(new Object());
857 >                threadAssertFalse(q.offerFirst(new Object(), SHORT_DELAY_MS, MILLISECONDS));
858 >                q.offerFirst(new Object(), LONG_DELAY_MS, MILLISECONDS);
859 >            }};
860  
861 <        try {
862 <            t.start();
863 <            Thread.sleep(SMALL_DELAY_MS);
864 <            t.interrupt();
968 <            t.join();
969 <        } catch (Exception e) {
970 <            unexpectedException();
971 <        }
861 >        t.start();
862 >        Thread.sleep(SMALL_DELAY_MS);
863 >        t.interrupt();
864 >        t.join();
865      }
866  
867      /**
868       * take retrieves elements in FIFO order
869       */
870 <    public void testTakeFirst() {
871 <        try {
872 <            LinkedBlockingDeque q = populatedDeque(SIZE);
873 <            for (int i = 0; i < SIZE; ++i) {
981 <                assertEquals(i, ((Integer)q.takeFirst()).intValue());
982 <            }
983 <        } catch (InterruptedException e) {
984 <            unexpectedException();
870 >    public void testTakeFirst() throws InterruptedException {
871 >        LinkedBlockingDeque q = populatedDeque(SIZE);
872 >        for (int i = 0; i < SIZE; ++i) {
873 >            assertEquals(i, ((Integer)q.takeFirst()).intValue());
874          }
875      }
876  
877      /**
878       * takeFirst blocks interruptibly when empty
879       */
880 <    public void testTakeFirstFromEmpty() {
880 >    public void testTakeFirstFromEmpty() throws InterruptedException {
881          final LinkedBlockingDeque q = new LinkedBlockingDeque(2);
882 <        Thread t = new Thread(new Runnable() {
883 <                public void run() {
884 <                    try {
885 <                        q.takeFirst();
886 <                        threadShouldThrow();
887 <                    } catch (InterruptedException success) { }
888 <                }
889 <            });
890 <        try {
1002 <            t.start();
1003 <            Thread.sleep(SHORT_DELAY_MS);
1004 <            t.interrupt();
1005 <            t.join();
1006 <        } catch (Exception e) {
1007 <            unexpectedException();
1008 <        }
882 >        Thread t = new ThreadShouldThrow(InterruptedException.class) {
883 >            public void realRun() throws InterruptedException {
884 >                q.takeFirst();
885 >            }};
886 >
887 >        t.start();
888 >        Thread.sleep(SHORT_DELAY_MS);
889 >        t.interrupt();
890 >        t.join();
891      }
892  
893      /**
894       * TakeFirst removes existing elements until empty, then blocks interruptibly
895       */
896 <    public void testBlockingTakeFirst() {
897 <        Thread t = new Thread(new Runnable() {
898 <                public void run() {
899 <                    try {
900 <                        LinkedBlockingDeque q = populatedDeque(SIZE);
901 <                        for (int i = 0; i < SIZE; ++i) {
902 <                            assertEquals(i, ((Integer)q.takeFirst()).intValue());
903 <                        }
904 <                        q.takeFirst();
905 <                        threadShouldThrow();
1024 <                    } catch (InterruptedException success) {
1025 <                    }
1026 <                }});
896 >    public void testBlockingTakeFirst() throws InterruptedException {
897 >        Thread t = new ThreadShouldThrow(InterruptedException.class) {
898 >            public void realRun() throws InterruptedException {
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 >            }};
905 >
906          t.start();
907 <        try {
908 <           Thread.sleep(SHORT_DELAY_MS);
909 <           t.interrupt();
1031 <           t.join();
1032 <        }
1033 <        catch (InterruptedException ie) {
1034 <            unexpectedException();
1035 <        }
907 >        Thread.sleep(SHORT_DELAY_MS);
908 >        t.interrupt();
909 >        t.join();
910      }
911  
912  
913      /**
914       * timed pollFirst with zero timeout succeeds when non-empty, else times out
915       */
916 <    public void testTimedPollFirst0() {
917 <        try {
918 <            LinkedBlockingDeque q = populatedDeque(SIZE);
919 <            for (int i = 0; i < SIZE; ++i) {
1046 <                assertEquals(i, ((Integer)q.pollFirst(0, MILLISECONDS)).intValue());
1047 <            }
1048 <            assertNull(q.pollFirst(0, MILLISECONDS));
1049 <        } catch (InterruptedException e) {
1050 <            unexpectedException();
916 >    public void testTimedPollFirst0() throws InterruptedException {
917 >        LinkedBlockingDeque q = populatedDeque(SIZE);
918 >        for (int i = 0; i < SIZE; ++i) {
919 >            assertEquals(i, ((Integer)q.pollFirst(0, MILLISECONDS)).intValue());
920          }
921 +        assertNull(q.pollFirst(0, MILLISECONDS));
922      }
923  
924      /**
925       * timed pollFirst with nonzero timeout succeeds when non-empty, else times out
926       */
927 <    public void testTimedPollFirst() {
928 <        try {
929 <            LinkedBlockingDeque q = populatedDeque(SIZE);
930 <            for (int i = 0; i < SIZE; ++i) {
1061 <                assertEquals(i, ((Integer)q.pollFirst(SHORT_DELAY_MS, MILLISECONDS)).intValue());
1062 <            }
1063 <            assertNull(q.pollFirst(SHORT_DELAY_MS, MILLISECONDS));
1064 <        } catch (InterruptedException e) {
1065 <            unexpectedException();
927 >    public void testTimedPollFirst() throws InterruptedException {
928 >        LinkedBlockingDeque q = populatedDeque(SIZE);
929 >        for (int i = 0; i < SIZE; ++i) {
930 >            assertEquals(i, ((Integer)q.pollFirst(SHORT_DELAY_MS, MILLISECONDS)).intValue());
931          }
932 +        assertNull(q.pollFirst(SHORT_DELAY_MS, MILLISECONDS));
933      }
934  
935      /**
936       * Interrupted timed pollFirst throws InterruptedException instead of
937       * returning timeout status
938       */
939 <    public void testInterruptedTimedPollFirst() {
940 <        Thread t = new Thread(new Runnable() {
941 <                public void run() {
942 <                    try {
943 <                        LinkedBlockingDeque q = populatedDeque(SIZE);
944 <                        for (int i = 0; i < SIZE; ++i) {
945 <                            threadAssertEquals(i, ((Integer)q.pollFirst(SHORT_DELAY_MS, MILLISECONDS)).intValue());
946 <                        }
947 <                        threadAssertNull(q.pollFirst(SHORT_DELAY_MS, MILLISECONDS));
948 <                    } catch (InterruptedException success) {
1083 <                    }
1084 <                }});
939 >    public void testInterruptedTimedPollFirst() throws InterruptedException {
940 >        Thread t = new ThreadShouldThrow(InterruptedException.class) {
941 >            public void realRun() throws InterruptedException {
942 >                LinkedBlockingDeque q = populatedDeque(SIZE);
943 >                for (int i = 0; i < SIZE; ++i) {
944 >                    threadAssertEquals(i, ((Integer)q.pollFirst(SHORT_DELAY_MS, MILLISECONDS)).intValue());
945 >                }
946 >                q.pollFirst(SMALL_DELAY_MS, MILLISECONDS);
947 >            }};
948 >
949          t.start();
950 <        try {
951 <           Thread.sleep(SHORT_DELAY_MS);
952 <           t.interrupt();
1089 <           t.join();
1090 <        }
1091 <        catch (InterruptedException ie) {
1092 <            unexpectedException();
1093 <        }
950 >        Thread.sleep(SHORT_DELAY_MS);
951 >        t.interrupt();
952 >        t.join();
953      }
954  
955      /**
956       *  timed pollFirst before a delayed offerFirst fails; after offerFirst succeeds;
957       *  on interruption throws
958       */
959 <    public void testTimedPollFirstWithOfferFirst() {
959 >    public void testTimedPollFirstWithOfferFirst() throws InterruptedException {
960          final LinkedBlockingDeque q = new LinkedBlockingDeque(2);
961 <        Thread t = new Thread(new Runnable() {
962 <                public void run() {
963 <                    try {
964 <                        threadAssertNull(q.pollFirst(SHORT_DELAY_MS, MILLISECONDS));
965 <                        q.pollFirst(LONG_DELAY_MS, MILLISECONDS);
966 <                        q.pollFirst(LONG_DELAY_MS, MILLISECONDS);
967 <                        threadShouldThrow();
968 <                    } catch (InterruptedException success) { }
969 <                }
970 <            });
971 <        try {
972 <            t.start();
1114 <            Thread.sleep(SMALL_DELAY_MS);
1115 <            assertTrue(q.offerFirst(zero, SHORT_DELAY_MS, MILLISECONDS));
1116 <            t.interrupt();
1117 <            t.join();
1118 <        } catch (Exception e) {
1119 <            unexpectedException();
1120 <        }
961 >        Thread t = new ThreadShouldThrow(InterruptedException.class) {
962 >            public void realRun() throws InterruptedException {
963 >                threadAssertNull(q.pollFirst(SHORT_DELAY_MS, MILLISECONDS));
964 >                q.pollFirst(LONG_DELAY_MS, MILLISECONDS);
965 >                q.pollFirst(LONG_DELAY_MS, MILLISECONDS);
966 >            }};
967 >
968 >        t.start();
969 >        Thread.sleep(SMALL_DELAY_MS);
970 >        assertTrue(q.offerFirst(zero, SHORT_DELAY_MS, MILLISECONDS));
971 >        t.interrupt();
972 >        t.join();
973      }
974  
975      /**
976       * putLast(null) throws NPE
977       */
978 <     public void testPutLastNull() {
978 >     public void testPutLastNull() throws InterruptedException {
979          try {
980              LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
981              q.putLast(null);
982              shouldThrow();
983 <        }
1132 <        catch (NullPointerException success) {
1133 <        }
1134 <        catch (InterruptedException ie) {
1135 <            unexpectedException();
1136 <        }
983 >        } catch (NullPointerException success) {}
984       }
985  
986      /**
987       * all elements successfully putLast are contained
988       */
989 <     public void testPutLast() {
990 <         try {
991 <             LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
992 <             for (int i = 0; i < SIZE; ++i) {
993 <                 Integer I = new Integer(i);
994 <                 q.putLast(I);
1148 <                 assertTrue(q.contains(I));
1149 <             }
1150 <             assertEquals(0, q.remainingCapacity());
989 >     public void testPutLast() throws InterruptedException {
990 >         LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
991 >         for (int i = 0; i < SIZE; ++i) {
992 >             Integer I = new Integer(i);
993 >             q.putLast(I);
994 >             assertTrue(q.contains(I));
995           }
996 <        catch (InterruptedException ie) {
1153 <            unexpectedException();
1154 <        }
996 >         assertEquals(0, q.remainingCapacity());
997      }
998  
999      /**
1000       * putLast blocks interruptibly if full
1001       */
1002 <    public void testBlockingPutLast() {
1002 >    public void testBlockingPutLast() throws InterruptedException {
1003          Thread t = new Thread(new Runnable() {
1004                  public void run() {
1005                      int added = 0;
# Line 1169 | Line 1011 | public class LinkedBlockingDequeTest ext
1011                          }
1012                          q.putLast(new Integer(SIZE));
1013                          threadShouldThrow();
1014 <                    } catch (InterruptedException ie) {
1014 >                    } catch (InterruptedException success) {
1015                          threadAssertEquals(added, SIZE);
1016                      }
1017                  }});
1018          t.start();
1019 <        try {
1020 <           Thread.sleep(SHORT_DELAY_MS);
1021 <           t.interrupt();
1180 <           t.join();
1181 <        }
1182 <        catch (InterruptedException ie) {
1183 <            unexpectedException();
1184 <        }
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() {
# Line 1202 | Line 1039 | public class LinkedBlockingDequeTest ext
1039                          q.putLast(new Object());
1040                          ++added;
1041                          threadShouldThrow();
1042 <                    } catch (InterruptedException e) {
1042 >                    } catch (InterruptedException success) {
1043                          threadAssertTrue(added >= 2);
1044                      }
1045                  }
1046              });
1047 <        try {
1048 <            t.start();
1049 <            Thread.sleep(SHORT_DELAY_MS);
1050 <            q.take();
1051 <            t.interrupt();
1052 <            t.join();
1216 <        } catch (Exception e) {
1217 <            unexpectedException();
1218 <        }
1047 >
1048 >        t.start();
1049 >        Thread.sleep(SHORT_DELAY_MS);
1050 >        q.take();
1051 >        t.interrupt();
1052 >        t.join();
1053      }
1054  
1055      /**
1056       * timed offerLast times out if full and elements not taken
1057       */
1058 <    public void testTimedOfferLast() {
1058 >    public void testTimedOfferLast() throws InterruptedException {
1059          final LinkedBlockingDeque q = new LinkedBlockingDeque(2);
1060 <        Thread t = new Thread(new Runnable() {
1061 <                public void run() {
1062 <                    try {
1063 <                        q.putLast(new Object());
1064 <                        q.putLast(new Object());
1065 <                        threadAssertFalse(q.offerLast(new Object(), SHORT_DELAY_MS, MILLISECONDS));
1066 <                        q.offerLast(new Object(), LONG_DELAY_MS, MILLISECONDS);
1233 <                        threadShouldThrow();
1234 <                    } catch (InterruptedException success) {}
1235 <                }
1236 <            });
1060 >        Thread t = new ThreadShouldThrow(InterruptedException.class) {
1061 >            public void realRun() throws InterruptedException {
1062 >                q.putLast(new Object());
1063 >                q.putLast(new Object());
1064 >                threadAssertFalse(q.offerLast(new Object(), SHORT_DELAY_MS, MILLISECONDS));
1065 >                q.offerLast(new Object(), LONG_DELAY_MS, MILLISECONDS);
1066 >            }};
1067  
1068 <        try {
1069 <            t.start();
1070 <            Thread.sleep(SMALL_DELAY_MS);
1071 <            t.interrupt();
1242 <            t.join();
1243 <        } catch (Exception e) {
1244 <            unexpectedException();
1245 <        }
1068 >        t.start();
1069 >        Thread.sleep(SMALL_DELAY_MS);
1070 >        t.interrupt();
1071 >        t.join();
1072      }
1073  
1074      /**
1075       * takeLast retrieves elements in FIFO order
1076       */
1077 <    public void testTakeLast() {
1078 <        try {
1079 <            LinkedBlockingDeque q = populatedDeque(SIZE);
1080 <            for (int i = 0; i < SIZE; ++i) {
1255 <                assertEquals(SIZE-i-1, ((Integer)q.takeLast()).intValue());
1256 <            }
1257 <        } catch (InterruptedException e) {
1258 <            unexpectedException();
1077 >    public void testTakeLast() throws InterruptedException {
1078 >        LinkedBlockingDeque q = populatedDeque(SIZE);
1079 >        for (int i = 0; i < SIZE; ++i) {
1080 >            assertEquals(SIZE-i-1, ((Integer)q.takeLast()).intValue());
1081          }
1082      }
1083  
1084      /**
1085       * takeLast blocks interruptibly when empty
1086       */
1087 <    public void testTakeLastFromEmpty() {
1087 >    public void testTakeLastFromEmpty() throws InterruptedException {
1088          final LinkedBlockingDeque q = new LinkedBlockingDeque(2);
1089 <        Thread t = new Thread(new Runnable() {
1090 <                public void run() {
1091 <                    try {
1092 <                        q.takeLast();
1093 <                        threadShouldThrow();
1094 <                    } catch (InterruptedException success) { }
1095 <                }
1096 <            });
1097 <        try {
1276 <            t.start();
1277 <            Thread.sleep(SHORT_DELAY_MS);
1278 <            t.interrupt();
1279 <            t.join();
1280 <        } catch (Exception e) {
1281 <            unexpectedException();
1282 <        }
1089 >        Thread t = new ThreadShouldThrow(InterruptedException.class) {
1090 >            public void realRun() throws InterruptedException {
1091 >                q.takeLast();
1092 >            }};
1093 >
1094 >        t.start();
1095 >        Thread.sleep(SHORT_DELAY_MS);
1096 >        t.interrupt();
1097 >        t.join();
1098      }
1099  
1100      /**
1101       * TakeLast removes existing elements until empty, then blocks interruptibly
1102       */
1103 <    public void testBlockingTakeLast() {
1104 <        Thread t = new Thread(new Runnable() {
1105 <                public void run() {
1106 <                    try {
1107 <                        LinkedBlockingDeque q = populatedDeque(SIZE);
1108 <                        for (int i = 0; i < SIZE; ++i) {
1109 <                            assertEquals(SIZE-i-1, ((Integer)q.takeLast()).intValue());
1110 <                        }
1111 <                        q.takeLast();
1112 <                        threadShouldThrow();
1298 <                    } catch (InterruptedException success) {
1299 <                    }
1300 <                }});
1103 >    public void testBlockingTakeLast() throws InterruptedException {
1104 >        Thread t = new ThreadShouldThrow(InterruptedException.class) {
1105 >            public void realRun() throws InterruptedException {
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 >            }};
1112 >
1113          t.start();
1114 <        try {
1115 <           Thread.sleep(SHORT_DELAY_MS);
1116 <           t.interrupt();
1305 <           t.join();
1306 <        }
1307 <        catch (InterruptedException ie) {
1308 <            unexpectedException();
1309 <        }
1114 >        Thread.sleep(SHORT_DELAY_MS);
1115 >        t.interrupt();
1116 >        t.join();
1117      }
1118  
1119  
1120      /**
1121       * timed pollLast with zero timeout succeeds when non-empty, else times out
1122       */
1123 <    public void testTimedPollLast0() {
1124 <        try {
1125 <            LinkedBlockingDeque q = populatedDeque(SIZE);
1126 <            for (int i = 0; i < SIZE; ++i) {
1320 <                assertEquals(SIZE-i-1, ((Integer)q.pollLast(0, MILLISECONDS)).intValue());
1321 <            }
1322 <            assertNull(q.pollLast(0, MILLISECONDS));
1323 <        } catch (InterruptedException e) {
1324 <            unexpectedException();
1123 >    public void testTimedPollLast0() throws InterruptedException {
1124 >        LinkedBlockingDeque q = populatedDeque(SIZE);
1125 >        for (int i = 0; i < SIZE; ++i) {
1126 >            assertEquals(SIZE-i-1, ((Integer)q.pollLast(0, MILLISECONDS)).intValue());
1127          }
1128 +        assertNull(q.pollLast(0, MILLISECONDS));
1129      }
1130  
1131      /**
1132       * timed pollLast with nonzero timeout succeeds when non-empty, else times out
1133       */
1134 <    public void testTimedPollLast() {
1135 <        try {
1136 <            LinkedBlockingDeque q = populatedDeque(SIZE);
1137 <            for (int i = 0; i < SIZE; ++i) {
1335 <                assertEquals(SIZE-i-1, ((Integer)q.pollLast(SHORT_DELAY_MS, MILLISECONDS)).intValue());
1336 <            }
1337 <            assertNull(q.pollLast(SHORT_DELAY_MS, MILLISECONDS));
1338 <        } catch (InterruptedException e) {
1339 <            unexpectedException();
1134 >    public void testTimedPollLast() throws InterruptedException {
1135 >        LinkedBlockingDeque q = populatedDeque(SIZE);
1136 >        for (int i = 0; i < SIZE; ++i) {
1137 >            assertEquals(SIZE-i-1, ((Integer)q.pollLast(SHORT_DELAY_MS, MILLISECONDS)).intValue());
1138          }
1139 +        assertNull(q.pollLast(SHORT_DELAY_MS, MILLISECONDS));
1140      }
1141  
1142      /**
1143       * Interrupted timed pollLast throws InterruptedException instead of
1144       * returning timeout status
1145       */
1146 <    public void testInterruptedTimedPollLast() {
1147 <        Thread t = new Thread(new Runnable() {
1148 <                public void run() {
1149 <                    try {
1150 <                        LinkedBlockingDeque q = populatedDeque(SIZE);
1151 <                        for (int i = 0; i < SIZE; ++i) {
1152 <                            threadAssertEquals(SIZE-i-1, ((Integer)q.pollLast(SHORT_DELAY_MS, MILLISECONDS)).intValue());
1153 <                        }
1154 <                        threadAssertNull(q.pollLast(SHORT_DELAY_MS, MILLISECONDS));
1155 <                    } catch (InterruptedException success) {
1357 <                    }
1358 <                }});
1146 >    public void testInterruptedTimedPollLast() throws InterruptedException {
1147 >        Thread t = new ThreadShouldThrow(InterruptedException.class) {
1148 >            public void realRun() throws InterruptedException {
1149 >                LinkedBlockingDeque q = populatedDeque(SIZE);
1150 >                for (int i = 0; i < SIZE; ++i) {
1151 >                    threadAssertEquals(SIZE-i-1, ((Integer)q.pollLast(SHORT_DELAY_MS, MILLISECONDS)).intValue());
1152 >                }
1153 >                q.pollLast(SMALL_DELAY_MS, MILLISECONDS);
1154 >            }};
1155 >
1156          t.start();
1157 <        try {
1158 <           Thread.sleep(SHORT_DELAY_MS);
1159 <           t.interrupt();
1363 <           t.join();
1364 <        }
1365 <        catch (InterruptedException ie) {
1366 <            unexpectedException();
1367 <        }
1157 >        Thread.sleep(SHORT_DELAY_MS);
1158 >        t.interrupt();
1159 >        t.join();
1160      }
1161  
1162      /**
1163       *  timed poll before a delayed offerLast fails; after offerLast succeeds;
1164       *  on interruption throws
1165       */
1166 <    public void testTimedPollWithOfferLast() {
1166 >    public void testTimedPollWithOfferLast() throws InterruptedException {
1167          final LinkedBlockingDeque q = new LinkedBlockingDeque(2);
1168 <        Thread t = new Thread(new Runnable() {
1169 <                public void run() {
1170 <                    try {
1171 <                        threadAssertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS));
1172 <                        q.poll(LONG_DELAY_MS, MILLISECONDS);
1173 <                        q.poll(LONG_DELAY_MS, MILLISECONDS);
1174 <                        threadShouldThrow();
1175 <                    } catch (InterruptedException success) { }
1176 <                }
1177 <            });
1178 <        try {
1179 <            t.start();
1180 <            Thread.sleep(SMALL_DELAY_MS);
1181 <            assertTrue(q.offerLast(zero, SHORT_DELAY_MS, MILLISECONDS));
1182 <            t.interrupt();
1391 <            t.join();
1392 <        } catch (Exception e) {
1393 <            unexpectedException();
1394 <        }
1168 >        Thread t = new Thread(new CheckedRunnable() {
1169 >            public void realRun() throws InterruptedException {
1170 >                assertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS));
1171 >                assertSame(zero, q.poll(LONG_DELAY_MS, MILLISECONDS));
1172 >                try {
1173 >                    q.poll(LONG_DELAY_MS, MILLISECONDS);
1174 >                    shouldThrow();
1175 >                } catch (InterruptedException success) {}
1176 >            }});
1177 >
1178 >        t.start();
1179 >        Thread.sleep(SMALL_DELAY_MS);
1180 >        assertTrue(q.offerLast(zero, SHORT_DELAY_MS, MILLISECONDS));
1181 >        t.interrupt();
1182 >        t.join();
1183      }
1184  
1185  
# Line 1407 | Line 1195 | public class LinkedBlockingDequeTest ext
1195          try {
1196              q.element();
1197              shouldThrow();
1198 <        }
1411 <        catch (NoSuchElementException success) {}
1198 >        } catch (NoSuchElementException success) {}
1199      }
1200  
1201      /**
# Line 1506 | Line 1293 | public class LinkedBlockingDequeTest ext
1293      /**
1294       * toArray contains all elements
1295       */
1296 <    public void testToArray() {
1296 >    public void testToArray() throws InterruptedException{
1297          LinkedBlockingDeque q = populatedDeque(SIZE);
1298          Object[] o = q.toArray();
1512        try {
1299          for (int i = 0; i < o.length; i++)
1300              assertEquals(o[i], q.take());
1515        } catch (InterruptedException e) {
1516            unexpectedException();
1517        }
1301      }
1302  
1303      /**
1304       * toArray(a) contains all elements
1305       */
1306 <    public void testToArray2() {
1306 >    public void testToArray2() throws InterruptedException {
1307          LinkedBlockingDeque q = populatedDeque(SIZE);
1308          Integer[] ints = new Integer[SIZE];
1309          ints = (Integer[])q.toArray(ints);
1310 <        try {
1311 <            for (int i = 0; i < ints.length; i++)
1529 <                assertEquals(ints[i], q.take());
1530 <        } catch (InterruptedException e) {
1531 <            unexpectedException();
1532 <        }
1310 >        for (int i = 0; i < ints.length; i++)
1311 >            assertEquals(ints[i], q.take());
1312      }
1313  
1314      /**
# Line 1551 | Line 1330 | public class LinkedBlockingDequeTest ext
1330              LinkedBlockingDeque q = populatedDeque(SIZE);
1331              Object o[] = q.toArray(new String[10] );
1332              shouldThrow();
1333 <        } catch (ArrayStoreException  success) {}
1333 >        } catch (ArrayStoreException success) {}
1334      }
1335  
1336  
1337      /**
1338       * iterator iterates through all elements
1339       */
1340 <    public void testIterator() {
1340 >    public void testIterator() throws InterruptedException {
1341          LinkedBlockingDeque q = populatedDeque(SIZE);
1342          Iterator it = q.iterator();
1343 <        try {
1344 <            while (it.hasNext()) {
1566 <                assertEquals(it.next(), q.take());
1567 <            }
1568 <        } catch (InterruptedException e) {
1569 <            unexpectedException();
1343 >        while (it.hasNext()) {
1344 >            assertEquals(it.next(), q.take());
1345          }
1346      }
1347  
# Line 1615 | Line 1390 | public class LinkedBlockingDequeTest ext
1390          q.add(one);
1391          q.add(two);
1392          q.add(three);
1393 <        try {
1394 <            for (Iterator it = q.iterator(); it.hasNext();) {
1395 <                q.remove();
1621 <                it.next();
1622 <            }
1623 <        }
1624 <        catch (ConcurrentModificationException e) {
1625 <            unexpectedException();
1393 >        for (Iterator it = q.iterator(); it.hasNext();) {
1394 >            q.remove();
1395 >            it.next();
1396          }
1397          assertEquals(0, q.size());
1398      }
# Line 1643 | Line 1413 | public class LinkedBlockingDequeTest ext
1413          assertFalse(it.hasNext());
1414          try {
1415              it.next();
1416 <        } catch (NoSuchElementException success) {
1417 <        }
1416 >            shouldThrow();
1417 >        } catch (NoSuchElementException success) {}
1418      }
1419  
1420      /**
# Line 1712 | Line 1482 | public class LinkedBlockingDequeTest ext
1482          q.add(one);
1483          q.add(two);
1484          ExecutorService executor = Executors.newFixedThreadPool(2);
1485 <        executor.execute(new Runnable() {
1486 <            public void run() {
1485 >        executor.execute(new CheckedRunnable() {
1486 >            public void realRun() throws InterruptedException {
1487                  threadAssertFalse(q.offer(three));
1488 <                try {
1489 <                    threadAssertTrue(q.offer(three, MEDIUM_DELAY_MS, MILLISECONDS));
1490 <                    threadAssertEquals(0, q.remainingCapacity());
1491 <                }
1492 <                catch (InterruptedException e) {
1493 <                    threadUnexpectedException();
1494 <                }
1495 <            }
1496 <        });
1727 <
1728 <        executor.execute(new Runnable() {
1729 <            public void run() {
1730 <                try {
1731 <                    Thread.sleep(SMALL_DELAY_MS);
1732 <                    threadAssertEquals(one, q.take());
1733 <                }
1734 <                catch (InterruptedException e) {
1735 <                    threadUnexpectedException();
1736 <                }
1737 <            }
1738 <        });
1488 >                threadAssertTrue(q.offer(three, MEDIUM_DELAY_MS, MILLISECONDS));
1489 >                threadAssertEquals(0, q.remainingCapacity());
1490 >            }});
1491 >
1492 >        executor.execute(new CheckedRunnable() {
1493 >            public void realRun() throws InterruptedException {
1494 >                Thread.sleep(SMALL_DELAY_MS);
1495 >                threadAssertEquals(one, q.take());
1496 >            }});
1497  
1498          joinPool(executor);
1499      }
# Line 1746 | Line 1504 | public class LinkedBlockingDequeTest ext
1504      public void testPollInExecutor() {
1505          final LinkedBlockingDeque q = new LinkedBlockingDeque(2);
1506          ExecutorService executor = Executors.newFixedThreadPool(2);
1507 <        executor.execute(new Runnable() {
1508 <            public void run() {
1507 >        executor.execute(new CheckedRunnable() {
1508 >            public void realRun() throws InterruptedException {
1509                  threadAssertNull(q.poll());
1510 <                try {
1511 <                    threadAssertTrue(null != q.poll(MEDIUM_DELAY_MS, MILLISECONDS));
1512 <                    threadAssertTrue(q.isEmpty());
1513 <                }
1514 <                catch (InterruptedException e) {
1515 <                    threadUnexpectedException();
1516 <                }
1517 <            }
1518 <        });
1761 <
1762 <        executor.execute(new Runnable() {
1763 <            public void run() {
1764 <                try {
1765 <                    Thread.sleep(SMALL_DELAY_MS);
1766 <                    q.put(one);
1767 <                }
1768 <                catch (InterruptedException e) {
1769 <                    threadUnexpectedException();
1770 <                }
1771 <            }
1772 <        });
1510 >                threadAssertTrue(null != q.poll(MEDIUM_DELAY_MS, MILLISECONDS));
1511 >                threadAssertTrue(q.isEmpty());
1512 >            }});
1513 >
1514 >        executor.execute(new CheckedRunnable() {
1515 >            public void realRun() throws InterruptedException {
1516 >                Thread.sleep(SMALL_DELAY_MS);
1517 >                q.put(one);
1518 >            }});
1519  
1520          joinPool(executor);
1521      }
# Line 1777 | Line 1523 | public class LinkedBlockingDequeTest ext
1523      /**
1524       * A deserialized serialized deque has same elements in same order
1525       */
1526 <    public void testSerialization() {
1526 >    public void testSerialization() throws Exception {
1527          LinkedBlockingDeque q = populatedDeque(SIZE);
1528  
1529 <        try {
1530 <            ByteArrayOutputStream bout = new ByteArrayOutputStream(10000);
1531 <            ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout));
1532 <            out.writeObject(q);
1533 <            out.close();
1534 <
1535 <            ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
1536 <            ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin));
1537 <            LinkedBlockingDeque r = (LinkedBlockingDeque)in.readObject();
1538 <            assertEquals(q.size(), r.size());
1539 <            while (!q.isEmpty())
1794 <                assertEquals(q.remove(), r.remove());
1795 <        } catch (Exception e) {
1796 <            unexpectedException();
1797 <        }
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())
1539 >            assertEquals(q.remove(), r.remove());
1540      }
1541  
1542      /**
# Line 1805 | Line 1547 | public class LinkedBlockingDequeTest ext
1547          try {
1548              q.drainTo(null);
1549              shouldThrow();
1550 <        } catch (NullPointerException success) {
1809 <        }
1550 >        } catch (NullPointerException success) {}
1551      }
1552  
1553      /**
# Line 1817 | Line 1558 | public class LinkedBlockingDequeTest ext
1558          try {
1559              q.drainTo(q);
1560              shouldThrow();
1561 <        } catch (IllegalArgumentException success) {
1821 <        }
1561 >        } catch (IllegalArgumentException success) {}
1562      }
1563  
1564      /**
# Line 1848 | Line 1588 | public class LinkedBlockingDequeTest ext
1588      /**
1589       * drainTo empties full deque, unblocking a waiting put.
1590       */
1591 <    public void testDrainToWithActivePut() {
1591 >    public void testDrainToWithActivePut() throws InterruptedException {
1592          final LinkedBlockingDeque q = populatedDeque(SIZE);
1593 <        Thread t = new Thread(new Runnable() {
1594 <                public void run() {
1595 <                    try {
1596 <                        q.put(new Integer(SIZE+1));
1597 <                    } catch (InterruptedException ie) {
1598 <                        threadUnexpectedException();
1599 <                    }
1600 <                }
1601 <            });
1602 <        try {
1603 <            t.start();
1604 <            ArrayList l = new ArrayList();
1605 <            q.drainTo(l);
1866 <            assertTrue(l.size() >= SIZE);
1867 <            for (int i = 0; i < SIZE; ++i)
1868 <                assertEquals(l.get(i), new Integer(i));
1869 <            t.join();
1870 <            assertTrue(q.size() + l.size() >= SIZE);
1871 <        } catch (Exception e) {
1872 <            unexpectedException();
1873 <        }
1593 >        Thread t = new Thread(new CheckedRunnable() {
1594 >            public void realRun() throws InterruptedException {
1595 >                q.put(new Integer(SIZE+1));
1596 >            }});
1597 >
1598 >        t.start();
1599 >        ArrayList l = new ArrayList();
1600 >        q.drainTo(l);
1601 >        assertTrue(l.size() >= SIZE);
1602 >        for (int i = 0; i < SIZE; ++i)
1603 >            assertEquals(l.get(i), new Integer(i));
1604 >        t.join();
1605 >        assertTrue(q.size() + l.size() >= SIZE);
1606      }
1607  
1608      /**
# Line 1881 | Line 1613 | public class LinkedBlockingDequeTest ext
1613          try {
1614              q.drainTo(null, 0);
1615              shouldThrow();
1616 <        } catch (NullPointerException success) {
1885 <        }
1616 >        } catch (NullPointerException success) {}
1617      }
1618  
1619      /**
# Line 1893 | Line 1624 | public class LinkedBlockingDequeTest ext
1624          try {
1625              q.drainTo(q, 0);
1626              shouldThrow();
1627 <        } catch (IllegalArgumentException success) {
1897 <        }
1627 >        } catch (IllegalArgumentException success) {}
1628      }
1629  
1630      /**

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines