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.12 by jsr166, Sat Nov 21 10:29:50 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 793 | Line 786 | public class LinkedBlockingDequeTest ext
786       * putFirst blocks interruptibly if full
787       */
788      public void testBlockingPutFirst() throws InterruptedException {
789 <        Thread t = new Thread(new Runnable() {
790 <                public void run() {
791 <                    int added = 0;
792 <                    try {
793 <                        LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
794 <                        for (int i = 0; i < SIZE; ++i) {
795 <                            q.putFirst(new Integer(i));
796 <                            ++added;
804 <                        }
805 <                        q.putFirst(new Integer(SIZE));
806 <                        threadShouldThrow();
807 <                    } catch (InterruptedException success) {
808 <                        threadAssertEquals(added, SIZE);
789 >        Thread t = new Thread(new CheckedRunnable() {
790 >            public void realRun() {
791 >                int added = 0;
792 >                try {
793 >                    LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
794 >                    for (int i = 0; i < SIZE; ++i) {
795 >                        q.putFirst(new Integer(i));
796 >                        ++added;
797                      }
798 <                }});
798 >                    q.putFirst(new Integer(SIZE));
799 >                    threadShouldThrow();
800 >                } catch (InterruptedException success) {
801 >                    threadAssertEquals(added, SIZE);
802 >                }
803 >            }});
804  
805          t.start();
806          Thread.sleep(SHORT_DELAY_MS);
# Line 820 | Line 813 | public class LinkedBlockingDequeTest ext
813       */
814      public void testPutFirstWithTake() throws InterruptedException {
815          final LinkedBlockingDeque q = new LinkedBlockingDeque(2);
816 <        Thread t = new Thread(new Runnable() {
817 <                public void run() {
818 <                    int added = 0;
819 <                    try {
820 <                        q.putFirst(new Object());
821 <                        ++added;
822 <                        q.putFirst(new Object());
823 <                        ++added;
824 <                        q.putFirst(new Object());
825 <                        ++added;
826 <                        q.putFirst(new Object());
827 <                        ++added;
828 <                        threadShouldThrow();
829 <                    } catch (InterruptedException success) {
830 <                        threadAssertTrue(added >= 2);
838 <                    }
816 >        Thread t = new Thread(new CheckedRunnable() {
817 >            public void realRun() {
818 >                int added = 0;
819 >                try {
820 >                    q.putFirst(new Object());
821 >                    ++added;
822 >                    q.putFirst(new Object());
823 >                    ++added;
824 >                    q.putFirst(new Object());
825 >                    ++added;
826 >                    q.putFirst(new Object());
827 >                    ++added;
828 >                    threadShouldThrow();
829 >                } catch (InterruptedException success) {
830 >                    threadAssertTrue(added >= 2);
831                  }
832 <            });
832 >            }});
833  
834          t.start();
835          Thread.sleep(SHORT_DELAY_MS);
# Line 1001 | Line 993 | public class LinkedBlockingDequeTest ext
993       * putLast blocks interruptibly if full
994       */
995      public void testBlockingPutLast() throws InterruptedException {
996 <        Thread t = new Thread(new Runnable() {
997 <                public void run() {
998 <                    int added = 0;
999 <                    try {
1000 <                        LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
1001 <                        for (int i = 0; i < SIZE; ++i) {
1002 <                            q.putLast(new Integer(i));
1003 <                            ++added;
1012 <                        }
1013 <                        q.putLast(new Integer(SIZE));
1014 <                        threadShouldThrow();
1015 <                    } catch (InterruptedException success) {
1016 <                        threadAssertEquals(added, SIZE);
996 >        Thread t = new Thread(new CheckedRunnable() {
997 >            public void realRun() {
998 >                int added = 0;
999 >                try {
1000 >                    LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
1001 >                    for (int i = 0; i < SIZE; ++i) {
1002 >                        q.putLast(new Integer(i));
1003 >                        ++added;
1004                      }
1005 <                }});
1005 >                    q.putLast(new Integer(SIZE));
1006 >                    threadShouldThrow();
1007 >                } catch (InterruptedException success) {
1008 >                    threadAssertEquals(added, SIZE);
1009 >                }
1010 >            }});
1011 >
1012          t.start();
1013          Thread.sleep(SHORT_DELAY_MS);
1014          t.interrupt();
# Line 1027 | Line 1020 | public class LinkedBlockingDequeTest ext
1020       */
1021      public void testPutLastWithTake() throws InterruptedException {
1022          final LinkedBlockingDeque q = new LinkedBlockingDeque(2);
1023 <        Thread t = new Thread(new Runnable() {
1024 <                public void run() {
1025 <                    int added = 0;
1026 <                    try {
1027 <                        q.putLast(new Object());
1028 <                        ++added;
1029 <                        q.putLast(new Object());
1030 <                        ++added;
1031 <                        q.putLast(new Object());
1032 <                        ++added;
1033 <                        q.putLast(new Object());
1034 <                        ++added;
1035 <                        threadShouldThrow();
1036 <                    } catch (InterruptedException success) {
1037 <                        threadAssertTrue(added >= 2);
1045 <                    }
1023 >        Thread t = new Thread(new CheckedRunnable() {
1024 >            public void realRun() {
1025 >                int added = 0;
1026 >                try {
1027 >                    q.putLast(new Object());
1028 >                    ++added;
1029 >                    q.putLast(new Object());
1030 >                    ++added;
1031 >                    q.putLast(new Object());
1032 >                    ++added;
1033 >                    q.putLast(new Object());
1034 >                    ++added;
1035 >                    threadShouldThrow();
1036 >                } catch (InterruptedException success) {
1037 >                    threadAssertTrue(added >= 2);
1038                  }
1039 <            });
1039 >            }});
1040  
1041          t.start();
1042          Thread.sleep(SHORT_DELAY_MS);
# Line 1559 | Line 1551 | public class LinkedBlockingDequeTest ext
1551          try {
1552              q.drainTo(q);
1553              shouldThrow();
1554 <        } catch (IllegalArgumentException success) {
1563 <        }
1554 >        } catch (IllegalArgumentException success) {}
1555      }
1556  
1557      /**

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines