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.4 by jsr166, Mon Nov 2 20:28:31 2009 UTC vs.
Revision 1.8 by jsr166, Sat Nov 21 02:33:20 2009 UTC

# Line 7 | Line 7
7   import junit.framework.*;
8   import java.util.*;
9   import java.util.concurrent.*;
10 + import static java.util.concurrent.TimeUnit.MILLISECONDS;
11   import java.io.*;
12  
13   public class LinkedBlockingDequeTest extends JSR166TestCase {
14      public static void main(String[] args) {
15 <        junit.textui.TestRunner.run (suite());
15 >        junit.textui.TestRunner.run (suite());
16      }
17  
18      public static Test suite() {
19 <        return new TestSuite(LinkedBlockingDequeTest.class);
19 >        return new TestSuite(LinkedBlockingDequeTest.class);
20      }
21  
22      /**
# Line 25 | Line 26 | public class LinkedBlockingDequeTest ext
26      private LinkedBlockingDeque populatedDeque(int n) {
27          LinkedBlockingDeque q = new LinkedBlockingDeque(n);
28          assertTrue(q.isEmpty());
29 <        for(int i = 0; i < n; i++)
30 <            assertTrue(q.offer(new Integer(i)));
29 >        for (int i = 0; i < n; i++)
30 >            assertTrue(q.offer(new Integer(i)));
31          assertFalse(q.isEmpty());
32          assertEquals(0, q.remainingCapacity());
33 <        assertEquals(n, q.size());
33 >        assertEquals(n, q.size());
34          return q;
35      }
36  
# Line 66 | Line 67 | public class LinkedBlockingDequeTest ext
67       * offer(null) throws NPE
68       */
69      public void testOfferFirstNull() {
70 <        try {
70 >        try {
71              LinkedBlockingDeque q = new LinkedBlockingDeque();
72              q.offerFirst(null);
73              shouldThrow();
# Line 100 | Line 101 | public class LinkedBlockingDequeTest ext
101          for (int i = 0; i < SIZE; ++i) {
102              assertEquals(i, ((Integer)q.pollFirst()).intValue());
103          }
104 <        assertNull(q.pollFirst());
104 >        assertNull(q.pollFirst());
105      }
106  
107      /**
# Line 111 | Line 112 | public class LinkedBlockingDequeTest ext
112          for (int i = SIZE-1; i >= 0; --i) {
113              assertEquals(i, ((Integer)q.pollLast()).intValue());
114          }
115 <        assertNull(q.pollLast());
115 >        assertNull(q.pollLast());
116      }
117  
118      /**
# Line 125 | Line 126 | public class LinkedBlockingDequeTest ext
126              assertTrue(q.peekFirst() == null ||
127                         i != ((Integer)q.peekFirst()).intValue());
128          }
129 <        assertNull(q.peekFirst());
129 >        assertNull(q.peekFirst());
130      }
131  
132      /**
# Line 139 | Line 140 | public class LinkedBlockingDequeTest ext
140              assertTrue(q.peek() == null ||
141                         i != ((Integer)q.peek()).intValue());
142          }
143 <        assertNull(q.peek());
143 >        assertNull(q.peek());
144      }
145  
146      /**
# Line 153 | Line 154 | public class LinkedBlockingDequeTest ext
154              assertTrue(q.peekLast() == null ||
155                         i != ((Integer)q.peekLast()).intValue());
156          }
157 <        assertNull(q.peekLast());
157 >        assertNull(q.peekLast());
158      }
159  
160      /**
# Line 186 | Line 187 | public class LinkedBlockingDequeTest ext
187              shouldThrow();
188          }
189          catch (NoSuchElementException success) {}
190 <        assertNull(q.peekLast());
190 >        assertNull(q.peekLast());
191      }
192  
193      /**
# Line 200 | Line 201 | public class LinkedBlockingDequeTest ext
201          try {
202              q.removeFirst();
203              shouldThrow();
204 <        } catch (NoSuchElementException success){
205 <        }
204 >        } catch (NoSuchElementException success) {
205 >        }
206      }
207  
208      /**
# Line 215 | Line 216 | public class LinkedBlockingDequeTest ext
216          try {
217              q.remove();
218              shouldThrow();
219 <        } catch (NoSuchElementException success){
220 <        }
219 >        } catch (NoSuchElementException success) {
220 >        }
221      }
222  
223      /**
# Line 255 | Line 256 | public class LinkedBlockingDequeTest ext
256      public void testAddFirst() {
257          LinkedBlockingDeque q = populatedDeque(3);
258          q.pollLast();
259 <        q.addFirst(four);
260 <        assertEquals(four,q.peekFirst());
259 >        q.addFirst(four);
260 >        assertEquals(four,q.peekFirst());
261      }
262  
263      /**
# Line 265 | Line 266 | public class LinkedBlockingDequeTest ext
266      public void testAddLast() {
267          LinkedBlockingDeque q = populatedDeque(3);
268          q.pollLast();
269 <        q.addLast(four);
270 <        assertEquals(four,q.peekLast());
269 >        q.addLast(four);
270 >        assertEquals(four,q.peekLast());
271      }
272  
273  
# Line 378 | Line 379 | public class LinkedBlockingDequeTest ext
379       * offer(null) throws NPE
380       */
381      public void testOfferNull() {
382 <        try {
382 >        try {
383              LinkedBlockingDeque q = new LinkedBlockingDeque(1);
384              q.offer(null);
385              shouldThrow();
# Line 389 | Line 390 | public class LinkedBlockingDequeTest ext
390       * add(null) throws NPE
391       */
392      public void testAddNull() {
393 <        try {
393 >        try {
394              LinkedBlockingDeque q = new LinkedBlockingDeque(1);
395              q.add(null);
396              shouldThrow();
# Line 400 | Line 401 | public class LinkedBlockingDequeTest ext
401       * push(null) throws NPE
402       */
403      public void testPushNull() {
404 <        try {
404 >        try {
405              LinkedBlockingDeque q = new LinkedBlockingDeque(1);
406              q.push(null);
407              shouldThrow();
# Line 411 | Line 412 | public class LinkedBlockingDequeTest ext
412       * push succeeds if not full; throws ISE if full
413       */
414      public void testPush() {
415 <        try {
415 >        try {
416              LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
417              for (int i = 0; i < SIZE; ++i) {
418                  Integer I = new Integer(i);
# Line 420 | Line 421 | public class LinkedBlockingDequeTest ext
421              }
422              assertEquals(0, q.remainingCapacity());
423              q.push(new Integer(SIZE));
424 <        } catch (IllegalStateException success){
425 <        }
424 >        } catch (IllegalStateException success) {
425 >        }
426      }
427  
428      /**
# Line 430 | Line 431 | public class LinkedBlockingDequeTest ext
431      public void testPushWithPeek() {
432          LinkedBlockingDeque q = populatedDeque(3);
433          q.pollLast();
434 <        q.push(four);
435 <        assertEquals(four,q.peekFirst());
434 >        q.push(four);
435 >        assertEquals(four,q.peekFirst());
436      }
437  
438  
# Line 446 | Line 447 | public class LinkedBlockingDequeTest ext
447          try {
448              q.pop();
449              shouldThrow();
450 <        } catch (NoSuchElementException success){
451 <        }
450 >        } catch (NoSuchElementException success) {
451 >        }
452      }
453  
454  
# Line 464 | Line 465 | public class LinkedBlockingDequeTest ext
465       * add succeeds if not full; throws ISE if full
466       */
467      public void testAdd() {
468 <        try {
468 >        try {
469              LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
470              for (int i = 0; i < SIZE; ++i) {
471                  assertTrue(q.add(new Integer(i)));
472              }
473              assertEquals(0, q.remainingCapacity());
474              q.add(new Integer(SIZE));
475 <        } catch (IllegalStateException success){
476 <        }
475 >        } catch (IllegalStateException success) {
476 >        }
477      }
478  
479      /**
# Line 563 | Line 564 | public class LinkedBlockingDequeTest ext
564       * put(null) throws NPE
565       */
566       public void testPutNull() {
567 <        try {
567 >        try {
568              LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
569              q.put(null);
570              shouldThrow();
571          }
572 <        catch (NullPointerException success){
573 <        }
572 >        catch (NullPointerException success) {
573 >        }
574          catch (InterruptedException ie) {
575 <            unexpectedException();
575 >            unexpectedException();
576          }
577       }
578  
# Line 589 | Line 590 | public class LinkedBlockingDequeTest ext
590               assertEquals(0, q.remainingCapacity());
591           }
592          catch (InterruptedException ie) {
593 <            unexpectedException();
593 >            unexpectedException();
594          }
595      }
596  
# Line 608 | Line 609 | public class LinkedBlockingDequeTest ext
609                          }
610                          q.put(new Integer(SIZE));
611                          threadShouldThrow();
612 <                    } catch (InterruptedException ie){
612 >                    } catch (InterruptedException ie) {
613                          threadAssertEquals(added, SIZE);
614                      }
615                  }});
# Line 619 | Line 620 | public class LinkedBlockingDequeTest ext
620             t.join();
621          }
622          catch (InterruptedException ie) {
623 <            unexpectedException();
623 >            unexpectedException();
624          }
625      }
626  
# Line 640 | Line 641 | public class LinkedBlockingDequeTest ext
641                          ++added;
642                          q.put(new Object());
643                          ++added;
644 <                        threadShouldThrow();
645 <                    } catch (InterruptedException e){
644 >                        threadShouldThrow();
645 >                    } catch (InterruptedException e) {
646                          threadAssertTrue(added >= 2);
647                      }
648                  }
# Line 652 | Line 653 | public class LinkedBlockingDequeTest ext
653              q.take();
654              t.interrupt();
655              t.join();
656 <        } catch (Exception e){
656 >        } catch (Exception e) {
657              unexpectedException();
658          }
659      }
# Line 667 | Line 668 | public class LinkedBlockingDequeTest ext
668                      try {
669                          q.put(new Object());
670                          q.put(new Object());
671 <                        threadAssertFalse(q.offer(new Object(), SHORT_DELAY_MS, TimeUnit.MILLISECONDS));
672 <                        q.offer(new Object(), LONG_DELAY_MS, TimeUnit.MILLISECONDS);
673 <                        threadShouldThrow();
674 <                    } catch (InterruptedException success){}
671 >                        threadAssertFalse(q.offer(new Object(), SHORT_DELAY_MS, MILLISECONDS));
672 >                        q.offer(new Object(), LONG_DELAY_MS, MILLISECONDS);
673 >                        threadShouldThrow();
674 >                    } catch (InterruptedException success) {}
675                  }
676              });
677  
# Line 679 | Line 680 | public class LinkedBlockingDequeTest ext
680              Thread.sleep(SMALL_DELAY_MS);
681              t.interrupt();
682              t.join();
683 <        } catch (Exception e){
683 >        } catch (Exception e) {
684              unexpectedException();
685          }
686      }
# Line 688 | Line 689 | public class LinkedBlockingDequeTest ext
689       * take retrieves elements in FIFO order
690       */
691      public void testTake() {
692 <        try {
692 >        try {
693              LinkedBlockingDeque q = populatedDeque(SIZE);
694              for (int i = 0; i < SIZE; ++i) {
695                  assertEquals(i, ((Integer)q.take()).intValue());
696              }
697 <        } catch (InterruptedException e){
698 <            unexpectedException();
699 <        }
697 >        } catch (InterruptedException e) {
698 >            unexpectedException();
699 >        }
700      }
701  
702      /**
# Line 707 | Line 708 | public class LinkedBlockingDequeTest ext
708                  public void run() {
709                      try {
710                          q.take();
711 <                        threadShouldThrow();
712 <                    } catch (InterruptedException success){ }
711 >                        threadShouldThrow();
712 >                    } catch (InterruptedException success) { }
713                  }
714              });
715          try {
# Line 716 | Line 717 | public class LinkedBlockingDequeTest ext
717              Thread.sleep(SHORT_DELAY_MS);
718              t.interrupt();
719              t.join();
720 <        } catch (Exception e){
720 >        } catch (Exception e) {
721              unexpectedException();
722          }
723      }
# Line 734 | Line 735 | public class LinkedBlockingDequeTest ext
735                          }
736                          q.take();
737                          threadShouldThrow();
738 <                    } catch (InterruptedException success){
738 >                    } catch (InterruptedException success) {
739                      }
740                  }});
741          t.start();
# Line 744 | Line 745 | public class LinkedBlockingDequeTest ext
745             t.join();
746          }
747          catch (InterruptedException ie) {
748 <            unexpectedException();
748 >            unexpectedException();
749          }
750      }
751  
# Line 757 | Line 758 | public class LinkedBlockingDequeTest ext
758          for (int i = 0; i < SIZE; ++i) {
759              assertEquals(i, ((Integer)q.poll()).intValue());
760          }
761 <        assertNull(q.poll());
761 >        assertNull(q.poll());
762      }
763  
764      /**
# Line 767 | Line 768 | public class LinkedBlockingDequeTest ext
768          try {
769              LinkedBlockingDeque q = populatedDeque(SIZE);
770              for (int i = 0; i < SIZE; ++i) {
771 <                assertEquals(i, ((Integer)q.poll(0, TimeUnit.MILLISECONDS)).intValue());
771 >                assertEquals(i, ((Integer)q.poll(0, MILLISECONDS)).intValue());
772              }
773 <            assertNull(q.poll(0, TimeUnit.MILLISECONDS));
774 <        } catch (InterruptedException e){
775 <            unexpectedException();
776 <        }
773 >            assertNull(q.poll(0, MILLISECONDS));
774 >        } catch (InterruptedException e) {
775 >            unexpectedException();
776 >        }
777      }
778  
779      /**
# Line 782 | Line 783 | public class LinkedBlockingDequeTest ext
783          try {
784              LinkedBlockingDeque q = populatedDeque(SIZE);
785              for (int i = 0; i < SIZE; ++i) {
786 <                assertEquals(i, ((Integer)q.poll(SHORT_DELAY_MS, TimeUnit.MILLISECONDS)).intValue());
786 >                assertEquals(i, ((Integer)q.poll(SHORT_DELAY_MS, MILLISECONDS)).intValue());
787              }
788 <            assertNull(q.poll(SHORT_DELAY_MS, TimeUnit.MILLISECONDS));
789 <        } catch (InterruptedException e){
790 <            unexpectedException();
791 <        }
788 >            assertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS));
789 >        } catch (InterruptedException e) {
790 >            unexpectedException();
791 >        }
792      }
793  
794      /**
# Line 800 | Line 801 | public class LinkedBlockingDequeTest ext
801                      try {
802                          LinkedBlockingDeque q = populatedDeque(SIZE);
803                          for (int i = 0; i < SIZE; ++i) {
804 <                            threadAssertEquals(i, ((Integer)q.poll(SHORT_DELAY_MS, TimeUnit.MILLISECONDS)).intValue());
804 >                            threadAssertEquals(i, ((Integer)q.poll(SHORT_DELAY_MS, MILLISECONDS)).intValue());
805                          }
806 <                        threadAssertNull(q.poll(SHORT_DELAY_MS, TimeUnit.MILLISECONDS));
807 <                    } catch (InterruptedException success){
806 >                        threadAssertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS));
807 >                    } catch (InterruptedException success) {
808                      }
809                  }});
810          t.start();
# Line 813 | Line 814 | public class LinkedBlockingDequeTest ext
814             t.join();
815          }
816          catch (InterruptedException ie) {
817 <            unexpectedException();
817 >            unexpectedException();
818          }
819      }
820  
# Line 826 | Line 827 | public class LinkedBlockingDequeTest ext
827          Thread t = new Thread(new Runnable() {
828                  public void run() {
829                      try {
830 <                        threadAssertNull(q.poll(SHORT_DELAY_MS, TimeUnit.MILLISECONDS));
831 <                        q.poll(LONG_DELAY_MS, TimeUnit.MILLISECONDS);
832 <                        q.poll(LONG_DELAY_MS, TimeUnit.MILLISECONDS);
833 <                        threadShouldThrow();
830 >                        threadAssertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS));
831 >                        q.poll(LONG_DELAY_MS, MILLISECONDS);
832 >                        q.poll(LONG_DELAY_MS, MILLISECONDS);
833 >                        threadShouldThrow();
834                      } catch (InterruptedException success) { }
835                  }
836              });
837          try {
838              t.start();
839              Thread.sleep(SMALL_DELAY_MS);
840 <            assertTrue(q.offer(zero, SHORT_DELAY_MS, TimeUnit.MILLISECONDS));
840 >            assertTrue(q.offer(zero, SHORT_DELAY_MS, MILLISECONDS));
841              t.interrupt();
842              t.join();
843 <        } catch (Exception e){
843 >        } catch (Exception e) {
844              unexpectedException();
845          }
846      }
# Line 849 | Line 850 | public class LinkedBlockingDequeTest ext
850       * putFirst(null) throws NPE
851       */
852       public void testPutFirstNull() {
853 <        try {
853 >        try {
854              LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
855              q.putFirst(null);
856              shouldThrow();
857          }
858 <        catch (NullPointerException success){
859 <        }
858 >        catch (NullPointerException success) {
859 >        }
860          catch (InterruptedException ie) {
861 <            unexpectedException();
861 >            unexpectedException();
862          }
863       }
864  
# Line 875 | Line 876 | public class LinkedBlockingDequeTest ext
876               assertEquals(0, q.remainingCapacity());
877           }
878          catch (InterruptedException ie) {
879 <            unexpectedException();
879 >            unexpectedException();
880          }
881      }
882  
# Line 894 | Line 895 | public class LinkedBlockingDequeTest ext
895                          }
896                          q.putFirst(new Integer(SIZE));
897                          threadShouldThrow();
898 <                    } catch (InterruptedException ie){
898 >                    } catch (InterruptedException ie) {
899                          threadAssertEquals(added, SIZE);
900                      }
901                  }});
# Line 905 | Line 906 | public class LinkedBlockingDequeTest ext
906             t.join();
907          }
908          catch (InterruptedException ie) {
909 <            unexpectedException();
909 >            unexpectedException();
910          }
911      }
912  
# Line 926 | Line 927 | public class LinkedBlockingDequeTest ext
927                          ++added;
928                          q.putFirst(new Object());
929                          ++added;
930 <                        threadShouldThrow();
931 <                    } catch (InterruptedException e){
930 >                        threadShouldThrow();
931 >                    } catch (InterruptedException e) {
932                          threadAssertTrue(added >= 2);
933                      }
934                  }
# Line 938 | Line 939 | public class LinkedBlockingDequeTest ext
939              q.take();
940              t.interrupt();
941              t.join();
942 <        } catch (Exception e){
942 >        } catch (Exception e) {
943              unexpectedException();
944          }
945      }
# Line 953 | Line 954 | public class LinkedBlockingDequeTest ext
954                      try {
955                          q.putFirst(new Object());
956                          q.putFirst(new Object());
957 <                        threadAssertFalse(q.offerFirst(new Object(), SHORT_DELAY_MS, TimeUnit.MILLISECONDS));
958 <                        q.offerFirst(new Object(), LONG_DELAY_MS, TimeUnit.MILLISECONDS);
959 <                        threadShouldThrow();
960 <                    } catch (InterruptedException success){}
957 >                        threadAssertFalse(q.offerFirst(new Object(), SHORT_DELAY_MS, MILLISECONDS));
958 >                        q.offerFirst(new Object(), LONG_DELAY_MS, MILLISECONDS);
959 >                        threadShouldThrow();
960 >                    } catch (InterruptedException success) {}
961                  }
962              });
963  
# Line 965 | Line 966 | public class LinkedBlockingDequeTest ext
966              Thread.sleep(SMALL_DELAY_MS);
967              t.interrupt();
968              t.join();
969 <        } catch (Exception e){
969 >        } catch (Exception e) {
970              unexpectedException();
971          }
972      }
# Line 974 | Line 975 | public class LinkedBlockingDequeTest ext
975       * take retrieves elements in FIFO order
976       */
977      public void testTakeFirst() {
978 <        try {
978 >        try {
979              LinkedBlockingDeque q = populatedDeque(SIZE);
980              for (int i = 0; i < SIZE; ++i) {
981                  assertEquals(i, ((Integer)q.takeFirst()).intValue());
982              }
983 <        } catch (InterruptedException e){
984 <            unexpectedException();
985 <        }
983 >        } catch (InterruptedException e) {
984 >            unexpectedException();
985 >        }
986      }
987  
988      /**
# Line 993 | Line 994 | public class LinkedBlockingDequeTest ext
994                  public void run() {
995                      try {
996                          q.takeFirst();
997 <                        threadShouldThrow();
998 <                    } catch (InterruptedException success){ }
997 >                        threadShouldThrow();
998 >                    } catch (InterruptedException success) { }
999                  }
1000              });
1001          try {
# Line 1002 | Line 1003 | public class LinkedBlockingDequeTest ext
1003              Thread.sleep(SHORT_DELAY_MS);
1004              t.interrupt();
1005              t.join();
1006 <        } catch (Exception e){
1006 >        } catch (Exception e) {
1007              unexpectedException();
1008          }
1009      }
# Line 1020 | Line 1021 | public class LinkedBlockingDequeTest ext
1021                          }
1022                          q.takeFirst();
1023                          threadShouldThrow();
1024 <                    } catch (InterruptedException success){
1024 >                    } catch (InterruptedException success) {
1025                      }
1026                  }});
1027          t.start();
# Line 1030 | Line 1031 | public class LinkedBlockingDequeTest ext
1031             t.join();
1032          }
1033          catch (InterruptedException ie) {
1034 <            unexpectedException();
1034 >            unexpectedException();
1035          }
1036      }
1037  
# Line 1042 | Line 1043 | public class LinkedBlockingDequeTest ext
1043          try {
1044              LinkedBlockingDeque q = populatedDeque(SIZE);
1045              for (int i = 0; i < SIZE; ++i) {
1046 <                assertEquals(i, ((Integer)q.pollFirst(0, TimeUnit.MILLISECONDS)).intValue());
1046 >                assertEquals(i, ((Integer)q.pollFirst(0, MILLISECONDS)).intValue());
1047              }
1048 <            assertNull(q.pollFirst(0, TimeUnit.MILLISECONDS));
1049 <        } catch (InterruptedException e){
1050 <            unexpectedException();
1051 <        }
1048 >            assertNull(q.pollFirst(0, MILLISECONDS));
1049 >        } catch (InterruptedException e) {
1050 >            unexpectedException();
1051 >        }
1052      }
1053  
1054      /**
# Line 1057 | Line 1058 | public class LinkedBlockingDequeTest ext
1058          try {
1059              LinkedBlockingDeque q = populatedDeque(SIZE);
1060              for (int i = 0; i < SIZE; ++i) {
1061 <                assertEquals(i, ((Integer)q.pollFirst(SHORT_DELAY_MS, TimeUnit.MILLISECONDS)).intValue());
1061 >                assertEquals(i, ((Integer)q.pollFirst(SHORT_DELAY_MS, MILLISECONDS)).intValue());
1062              }
1063 <            assertNull(q.pollFirst(SHORT_DELAY_MS, TimeUnit.MILLISECONDS));
1064 <        } catch (InterruptedException e){
1065 <            unexpectedException();
1066 <        }
1063 >            assertNull(q.pollFirst(SHORT_DELAY_MS, MILLISECONDS));
1064 >        } catch (InterruptedException e) {
1065 >            unexpectedException();
1066 >        }
1067      }
1068  
1069      /**
# Line 1075 | Line 1076 | public class LinkedBlockingDequeTest ext
1076                      try {
1077                          LinkedBlockingDeque q = populatedDeque(SIZE);
1078                          for (int i = 0; i < SIZE; ++i) {
1079 <                            threadAssertEquals(i, ((Integer)q.pollFirst(SHORT_DELAY_MS, TimeUnit.MILLISECONDS)).intValue());
1079 >                            threadAssertEquals(i, ((Integer)q.pollFirst(SHORT_DELAY_MS, MILLISECONDS)).intValue());
1080                          }
1081 <                        threadAssertNull(q.pollFirst(SHORT_DELAY_MS, TimeUnit.MILLISECONDS));
1082 <                    } catch (InterruptedException success){
1081 >                        threadAssertNull(q.pollFirst(SHORT_DELAY_MS, MILLISECONDS));
1082 >                    } catch (InterruptedException success) {
1083                      }
1084                  }});
1085          t.start();
# Line 1088 | Line 1089 | public class LinkedBlockingDequeTest ext
1089             t.join();
1090          }
1091          catch (InterruptedException ie) {
1092 <            unexpectedException();
1092 >            unexpectedException();
1093          }
1094      }
1095  
# Line 1101 | Line 1102 | public class LinkedBlockingDequeTest ext
1102          Thread t = new Thread(new Runnable() {
1103                  public void run() {
1104                      try {
1105 <                        threadAssertNull(q.pollFirst(SHORT_DELAY_MS, TimeUnit.MILLISECONDS));
1106 <                        q.pollFirst(LONG_DELAY_MS, TimeUnit.MILLISECONDS);
1107 <                        q.pollFirst(LONG_DELAY_MS, TimeUnit.MILLISECONDS);
1108 <                        threadShouldThrow();
1105 >                        threadAssertNull(q.pollFirst(SHORT_DELAY_MS, MILLISECONDS));
1106 >                        q.pollFirst(LONG_DELAY_MS, MILLISECONDS);
1107 >                        q.pollFirst(LONG_DELAY_MS, MILLISECONDS);
1108 >                        threadShouldThrow();
1109                      } catch (InterruptedException success) { }
1110                  }
1111              });
1112          try {
1113              t.start();
1114              Thread.sleep(SMALL_DELAY_MS);
1115 <            assertTrue(q.offerFirst(zero, SHORT_DELAY_MS, TimeUnit.MILLISECONDS));
1115 >            assertTrue(q.offerFirst(zero, SHORT_DELAY_MS, MILLISECONDS));
1116              t.interrupt();
1117              t.join();
1118 <        } catch (Exception e){
1118 >        } catch (Exception e) {
1119              unexpectedException();
1120          }
1121      }
# Line 1123 | Line 1124 | public class LinkedBlockingDequeTest ext
1124       * putLast(null) throws NPE
1125       */
1126       public void testPutLastNull() {
1127 <        try {
1127 >        try {
1128              LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
1129              q.putLast(null);
1130              shouldThrow();
1131          }
1132 <        catch (NullPointerException success){
1133 <        }
1132 >        catch (NullPointerException success) {
1133 >        }
1134          catch (InterruptedException ie) {
1135 <            unexpectedException();
1135 >            unexpectedException();
1136          }
1137       }
1138  
# Line 1149 | Line 1150 | public class LinkedBlockingDequeTest ext
1150               assertEquals(0, q.remainingCapacity());
1151           }
1152          catch (InterruptedException ie) {
1153 <            unexpectedException();
1153 >            unexpectedException();
1154          }
1155      }
1156  
# Line 1168 | Line 1169 | public class LinkedBlockingDequeTest ext
1169                          }
1170                          q.putLast(new Integer(SIZE));
1171                          threadShouldThrow();
1172 <                    } catch (InterruptedException ie){
1172 >                    } catch (InterruptedException ie) {
1173                          threadAssertEquals(added, SIZE);
1174                      }
1175                  }});
# Line 1179 | Line 1180 | public class LinkedBlockingDequeTest ext
1180             t.join();
1181          }
1182          catch (InterruptedException ie) {
1183 <            unexpectedException();
1183 >            unexpectedException();
1184          }
1185      }
1186  
# Line 1200 | Line 1201 | public class LinkedBlockingDequeTest ext
1201                          ++added;
1202                          q.putLast(new Object());
1203                          ++added;
1204 <                        threadShouldThrow();
1205 <                    } catch (InterruptedException e){
1204 >                        threadShouldThrow();
1205 >                    } catch (InterruptedException e) {
1206                          threadAssertTrue(added >= 2);
1207                      }
1208                  }
# Line 1212 | Line 1213 | public class LinkedBlockingDequeTest ext
1213              q.take();
1214              t.interrupt();
1215              t.join();
1216 <        } catch (Exception e){
1216 >        } catch (Exception e) {
1217              unexpectedException();
1218          }
1219      }
# Line 1227 | Line 1228 | public class LinkedBlockingDequeTest ext
1228                      try {
1229                          q.putLast(new Object());
1230                          q.putLast(new Object());
1231 <                        threadAssertFalse(q.offerLast(new Object(), SHORT_DELAY_MS, TimeUnit.MILLISECONDS));
1232 <                        q.offerLast(new Object(), LONG_DELAY_MS, TimeUnit.MILLISECONDS);
1233 <                        threadShouldThrow();
1234 <                    } catch (InterruptedException success){}
1231 >                        threadAssertFalse(q.offerLast(new Object(), SHORT_DELAY_MS, MILLISECONDS));
1232 >                        q.offerLast(new Object(), LONG_DELAY_MS, MILLISECONDS);
1233 >                        threadShouldThrow();
1234 >                    } catch (InterruptedException success) {}
1235                  }
1236              });
1237  
# Line 1239 | Line 1240 | public class LinkedBlockingDequeTest ext
1240              Thread.sleep(SMALL_DELAY_MS);
1241              t.interrupt();
1242              t.join();
1243 <        } catch (Exception e){
1243 >        } catch (Exception e) {
1244              unexpectedException();
1245          }
1246      }
# Line 1248 | Line 1249 | public class LinkedBlockingDequeTest ext
1249       * takeLast retrieves elements in FIFO order
1250       */
1251      public void testTakeLast() {
1252 <        try {
1252 >        try {
1253              LinkedBlockingDeque q = populatedDeque(SIZE);
1254              for (int i = 0; i < SIZE; ++i) {
1255                  assertEquals(SIZE-i-1, ((Integer)q.takeLast()).intValue());
1256              }
1257 <        } catch (InterruptedException e){
1258 <            unexpectedException();
1259 <        }
1257 >        } catch (InterruptedException e) {
1258 >            unexpectedException();
1259 >        }
1260      }
1261  
1262      /**
# Line 1267 | Line 1268 | public class LinkedBlockingDequeTest ext
1268                  public void run() {
1269                      try {
1270                          q.takeLast();
1271 <                        threadShouldThrow();
1272 <                    } catch (InterruptedException success){ }
1271 >                        threadShouldThrow();
1272 >                    } catch (InterruptedException success) { }
1273                  }
1274              });
1275          try {
# Line 1276 | Line 1277 | public class LinkedBlockingDequeTest ext
1277              Thread.sleep(SHORT_DELAY_MS);
1278              t.interrupt();
1279              t.join();
1280 <        } catch (Exception e){
1280 >        } catch (Exception e) {
1281              unexpectedException();
1282          }
1283      }
# Line 1294 | Line 1295 | public class LinkedBlockingDequeTest ext
1295                          }
1296                          q.takeLast();
1297                          threadShouldThrow();
1298 <                    } catch (InterruptedException success){
1298 >                    } catch (InterruptedException success) {
1299                      }
1300                  }});
1301          t.start();
# Line 1304 | Line 1305 | public class LinkedBlockingDequeTest ext
1305             t.join();
1306          }
1307          catch (InterruptedException ie) {
1308 <            unexpectedException();
1308 >            unexpectedException();
1309          }
1310      }
1311  
# Line 1316 | Line 1317 | public class LinkedBlockingDequeTest ext
1317          try {
1318              LinkedBlockingDeque q = populatedDeque(SIZE);
1319              for (int i = 0; i < SIZE; ++i) {
1320 <                assertEquals(SIZE-i-1, ((Integer)q.pollLast(0, TimeUnit.MILLISECONDS)).intValue());
1320 >                assertEquals(SIZE-i-1, ((Integer)q.pollLast(0, MILLISECONDS)).intValue());
1321              }
1322 <            assertNull(q.pollLast(0, TimeUnit.MILLISECONDS));
1323 <        } catch (InterruptedException e){
1324 <            unexpectedException();
1325 <        }
1322 >            assertNull(q.pollLast(0, MILLISECONDS));
1323 >        } catch (InterruptedException e) {
1324 >            unexpectedException();
1325 >        }
1326      }
1327  
1328      /**
# Line 1331 | Line 1332 | public class LinkedBlockingDequeTest ext
1332          try {
1333              LinkedBlockingDeque q = populatedDeque(SIZE);
1334              for (int i = 0; i < SIZE; ++i) {
1335 <                assertEquals(SIZE-i-1, ((Integer)q.pollLast(SHORT_DELAY_MS, TimeUnit.MILLISECONDS)).intValue());
1335 >                assertEquals(SIZE-i-1, ((Integer)q.pollLast(SHORT_DELAY_MS, MILLISECONDS)).intValue());
1336              }
1337 <            assertNull(q.pollLast(SHORT_DELAY_MS, TimeUnit.MILLISECONDS));
1338 <        } catch (InterruptedException e){
1339 <            unexpectedException();
1340 <        }
1337 >            assertNull(q.pollLast(SHORT_DELAY_MS, MILLISECONDS));
1338 >        } catch (InterruptedException e) {
1339 >            unexpectedException();
1340 >        }
1341      }
1342  
1343      /**
# Line 1349 | Line 1350 | public class LinkedBlockingDequeTest ext
1350                      try {
1351                          LinkedBlockingDeque q = populatedDeque(SIZE);
1352                          for (int i = 0; i < SIZE; ++i) {
1353 <                            threadAssertEquals(SIZE-i-1, ((Integer)q.pollLast(SHORT_DELAY_MS, TimeUnit.MILLISECONDS)).intValue());
1353 >                            threadAssertEquals(SIZE-i-1, ((Integer)q.pollLast(SHORT_DELAY_MS, MILLISECONDS)).intValue());
1354                          }
1355 <                        threadAssertNull(q.pollLast(SHORT_DELAY_MS, TimeUnit.MILLISECONDS));
1356 <                    } catch (InterruptedException success){
1355 >                        threadAssertNull(q.pollLast(SHORT_DELAY_MS, MILLISECONDS));
1356 >                    } catch (InterruptedException success) {
1357                      }
1358                  }});
1359          t.start();
# Line 1362 | Line 1363 | public class LinkedBlockingDequeTest ext
1363             t.join();
1364          }
1365          catch (InterruptedException ie) {
1366 <            unexpectedException();
1366 >            unexpectedException();
1367          }
1368      }
1369  
# Line 1375 | Line 1376 | public class LinkedBlockingDequeTest ext
1376          Thread t = new Thread(new Runnable() {
1377                  public void run() {
1378                      try {
1379 <                        threadAssertNull(q.poll(SHORT_DELAY_MS, TimeUnit.MILLISECONDS));
1380 <                        q.poll(LONG_DELAY_MS, TimeUnit.MILLISECONDS);
1381 <                        q.poll(LONG_DELAY_MS, TimeUnit.MILLISECONDS);
1382 <                        threadShouldThrow();
1379 >                        threadAssertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS));
1380 >                        q.poll(LONG_DELAY_MS, MILLISECONDS);
1381 >                        q.poll(LONG_DELAY_MS, MILLISECONDS);
1382 >                        threadShouldThrow();
1383                      } catch (InterruptedException success) { }
1384                  }
1385              });
1386          try {
1387              t.start();
1388              Thread.sleep(SMALL_DELAY_MS);
1389 <            assertTrue(q.offerLast(zero, SHORT_DELAY_MS, TimeUnit.MILLISECONDS));
1389 >            assertTrue(q.offerLast(zero, SHORT_DELAY_MS, MILLISECONDS));
1390              t.interrupt();
1391              t.join();
1392 <        } catch (Exception e){
1392 >        } catch (Exception e) {
1393              unexpectedException();
1394          }
1395      }
# Line 1507 | Line 1508 | public class LinkedBlockingDequeTest ext
1508       */
1509      public void testToArray() {
1510          LinkedBlockingDeque q = populatedDeque(SIZE);
1511 <        Object[] o = q.toArray();
1512 <        try {
1513 <        for(int i = 0; i < o.length; i++)
1514 <            assertEquals(o[i], q.take());
1515 <        } catch (InterruptedException e){
1516 <            unexpectedException();
1517 <        }
1511 >        Object[] o = q.toArray();
1512 >        try {
1513 >        for (int i = 0; i < o.length; i++)
1514 >            assertEquals(o[i], q.take());
1515 >        } catch (InterruptedException e) {
1516 >            unexpectedException();
1517 >        }
1518      }
1519  
1520      /**
# Line 1521 | Line 1522 | public class LinkedBlockingDequeTest ext
1522       */
1523      public void testToArray2() {
1524          LinkedBlockingDeque q = populatedDeque(SIZE);
1525 <        Integer[] ints = new Integer[SIZE];
1526 <        ints = (Integer[])q.toArray(ints);
1527 <        try {
1528 <            for(int i = 0; i < ints.length; i++)
1529 <                assertEquals(ints[i], q.take());
1530 <        } catch (InterruptedException e){
1531 <            unexpectedException();
1532 <        }
1525 >        Integer[] ints = new Integer[SIZE];
1526 >        ints = (Integer[])q.toArray(ints);
1527 >        try {
1528 >            for (int i = 0; i < ints.length; i++)
1529 >                assertEquals(ints[i], q.take());
1530 >        } catch (InterruptedException e) {
1531 >            unexpectedException();
1532 >        }
1533      }
1534  
1535      /**
1536       * toArray(null) throws NPE
1537       */
1538      public void testToArray_BadArg() {
1539 <        try {
1539 >        try {
1540              LinkedBlockingDeque q = populatedDeque(SIZE);
1541 <            Object o[] = q.toArray(null);
1542 <            shouldThrow();
1543 <        } catch(NullPointerException success){}
1541 >            Object o[] = q.toArray(null);
1542 >            shouldThrow();
1543 >        } catch (NullPointerException success) {}
1544      }
1545  
1546      /**
1547       * toArray with incompatible array type throws CCE
1548       */
1549      public void testToArray1_BadArg() {
1550 <        try {
1550 >        try {
1551              LinkedBlockingDeque q = populatedDeque(SIZE);
1552 <            Object o[] = q.toArray(new String[10] );
1553 <            shouldThrow();
1554 <        } catch(ArrayStoreException  success){}
1552 >            Object o[] = q.toArray(new String[10] );
1553 >            shouldThrow();
1554 >        } catch (ArrayStoreException  success) {}
1555      }
1556  
1557  
# Line 1559 | Line 1560 | public class LinkedBlockingDequeTest ext
1560       */
1561      public void testIterator() {
1562          LinkedBlockingDeque q = populatedDeque(SIZE);
1563 <        Iterator it = q.iterator();
1564 <        try {
1565 <            while(it.hasNext()){
1566 <                assertEquals(it.next(), q.take());
1567 <            }
1568 <        } catch (InterruptedException e){
1569 <            unexpectedException();
1570 <        }
1563 >        Iterator it = q.iterator();
1564 >        try {
1565 >            while (it.hasNext()) {
1566 >                assertEquals(it.next(), q.take());
1567 >            }
1568 >        } catch (InterruptedException e) {
1569 >            unexpectedException();
1570 >        }
1571      }
1572  
1573      /**
# Line 1633 | Line 1634 | public class LinkedBlockingDequeTest ext
1634      public void testDescendingIterator() {
1635          LinkedBlockingDeque q = populatedDeque(SIZE);
1636          int i = 0;
1637 <        Iterator it = q.descendingIterator();
1638 <        while(it.hasNext()) {
1637 >        Iterator it = q.descendingIterator();
1638 >        while (it.hasNext()) {
1639              assertTrue(q.contains(it.next()));
1640              ++i;
1641          }
# Line 1642 | Line 1643 | public class LinkedBlockingDequeTest ext
1643          assertFalse(it.hasNext());
1644          try {
1645              it.next();
1646 <        } catch(NoSuchElementException success) {
1646 >        } catch (NoSuchElementException success) {
1647          }
1648      }
1649  
# Line 1715 | Line 1716 | public class LinkedBlockingDequeTest ext
1716              public void run() {
1717                  threadAssertFalse(q.offer(three));
1718                  try {
1719 <                    threadAssertTrue(q.offer(three, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS));
1719 >                    threadAssertTrue(q.offer(three, MEDIUM_DELAY_MS, MILLISECONDS));
1720                      threadAssertEquals(0, q.remainingCapacity());
1721                  }
1722                  catch (InterruptedException e) {
# Line 1749 | Line 1750 | public class LinkedBlockingDequeTest ext
1750              public void run() {
1751                  threadAssertNull(q.poll());
1752                  try {
1753 <                    threadAssertTrue(null != q.poll(MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS));
1753 >                    threadAssertTrue(null != q.poll(MEDIUM_DELAY_MS, MILLISECONDS));
1754                      threadAssertTrue(q.isEmpty());
1755                  }
1756                  catch (InterruptedException e) {
# Line 1791 | Line 1792 | public class LinkedBlockingDequeTest ext
1792              assertEquals(q.size(), r.size());
1793              while (!q.isEmpty())
1794                  assertEquals(q.remove(), r.remove());
1795 <        } catch(Exception e){
1795 >        } catch (Exception e) {
1796              unexpectedException();
1797          }
1798      }
# Line 1804 | Line 1805 | public class LinkedBlockingDequeTest ext
1805          try {
1806              q.drainTo(null);
1807              shouldThrow();
1808 <        } catch(NullPointerException success) {
1808 >        } catch (NullPointerException success) {
1809          }
1810      }
1811  
# Line 1816 | Line 1817 | public class LinkedBlockingDequeTest ext
1817          try {
1818              q.drainTo(q);
1819              shouldThrow();
1820 <        } catch(IllegalArgumentException success) {
1820 >        } catch (IllegalArgumentException success) {
1821          }
1822      }
1823  
# Line 1853 | Line 1854 | public class LinkedBlockingDequeTest ext
1854                  public void run() {
1855                      try {
1856                          q.put(new Integer(SIZE+1));
1857 <                    } catch (InterruptedException ie){
1857 >                    } catch (InterruptedException ie) {
1858                          threadUnexpectedException();
1859                      }
1860                  }
# Line 1867 | Line 1868 | public class LinkedBlockingDequeTest ext
1868                  assertEquals(l.get(i), new Integer(i));
1869              t.join();
1870              assertTrue(q.size() + l.size() >= SIZE);
1871 <        } catch(Exception e){
1871 >        } catch (Exception e) {
1872              unexpectedException();
1873          }
1874      }
# Line 1880 | Line 1881 | public class LinkedBlockingDequeTest ext
1881          try {
1882              q.drainTo(null, 0);
1883              shouldThrow();
1884 <        } catch(NullPointerException success) {
1884 >        } catch (NullPointerException success) {
1885          }
1886      }
1887  
# Line 1892 | Line 1893 | public class LinkedBlockingDequeTest ext
1893          try {
1894              q.drainTo(q, 0);
1895              shouldThrow();
1896 <        } catch(IllegalArgumentException success) {
1896 >        } catch (IllegalArgumentException success) {
1897          }
1898      }
1899  
# Line 1902 | Line 1903 | public class LinkedBlockingDequeTest ext
1903      public void testDrainToN() {
1904          LinkedBlockingDeque q = new LinkedBlockingDeque();
1905          for (int i = 0; i < SIZE + 2; ++i) {
1906 <            for(int j = 0; j < SIZE; j++)
1906 >            for (int j = 0; j < SIZE; j++)
1907                  assertTrue(q.offer(new Integer(j)));
1908              ArrayList l = new ArrayList();
1909              q.drainTo(l, i);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines