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.13 by jsr166, Sat Nov 21 19:11:53 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 281 | Line 276 | public class LinkedBlockingDequeTest ext
276      }
277  
278      /**
279 <     * Constructor throws IAE if  capacity argument nonpositive
279 >     * Constructor throws IAE if capacity argument nonpositive
280       */
281      public void testConstructor2() {
282          try {
283              LinkedBlockingDeque q = new LinkedBlockingDeque(0);
284              shouldThrow();
285 <        }
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      /**
323       * Deque contains all elements of collection used to initialize
324       */
325      public void testConstructor6() {
326 <        try {
327 <            Integer[] ints = new Integer[SIZE];
328 <            for (int i = 0; i < SIZE; ++i)
329 <                ints[i] = new Integer(i);
330 <            LinkedBlockingDeque q = new LinkedBlockingDeque(Arrays.asList(ints));
331 <            for (int i = 0; i < SIZE; ++i)
341 <                assertEquals(ints[i], q.poll());
342 <        }
343 <        finally {}
326 >        Integer[] ints = new Integer[SIZE];
327 >        for (int i = 0; i < SIZE; ++i)
328 >            ints[i] = new Integer(i);
329 >        LinkedBlockingDeque q = new LinkedBlockingDeque(Arrays.asList(ints));
330 >        for (int i = 0; i < SIZE; ++i)
331 >            assertEquals(ints[i], q.poll());
332      }
333  
334      /**
# Line 383 | Line 371 | public class LinkedBlockingDequeTest ext
371              LinkedBlockingDeque q = new LinkedBlockingDeque(1);
372              q.offer(null);
373              shouldThrow();
374 <        } catch (NullPointerException success) { }
374 >        } catch (NullPointerException success) {}
375      }
376  
377      /**
# Line 394 | Line 382 | public class LinkedBlockingDequeTest ext
382              LinkedBlockingDeque q = new LinkedBlockingDeque(1);
383              q.add(null);
384              shouldThrow();
385 <        } catch (NullPointerException success) { }
385 >        } catch (NullPointerException success) {}
386      }
387  
388      /**
# Line 405 | Line 393 | public class LinkedBlockingDequeTest ext
393              LinkedBlockingDeque q = new LinkedBlockingDeque(1);
394              q.push(null);
395              shouldThrow();
396 <        } catch (NullPointerException success) { }
396 >        } catch (NullPointerException success) {}
397      }
398  
399      /**
# Line 421 | Line 409 | public class LinkedBlockingDequeTest ext
409              }
410              assertEquals(0, q.remainingCapacity());
411              q.push(new Integer(SIZE));
412 <        } catch (IllegalStateException success) {
413 <        }
412 >            shouldThrow();
413 >        } catch (IllegalStateException success) {}
414      }
415  
416      /**
# Line 447 | Line 435 | public class LinkedBlockingDequeTest ext
435          try {
436              q.pop();
437              shouldThrow();
438 <        } catch (NoSuchElementException success) {
451 <        }
438 >        } catch (NoSuchElementException success) {}
439      }
440  
441  
# Line 472 | Line 459 | public class LinkedBlockingDequeTest ext
459              }
460              assertEquals(0, q.remainingCapacity());
461              q.add(new Integer(SIZE));
462 <        } catch (IllegalStateException success) {
463 <        }
462 >            shouldThrow();
463 >        } catch (IllegalStateException success) {}
464      }
465  
466      /**
# Line 484 | Line 471 | public class LinkedBlockingDequeTest ext
471              LinkedBlockingDeque q = new LinkedBlockingDeque(1);
472              q.addAll(null);
473              shouldThrow();
474 <        }
488 <        catch (NullPointerException success) {}
474 >        } catch (NullPointerException success) {}
475      }
476  
477      /**
# Line 496 | Line 482 | public class LinkedBlockingDequeTest ext
482              LinkedBlockingDeque q = populatedDeque(SIZE);
483              q.addAll(q);
484              shouldThrow();
485 <        }
500 <        catch (IllegalArgumentException success) {}
485 >        } catch (IllegalArgumentException success) {}
486      }
487  
488      /**
# Line 509 | Line 494 | public class LinkedBlockingDequeTest ext
494              Integer[] ints = new Integer[SIZE];
495              q.addAll(Arrays.asList(ints));
496              shouldThrow();
497 <        }
513 <        catch (NullPointerException success) {}
497 >        } catch (NullPointerException success) {}
498      }
499      /**
500       * addAll of a collection with any null elements throws NPE after
# Line 524 | Line 508 | public class LinkedBlockingDequeTest ext
508                  ints[i] = new Integer(i);
509              q.addAll(Arrays.asList(ints));
510              shouldThrow();
511 <        }
528 <        catch (NullPointerException success) {}
511 >        } catch (NullPointerException success) {}
512      }
513      /**
514       * addAll throws ISE if not enough room
# Line 538 | Line 521 | public class LinkedBlockingDequeTest ext
521                  ints[i] = new Integer(i);
522              q.addAll(Arrays.asList(ints));
523              shouldThrow();
524 <        }
542 <        catch (IllegalStateException success) {}
524 >        } catch (IllegalStateException success) {}
525      }
526      /**
527       * Deque contains all elements, in traversal order, of successful addAll
528       */
529      public void testAddAll5() {
530 <        try {
531 <            Integer[] empty = new Integer[0];
532 <            Integer[] ints = new Integer[SIZE];
533 <            for (int i = 0; i < SIZE; ++i)
534 <                ints[i] = new Integer(i);
535 <            LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
536 <            assertFalse(q.addAll(Arrays.asList(empty)));
537 <            assertTrue(q.addAll(Arrays.asList(ints)));
538 <            for (int i = 0; i < SIZE; ++i)
557 <                assertEquals(ints[i], q.poll());
558 <        }
559 <        finally {}
530 >        Integer[] empty = new Integer[0];
531 >        Integer[] ints = new Integer[SIZE];
532 >        for (int i = 0; i < SIZE; ++i)
533 >            ints[i] = new Integer(i);
534 >        LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
535 >        assertFalse(q.addAll(Arrays.asList(empty)));
536 >        assertTrue(q.addAll(Arrays.asList(ints)));
537 >        for (int i = 0; i < SIZE; ++i)
538 >            assertEquals(ints[i], q.poll());
539      }
540  
541  
542      /**
543       * put(null) throws NPE
544       */
545 <     public void testPutNull() {
545 >    public void testPutNull() throws InterruptedException {
546          try {
547              LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
548              q.put(null);
549              shouldThrow();
550 <        }
551 <        catch (NullPointerException success) {
573 <        }
574 <        catch (InterruptedException ie) {
575 <            unexpectedException();
576 <        }
577 <     }
550 >        } catch (NullPointerException success) {}
551 >    }
552  
553      /**
554       * all elements successfully put are contained
555       */
556 <     public void testPut() {
557 <         try {
558 <             LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
559 <             for (int i = 0; i < SIZE; ++i) {
560 <                 Integer I = new Integer(i);
561 <                 q.put(I);
588 <                 assertTrue(q.contains(I));
589 <             }
590 <             assertEquals(0, q.remainingCapacity());
591 <         }
592 <        catch (InterruptedException ie) {
593 <            unexpectedException();
556 >    public void testPut() throws InterruptedException {
557 >        LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
558 >        for (int i = 0; i < SIZE; ++i) {
559 >            Integer I = new Integer(i);
560 >            q.put(I);
561 >            assertTrue(q.contains(I));
562          }
563 +        assertEquals(0, q.remainingCapacity());
564      }
565  
566      /**
567       * put blocks interruptibly if full
568       */
569 <    public void testBlockingPut() {
570 <        Thread t = new Thread(new Runnable() {
571 <                public void run() {
572 <                    int added = 0;
573 <                    try {
574 <                        LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
575 <                        for (int i = 0; i < SIZE; ++i) {
576 <                            q.put(new Integer(i));
577 <                            ++added;
609 <                        }
610 <                        q.put(new Integer(SIZE));
611 <                        threadShouldThrow();
612 <                    } catch (InterruptedException ie) {
613 <                        threadAssertEquals(added, SIZE);
569 >    public void testBlockingPut() throws InterruptedException {
570 >        Thread t = new Thread(new CheckedRunnable() {
571 >            public void realRun() {
572 >                int added = 0;
573 >                try {
574 >                    LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
575 >                    for (int i = 0; i < SIZE; ++i) {
576 >                        q.put(new Integer(i));
577 >                        ++added;
578                      }
579 <                }});
579 >                    q.put(new Integer(SIZE));
580 >                    threadShouldThrow();
581 >                } catch (InterruptedException success) {
582 >                    threadAssertEquals(added, SIZE);
583 >                }
584 >            }});
585 >
586          t.start();
587 <        try {
588 <           Thread.sleep(SHORT_DELAY_MS);
589 <           t.interrupt();
620 <           t.join();
621 <        }
622 <        catch (InterruptedException ie) {
623 <            unexpectedException();
624 <        }
587 >        Thread.sleep(SHORT_DELAY_MS);
588 >        t.interrupt();
589 >        t.join();
590      }
591  
592      /**
593       * put blocks waiting for take when full
594       */
595 <    public void testPutWithTake() {
595 >    public void testPutWithTake() throws InterruptedException {
596          final LinkedBlockingDeque q = new LinkedBlockingDeque(2);
597 <        Thread t = new Thread(new Runnable() {
598 <                public void run() {
599 <                    int added = 0;
600 <                    try {
601 <                        q.put(new Object());
602 <                        ++added;
603 <                        q.put(new Object());
604 <                        ++added;
605 <                        q.put(new Object());
606 <                        ++added;
607 <                        q.put(new Object());
608 <                        ++added;
609 <                        threadShouldThrow();
610 <                    } catch (InterruptedException e) {
611 <                        threadAssertTrue(added >= 2);
647 <                    }
597 >        Thread t = new Thread(new CheckedRunnable() {
598 >            public void realRun() {
599 >                int added = 0;
600 >                try {
601 >                    q.put(new Object());
602 >                    ++added;
603 >                    q.put(new Object());
604 >                    ++added;
605 >                    q.put(new Object());
606 >                    ++added;
607 >                    q.put(new Object());
608 >                    ++added;
609 >                    threadShouldThrow();
610 >                } catch (InterruptedException success) {
611 >                    threadAssertTrue(added >= 2);
612                  }
613 <            });
614 <        try {
615 <            t.start();
616 <            Thread.sleep(SHORT_DELAY_MS);
617 <            q.take();
618 <            t.interrupt();
619 <            t.join();
656 <        } catch (Exception e) {
657 <            unexpectedException();
658 <        }
613 >            }});
614 >
615 >        t.start();
616 >        Thread.sleep(SHORT_DELAY_MS);
617 >        q.take();
618 >        t.interrupt();
619 >        t.join();
620      }
621  
622      /**
623       * timed offer times out if full and elements not taken
624       */
625 <    public void testTimedOffer() {
625 >    public void testTimedOffer() throws InterruptedException {
626          final LinkedBlockingDeque q = new LinkedBlockingDeque(2);
627 <        Thread t = new Thread(new Runnable() {
628 <                public void run() {
629 <                    try {
630 <                        q.put(new Object());
631 <                        q.put(new Object());
632 <                        threadAssertFalse(q.offer(new Object(), SHORT_DELAY_MS, MILLISECONDS));
633 <                        q.offer(new Object(), LONG_DELAY_MS, MILLISECONDS);
673 <                        threadShouldThrow();
674 <                    } catch (InterruptedException success) {}
675 <                }
676 <            });
627 >        Thread t = new ThreadShouldThrow(InterruptedException.class) {
628 >            public void realRun() throws InterruptedException {
629 >                q.put(new Object());
630 >                q.put(new Object());
631 >                threadAssertFalse(q.offer(new Object(), SHORT_DELAY_MS, MILLISECONDS));
632 >                q.offer(new Object(), LONG_DELAY_MS, MILLISECONDS);
633 >            }};
634  
635 <        try {
636 <            t.start();
637 <            Thread.sleep(SMALL_DELAY_MS);
638 <            t.interrupt();
682 <            t.join();
683 <        } catch (Exception e) {
684 <            unexpectedException();
685 <        }
635 >        t.start();
636 >        Thread.sleep(SMALL_DELAY_MS);
637 >        t.interrupt();
638 >        t.join();
639      }
640  
641      /**
642       * take retrieves elements in FIFO order
643       */
644 <    public void testTake() {
645 <        try {
646 <            LinkedBlockingDeque q = populatedDeque(SIZE);
647 <            for (int i = 0; i < SIZE; ++i) {
695 <                assertEquals(i, ((Integer)q.take()).intValue());
696 <            }
697 <        } catch (InterruptedException e) {
698 <            unexpectedException();
644 >    public void testTake() throws InterruptedException {
645 >        LinkedBlockingDeque q = populatedDeque(SIZE);
646 >        for (int i = 0; i < SIZE; ++i) {
647 >            assertEquals(i, ((Integer)q.take()).intValue());
648          }
649      }
650  
651      /**
652       * take blocks interruptibly when empty
653       */
654 <    public void testTakeFromEmpty() {
654 >    public void testTakeFromEmpty() throws InterruptedException {
655          final LinkedBlockingDeque q = new LinkedBlockingDeque(2);
656 <        Thread t = new Thread(new Runnable() {
657 <                public void run() {
658 <                    try {
659 <                        q.take();
660 <                        threadShouldThrow();
661 <                    } catch (InterruptedException success) { }
662 <                }
663 <            });
664 <        try {
716 <            t.start();
717 <            Thread.sleep(SHORT_DELAY_MS);
718 <            t.interrupt();
719 <            t.join();
720 <        } catch (Exception e) {
721 <            unexpectedException();
722 <        }
656 >        Thread t = new ThreadShouldThrow(InterruptedException.class) {
657 >            public void realRun() throws InterruptedException {
658 >                q.take();
659 >            }};
660 >
661 >        t.start();
662 >        Thread.sleep(SHORT_DELAY_MS);
663 >        t.interrupt();
664 >        t.join();
665      }
666  
667      /**
668       * Take removes existing elements until empty, then blocks interruptibly
669       */
670 <    public void testBlockingTake() {
671 <        Thread t = new Thread(new Runnable() {
672 <                public void run() {
673 <                    try {
674 <                        LinkedBlockingDeque q = populatedDeque(SIZE);
675 <                        for (int i = 0; i < SIZE; ++i) {
676 <                            assertEquals(i, ((Integer)q.take()).intValue());
677 <                        }
678 <                        q.take();
679 <                        threadShouldThrow();
738 <                    } catch (InterruptedException success) {
739 <                    }
740 <                }});
670 >    public void testBlockingTake() throws InterruptedException {
671 >        Thread t = new ThreadShouldThrow(InterruptedException.class) {
672 >            public void realRun() throws InterruptedException {
673 >                LinkedBlockingDeque q = populatedDeque(SIZE);
674 >                for (int i = 0; i < SIZE; ++i) {
675 >                    assertEquals(i, ((Integer)q.take()).intValue());
676 >                }
677 >                q.take();
678 >            }};
679 >
680          t.start();
681 <        try {
682 <           Thread.sleep(SHORT_DELAY_MS);
683 <           t.interrupt();
745 <           t.join();
746 <        }
747 <        catch (InterruptedException ie) {
748 <            unexpectedException();
749 <        }
681 >        Thread.sleep(SHORT_DELAY_MS);
682 >        t.interrupt();
683 >        t.join();
684      }
685  
686  
# Line 764 | Line 698 | public class LinkedBlockingDequeTest ext
698      /**
699       * timed poll with zero timeout succeeds when non-empty, else times out
700       */
701 <    public void testTimedPoll0() {
702 <        try {
703 <            LinkedBlockingDeque q = populatedDeque(SIZE);
704 <            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();
701 >    public void testTimedPoll0() throws InterruptedException {
702 >        LinkedBlockingDeque q = populatedDeque(SIZE);
703 >        for (int i = 0; i < SIZE; ++i) {
704 >            assertEquals(i, ((Integer)q.poll(0, MILLISECONDS)).intValue());
705          }
706 +        assertNull(q.poll(0, MILLISECONDS));
707      }
708  
709      /**
710       * timed poll with nonzero timeout succeeds when non-empty, else times out
711       */
712 <    public void testTimedPoll() {
713 <        try {
714 <            LinkedBlockingDeque q = populatedDeque(SIZE);
715 <            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();
712 >    public void testTimedPoll() throws InterruptedException {
713 >        LinkedBlockingDeque q = populatedDeque(SIZE);
714 >        for (int i = 0; i < SIZE; ++i) {
715 >            assertEquals(i, ((Integer)q.poll(SHORT_DELAY_MS, MILLISECONDS)).intValue());
716          }
717 +        assertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS));
718      }
719  
720      /**
721       * Interrupted timed poll throws InterruptedException instead of
722       * returning timeout status
723       */
724 <    public void testInterruptedTimedPoll() {
725 <        Thread t = new Thread(new Runnable() {
726 <                public void run() {
727 <                    try {
728 <                        LinkedBlockingDeque q = populatedDeque(SIZE);
729 <                        for (int i = 0; i < SIZE; ++i) {
730 <                            threadAssertEquals(i, ((Integer)q.poll(SHORT_DELAY_MS, MILLISECONDS)).intValue());
731 <                        }
732 <                        threadAssertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS));
733 <                    } catch (InterruptedException success) {
734 <                    }
735 <                }});
724 >    public void testInterruptedTimedPoll() throws InterruptedException {
725 >        Thread t = new Thread(new CheckedRunnable() {
726 >            public void realRun() throws InterruptedException {
727 >                LinkedBlockingDeque q = populatedDeque(SIZE);
728 >                for (int i = 0; i < SIZE; ++i) {
729 >                    assertEquals(i, ((Integer)q.poll(SHORT_DELAY_MS, MILLISECONDS)).intValue());
730 >                }
731 >                try {
732 >                    q.poll(SMALL_DELAY_MS, MILLISECONDS);
733 >                    shouldThrow();
734 >                } catch (InterruptedException success) {}
735 >            }});
736 >
737          t.start();
738 <        try {
739 <           Thread.sleep(SHORT_DELAY_MS);
740 <           t.interrupt();
814 <           t.join();
815 <        }
816 <        catch (InterruptedException ie) {
817 <            unexpectedException();
818 <        }
738 >        Thread.sleep(SHORT_DELAY_MS);
739 >        t.interrupt();
740 >        t.join();
741      }
742  
743      /**
744       *  timed poll before a delayed offer fails; after offer succeeds;
745       *  on interruption throws
746       */
747 <    public void testTimedPollWithOffer() {
747 >    public void testTimedPollWithOffer() throws InterruptedException {
748          final LinkedBlockingDeque q = new LinkedBlockingDeque(2);
749 <        Thread t = new Thread(new Runnable() {
750 <                public void run() {
751 <                    try {
752 <                        threadAssertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS));
753 <                        q.poll(LONG_DELAY_MS, MILLISECONDS);
754 <                        q.poll(LONG_DELAY_MS, MILLISECONDS);
755 <                        threadShouldThrow();
756 <                    } catch (InterruptedException success) { }
757 <                }
758 <            });
759 <        try {
760 <            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 <        }
749 >        Thread t = new ThreadShouldThrow(InterruptedException.class) {
750 >            public void realRun() throws InterruptedException {
751 >                threadAssertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS));
752 >                q.poll(LONG_DELAY_MS, MILLISECONDS);
753 >                q.poll(LONG_DELAY_MS, MILLISECONDS);
754 >            }};
755 >
756 >        t.start();
757 >        Thread.sleep(SMALL_DELAY_MS);
758 >        assertTrue(q.offer(zero, SHORT_DELAY_MS, MILLISECONDS));
759 >        t.interrupt();
760 >        t.join();
761      }
762  
763  
764      /**
765       * putFirst(null) throws NPE
766       */
767 <     public void testPutFirstNull() {
767 >     public void testPutFirstNull() throws InterruptedException {
768          try {
769              LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
770              q.putFirst(null);
771              shouldThrow();
772 <        }
858 <        catch (NullPointerException success) {
859 <        }
860 <        catch (InterruptedException ie) {
861 <            unexpectedException();
862 <        }
772 >        } catch (NullPointerException success) {}
773       }
774  
775      /**
776       * all elements successfully putFirst are contained
777       */
778 <     public void testPutFirst() {
779 <         try {
780 <             LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
781 <             for (int i = 0; i < SIZE; ++i) {
782 <                 Integer I = new Integer(i);
783 <                 q.putFirst(I);
874 <                 assertTrue(q.contains(I));
875 <             }
876 <             assertEquals(0, q.remainingCapacity());
778 >     public void testPutFirst() throws InterruptedException {
779 >         LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
780 >         for (int i = 0; i < SIZE; ++i) {
781 >             Integer I = new Integer(i);
782 >             q.putFirst(I);
783 >             assertTrue(q.contains(I));
784           }
785 <        catch (InterruptedException ie) {
879 <            unexpectedException();
880 <        }
785 >         assertEquals(0, q.remainingCapacity());
786      }
787  
788      /**
789       * putFirst blocks interruptibly if full
790       */
791 <    public void testBlockingPutFirst() {
792 <        Thread t = new Thread(new Runnable() {
793 <                public void run() {
794 <                    int added = 0;
795 <                    try {
796 <                        LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
797 <                        for (int i = 0; i < SIZE; ++i) {
798 <                            q.putFirst(new Integer(i));
799 <                            ++added;
895 <                        }
896 <                        q.putFirst(new Integer(SIZE));
897 <                        threadShouldThrow();
898 <                    } catch (InterruptedException ie) {
899 <                        threadAssertEquals(added, SIZE);
791 >    public void testBlockingPutFirst() throws InterruptedException {
792 >        Thread t = new Thread(new CheckedRunnable() {
793 >            public void realRun() {
794 >                int added = 0;
795 >                try {
796 >                    LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
797 >                    for (int i = 0; i < SIZE; ++i) {
798 >                        q.putFirst(new Integer(i));
799 >                        ++added;
800                      }
801 <                }});
801 >                    q.putFirst(new Integer(SIZE));
802 >                    threadShouldThrow();
803 >                } catch (InterruptedException success) {
804 >                    threadAssertEquals(added, SIZE);
805 >                }
806 >            }});
807 >
808          t.start();
809 <        try {
810 <           Thread.sleep(SHORT_DELAY_MS);
811 <           t.interrupt();
906 <           t.join();
907 <        }
908 <        catch (InterruptedException ie) {
909 <            unexpectedException();
910 <        }
809 >        Thread.sleep(SHORT_DELAY_MS);
810 >        t.interrupt();
811 >        t.join();
812      }
813  
814      /**
815       * putFirst blocks waiting for take when full
816       */
817 <    public void testPutFirstWithTake() {
817 >    public void testPutFirstWithTake() throws InterruptedException {
818          final LinkedBlockingDeque q = new LinkedBlockingDeque(2);
819 <        Thread t = new Thread(new Runnable() {
820 <                public void run() {
821 <                    int added = 0;
822 <                    try {
823 <                        q.putFirst(new Object());
824 <                        ++added;
825 <                        q.putFirst(new Object());
826 <                        ++added;
827 <                        q.putFirst(new Object());
828 <                        ++added;
829 <                        q.putFirst(new Object());
830 <                        ++added;
831 <                        threadShouldThrow();
832 <                    } catch (InterruptedException e) {
833 <                        threadAssertTrue(added >= 2);
933 <                    }
819 >        Thread t = new Thread(new CheckedRunnable() {
820 >            public void realRun() {
821 >                int added = 0;
822 >                try {
823 >                    q.putFirst(new Object());
824 >                    ++added;
825 >                    q.putFirst(new Object());
826 >                    ++added;
827 >                    q.putFirst(new Object());
828 >                    ++added;
829 >                    q.putFirst(new Object());
830 >                    ++added;
831 >                    threadShouldThrow();
832 >                } catch (InterruptedException success) {
833 >                    threadAssertTrue(added >= 2);
834                  }
835 <            });
836 <        try {
837 <            t.start();
838 <            Thread.sleep(SHORT_DELAY_MS);
839 <            q.take();
840 <            t.interrupt();
841 <            t.join();
942 <        } catch (Exception e) {
943 <            unexpectedException();
944 <        }
835 >            }});
836 >
837 >        t.start();
838 >        Thread.sleep(SHORT_DELAY_MS);
839 >        q.take();
840 >        t.interrupt();
841 >        t.join();
842      }
843  
844      /**
845       * timed offerFirst times out if full and elements not taken
846       */
847 <    public void testTimedOfferFirst() {
847 >    public void testTimedOfferFirst() throws InterruptedException {
848          final LinkedBlockingDeque q = new LinkedBlockingDeque(2);
849 <        Thread t = new Thread(new Runnable() {
850 <                public void run() {
851 <                    try {
852 <                        q.putFirst(new Object());
853 <                        q.putFirst(new Object());
854 <                        threadAssertFalse(q.offerFirst(new Object(), SHORT_DELAY_MS, MILLISECONDS));
855 <                        q.offerFirst(new Object(), LONG_DELAY_MS, MILLISECONDS);
959 <                        threadShouldThrow();
960 <                    } catch (InterruptedException success) {}
961 <                }
962 <            });
849 >        Thread t = new ThreadShouldThrow(InterruptedException.class) {
850 >            public void realRun() throws InterruptedException {
851 >                q.putFirst(new Object());
852 >                q.putFirst(new Object());
853 >                threadAssertFalse(q.offerFirst(new Object(), SHORT_DELAY_MS, MILLISECONDS));
854 >                q.offerFirst(new Object(), LONG_DELAY_MS, MILLISECONDS);
855 >            }};
856  
857 <        try {
858 <            t.start();
859 <            Thread.sleep(SMALL_DELAY_MS);
860 <            t.interrupt();
968 <            t.join();
969 <        } catch (Exception e) {
970 <            unexpectedException();
971 <        }
857 >        t.start();
858 >        Thread.sleep(SMALL_DELAY_MS);
859 >        t.interrupt();
860 >        t.join();
861      }
862  
863      /**
864       * take retrieves elements in FIFO order
865       */
866 <    public void testTakeFirst() {
867 <        try {
868 <            LinkedBlockingDeque q = populatedDeque(SIZE);
869 <            for (int i = 0; i < SIZE; ++i) {
981 <                assertEquals(i, ((Integer)q.takeFirst()).intValue());
982 <            }
983 <        } catch (InterruptedException e) {
984 <            unexpectedException();
866 >    public void testTakeFirst() throws InterruptedException {
867 >        LinkedBlockingDeque q = populatedDeque(SIZE);
868 >        for (int i = 0; i < SIZE; ++i) {
869 >            assertEquals(i, ((Integer)q.takeFirst()).intValue());
870          }
871      }
872  
873      /**
874       * takeFirst blocks interruptibly when empty
875       */
876 <    public void testTakeFirstFromEmpty() {
876 >    public void testTakeFirstFromEmpty() throws InterruptedException {
877          final LinkedBlockingDeque q = new LinkedBlockingDeque(2);
878 <        Thread t = new Thread(new Runnable() {
879 <                public void run() {
880 <                    try {
881 <                        q.takeFirst();
882 <                        threadShouldThrow();
883 <                    } catch (InterruptedException success) { }
884 <                }
885 <            });
886 <        try {
1002 <            t.start();
1003 <            Thread.sleep(SHORT_DELAY_MS);
1004 <            t.interrupt();
1005 <            t.join();
1006 <        } catch (Exception e) {
1007 <            unexpectedException();
1008 <        }
878 >        Thread t = new ThreadShouldThrow(InterruptedException.class) {
879 >            public void realRun() throws InterruptedException {
880 >                q.takeFirst();
881 >            }};
882 >
883 >        t.start();
884 >        Thread.sleep(SHORT_DELAY_MS);
885 >        t.interrupt();
886 >        t.join();
887      }
888  
889      /**
890       * TakeFirst removes existing elements until empty, then blocks interruptibly
891       */
892 <    public void testBlockingTakeFirst() {
893 <        Thread t = new Thread(new Runnable() {
894 <                public void run() {
895 <                    try {
896 <                        LinkedBlockingDeque q = populatedDeque(SIZE);
897 <                        for (int i = 0; i < SIZE; ++i) {
898 <                            assertEquals(i, ((Integer)q.takeFirst()).intValue());
899 <                        }
900 <                        q.takeFirst();
901 <                        threadShouldThrow();
1024 <                    } catch (InterruptedException success) {
1025 <                    }
1026 <                }});
892 >    public void testBlockingTakeFirst() throws InterruptedException {
893 >        Thread t = new ThreadShouldThrow(InterruptedException.class) {
894 >            public void realRun() throws InterruptedException {
895 >                LinkedBlockingDeque q = populatedDeque(SIZE);
896 >                for (int i = 0; i < SIZE; ++i) {
897 >                    assertEquals(i, ((Integer)q.takeFirst()).intValue());
898 >                }
899 >                q.takeFirst();
900 >            }};
901 >
902          t.start();
903 <        try {
904 <           Thread.sleep(SHORT_DELAY_MS);
905 <           t.interrupt();
1031 <           t.join();
1032 <        }
1033 <        catch (InterruptedException ie) {
1034 <            unexpectedException();
1035 <        }
903 >        Thread.sleep(SHORT_DELAY_MS);
904 >        t.interrupt();
905 >        t.join();
906      }
907  
908  
909      /**
910       * timed pollFirst with zero timeout succeeds when non-empty, else times out
911       */
912 <    public void testTimedPollFirst0() {
913 <        try {
914 <            LinkedBlockingDeque q = populatedDeque(SIZE);
915 <            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();
912 >    public void testTimedPollFirst0() throws InterruptedException {
913 >        LinkedBlockingDeque q = populatedDeque(SIZE);
914 >        for (int i = 0; i < SIZE; ++i) {
915 >            assertEquals(i, ((Integer)q.pollFirst(0, MILLISECONDS)).intValue());
916          }
917 +        assertNull(q.pollFirst(0, MILLISECONDS));
918      }
919  
920      /**
921       * timed pollFirst with nonzero timeout succeeds when non-empty, else times out
922       */
923 <    public void testTimedPollFirst() {
924 <        try {
925 <            LinkedBlockingDeque q = populatedDeque(SIZE);
926 <            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();
923 >    public void testTimedPollFirst() throws InterruptedException {
924 >        LinkedBlockingDeque q = populatedDeque(SIZE);
925 >        for (int i = 0; i < SIZE; ++i) {
926 >            assertEquals(i, ((Integer)q.pollFirst(SHORT_DELAY_MS, MILLISECONDS)).intValue());
927          }
928 +        assertNull(q.pollFirst(SHORT_DELAY_MS, MILLISECONDS));
929      }
930  
931      /**
932       * Interrupted timed pollFirst throws InterruptedException instead of
933       * returning timeout status
934       */
935 <    public void testInterruptedTimedPollFirst() {
936 <        Thread t = new Thread(new Runnable() {
937 <                public void run() {
938 <                    try {
939 <                        LinkedBlockingDeque q = populatedDeque(SIZE);
940 <                        for (int i = 0; i < SIZE; ++i) {
941 <                            threadAssertEquals(i, ((Integer)q.pollFirst(SHORT_DELAY_MS, MILLISECONDS)).intValue());
942 <                        }
943 <                        threadAssertNull(q.pollFirst(SHORT_DELAY_MS, MILLISECONDS));
944 <                    } catch (InterruptedException success) {
945 <                    }
946 <                }});
935 >    public void testInterruptedTimedPollFirst() throws InterruptedException {
936 >        Thread t = new Thread(new CheckedRunnable() {
937 >            public void realRun() throws InterruptedException {
938 >                LinkedBlockingDeque q = populatedDeque(SIZE);
939 >                for (int i = 0; i < SIZE; ++i) {
940 >                    assertEquals(i, ((Integer)q.pollFirst(SHORT_DELAY_MS, MILLISECONDS)).intValue());
941 >                }
942 >                try {
943 >                    q.pollFirst(SMALL_DELAY_MS, MILLISECONDS);
944 >                    shouldThrow();
945 >                } catch (InterruptedException success) {}
946 >            }});
947 >
948          t.start();
949 <        try {
950 <           Thread.sleep(SHORT_DELAY_MS);
951 <           t.interrupt();
1089 <           t.join();
1090 <        }
1091 <        catch (InterruptedException ie) {
1092 <            unexpectedException();
1093 <        }
949 >        Thread.sleep(SHORT_DELAY_MS);
950 >        t.interrupt();
951 >        t.join();
952      }
953  
954      /**
955       *  timed pollFirst before a delayed offerFirst fails; after offerFirst succeeds;
956       *  on interruption throws
957       */
958 <    public void testTimedPollFirstWithOfferFirst() {
958 >    public void testTimedPollFirstWithOfferFirst() throws InterruptedException {
959          final LinkedBlockingDeque q = new LinkedBlockingDeque(2);
960 <        Thread t = new Thread(new Runnable() {
961 <                public void run() {
962 <                    try {
963 <                        threadAssertNull(q.pollFirst(SHORT_DELAY_MS, MILLISECONDS));
964 <                        q.pollFirst(LONG_DELAY_MS, MILLISECONDS);
965 <                        q.pollFirst(LONG_DELAY_MS, MILLISECONDS);
966 <                        threadShouldThrow();
967 <                    } catch (InterruptedException success) { }
968 <                }
969 <            });
970 <        try {
971 <            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 <        }
960 >        Thread t = new ThreadShouldThrow(InterruptedException.class) {
961 >            public void realRun() throws InterruptedException {
962 >                threadAssertNull(q.pollFirst(SHORT_DELAY_MS, MILLISECONDS));
963 >                q.pollFirst(LONG_DELAY_MS, MILLISECONDS);
964 >                q.pollFirst(LONG_DELAY_MS, MILLISECONDS);
965 >            }};
966 >
967 >        t.start();
968 >        Thread.sleep(SMALL_DELAY_MS);
969 >        assertTrue(q.offerFirst(zero, SHORT_DELAY_MS, MILLISECONDS));
970 >        t.interrupt();
971 >        t.join();
972      }
973  
974      /**
975       * putLast(null) throws NPE
976       */
977 <     public void testPutLastNull() {
977 >     public void testPutLastNull() throws InterruptedException {
978          try {
979              LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
980              q.putLast(null);
981              shouldThrow();
982 <        }
1132 <        catch (NullPointerException success) {
1133 <        }
1134 <        catch (InterruptedException ie) {
1135 <            unexpectedException();
1136 <        }
982 >        } catch (NullPointerException success) {}
983       }
984  
985      /**
986       * all elements successfully putLast are contained
987       */
988 <     public void testPutLast() {
989 <         try {
990 <             LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
991 <             for (int i = 0; i < SIZE; ++i) {
992 <                 Integer I = new Integer(i);
993 <                 q.putLast(I);
1148 <                 assertTrue(q.contains(I));
1149 <             }
1150 <             assertEquals(0, q.remainingCapacity());
988 >     public void testPutLast() throws InterruptedException {
989 >         LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
990 >         for (int i = 0; i < SIZE; ++i) {
991 >             Integer I = new Integer(i);
992 >             q.putLast(I);
993 >             assertTrue(q.contains(I));
994           }
995 <        catch (InterruptedException ie) {
1153 <            unexpectedException();
1154 <        }
995 >         assertEquals(0, q.remainingCapacity());
996      }
997  
998      /**
999       * putLast blocks interruptibly if full
1000       */
1001 <    public void testBlockingPutLast() {
1002 <        Thread t = new Thread(new Runnable() {
1003 <                public void run() {
1004 <                    int added = 0;
1005 <                    try {
1006 <                        LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
1007 <                        for (int i = 0; i < SIZE; ++i) {
1008 <                            q.putLast(new Integer(i));
1009 <                            ++added;
1169 <                        }
1170 <                        q.putLast(new Integer(SIZE));
1171 <                        threadShouldThrow();
1172 <                    } catch (InterruptedException ie) {
1173 <                        threadAssertEquals(added, SIZE);
1001 >    public void testBlockingPutLast() throws InterruptedException {
1002 >        Thread t = new Thread(new CheckedRunnable() {
1003 >            public void realRun() {
1004 >                int added = 0;
1005 >                try {
1006 >                    LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
1007 >                    for (int i = 0; i < SIZE; ++i) {
1008 >                        q.putLast(new Integer(i));
1009 >                        ++added;
1010                      }
1011 <                }});
1011 >                    q.putLast(new Integer(SIZE));
1012 >                    threadShouldThrow();
1013 >                } catch (InterruptedException success) {
1014 >                    threadAssertEquals(added, SIZE);
1015 >                }
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() {
1031 <                    int added = 0;
1032 <                    try {
1033 <                        q.putLast(new Object());
1034 <                        ++added;
1035 <                        q.putLast(new Object());
1036 <                        ++added;
1037 <                        q.putLast(new Object());
1038 <                        ++added;
1039 <                        q.putLast(new Object());
1040 <                        ++added;
1041 <                        threadShouldThrow();
1042 <                    } catch (InterruptedException e) {
1043 <                        threadAssertTrue(added >= 2);
1207 <                    }
1029 >        Thread t = new Thread(new CheckedRunnable() {
1030 >            public void realRun() {
1031 >                int added = 0;
1032 >                try {
1033 >                    q.putLast(new Object());
1034 >                    ++added;
1035 >                    q.putLast(new Object());
1036 >                    ++added;
1037 >                    q.putLast(new Object());
1038 >                    ++added;
1039 >                    q.putLast(new Object());
1040 >                    ++added;
1041 >                    threadShouldThrow();
1042 >                } catch (InterruptedException success) {
1043 >                    threadAssertTrue(added >= 2);
1044                  }
1045 <            });
1046 <        try {
1047 <            t.start();
1048 <            Thread.sleep(SHORT_DELAY_MS);
1049 <            q.take();
1050 <            t.interrupt();
1051 <            t.join();
1216 <        } catch (Exception e) {
1217 <            unexpectedException();
1218 <        }
1045 >            }});
1046 >
1047 >        t.start();
1048 >        Thread.sleep(SHORT_DELAY_MS);
1049 >        q.take();
1050 >        t.interrupt();
1051 >        t.join();
1052      }
1053  
1054      /**
1055       * timed offerLast times out if full and elements not taken
1056       */
1057 <    public void testTimedOfferLast() {
1057 >    public void testTimedOfferLast() throws InterruptedException {
1058          final LinkedBlockingDeque q = new LinkedBlockingDeque(2);
1059 <        Thread t = new Thread(new Runnable() {
1060 <                public void run() {
1061 <                    try {
1062 <                        q.putLast(new Object());
1063 <                        q.putLast(new Object());
1064 <                        threadAssertFalse(q.offerLast(new Object(), SHORT_DELAY_MS, MILLISECONDS));
1065 <                        q.offerLast(new Object(), LONG_DELAY_MS, MILLISECONDS);
1233 <                        threadShouldThrow();
1234 <                    } catch (InterruptedException success) {}
1235 <                }
1236 <            });
1059 >        Thread t = new ThreadShouldThrow(InterruptedException.class) {
1060 >            public void realRun() throws InterruptedException {
1061 >                q.putLast(new Object());
1062 >                q.putLast(new Object());
1063 >                threadAssertFalse(q.offerLast(new Object(), SHORT_DELAY_MS, MILLISECONDS));
1064 >                q.offerLast(new Object(), LONG_DELAY_MS, MILLISECONDS);
1065 >            }};
1066  
1067 <        try {
1068 <            t.start();
1069 <            Thread.sleep(SMALL_DELAY_MS);
1070 <            t.interrupt();
1242 <            t.join();
1243 <        } catch (Exception e) {
1244 <            unexpectedException();
1245 <        }
1067 >        t.start();
1068 >        Thread.sleep(SMALL_DELAY_MS);
1069 >        t.interrupt();
1070 >        t.join();
1071      }
1072  
1073      /**
1074       * takeLast retrieves elements in FIFO order
1075       */
1076 <    public void testTakeLast() {
1077 <        try {
1078 <            LinkedBlockingDeque q = populatedDeque(SIZE);
1079 <            for (int i = 0; i < SIZE; ++i) {
1255 <                assertEquals(SIZE-i-1, ((Integer)q.takeLast()).intValue());
1256 <            }
1257 <        } catch (InterruptedException e) {
1258 <            unexpectedException();
1076 >    public void testTakeLast() throws InterruptedException {
1077 >        LinkedBlockingDeque q = populatedDeque(SIZE);
1078 >        for (int i = 0; i < SIZE; ++i) {
1079 >            assertEquals(SIZE-i-1, ((Integer)q.takeLast()).intValue());
1080          }
1081      }
1082  
1083      /**
1084       * takeLast blocks interruptibly when empty
1085       */
1086 <    public void testTakeLastFromEmpty() {
1086 >    public void testTakeLastFromEmpty() throws InterruptedException {
1087          final LinkedBlockingDeque q = new LinkedBlockingDeque(2);
1088 <        Thread t = new Thread(new Runnable() {
1089 <                public void run() {
1090 <                    try {
1091 <                        q.takeLast();
1092 <                        threadShouldThrow();
1093 <                    } catch (InterruptedException success) { }
1094 <                }
1095 <            });
1096 <        try {
1276 <            t.start();
1277 <            Thread.sleep(SHORT_DELAY_MS);
1278 <            t.interrupt();
1279 <            t.join();
1280 <        } catch (Exception e) {
1281 <            unexpectedException();
1282 <        }
1088 >        Thread t = new ThreadShouldThrow(InterruptedException.class) {
1089 >            public void realRun() throws InterruptedException {
1090 >                q.takeLast();
1091 >            }};
1092 >
1093 >        t.start();
1094 >        Thread.sleep(SHORT_DELAY_MS);
1095 >        t.interrupt();
1096 >        t.join();
1097      }
1098  
1099      /**
1100       * TakeLast removes existing elements until empty, then blocks interruptibly
1101       */
1102 <    public void testBlockingTakeLast() {
1103 <        Thread t = new Thread(new Runnable() {
1104 <                public void run() {
1105 <                    try {
1106 <                        LinkedBlockingDeque q = populatedDeque(SIZE);
1107 <                        for (int i = 0; i < SIZE; ++i) {
1108 <                            assertEquals(SIZE-i-1, ((Integer)q.takeLast()).intValue());
1109 <                        }
1110 <                        q.takeLast();
1111 <                        threadShouldThrow();
1298 <                    } catch (InterruptedException success) {
1299 <                    }
1300 <                }});
1102 >    public void testBlockingTakeLast() throws InterruptedException {
1103 >        Thread t = new ThreadShouldThrow(InterruptedException.class) {
1104 >            public void realRun() throws InterruptedException {
1105 >                LinkedBlockingDeque q = populatedDeque(SIZE);
1106 >                for (int i = 0; i < SIZE; ++i) {
1107 >                    assertEquals(SIZE-i-1, ((Integer)q.takeLast()).intValue());
1108 >                }
1109 >                q.takeLast();
1110 >            }};
1111 >
1112          t.start();
1113 <        try {
1114 <           Thread.sleep(SHORT_DELAY_MS);
1115 <           t.interrupt();
1305 <           t.join();
1306 <        }
1307 <        catch (InterruptedException ie) {
1308 <            unexpectedException();
1309 <        }
1113 >        Thread.sleep(SHORT_DELAY_MS);
1114 >        t.interrupt();
1115 >        t.join();
1116      }
1117  
1118  
1119      /**
1120       * timed pollLast with zero timeout succeeds when non-empty, else times out
1121       */
1122 <    public void testTimedPollLast0() {
1123 <        try {
1124 <            LinkedBlockingDeque q = populatedDeque(SIZE);
1125 <            for (int i = 0; i < SIZE; ++i) {
1320 <                assertEquals(SIZE-i-1, ((Integer)q.pollLast(0, MILLISECONDS)).intValue());
1321 <            }
1322 <            assertNull(q.pollLast(0, MILLISECONDS));
1323 <        } catch (InterruptedException e) {
1324 <            unexpectedException();
1122 >    public void testTimedPollLast0() throws InterruptedException {
1123 >        LinkedBlockingDeque q = populatedDeque(SIZE);
1124 >        for (int i = 0; i < SIZE; ++i) {
1125 >            assertEquals(SIZE-i-1, ((Integer)q.pollLast(0, MILLISECONDS)).intValue());
1126          }
1127 +        assertNull(q.pollLast(0, MILLISECONDS));
1128      }
1129  
1130      /**
1131       * timed pollLast with nonzero timeout succeeds when non-empty, else times out
1132       */
1133 <    public void testTimedPollLast() {
1134 <        try {
1135 <            LinkedBlockingDeque q = populatedDeque(SIZE);
1136 <            for (int i = 0; i < SIZE; ++i) {
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();
1133 >    public void testTimedPollLast() throws InterruptedException {
1134 >        LinkedBlockingDeque q = populatedDeque(SIZE);
1135 >        for (int i = 0; i < SIZE; ++i) {
1136 >            assertEquals(SIZE-i-1, ((Integer)q.pollLast(SHORT_DELAY_MS, MILLISECONDS)).intValue());
1137          }
1138 +        assertNull(q.pollLast(SHORT_DELAY_MS, MILLISECONDS));
1139      }
1140  
1141      /**
1142       * Interrupted timed pollLast throws InterruptedException instead of
1143       * returning timeout status
1144       */
1145 <    public void testInterruptedTimedPollLast() {
1146 <        Thread t = new Thread(new Runnable() {
1147 <                public void run() {
1148 <                    try {
1149 <                        LinkedBlockingDeque q = populatedDeque(SIZE);
1150 <                        for (int i = 0; i < SIZE; ++i) {
1151 <                            threadAssertEquals(SIZE-i-1, ((Integer)q.pollLast(SHORT_DELAY_MS, MILLISECONDS)).intValue());
1152 <                        }
1153 <                        threadAssertNull(q.pollLast(SHORT_DELAY_MS, MILLISECONDS));
1154 <                    } catch (InterruptedException success) {
1155 <                    }
1156 <                }});
1145 >    public void testInterruptedTimedPollLast() throws InterruptedException {
1146 >        Thread t = new Thread(new CheckedRunnable() {
1147 >            public void realRun() throws InterruptedException {
1148 >                LinkedBlockingDeque q = populatedDeque(SIZE);
1149 >                for (int i = 0; i < SIZE; ++i) {
1150 >                    assertEquals(SIZE-i-1, ((Integer)q.pollLast(SHORT_DELAY_MS, MILLISECONDS)).intValue());
1151 >                }
1152 >                try {
1153 >                    q.pollLast(SMALL_DELAY_MS, MILLISECONDS);
1154 >                    shouldThrow();
1155 >                } catch (InterruptedException success) {}
1156 >            }});
1157 >
1158          t.start();
1159 <        try {
1160 <           Thread.sleep(SHORT_DELAY_MS);
1161 <           t.interrupt();
1363 <           t.join();
1364 <        }
1365 <        catch (InterruptedException ie) {
1366 <            unexpectedException();
1367 <        }
1159 >        Thread.sleep(SHORT_DELAY_MS);
1160 >        t.interrupt();
1161 >        t.join();
1162      }
1163  
1164      /**
1165       *  timed poll before a delayed offerLast fails; after offerLast succeeds;
1166       *  on interruption throws
1167       */
1168 <    public void testTimedPollWithOfferLast() {
1168 >    public void testTimedPollWithOfferLast() throws InterruptedException {
1169          final LinkedBlockingDeque q = new LinkedBlockingDeque(2);
1170 <        Thread t = new Thread(new Runnable() {
1171 <                public void run() {
1172 <                    try {
1173 <                        threadAssertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS));
1174 <                        q.poll(LONG_DELAY_MS, MILLISECONDS);
1175 <                        q.poll(LONG_DELAY_MS, MILLISECONDS);
1176 <                        threadShouldThrow();
1177 <                    } catch (InterruptedException success) { }
1178 <                }
1179 <            });
1180 <        try {
1181 <            t.start();
1182 <            Thread.sleep(SMALL_DELAY_MS);
1183 <            assertTrue(q.offerLast(zero, SHORT_DELAY_MS, MILLISECONDS));
1184 <            t.interrupt();
1391 <            t.join();
1392 <        } catch (Exception e) {
1393 <            unexpectedException();
1394 <        }
1170 >        Thread t = new Thread(new CheckedRunnable() {
1171 >            public void realRun() throws InterruptedException {
1172 >                assertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS));
1173 >                assertSame(zero, q.poll(LONG_DELAY_MS, MILLISECONDS));
1174 >                try {
1175 >                    q.poll(LONG_DELAY_MS, MILLISECONDS);
1176 >                    shouldThrow();
1177 >                } catch (InterruptedException success) {}
1178 >            }});
1179 >
1180 >        t.start();
1181 >        Thread.sleep(SMALL_DELAY_MS);
1182 >        assertTrue(q.offerLast(zero, SHORT_DELAY_MS, MILLISECONDS));
1183 >        t.interrupt();
1184 >        t.join();
1185      }
1186  
1187  
# Line 1407 | Line 1197 | public class LinkedBlockingDequeTest ext
1197          try {
1198              q.element();
1199              shouldThrow();
1200 <        }
1411 <        catch (NoSuchElementException success) {}
1200 >        } catch (NoSuchElementException success) {}
1201      }
1202  
1203      /**
# Line 1506 | Line 1295 | public class LinkedBlockingDequeTest ext
1295      /**
1296       * toArray contains all elements
1297       */
1298 <    public void testToArray() {
1298 >    public void testToArray() throws InterruptedException{
1299          LinkedBlockingDeque q = populatedDeque(SIZE);
1300          Object[] o = q.toArray();
1512        try {
1301          for (int i = 0; i < o.length; i++)
1302              assertEquals(o[i], q.take());
1515        } catch (InterruptedException e) {
1516            unexpectedException();
1517        }
1303      }
1304  
1305      /**
1306       * toArray(a) contains all elements
1307       */
1308 <    public void testToArray2() {
1308 >    public void testToArray2() throws InterruptedException {
1309          LinkedBlockingDeque q = populatedDeque(SIZE);
1310          Integer[] ints = new Integer[SIZE];
1311          ints = (Integer[])q.toArray(ints);
1312 <        try {
1313 <            for (int i = 0; i < ints.length; i++)
1529 <                assertEquals(ints[i], q.take());
1530 <        } catch (InterruptedException e) {
1531 <            unexpectedException();
1532 <        }
1312 >        for (int i = 0; i < ints.length; i++)
1313 >            assertEquals(ints[i], q.take());
1314      }
1315  
1316      /**
# Line 1551 | Line 1332 | public class LinkedBlockingDequeTest ext
1332              LinkedBlockingDeque q = populatedDeque(SIZE);
1333              Object o[] = q.toArray(new String[10] );
1334              shouldThrow();
1335 <        } catch (ArrayStoreException  success) {}
1335 >        } catch (ArrayStoreException success) {}
1336      }
1337  
1338  
1339      /**
1340       * iterator iterates through all elements
1341       */
1342 <    public void testIterator() {
1342 >    public void testIterator() throws InterruptedException {
1343          LinkedBlockingDeque q = populatedDeque(SIZE);
1344          Iterator it = q.iterator();
1345 <        try {
1346 <            while (it.hasNext()) {
1566 <                assertEquals(it.next(), q.take());
1567 <            }
1568 <        } catch (InterruptedException e) {
1569 <            unexpectedException();
1345 >        while (it.hasNext()) {
1346 >            assertEquals(it.next(), q.take());
1347          }
1348      }
1349  
# Line 1615 | Line 1392 | public class LinkedBlockingDequeTest ext
1392          q.add(one);
1393          q.add(two);
1394          q.add(three);
1395 <        try {
1396 <            for (Iterator it = q.iterator(); it.hasNext();) {
1397 <                q.remove();
1621 <                it.next();
1622 <            }
1623 <        }
1624 <        catch (ConcurrentModificationException e) {
1625 <            unexpectedException();
1395 >        for (Iterator it = q.iterator(); it.hasNext();) {
1396 >            q.remove();
1397 >            it.next();
1398          }
1399          assertEquals(0, q.size());
1400      }
# Line 1643 | Line 1415 | public class LinkedBlockingDequeTest ext
1415          assertFalse(it.hasNext());
1416          try {
1417              it.next();
1418 <        } catch (NoSuchElementException success) {
1419 <        }
1418 >            shouldThrow();
1419 >        } catch (NoSuchElementException success) {}
1420      }
1421  
1422      /**
# Line 1712 | Line 1484 | public class LinkedBlockingDequeTest ext
1484          q.add(one);
1485          q.add(two);
1486          ExecutorService executor = Executors.newFixedThreadPool(2);
1487 <        executor.execute(new Runnable() {
1488 <            public void run() {
1487 >        executor.execute(new CheckedRunnable() {
1488 >            public void realRun() throws InterruptedException {
1489                  threadAssertFalse(q.offer(three));
1490 <                try {
1491 <                    threadAssertTrue(q.offer(three, MEDIUM_DELAY_MS, MILLISECONDS));
1492 <                    threadAssertEquals(0, q.remainingCapacity());
1493 <                }
1494 <                catch (InterruptedException e) {
1495 <                    threadUnexpectedException();
1496 <                }
1497 <            }
1498 <        });
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 <        });
1490 >                threadAssertTrue(q.offer(three, MEDIUM_DELAY_MS, MILLISECONDS));
1491 >                threadAssertEquals(0, q.remainingCapacity());
1492 >            }});
1493 >
1494 >        executor.execute(new CheckedRunnable() {
1495 >            public void realRun() throws InterruptedException {
1496 >                Thread.sleep(SMALL_DELAY_MS);
1497 >                threadAssertEquals(one, q.take());
1498 >            }});
1499  
1500          joinPool(executor);
1501      }
# Line 1746 | Line 1506 | public class LinkedBlockingDequeTest ext
1506      public void testPollInExecutor() {
1507          final LinkedBlockingDeque q = new LinkedBlockingDeque(2);
1508          ExecutorService executor = Executors.newFixedThreadPool(2);
1509 <        executor.execute(new Runnable() {
1510 <            public void run() {
1509 >        executor.execute(new CheckedRunnable() {
1510 >            public void realRun() throws InterruptedException {
1511                  threadAssertNull(q.poll());
1512 <                try {
1513 <                    threadAssertTrue(null != q.poll(MEDIUM_DELAY_MS, MILLISECONDS));
1514 <                    threadAssertTrue(q.isEmpty());
1515 <                }
1516 <                catch (InterruptedException e) {
1517 <                    threadUnexpectedException();
1518 <                }
1519 <            }
1520 <        });
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 <        });
1512 >                threadAssertTrue(null != q.poll(MEDIUM_DELAY_MS, MILLISECONDS));
1513 >                threadAssertTrue(q.isEmpty());
1514 >            }});
1515 >
1516 >        executor.execute(new CheckedRunnable() {
1517 >            public void realRun() throws InterruptedException {
1518 >                Thread.sleep(SMALL_DELAY_MS);
1519 >                q.put(one);
1520 >            }});
1521  
1522          joinPool(executor);
1523      }
# Line 1777 | Line 1525 | public class LinkedBlockingDequeTest ext
1525      /**
1526       * A deserialized serialized deque has same elements in same order
1527       */
1528 <    public void testSerialization() {
1528 >    public void testSerialization() throws Exception {
1529          LinkedBlockingDeque q = populatedDeque(SIZE);
1530  
1531 <        try {
1532 <            ByteArrayOutputStream bout = new ByteArrayOutputStream(10000);
1533 <            ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout));
1534 <            out.writeObject(q);
1535 <            out.close();
1536 <
1537 <            ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
1538 <            ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin));
1539 <            LinkedBlockingDeque r = (LinkedBlockingDeque)in.readObject();
1540 <            assertEquals(q.size(), r.size());
1541 <            while (!q.isEmpty())
1794 <                assertEquals(q.remove(), r.remove());
1795 <        } catch (Exception e) {
1796 <            unexpectedException();
1797 <        }
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())
1541 >            assertEquals(q.remove(), r.remove());
1542      }
1543  
1544      /**
# Line 1805 | Line 1549 | public class LinkedBlockingDequeTest ext
1549          try {
1550              q.drainTo(null);
1551              shouldThrow();
1552 <        } catch (NullPointerException success) {
1809 <        }
1552 >        } catch (NullPointerException success) {}
1553      }
1554  
1555      /**
# Line 1817 | Line 1560 | public class LinkedBlockingDequeTest ext
1560          try {
1561              q.drainTo(q);
1562              shouldThrow();
1563 <        } catch (IllegalArgumentException success) {
1821 <        }
1563 >        } catch (IllegalArgumentException success) {}
1564      }
1565  
1566      /**
# 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