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.9 by jsr166, Sat Nov 21 08:37:39 2009 UTC vs.
Revision 1.14 by jsr166, Sat Nov 21 21:00:34 2009 UTC

# Line 276 | 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 {
# Line 323 | Line 323 | public class LinkedBlockingDequeTest ext
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)
332 <                assertEquals(ints[i], q.poll());
333 <        }
334 <        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 530 | Line 527 | public class LinkedBlockingDequeTest ext
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)
542 <                assertEquals(ints[i], q.poll());
543 <        }
544 <        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() throws InterruptedException {
545 >    public void testPutNull() throws InterruptedException {
546          try {
547              LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
548              q.put(null);
549              shouldThrow();
550          } catch (NullPointerException success) {}
551 <     }
551 >    }
552  
553      /**
554       * all elements successfully put are contained
555       */
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());
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      /**
# Line 600 | Line 594 | public class LinkedBlockingDequeTest ext
594       */
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 success) {
611 <                        threadAssertTrue(added >= 2);
618 <                    }
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 <            });
613 >            }});
614  
615          t.start();
616          Thread.sleep(SHORT_DELAY_MS);
# Line 729 | Line 722 | public class LinkedBlockingDequeTest ext
722       * returning timeout status
723       */
724      public void testInterruptedTimedPoll() throws InterruptedException {
725 <        Thread t = new ThreadShouldThrow(InterruptedException.class) {
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 <                    threadAssertEquals(i, ((Integer)q.poll(SHORT_DELAY_MS, MILLISECONDS)).intValue());
729 >                    assertEquals(i, ((Integer)q.poll(SHORT_DELAY_MS, MILLISECONDS)).intValue());
730                  }
731 <                q.poll(SMALL_DELAY_MS, MILLISECONDS);
732 <            }};
731 >                try {
732 >                    q.poll(SMALL_DELAY_MS, MILLISECONDS);
733 >                    shouldThrow();
734 >                } catch (InterruptedException success) {}
735 >            }});
736  
737          t.start();
738          Thread.sleep(SHORT_DELAY_MS);
# Line 750 | Line 746 | public class LinkedBlockingDequeTest ext
746       */
747      public void testTimedPollWithOffer() throws InterruptedException {
748          final LinkedBlockingDeque q = new LinkedBlockingDeque(2);
749 <        Thread t = new ThreadShouldThrow(InterruptedException.class) {
749 >        Thread t = new Thread(new CheckedRunnable() {
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 <            }};
751 >                assertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS));
752 >                assertSame(zero, q.poll(LONG_DELAY_MS, MILLISECONDS));
753 >                try {
754 >                    q.poll(LONG_DELAY_MS, MILLISECONDS);
755 >                    shouldThrow();
756 >                } catch (InterruptedException success) {}
757 >            }});
758  
759          t.start();
760          Thread.sleep(SMALL_DELAY_MS);
# Line 793 | Line 792 | public class LinkedBlockingDequeTest ext
792       * putFirst blocks interruptibly if full
793       */
794      public void testBlockingPutFirst() throws InterruptedException {
795 <        Thread t = new Thread(new Runnable() {
796 <                public void run() {
797 <                    int added = 0;
798 <                    try {
799 <                        LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
800 <                        for (int i = 0; i < SIZE; ++i) {
801 <                            q.putFirst(new Integer(i));
802 <                            ++added;
804 <                        }
805 <                        q.putFirst(new Integer(SIZE));
806 <                        threadShouldThrow();
807 <                    } catch (InterruptedException success) {
808 <                        threadAssertEquals(added, SIZE);
795 >        Thread t = new Thread(new CheckedRunnable() {
796 >            public void realRun() {
797 >                int added = 0;
798 >                try {
799 >                    LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
800 >                    for (int i = 0; i < SIZE; ++i) {
801 >                        q.putFirst(new Integer(i));
802 >                        ++added;
803                      }
804 <                }});
804 >                    q.putFirst(new Integer(SIZE));
805 >                    threadShouldThrow();
806 >                } catch (InterruptedException success) {
807 >                    threadAssertEquals(added, SIZE);
808 >                }
809 >            }});
810  
811          t.start();
812          Thread.sleep(SHORT_DELAY_MS);
# Line 820 | Line 819 | public class LinkedBlockingDequeTest ext
819       */
820      public void testPutFirstWithTake() throws InterruptedException {
821          final LinkedBlockingDeque q = new LinkedBlockingDeque(2);
822 <        Thread t = new Thread(new Runnable() {
823 <                public void run() {
824 <                    int added = 0;
825 <                    try {
826 <                        q.putFirst(new Object());
827 <                        ++added;
828 <                        q.putFirst(new Object());
829 <                        ++added;
830 <                        q.putFirst(new Object());
831 <                        ++added;
832 <                        q.putFirst(new Object());
833 <                        ++added;
834 <                        threadShouldThrow();
835 <                    } catch (InterruptedException success) {
836 <                        threadAssertTrue(added >= 2);
838 <                    }
822 >        Thread t = new Thread(new CheckedRunnable() {
823 >            public void realRun() {
824 >                int added = 0;
825 >                try {
826 >                    q.putFirst(new Object());
827 >                    ++added;
828 >                    q.putFirst(new Object());
829 >                    ++added;
830 >                    q.putFirst(new Object());
831 >                    ++added;
832 >                    q.putFirst(new Object());
833 >                    ++added;
834 >                    threadShouldThrow();
835 >                } catch (InterruptedException success) {
836 >                    threadAssertTrue(added >= 2);
837                  }
838 <            });
838 >            }});
839  
840          t.start();
841          Thread.sleep(SHORT_DELAY_MS);
# Line 938 | Line 936 | public class LinkedBlockingDequeTest ext
936       * returning timeout status
937       */
938      public void testInterruptedTimedPollFirst() throws InterruptedException {
939 <        Thread t = new ThreadShouldThrow(InterruptedException.class) {
939 >        Thread t = new Thread(new CheckedRunnable() {
940              public void realRun() throws InterruptedException {
941                  LinkedBlockingDeque q = populatedDeque(SIZE);
942                  for (int i = 0; i < SIZE; ++i) {
943 <                    threadAssertEquals(i, ((Integer)q.pollFirst(SHORT_DELAY_MS, MILLISECONDS)).intValue());
943 >                    assertEquals(i, ((Integer)q.pollFirst(SHORT_DELAY_MS, MILLISECONDS)).intValue());
944                  }
945 <                q.pollFirst(SMALL_DELAY_MS, MILLISECONDS);
946 <            }};
945 >                try {
946 >                    q.pollFirst(SMALL_DELAY_MS, MILLISECONDS);
947 >                    shouldThrow();
948 >                } catch (InterruptedException success) {}
949 >            }});
950  
951          t.start();
952          Thread.sleep(SHORT_DELAY_MS);
# Line 959 | Line 960 | public class LinkedBlockingDequeTest ext
960       */
961      public void testTimedPollFirstWithOfferFirst() throws InterruptedException {
962          final LinkedBlockingDeque q = new LinkedBlockingDeque(2);
963 <        Thread t = new ThreadShouldThrow(InterruptedException.class) {
963 >        Thread t = new Thread(new CheckedRunnable() {
964              public void realRun() throws InterruptedException {
965 <                threadAssertNull(q.pollFirst(SHORT_DELAY_MS, MILLISECONDS));
966 <                q.pollFirst(LONG_DELAY_MS, MILLISECONDS);
967 <                q.pollFirst(LONG_DELAY_MS, MILLISECONDS);
968 <            }};
965 >                assertNull(q.pollFirst(SHORT_DELAY_MS, MILLISECONDS));
966 >                assertSame(zero, q.pollFirst(LONG_DELAY_MS, MILLISECONDS));
967 >                try {
968 >                    q.pollFirst(LONG_DELAY_MS, MILLISECONDS);
969 >                    shouldThrow();
970 >                } catch (InterruptedException success) {}
971 >            }});
972  
973          t.start();
974          Thread.sleep(SMALL_DELAY_MS);
# Line 1001 | Line 1005 | public class LinkedBlockingDequeTest ext
1005       * putLast blocks interruptibly if full
1006       */
1007      public void testBlockingPutLast() throws InterruptedException {
1008 <        Thread t = new Thread(new Runnable() {
1009 <                public void run() {
1010 <                    int added = 0;
1011 <                    try {
1012 <                        LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
1013 <                        for (int i = 0; i < SIZE; ++i) {
1014 <                            q.putLast(new Integer(i));
1015 <                            ++added;
1012 <                        }
1013 <                        q.putLast(new Integer(SIZE));
1014 <                        threadShouldThrow();
1015 <                    } catch (InterruptedException success) {
1016 <                        threadAssertEquals(added, SIZE);
1008 >        Thread t = new Thread(new CheckedRunnable() {
1009 >            public void realRun() {
1010 >                int added = 0;
1011 >                try {
1012 >                    LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
1013 >                    for (int i = 0; i < SIZE; ++i) {
1014 >                        q.putLast(new Integer(i));
1015 >                        ++added;
1016                      }
1017 <                }});
1017 >                    q.putLast(new Integer(SIZE));
1018 >                    threadShouldThrow();
1019 >                } catch (InterruptedException success) {
1020 >                    threadAssertEquals(added, SIZE);
1021 >                }
1022 >            }});
1023 >
1024          t.start();
1025          Thread.sleep(SHORT_DELAY_MS);
1026          t.interrupt();
# Line 1027 | Line 1032 | public class LinkedBlockingDequeTest ext
1032       */
1033      public void testPutLastWithTake() throws InterruptedException {
1034          final LinkedBlockingDeque q = new LinkedBlockingDeque(2);
1035 <        Thread t = new Thread(new Runnable() {
1036 <                public void run() {
1037 <                    int added = 0;
1038 <                    try {
1039 <                        q.putLast(new Object());
1040 <                        ++added;
1041 <                        q.putLast(new Object());
1042 <                        ++added;
1043 <                        q.putLast(new Object());
1044 <                        ++added;
1045 <                        q.putLast(new Object());
1046 <                        ++added;
1047 <                        threadShouldThrow();
1048 <                    } catch (InterruptedException success) {
1049 <                        threadAssertTrue(added >= 2);
1045 <                    }
1035 >        Thread t = new Thread(new CheckedRunnable() {
1036 >            public void realRun() {
1037 >                int added = 0;
1038 >                try {
1039 >                    q.putLast(new Object());
1040 >                    ++added;
1041 >                    q.putLast(new Object());
1042 >                    ++added;
1043 >                    q.putLast(new Object());
1044 >                    ++added;
1045 >                    q.putLast(new Object());
1046 >                    ++added;
1047 >                    threadShouldThrow();
1048 >                } catch (InterruptedException success) {
1049 >                    threadAssertTrue(added >= 2);
1050                  }
1051 <            });
1051 >            }});
1052  
1053          t.start();
1054          Thread.sleep(SHORT_DELAY_MS);
# Line 1145 | Line 1149 | public class LinkedBlockingDequeTest ext
1149       * returning timeout status
1150       */
1151      public void testInterruptedTimedPollLast() throws InterruptedException {
1152 <        Thread t = new ThreadShouldThrow(InterruptedException.class) {
1152 >        Thread t = new Thread(new CheckedRunnable() {
1153              public void realRun() throws InterruptedException {
1154                  LinkedBlockingDeque q = populatedDeque(SIZE);
1155                  for (int i = 0; i < SIZE; ++i) {
1156 <                    threadAssertEquals(SIZE-i-1, ((Integer)q.pollLast(SHORT_DELAY_MS, MILLISECONDS)).intValue());
1156 >                    assertEquals(SIZE-i-1, ((Integer)q.pollLast(SHORT_DELAY_MS, MILLISECONDS)).intValue());
1157                  }
1158 <                q.pollLast(SMALL_DELAY_MS, MILLISECONDS);
1159 <            }};
1158 >                try {
1159 >                    q.pollLast(SMALL_DELAY_MS, MILLISECONDS);
1160 >                    shouldThrow();
1161 >                } catch (InterruptedException success) {}
1162 >            }});
1163  
1164          t.start();
1165          Thread.sleep(SHORT_DELAY_MS);
# Line 1559 | Line 1566 | public class LinkedBlockingDequeTest ext
1566          try {
1567              q.drainTo(q);
1568              shouldThrow();
1569 <        } catch (IllegalArgumentException success) {
1563 <        }
1569 >        } catch (IllegalArgumentException success) {}
1570      }
1571  
1572      /**

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines