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.9 by jsr166, Sat Nov 21 08:37:39 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 <        }
572 <        catch (NullPointerException success) {
573 <        }
574 <        catch (InterruptedException ie) {
575 <            unexpectedException();
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);
588 <                 assertTrue(q.contains(I));
589 <             }
590 <             assertEquals(0, q.remainingCapacity());
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 <        catch (InterruptedException ie) {
593 <            unexpectedException();
594 <        }
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() {
# Line 642 | Line 613 | public class LinkedBlockingDequeTest ext
613                          q.put(new Object());
614                          ++added;
615                          threadShouldThrow();
616 <                    } catch (InterruptedException e) {
616 >                    } catch (InterruptedException success) {
617                          threadAssertTrue(added >= 2);
618                      }
619                  }
620              });
621 <        try {
622 <            t.start();
623 <            Thread.sleep(SHORT_DELAY_MS);
624 <            q.take();
625 <            t.interrupt();
626 <            t.join();
656 <        } catch (Exception e) {
657 <            unexpectedException();
658 <        }
621 >
622 >        t.start();
623 >        Thread.sleep(SHORT_DELAY_MS);
624 >        q.take();
625 >        t.interrupt();
626 >        t.join();
627      }
628  
629      /**
630       * timed offer times out if full and elements not taken
631       */
632 <    public void testTimedOffer() {
632 >    public void testTimedOffer() throws InterruptedException {
633          final LinkedBlockingDeque q = new LinkedBlockingDeque(2);
634 <        Thread t = new Thread(new Runnable() {
635 <                public void run() {
636 <                    try {
637 <                        q.put(new Object());
638 <                        q.put(new Object());
639 <                        threadAssertFalse(q.offer(new Object(), SHORT_DELAY_MS, MILLISECONDS));
640 <                        q.offer(new Object(), LONG_DELAY_MS, MILLISECONDS);
673 <                        threadShouldThrow();
674 <                    } catch (InterruptedException success) {}
675 <                }
676 <            });
634 >        Thread t = new ThreadShouldThrow(InterruptedException.class) {
635 >            public void realRun() throws InterruptedException {
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);
640 >            }};
641  
642 <        try {
643 <            t.start();
644 <            Thread.sleep(SMALL_DELAY_MS);
645 <            t.interrupt();
682 <            t.join();
683 <        } catch (Exception e) {
684 <            unexpectedException();
685 <        }
642 >        t.start();
643 >        Thread.sleep(SMALL_DELAY_MS);
644 >        t.interrupt();
645 >        t.join();
646      }
647  
648      /**
649       * take retrieves elements in FIFO order
650       */
651 <    public void testTake() {
652 <        try {
653 <            LinkedBlockingDeque q = populatedDeque(SIZE);
654 <            for (int i = 0; i < SIZE; ++i) {
695 <                assertEquals(i, ((Integer)q.take()).intValue());
696 <            }
697 <        } catch (InterruptedException e) {
698 <            unexpectedException();
651 >    public void testTake() throws InterruptedException {
652 >        LinkedBlockingDeque q = populatedDeque(SIZE);
653 >        for (int i = 0; i < SIZE; ++i) {
654 >            assertEquals(i, ((Integer)q.take()).intValue());
655          }
656      }
657  
658      /**
659       * take blocks interruptibly when empty
660       */
661 <    public void testTakeFromEmpty() {
661 >    public void testTakeFromEmpty() throws InterruptedException {
662          final LinkedBlockingDeque q = new LinkedBlockingDeque(2);
663 <        Thread t = new Thread(new Runnable() {
664 <                public void run() {
665 <                    try {
666 <                        q.take();
667 <                        threadShouldThrow();
668 <                    } catch (InterruptedException success) { }
669 <                }
670 <            });
671 <        try {
716 <            t.start();
717 <            Thread.sleep(SHORT_DELAY_MS);
718 <            t.interrupt();
719 <            t.join();
720 <        } catch (Exception e) {
721 <            unexpectedException();
722 <        }
663 >        Thread t = new ThreadShouldThrow(InterruptedException.class) {
664 >            public void realRun() throws InterruptedException {
665 >                q.take();
666 >            }};
667 >
668 >        t.start();
669 >        Thread.sleep(SHORT_DELAY_MS);
670 >        t.interrupt();
671 >        t.join();
672      }
673  
674      /**
675       * Take removes existing elements until empty, then blocks interruptibly
676       */
677 <    public void testBlockingTake() {
678 <        Thread t = new Thread(new Runnable() {
679 <                public void run() {
680 <                    try {
681 <                        LinkedBlockingDeque q = populatedDeque(SIZE);
682 <                        for (int i = 0; i < SIZE; ++i) {
683 <                            assertEquals(i, ((Integer)q.take()).intValue());
684 <                        }
685 <                        q.take();
686 <                        threadShouldThrow();
738 <                    } catch (InterruptedException success) {
739 <                    }
740 <                }});
677 >    public void testBlockingTake() throws InterruptedException {
678 >        Thread t = new ThreadShouldThrow(InterruptedException.class) {
679 >            public void realRun() throws InterruptedException {
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 >            }};
686 >
687          t.start();
688 <        try {
689 <           Thread.sleep(SHORT_DELAY_MS);
690 <           t.interrupt();
745 <           t.join();
746 <        }
747 <        catch (InterruptedException ie) {
748 <            unexpectedException();
749 <        }
688 >        Thread.sleep(SHORT_DELAY_MS);
689 >        t.interrupt();
690 >        t.join();
691      }
692  
693  
# Line 764 | Line 705 | public class LinkedBlockingDequeTest ext
705      /**
706       * timed poll with zero timeout succeeds when non-empty, else times out
707       */
708 <    public void testTimedPoll0() {
709 <        try {
710 <            LinkedBlockingDeque q = populatedDeque(SIZE);
711 <            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();
708 >    public void testTimedPoll0() throws InterruptedException {
709 >        LinkedBlockingDeque q = populatedDeque(SIZE);
710 >        for (int i = 0; i < SIZE; ++i) {
711 >            assertEquals(i, ((Integer)q.poll(0, MILLISECONDS)).intValue());
712          }
713 +        assertNull(q.poll(0, MILLISECONDS));
714      }
715  
716      /**
717       * timed poll with nonzero timeout succeeds when non-empty, else times out
718       */
719 <    public void testTimedPoll() {
720 <        try {
721 <            LinkedBlockingDeque q = populatedDeque(SIZE);
722 <            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();
719 >    public void testTimedPoll() throws InterruptedException {
720 >        LinkedBlockingDeque q = populatedDeque(SIZE);
721 >        for (int i = 0; i < SIZE; ++i) {
722 >            assertEquals(i, ((Integer)q.poll(SHORT_DELAY_MS, MILLISECONDS)).intValue());
723          }
724 +        assertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS));
725      }
726  
727      /**
728       * Interrupted timed poll throws InterruptedException instead of
729       * returning timeout status
730       */
731 <    public void testInterruptedTimedPoll() {
732 <        Thread t = new Thread(new Runnable() {
733 <                public void run() {
734 <                    try {
735 <                        LinkedBlockingDeque q = populatedDeque(SIZE);
736 <                        for (int i = 0; i < SIZE; ++i) {
737 <                            threadAssertEquals(i, ((Integer)q.poll(SHORT_DELAY_MS, MILLISECONDS)).intValue());
738 <                        }
739 <                        threadAssertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS));
740 <                    } catch (InterruptedException success) {
808 <                    }
809 <                }});
731 >    public void testInterruptedTimedPoll() throws InterruptedException {
732 >        Thread t = new ThreadShouldThrow(InterruptedException.class) {
733 >            public void realRun() throws InterruptedException {
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 >                q.poll(SMALL_DELAY_MS, MILLISECONDS);
739 >            }};
740 >
741          t.start();
742 <        try {
743 <           Thread.sleep(SHORT_DELAY_MS);
744 <           t.interrupt();
814 <           t.join();
815 <        }
816 <        catch (InterruptedException ie) {
817 <            unexpectedException();
818 <        }
742 >        Thread.sleep(SHORT_DELAY_MS);
743 >        t.interrupt();
744 >        t.join();
745      }
746  
747      /**
748       *  timed poll before a delayed offer fails; after offer succeeds;
749       *  on interruption throws
750       */
751 <    public void testTimedPollWithOffer() {
751 >    public void testTimedPollWithOffer() throws InterruptedException {
752          final LinkedBlockingDeque q = new LinkedBlockingDeque(2);
753 <        Thread t = new Thread(new Runnable() {
754 <                public void run() {
755 <                    try {
756 <                        threadAssertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS));
757 <                        q.poll(LONG_DELAY_MS, MILLISECONDS);
758 <                        q.poll(LONG_DELAY_MS, MILLISECONDS);
759 <                        threadShouldThrow();
760 <                    } catch (InterruptedException success) { }
761 <                }
762 <            });
763 <        try {
764 <            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 <        }
753 >        Thread t = new ThreadShouldThrow(InterruptedException.class) {
754 >            public void realRun() throws InterruptedException {
755 >                threadAssertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS));
756 >                q.poll(LONG_DELAY_MS, MILLISECONDS);
757 >                q.poll(LONG_DELAY_MS, MILLISECONDS);
758 >            }};
759 >
760 >        t.start();
761 >        Thread.sleep(SMALL_DELAY_MS);
762 >        assertTrue(q.offer(zero, SHORT_DELAY_MS, MILLISECONDS));
763 >        t.interrupt();
764 >        t.join();
765      }
766  
767  
768      /**
769       * putFirst(null) throws NPE
770       */
771 <     public void testPutFirstNull() {
771 >     public void testPutFirstNull() throws InterruptedException {
772          try {
773              LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
774              q.putFirst(null);
775              shouldThrow();
776 <        }
858 <        catch (NullPointerException success) {
859 <        }
860 <        catch (InterruptedException ie) {
861 <            unexpectedException();
862 <        }
776 >        } catch (NullPointerException success) {}
777       }
778  
779      /**
780       * all elements successfully putFirst are contained
781       */
782 <     public void testPutFirst() {
783 <         try {
784 <             LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
785 <             for (int i = 0; i < SIZE; ++i) {
786 <                 Integer I = new Integer(i);
787 <                 q.putFirst(I);
874 <                 assertTrue(q.contains(I));
875 <             }
876 <             assertEquals(0, q.remainingCapacity());
782 >     public void testPutFirst() throws InterruptedException {
783 >         LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
784 >         for (int i = 0; i < SIZE; ++i) {
785 >             Integer I = new Integer(i);
786 >             q.putFirst(I);
787 >             assertTrue(q.contains(I));
788           }
789 <        catch (InterruptedException ie) {
879 <            unexpectedException();
880 <        }
789 >         assertEquals(0, q.remainingCapacity());
790      }
791  
792      /**
793       * putFirst blocks interruptibly if full
794       */
795 <    public void testBlockingPutFirst() {
795 >    public void testBlockingPutFirst() throws InterruptedException {
796          Thread t = new Thread(new Runnable() {
797                  public void run() {
798                      int added = 0;
# Line 895 | Line 804 | public class LinkedBlockingDequeTest ext
804                          }
805                          q.putFirst(new Integer(SIZE));
806                          threadShouldThrow();
807 <                    } catch (InterruptedException ie) {
807 >                    } catch (InterruptedException success) {
808                          threadAssertEquals(added, SIZE);
809                      }
810                  }});
811 +
812          t.start();
813 <        try {
814 <           Thread.sleep(SHORT_DELAY_MS);
815 <           t.interrupt();
906 <           t.join();
907 <        }
908 <        catch (InterruptedException ie) {
909 <            unexpectedException();
910 <        }
813 >        Thread.sleep(SHORT_DELAY_MS);
814 >        t.interrupt();
815 >        t.join();
816      }
817  
818      /**
819       * putFirst blocks waiting for take when full
820       */
821 <    public void testPutFirstWithTake() {
821 >    public void testPutFirstWithTake() throws InterruptedException {
822          final LinkedBlockingDeque q = new LinkedBlockingDeque(2);
823          Thread t = new Thread(new Runnable() {
824                  public void run() {
# Line 928 | Line 833 | public class LinkedBlockingDequeTest ext
833                          q.putFirst(new Object());
834                          ++added;
835                          threadShouldThrow();
836 <                    } catch (InterruptedException e) {
836 >                    } catch (InterruptedException success) {
837                          threadAssertTrue(added >= 2);
838                      }
839                  }
840              });
841 <        try {
842 <            t.start();
843 <            Thread.sleep(SHORT_DELAY_MS);
844 <            q.take();
845 <            t.interrupt();
846 <            t.join();
942 <        } catch (Exception e) {
943 <            unexpectedException();
944 <        }
841 >
842 >        t.start();
843 >        Thread.sleep(SHORT_DELAY_MS);
844 >        q.take();
845 >        t.interrupt();
846 >        t.join();
847      }
848  
849      /**
850       * timed offerFirst times out if full and elements not taken
851       */
852 <    public void testTimedOfferFirst() {
852 >    public void testTimedOfferFirst() throws InterruptedException {
853          final LinkedBlockingDeque q = new LinkedBlockingDeque(2);
854 <        Thread t = new Thread(new Runnable() {
855 <                public void run() {
856 <                    try {
857 <                        q.putFirst(new Object());
858 <                        q.putFirst(new Object());
859 <                        threadAssertFalse(q.offerFirst(new Object(), SHORT_DELAY_MS, MILLISECONDS));
860 <                        q.offerFirst(new Object(), LONG_DELAY_MS, MILLISECONDS);
959 <                        threadShouldThrow();
960 <                    } catch (InterruptedException success) {}
961 <                }
962 <            });
854 >        Thread t = new ThreadShouldThrow(InterruptedException.class) {
855 >            public void realRun() throws InterruptedException {
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);
860 >            }};
861  
862 <        try {
863 <            t.start();
864 <            Thread.sleep(SMALL_DELAY_MS);
865 <            t.interrupt();
968 <            t.join();
969 <        } catch (Exception e) {
970 <            unexpectedException();
971 <        }
862 >        t.start();
863 >        Thread.sleep(SMALL_DELAY_MS);
864 >        t.interrupt();
865 >        t.join();
866      }
867  
868      /**
869       * take retrieves elements in FIFO order
870       */
871 <    public void testTakeFirst() {
872 <        try {
873 <            LinkedBlockingDeque q = populatedDeque(SIZE);
874 <            for (int i = 0; i < SIZE; ++i) {
981 <                assertEquals(i, ((Integer)q.takeFirst()).intValue());
982 <            }
983 <        } catch (InterruptedException e) {
984 <            unexpectedException();
871 >    public void testTakeFirst() throws InterruptedException {
872 >        LinkedBlockingDeque q = populatedDeque(SIZE);
873 >        for (int i = 0; i < SIZE; ++i) {
874 >            assertEquals(i, ((Integer)q.takeFirst()).intValue());
875          }
876      }
877  
878      /**
879       * takeFirst blocks interruptibly when empty
880       */
881 <    public void testTakeFirstFromEmpty() {
881 >    public void testTakeFirstFromEmpty() throws InterruptedException {
882          final LinkedBlockingDeque q = new LinkedBlockingDeque(2);
883 <        Thread t = new Thread(new Runnable() {
884 <                public void run() {
885 <                    try {
886 <                        q.takeFirst();
887 <                        threadShouldThrow();
888 <                    } catch (InterruptedException success) { }
889 <                }
890 <            });
891 <        try {
1002 <            t.start();
1003 <            Thread.sleep(SHORT_DELAY_MS);
1004 <            t.interrupt();
1005 <            t.join();
1006 <        } catch (Exception e) {
1007 <            unexpectedException();
1008 <        }
883 >        Thread t = new ThreadShouldThrow(InterruptedException.class) {
884 >            public void realRun() throws InterruptedException {
885 >                q.takeFirst();
886 >            }};
887 >
888 >        t.start();
889 >        Thread.sleep(SHORT_DELAY_MS);
890 >        t.interrupt();
891 >        t.join();
892      }
893  
894      /**
895       * TakeFirst removes existing elements until empty, then blocks interruptibly
896       */
897 <    public void testBlockingTakeFirst() {
898 <        Thread t = new Thread(new Runnable() {
899 <                public void run() {
900 <                    try {
901 <                        LinkedBlockingDeque q = populatedDeque(SIZE);
902 <                        for (int i = 0; i < SIZE; ++i) {
903 <                            assertEquals(i, ((Integer)q.takeFirst()).intValue());
904 <                        }
905 <                        q.takeFirst();
906 <                        threadShouldThrow();
1024 <                    } catch (InterruptedException success) {
1025 <                    }
1026 <                }});
897 >    public void testBlockingTakeFirst() throws InterruptedException {
898 >        Thread t = new ThreadShouldThrow(InterruptedException.class) {
899 >            public void realRun() throws InterruptedException {
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 >            }};
906 >
907          t.start();
908 <        try {
909 <           Thread.sleep(SHORT_DELAY_MS);
910 <           t.interrupt();
1031 <           t.join();
1032 <        }
1033 <        catch (InterruptedException ie) {
1034 <            unexpectedException();
1035 <        }
908 >        Thread.sleep(SHORT_DELAY_MS);
909 >        t.interrupt();
910 >        t.join();
911      }
912  
913  
914      /**
915       * timed pollFirst with zero timeout succeeds when non-empty, else times out
916       */
917 <    public void testTimedPollFirst0() {
918 <        try {
919 <            LinkedBlockingDeque q = populatedDeque(SIZE);
920 <            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();
917 >    public void testTimedPollFirst0() throws InterruptedException {
918 >        LinkedBlockingDeque q = populatedDeque(SIZE);
919 >        for (int i = 0; i < SIZE; ++i) {
920 >            assertEquals(i, ((Integer)q.pollFirst(0, MILLISECONDS)).intValue());
921          }
922 +        assertNull(q.pollFirst(0, MILLISECONDS));
923      }
924  
925      /**
926       * timed pollFirst with nonzero timeout succeeds when non-empty, else times out
927       */
928 <    public void testTimedPollFirst() {
929 <        try {
930 <            LinkedBlockingDeque q = populatedDeque(SIZE);
931 <            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();
928 >    public void testTimedPollFirst() throws InterruptedException {
929 >        LinkedBlockingDeque q = populatedDeque(SIZE);
930 >        for (int i = 0; i < SIZE; ++i) {
931 >            assertEquals(i, ((Integer)q.pollFirst(SHORT_DELAY_MS, MILLISECONDS)).intValue());
932          }
933 +        assertNull(q.pollFirst(SHORT_DELAY_MS, MILLISECONDS));
934      }
935  
936      /**
937       * Interrupted timed pollFirst throws InterruptedException instead of
938       * returning timeout status
939       */
940 <    public void testInterruptedTimedPollFirst() {
941 <        Thread t = new Thread(new Runnable() {
942 <                public void run() {
943 <                    try {
944 <                        LinkedBlockingDeque q = populatedDeque(SIZE);
945 <                        for (int i = 0; i < SIZE; ++i) {
946 <                            threadAssertEquals(i, ((Integer)q.pollFirst(SHORT_DELAY_MS, MILLISECONDS)).intValue());
947 <                        }
948 <                        threadAssertNull(q.pollFirst(SHORT_DELAY_MS, MILLISECONDS));
949 <                    } catch (InterruptedException success) {
1083 <                    }
1084 <                }});
940 >    public void testInterruptedTimedPollFirst() throws InterruptedException {
941 >        Thread t = new ThreadShouldThrow(InterruptedException.class) {
942 >            public void realRun() throws InterruptedException {
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 >                q.pollFirst(SMALL_DELAY_MS, MILLISECONDS);
948 >            }};
949 >
950          t.start();
951 <        try {
952 <           Thread.sleep(SHORT_DELAY_MS);
953 <           t.interrupt();
1089 <           t.join();
1090 <        }
1091 <        catch (InterruptedException ie) {
1092 <            unexpectedException();
1093 <        }
951 >        Thread.sleep(SHORT_DELAY_MS);
952 >        t.interrupt();
953 >        t.join();
954      }
955  
956      /**
957       *  timed pollFirst before a delayed offerFirst fails; after offerFirst succeeds;
958       *  on interruption throws
959       */
960 <    public void testTimedPollFirstWithOfferFirst() {
960 >    public void testTimedPollFirstWithOfferFirst() throws InterruptedException {
961          final LinkedBlockingDeque q = new LinkedBlockingDeque(2);
962 <        Thread t = new Thread(new Runnable() {
963 <                public void run() {
964 <                    try {
965 <                        threadAssertNull(q.pollFirst(SHORT_DELAY_MS, MILLISECONDS));
966 <                        q.pollFirst(LONG_DELAY_MS, MILLISECONDS);
967 <                        q.pollFirst(LONG_DELAY_MS, MILLISECONDS);
968 <                        threadShouldThrow();
969 <                    } catch (InterruptedException success) { }
970 <                }
971 <            });
972 <        try {
973 <            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 <        }
962 >        Thread t = new ThreadShouldThrow(InterruptedException.class) {
963 >            public void realRun() throws InterruptedException {
964 >                threadAssertNull(q.pollFirst(SHORT_DELAY_MS, MILLISECONDS));
965 >                q.pollFirst(LONG_DELAY_MS, MILLISECONDS);
966 >                q.pollFirst(LONG_DELAY_MS, MILLISECONDS);
967 >            }};
968 >
969 >        t.start();
970 >        Thread.sleep(SMALL_DELAY_MS);
971 >        assertTrue(q.offerFirst(zero, SHORT_DELAY_MS, MILLISECONDS));
972 >        t.interrupt();
973 >        t.join();
974      }
975  
976      /**
977       * putLast(null) throws NPE
978       */
979 <     public void testPutLastNull() {
979 >     public void testPutLastNull() throws InterruptedException {
980          try {
981              LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
982              q.putLast(null);
983              shouldThrow();
984 <        }
1132 <        catch (NullPointerException success) {
1133 <        }
1134 <        catch (InterruptedException ie) {
1135 <            unexpectedException();
1136 <        }
984 >        } catch (NullPointerException success) {}
985       }
986  
987      /**
988       * all elements successfully putLast are contained
989       */
990 <     public void testPutLast() {
991 <         try {
992 <             LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
993 <             for (int i = 0; i < SIZE; ++i) {
994 <                 Integer I = new Integer(i);
995 <                 q.putLast(I);
1148 <                 assertTrue(q.contains(I));
1149 <             }
1150 <             assertEquals(0, q.remainingCapacity());
990 >     public void testPutLast() throws InterruptedException {
991 >         LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
992 >         for (int i = 0; i < SIZE; ++i) {
993 >             Integer I = new Integer(i);
994 >             q.putLast(I);
995 >             assertTrue(q.contains(I));
996           }
997 <        catch (InterruptedException ie) {
1153 <            unexpectedException();
1154 <        }
997 >         assertEquals(0, q.remainingCapacity());
998      }
999  
1000      /**
1001       * putLast blocks interruptibly if full
1002       */
1003 <    public void testBlockingPutLast() {
1003 >    public void testBlockingPutLast() throws InterruptedException {
1004          Thread t = new Thread(new Runnable() {
1005                  public void run() {
1006                      int added = 0;
# Line 1169 | Line 1012 | public class LinkedBlockingDequeTest ext
1012                          }
1013                          q.putLast(new Integer(SIZE));
1014                          threadShouldThrow();
1015 <                    } catch (InterruptedException ie) {
1015 >                    } catch (InterruptedException success) {
1016                          threadAssertEquals(added, SIZE);
1017                      }
1018                  }});
1019          t.start();
1020 <        try {
1021 <           Thread.sleep(SHORT_DELAY_MS);
1022 <           t.interrupt();
1180 <           t.join();
1181 <        }
1182 <        catch (InterruptedException ie) {
1183 <            unexpectedException();
1184 <        }
1020 >        Thread.sleep(SHORT_DELAY_MS);
1021 >        t.interrupt();
1022 >        t.join();
1023      }
1024  
1025      /**
1026       * putLast blocks waiting for take when full
1027       */
1028 <    public void testPutLastWithTake() {
1028 >    public void testPutLastWithTake() throws InterruptedException {
1029          final LinkedBlockingDeque q = new LinkedBlockingDeque(2);
1030          Thread t = new Thread(new Runnable() {
1031                  public void run() {
# Line 1202 | Line 1040 | public class LinkedBlockingDequeTest ext
1040                          q.putLast(new Object());
1041                          ++added;
1042                          threadShouldThrow();
1043 <                    } catch (InterruptedException e) {
1043 >                    } catch (InterruptedException success) {
1044                          threadAssertTrue(added >= 2);
1045                      }
1046                  }
1047              });
1048 <        try {
1049 <            t.start();
1050 <            Thread.sleep(SHORT_DELAY_MS);
1051 <            q.take();
1052 <            t.interrupt();
1053 <            t.join();
1216 <        } catch (Exception e) {
1217 <            unexpectedException();
1218 <        }
1048 >
1049 >        t.start();
1050 >        Thread.sleep(SHORT_DELAY_MS);
1051 >        q.take();
1052 >        t.interrupt();
1053 >        t.join();
1054      }
1055  
1056      /**
1057       * timed offerLast times out if full and elements not taken
1058       */
1059 <    public void testTimedOfferLast() {
1059 >    public void testTimedOfferLast() throws InterruptedException {
1060          final LinkedBlockingDeque q = new LinkedBlockingDeque(2);
1061 <        Thread t = new Thread(new Runnable() {
1062 <                public void run() {
1063 <                    try {
1064 <                        q.putLast(new Object());
1065 <                        q.putLast(new Object());
1066 <                        threadAssertFalse(q.offerLast(new Object(), SHORT_DELAY_MS, MILLISECONDS));
1067 <                        q.offerLast(new Object(), LONG_DELAY_MS, MILLISECONDS);
1233 <                        threadShouldThrow();
1234 <                    } catch (InterruptedException success) {}
1235 <                }
1236 <            });
1061 >        Thread t = new ThreadShouldThrow(InterruptedException.class) {
1062 >            public void realRun() throws InterruptedException {
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);
1067 >            }};
1068  
1069 <        try {
1070 <            t.start();
1071 <            Thread.sleep(SMALL_DELAY_MS);
1072 <            t.interrupt();
1242 <            t.join();
1243 <        } catch (Exception e) {
1244 <            unexpectedException();
1245 <        }
1069 >        t.start();
1070 >        Thread.sleep(SMALL_DELAY_MS);
1071 >        t.interrupt();
1072 >        t.join();
1073      }
1074  
1075      /**
1076       * takeLast retrieves elements in FIFO order
1077       */
1078 <    public void testTakeLast() {
1079 <        try {
1080 <            LinkedBlockingDeque q = populatedDeque(SIZE);
1081 <            for (int i = 0; i < SIZE; ++i) {
1255 <                assertEquals(SIZE-i-1, ((Integer)q.takeLast()).intValue());
1256 <            }
1257 <        } catch (InterruptedException e) {
1258 <            unexpectedException();
1078 >    public void testTakeLast() throws InterruptedException {
1079 >        LinkedBlockingDeque q = populatedDeque(SIZE);
1080 >        for (int i = 0; i < SIZE; ++i) {
1081 >            assertEquals(SIZE-i-1, ((Integer)q.takeLast()).intValue());
1082          }
1083      }
1084  
1085      /**
1086       * takeLast blocks interruptibly when empty
1087       */
1088 <    public void testTakeLastFromEmpty() {
1088 >    public void testTakeLastFromEmpty() throws InterruptedException {
1089          final LinkedBlockingDeque q = new LinkedBlockingDeque(2);
1090 <        Thread t = new Thread(new Runnable() {
1091 <                public void run() {
1092 <                    try {
1093 <                        q.takeLast();
1094 <                        threadShouldThrow();
1095 <                    } catch (InterruptedException success) { }
1096 <                }
1097 <            });
1098 <        try {
1276 <            t.start();
1277 <            Thread.sleep(SHORT_DELAY_MS);
1278 <            t.interrupt();
1279 <            t.join();
1280 <        } catch (Exception e) {
1281 <            unexpectedException();
1282 <        }
1090 >        Thread t = new ThreadShouldThrow(InterruptedException.class) {
1091 >            public void realRun() throws InterruptedException {
1092 >                q.takeLast();
1093 >            }};
1094 >
1095 >        t.start();
1096 >        Thread.sleep(SHORT_DELAY_MS);
1097 >        t.interrupt();
1098 >        t.join();
1099      }
1100  
1101      /**
1102       * TakeLast removes existing elements until empty, then blocks interruptibly
1103       */
1104 <    public void testBlockingTakeLast() {
1105 <        Thread t = new Thread(new Runnable() {
1106 <                public void run() {
1107 <                    try {
1108 <                        LinkedBlockingDeque q = populatedDeque(SIZE);
1109 <                        for (int i = 0; i < SIZE; ++i) {
1110 <                            assertEquals(SIZE-i-1, ((Integer)q.takeLast()).intValue());
1111 <                        }
1112 <                        q.takeLast();
1113 <                        threadShouldThrow();
1298 <                    } catch (InterruptedException success) {
1299 <                    }
1300 <                }});
1104 >    public void testBlockingTakeLast() throws InterruptedException {
1105 >        Thread t = new ThreadShouldThrow(InterruptedException.class) {
1106 >            public void realRun() throws InterruptedException {
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 >            }};
1113 >
1114          t.start();
1115 <        try {
1116 <           Thread.sleep(SHORT_DELAY_MS);
1117 <           t.interrupt();
1305 <           t.join();
1306 <        }
1307 <        catch (InterruptedException ie) {
1308 <            unexpectedException();
1309 <        }
1115 >        Thread.sleep(SHORT_DELAY_MS);
1116 >        t.interrupt();
1117 >        t.join();
1118      }
1119  
1120  
1121      /**
1122       * timed pollLast with zero timeout succeeds when non-empty, else times out
1123       */
1124 <    public void testTimedPollLast0() {
1125 <        try {
1126 <            LinkedBlockingDeque q = populatedDeque(SIZE);
1127 <            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();
1124 >    public void testTimedPollLast0() throws InterruptedException {
1125 >        LinkedBlockingDeque q = populatedDeque(SIZE);
1126 >        for (int i = 0; i < SIZE; ++i) {
1127 >            assertEquals(SIZE-i-1, ((Integer)q.pollLast(0, MILLISECONDS)).intValue());
1128          }
1129 +        assertNull(q.pollLast(0, MILLISECONDS));
1130      }
1131  
1132      /**
1133       * timed pollLast with nonzero timeout succeeds when non-empty, else times out
1134       */
1135 <    public void testTimedPollLast() {
1136 <        try {
1137 <            LinkedBlockingDeque q = populatedDeque(SIZE);
1138 <            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();
1135 >    public void testTimedPollLast() throws InterruptedException {
1136 >        LinkedBlockingDeque q = populatedDeque(SIZE);
1137 >        for (int i = 0; i < SIZE; ++i) {
1138 >            assertEquals(SIZE-i-1, ((Integer)q.pollLast(SHORT_DELAY_MS, MILLISECONDS)).intValue());
1139          }
1140 +        assertNull(q.pollLast(SHORT_DELAY_MS, MILLISECONDS));
1141      }
1142  
1143      /**
1144       * Interrupted timed pollLast throws InterruptedException instead of
1145       * returning timeout status
1146       */
1147 <    public void testInterruptedTimedPollLast() {
1148 <        Thread t = new Thread(new Runnable() {
1149 <                public void run() {
1150 <                    try {
1151 <                        LinkedBlockingDeque q = populatedDeque(SIZE);
1152 <                        for (int i = 0; i < SIZE; ++i) {
1153 <                            threadAssertEquals(SIZE-i-1, ((Integer)q.pollLast(SHORT_DELAY_MS, MILLISECONDS)).intValue());
1154 <                        }
1155 <                        threadAssertNull(q.pollLast(SHORT_DELAY_MS, MILLISECONDS));
1156 <                    } catch (InterruptedException success) {
1357 <                    }
1358 <                }});
1147 >    public void testInterruptedTimedPollLast() throws InterruptedException {
1148 >        Thread t = new ThreadShouldThrow(InterruptedException.class) {
1149 >            public void realRun() throws InterruptedException {
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 >                q.pollLast(SMALL_DELAY_MS, MILLISECONDS);
1155 >            }};
1156 >
1157          t.start();
1158 <        try {
1159 <           Thread.sleep(SHORT_DELAY_MS);
1160 <           t.interrupt();
1363 <           t.join();
1364 <        }
1365 <        catch (InterruptedException ie) {
1366 <            unexpectedException();
1367 <        }
1158 >        Thread.sleep(SHORT_DELAY_MS);
1159 >        t.interrupt();
1160 >        t.join();
1161      }
1162  
1163      /**
1164       *  timed poll before a delayed offerLast fails; after offerLast succeeds;
1165       *  on interruption throws
1166       */
1167 <    public void testTimedPollWithOfferLast() {
1167 >    public void testTimedPollWithOfferLast() throws InterruptedException {
1168          final LinkedBlockingDeque q = new LinkedBlockingDeque(2);
1169 <        Thread t = new Thread(new Runnable() {
1170 <                public void run() {
1171 <                    try {
1172 <                        threadAssertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS));
1173 <                        q.poll(LONG_DELAY_MS, MILLISECONDS);
1174 <                        q.poll(LONG_DELAY_MS, MILLISECONDS);
1175 <                        threadShouldThrow();
1176 <                    } catch (InterruptedException success) { }
1177 <                }
1178 <            });
1179 <        try {
1180 <            t.start();
1181 <            Thread.sleep(SMALL_DELAY_MS);
1182 <            assertTrue(q.offerLast(zero, SHORT_DELAY_MS, MILLISECONDS));
1183 <            t.interrupt();
1391 <            t.join();
1392 <        } catch (Exception e) {
1393 <            unexpectedException();
1394 <        }
1169 >        Thread t = new Thread(new CheckedRunnable() {
1170 >            public void realRun() throws InterruptedException {
1171 >                assertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS));
1172 >                assertSame(zero, q.poll(LONG_DELAY_MS, MILLISECONDS));
1173 >                try {
1174 >                    q.poll(LONG_DELAY_MS, MILLISECONDS);
1175 >                    shouldThrow();
1176 >                } catch (InterruptedException success) {}
1177 >            }});
1178 >
1179 >        t.start();
1180 >        Thread.sleep(SMALL_DELAY_MS);
1181 >        assertTrue(q.offerLast(zero, SHORT_DELAY_MS, MILLISECONDS));
1182 >        t.interrupt();
1183 >        t.join();
1184      }
1185  
1186  
# Line 1407 | Line 1196 | public class LinkedBlockingDequeTest ext
1196          try {
1197              q.element();
1198              shouldThrow();
1199 <        }
1411 <        catch (NoSuchElementException success) {}
1199 >        } catch (NoSuchElementException success) {}
1200      }
1201  
1202      /**
# Line 1506 | Line 1294 | public class LinkedBlockingDequeTest ext
1294      /**
1295       * toArray contains all elements
1296       */
1297 <    public void testToArray() {
1297 >    public void testToArray() throws InterruptedException{
1298          LinkedBlockingDeque q = populatedDeque(SIZE);
1299          Object[] o = q.toArray();
1512        try {
1300          for (int i = 0; i < o.length; i++)
1301              assertEquals(o[i], q.take());
1515        } catch (InterruptedException e) {
1516            unexpectedException();
1517        }
1302      }
1303  
1304      /**
1305       * toArray(a) contains all elements
1306       */
1307 <    public void testToArray2() {
1307 >    public void testToArray2() throws InterruptedException {
1308          LinkedBlockingDeque q = populatedDeque(SIZE);
1309          Integer[] ints = new Integer[SIZE];
1310          ints = (Integer[])q.toArray(ints);
1311 <        try {
1312 <            for (int i = 0; i < ints.length; i++)
1529 <                assertEquals(ints[i], q.take());
1530 <        } catch (InterruptedException e) {
1531 <            unexpectedException();
1532 <        }
1311 >        for (int i = 0; i < ints.length; i++)
1312 >            assertEquals(ints[i], q.take());
1313      }
1314  
1315      /**
# Line 1551 | Line 1331 | public class LinkedBlockingDequeTest ext
1331              LinkedBlockingDeque q = populatedDeque(SIZE);
1332              Object o[] = q.toArray(new String[10] );
1333              shouldThrow();
1334 <        } catch (ArrayStoreException  success) {}
1334 >        } catch (ArrayStoreException success) {}
1335      }
1336  
1337  
1338      /**
1339       * iterator iterates through all elements
1340       */
1341 <    public void testIterator() {
1341 >    public void testIterator() throws InterruptedException {
1342          LinkedBlockingDeque q = populatedDeque(SIZE);
1343          Iterator it = q.iterator();
1344 <        try {
1345 <            while (it.hasNext()) {
1566 <                assertEquals(it.next(), q.take());
1567 <            }
1568 <        } catch (InterruptedException e) {
1569 <            unexpectedException();
1344 >        while (it.hasNext()) {
1345 >            assertEquals(it.next(), q.take());
1346          }
1347      }
1348  
# Line 1615 | Line 1391 | public class LinkedBlockingDequeTest ext
1391          q.add(one);
1392          q.add(two);
1393          q.add(three);
1394 <        try {
1395 <            for (Iterator it = q.iterator(); it.hasNext();) {
1396 <                q.remove();
1621 <                it.next();
1622 <            }
1623 <        }
1624 <        catch (ConcurrentModificationException e) {
1625 <            unexpectedException();
1394 >        for (Iterator it = q.iterator(); it.hasNext();) {
1395 >            q.remove();
1396 >            it.next();
1397          }
1398          assertEquals(0, q.size());
1399      }
# Line 1643 | Line 1414 | public class LinkedBlockingDequeTest ext
1414          assertFalse(it.hasNext());
1415          try {
1416              it.next();
1417 <        } catch (NoSuchElementException success) {
1418 <        }
1417 >            shouldThrow();
1418 >        } catch (NoSuchElementException success) {}
1419      }
1420  
1421      /**
# Line 1712 | Line 1483 | public class LinkedBlockingDequeTest ext
1483          q.add(one);
1484          q.add(two);
1485          ExecutorService executor = Executors.newFixedThreadPool(2);
1486 <        executor.execute(new Runnable() {
1487 <            public void run() {
1486 >        executor.execute(new CheckedRunnable() {
1487 >            public void realRun() throws InterruptedException {
1488                  threadAssertFalse(q.offer(three));
1489 <                try {
1490 <                    threadAssertTrue(q.offer(three, MEDIUM_DELAY_MS, MILLISECONDS));
1491 <                    threadAssertEquals(0, q.remainingCapacity());
1492 <                }
1493 <                catch (InterruptedException e) {
1494 <                    threadUnexpectedException();
1495 <                }
1496 <            }
1497 <        });
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 <        });
1489 >                threadAssertTrue(q.offer(three, MEDIUM_DELAY_MS, MILLISECONDS));
1490 >                threadAssertEquals(0, q.remainingCapacity());
1491 >            }});
1492 >
1493 >        executor.execute(new CheckedRunnable() {
1494 >            public void realRun() throws InterruptedException {
1495 >                Thread.sleep(SMALL_DELAY_MS);
1496 >                threadAssertEquals(one, q.take());
1497 >            }});
1498  
1499          joinPool(executor);
1500      }
# Line 1746 | Line 1505 | public class LinkedBlockingDequeTest ext
1505      public void testPollInExecutor() {
1506          final LinkedBlockingDeque q = new LinkedBlockingDeque(2);
1507          ExecutorService executor = Executors.newFixedThreadPool(2);
1508 <        executor.execute(new Runnable() {
1509 <            public void run() {
1508 >        executor.execute(new CheckedRunnable() {
1509 >            public void realRun() throws InterruptedException {
1510                  threadAssertNull(q.poll());
1511 <                try {
1512 <                    threadAssertTrue(null != q.poll(MEDIUM_DELAY_MS, MILLISECONDS));
1513 <                    threadAssertTrue(q.isEmpty());
1514 <                }
1515 <                catch (InterruptedException e) {
1516 <                    threadUnexpectedException();
1517 <                }
1518 <            }
1519 <        });
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 <        });
1511 >                threadAssertTrue(null != q.poll(MEDIUM_DELAY_MS, MILLISECONDS));
1512 >                threadAssertTrue(q.isEmpty());
1513 >            }});
1514 >
1515 >        executor.execute(new CheckedRunnable() {
1516 >            public void realRun() throws InterruptedException {
1517 >                Thread.sleep(SMALL_DELAY_MS);
1518 >                q.put(one);
1519 >            }});
1520  
1521          joinPool(executor);
1522      }
# Line 1777 | Line 1524 | public class LinkedBlockingDequeTest ext
1524      /**
1525       * A deserialized serialized deque has same elements in same order
1526       */
1527 <    public void testSerialization() {
1527 >    public void testSerialization() throws Exception {
1528          LinkedBlockingDeque q = populatedDeque(SIZE);
1529  
1530 <        try {
1531 <            ByteArrayOutputStream bout = new ByteArrayOutputStream(10000);
1532 <            ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout));
1533 <            out.writeObject(q);
1534 <            out.close();
1535 <
1536 <            ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
1537 <            ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin));
1538 <            LinkedBlockingDeque r = (LinkedBlockingDeque)in.readObject();
1539 <            assertEquals(q.size(), r.size());
1540 <            while (!q.isEmpty())
1794 <                assertEquals(q.remove(), r.remove());
1795 <        } catch (Exception e) {
1796 <            unexpectedException();
1797 <        }
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())
1540 >            assertEquals(q.remove(), r.remove());
1541      }
1542  
1543      /**
# Line 1805 | Line 1548 | public class LinkedBlockingDequeTest ext
1548          try {
1549              q.drainTo(null);
1550              shouldThrow();
1551 <        } catch (NullPointerException success) {
1809 <        }
1551 >        } catch (NullPointerException success) {}
1552      }
1553  
1554      /**
# Line 1848 | Line 1590 | public class LinkedBlockingDequeTest ext
1590      /**
1591       * drainTo empties full deque, unblocking a waiting put.
1592       */
1593 <    public void testDrainToWithActivePut() {
1593 >    public void testDrainToWithActivePut() throws InterruptedException {
1594          final LinkedBlockingDeque q = populatedDeque(SIZE);
1595 <        Thread t = new Thread(new Runnable() {
1596 <                public void run() {
1597 <                    try {
1598 <                        q.put(new Integer(SIZE+1));
1599 <                    } catch (InterruptedException ie) {
1600 <                        threadUnexpectedException();
1601 <                    }
1602 <                }
1603 <            });
1604 <        try {
1605 <            t.start();
1606 <            ArrayList l = new ArrayList();
1607 <            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 <        }
1595 >        Thread t = new Thread(new CheckedRunnable() {
1596 >            public void realRun() throws InterruptedException {
1597 >                q.put(new Integer(SIZE+1));
1598 >            }});
1599 >
1600 >        t.start();
1601 >        ArrayList l = new ArrayList();
1602 >        q.drainTo(l);
1603 >        assertTrue(l.size() >= SIZE);
1604 >        for (int i = 0; i < SIZE; ++i)
1605 >            assertEquals(l.get(i), new Integer(i));
1606 >        t.join();
1607 >        assertTrue(q.size() + l.size() >= SIZE);
1608      }
1609  
1610      /**
# Line 1881 | Line 1615 | public class LinkedBlockingDequeTest ext
1615          try {
1616              q.drainTo(null, 0);
1617              shouldThrow();
1618 <        } catch (NullPointerException success) {
1885 <        }
1618 >        } catch (NullPointerException success) {}
1619      }
1620  
1621      /**
# Line 1893 | Line 1626 | public class LinkedBlockingDequeTest ext
1626          try {
1627              q.drainTo(q, 0);
1628              shouldThrow();
1629 <        } catch (IllegalArgumentException success) {
1897 <        }
1629 >        } catch (IllegalArgumentException success) {}
1630      }
1631  
1632      /**

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines