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.10 by jsr166, Sat Nov 21 09:28:16 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  
# Line 792 | 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;
803 <                        }
804 <                        q.putFirst(new Integer(SIZE));
805 <                        threadShouldThrow();
806 <                    } catch (InterruptedException success) {
807 <                        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 819 | 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);
837 <                    }
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 1000 | 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;
1011 <                        }
1012 <                        q.putLast(new Integer(SIZE));
1013 <                        threadShouldThrow();
1014 <                    } catch (InterruptedException success) {
1015 <                        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 1026 | 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);
1044 <                    }
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);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines