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.3 by dl, Fri Sep 16 11:16:03 2005 UTC vs.
Revision 1.4 by jsr166, Mon Nov 2 20:28:31 2009 UTC

# Line 11 | Line 11 | import java.io.*;
11  
12   public class LinkedBlockingDequeTest extends JSR166TestCase {
13      public static void main(String[] args) {
14 <        junit.textui.TestRunner.run (suite());  
14 >        junit.textui.TestRunner.run (suite());
15      }
16  
17      public static Test suite() {
# Line 70 | Line 70 | public class LinkedBlockingDequeTest ext
70              LinkedBlockingDeque q = new LinkedBlockingDeque();
71              q.offerFirst(null);
72              shouldThrow();
73 <        } catch (NullPointerException success) {
74 <        }  
73 >        } catch (NullPointerException success) {
74 >        }
75      }
76  
77      /**
78 <     * OfferFirst succeeds
78 >     * OfferFirst succeeds
79       */
80      public void testOfferFirst() {
81          LinkedBlockingDeque q = new LinkedBlockingDeque();
# Line 84 | Line 84 | public class LinkedBlockingDequeTest ext
84      }
85  
86      /**
87 <     * OfferLast succeeds
87 >     * OfferLast succeeds
88       */
89      public void testOfferLast() {
90          LinkedBlockingDeque q = new LinkedBlockingDeque();
# Line 201 | Line 201 | public class LinkedBlockingDequeTest ext
201              q.removeFirst();
202              shouldThrow();
203          } catch (NoSuchElementException success){
204 <        }  
204 >        }
205      }
206  
207      /**
# Line 216 | Line 216 | public class LinkedBlockingDequeTest ext
216              q.remove();
217              shouldThrow();
218          } catch (NoSuchElementException success){
219 <        }  
219 >        }
220      }
221  
222      /**
# Line 257 | Line 257 | public class LinkedBlockingDequeTest ext
257          q.pollLast();
258          q.addFirst(four);
259          assertEquals(four,q.peekFirst());
260 <    }  
260 >    }
261  
262      /**
263       * peekLast returns element inserted with addLast
# Line 267 | Line 267 | public class LinkedBlockingDequeTest ext
267          q.pollLast();
268          q.addLast(four);
269          assertEquals(four,q.peekLast());
270 <    }  
270 >    }
271  
272  
273      /**
# Line 382 | Line 382 | public class LinkedBlockingDequeTest ext
382              LinkedBlockingDeque q = new LinkedBlockingDeque(1);
383              q.offer(null);
384              shouldThrow();
385 <        } catch (NullPointerException success) { }  
385 >        } catch (NullPointerException success) { }
386      }
387  
388      /**
# Line 393 | Line 393 | public class LinkedBlockingDequeTest ext
393              LinkedBlockingDeque q = new LinkedBlockingDeque(1);
394              q.add(null);
395              shouldThrow();
396 <        } catch (NullPointerException success) { }  
396 >        } catch (NullPointerException success) { }
397      }
398  
399      /**
# Line 404 | Line 404 | public class LinkedBlockingDequeTest ext
404              LinkedBlockingDeque q = new LinkedBlockingDeque(1);
405              q.push(null);
406              shouldThrow();
407 <        } catch (NullPointerException success) { }  
407 >        } catch (NullPointerException success) { }
408      }
409  
410      /**
# Line 421 | Line 421 | public class LinkedBlockingDequeTest ext
421              assertEquals(0, q.remainingCapacity());
422              q.push(new Integer(SIZE));
423          } catch (IllegalStateException success){
424 <        }  
424 >        }
425      }
426  
427      /**
# Line 432 | Line 432 | public class LinkedBlockingDequeTest ext
432          q.pollLast();
433          q.push(four);
434          assertEquals(four,q.peekFirst());
435 <    }  
435 >    }
436  
437  
438      /**
# Line 447 | Line 447 | public class LinkedBlockingDequeTest ext
447              q.pop();
448              shouldThrow();
449          } catch (NoSuchElementException success){
450 <        }  
450 >        }
451      }
452  
453  
# Line 472 | Line 472 | public class LinkedBlockingDequeTest ext
472              assertEquals(0, q.remainingCapacity());
473              q.add(new Integer(SIZE));
474          } catch (IllegalStateException success){
475 <        }  
475 >        }
476      }
477  
478      /**
# Line 567 | Line 567 | public class LinkedBlockingDequeTest ext
567              LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
568              q.put(null);
569              shouldThrow();
570 <        }
570 >        }
571          catch (NullPointerException success){
572 <        }  
572 >        }
573          catch (InterruptedException ie) {
574              unexpectedException();
575          }
# Line 610 | Line 610 | public class LinkedBlockingDequeTest ext
610                          threadShouldThrow();
611                      } catch (InterruptedException ie){
612                          threadAssertEquals(added, SIZE);
613 <                    }  
613 >                    }
614                  }});
615          t.start();
616 <        try {
617 <           Thread.sleep(SHORT_DELAY_MS);
616 >        try {
617 >           Thread.sleep(SHORT_DELAY_MS);
618             t.interrupt();
619             t.join();
620          }
# Line 673 | Line 673 | public class LinkedBlockingDequeTest ext
673                      } catch (InterruptedException success){}
674                  }
675              });
676 <        
676 >
677          try {
678              t.start();
679              Thread.sleep(SMALL_DELAY_MS);
# Line 695 | Line 695 | public class LinkedBlockingDequeTest ext
695              }
696          } catch (InterruptedException e){
697              unexpectedException();
698 <        }  
698 >        }
699      }
700  
701      /**
# Line 708 | Line 708 | public class LinkedBlockingDequeTest ext
708                      try {
709                          q.take();
710                          threadShouldThrow();
711 <                    } catch (InterruptedException success){ }                
711 >                    } catch (InterruptedException success){ }
712                  }
713              });
714          try {
# Line 735 | Line 735 | public class LinkedBlockingDequeTest ext
735                          q.take();
736                          threadShouldThrow();
737                      } catch (InterruptedException success){
738 <                    }  
738 >                    }
739                  }});
740          t.start();
741 <        try {
742 <           Thread.sleep(SHORT_DELAY_MS);
741 >        try {
742 >           Thread.sleep(SHORT_DELAY_MS);
743             t.interrupt();
744             t.join();
745          }
# Line 772 | Line 772 | public class LinkedBlockingDequeTest ext
772              assertNull(q.poll(0, TimeUnit.MILLISECONDS));
773          } catch (InterruptedException e){
774              unexpectedException();
775 <        }  
775 >        }
776      }
777  
778      /**
# Line 787 | Line 787 | public class LinkedBlockingDequeTest ext
787              assertNull(q.poll(SHORT_DELAY_MS, TimeUnit.MILLISECONDS));
788          } catch (InterruptedException e){
789              unexpectedException();
790 <        }  
790 >        }
791      }
792  
793      /**
# Line 804 | Line 804 | public class LinkedBlockingDequeTest ext
804                          }
805                          threadAssertNull(q.poll(SHORT_DELAY_MS, TimeUnit.MILLISECONDS));
806                      } catch (InterruptedException success){
807 <                    }  
807 >                    }
808                  }});
809          t.start();
810 <        try {
811 <           Thread.sleep(SHORT_DELAY_MS);
810 >        try {
811 >           Thread.sleep(SHORT_DELAY_MS);
812             t.interrupt();
813             t.join();
814          }
# Line 830 | Line 830 | public class LinkedBlockingDequeTest ext
830                          q.poll(LONG_DELAY_MS, TimeUnit.MILLISECONDS);
831                          q.poll(LONG_DELAY_MS, TimeUnit.MILLISECONDS);
832                          threadShouldThrow();
833 <                    } catch (InterruptedException success) { }                
833 >                    } catch (InterruptedException success) { }
834                  }
835              });
836          try {
# Line 842 | Line 842 | public class LinkedBlockingDequeTest ext
842          } catch (Exception e){
843              unexpectedException();
844          }
845 <    }  
845 >    }
846  
847  
848      /**
# Line 853 | Line 853 | public class LinkedBlockingDequeTest ext
853              LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
854              q.putFirst(null);
855              shouldThrow();
856 <        }
856 >        }
857          catch (NullPointerException success){
858 <        }  
858 >        }
859          catch (InterruptedException ie) {
860              unexpectedException();
861          }
# Line 896 | Line 896 | public class LinkedBlockingDequeTest ext
896                          threadShouldThrow();
897                      } catch (InterruptedException ie){
898                          threadAssertEquals(added, SIZE);
899 <                    }  
899 >                    }
900                  }});
901          t.start();
902 <        try {
903 <           Thread.sleep(SHORT_DELAY_MS);
902 >        try {
903 >           Thread.sleep(SHORT_DELAY_MS);
904             t.interrupt();
905             t.join();
906          }
# Line 959 | Line 959 | public class LinkedBlockingDequeTest ext
959                      } catch (InterruptedException success){}
960                  }
961              });
962 <        
962 >
963          try {
964              t.start();
965              Thread.sleep(SMALL_DELAY_MS);
# Line 981 | Line 981 | public class LinkedBlockingDequeTest ext
981              }
982          } catch (InterruptedException e){
983              unexpectedException();
984 <        }  
984 >        }
985      }
986  
987      /**
# Line 994 | Line 994 | public class LinkedBlockingDequeTest ext
994                      try {
995                          q.takeFirst();
996                          threadShouldThrow();
997 <                    } catch (InterruptedException success){ }                
997 >                    } catch (InterruptedException success){ }
998                  }
999              });
1000          try {
# Line 1021 | Line 1021 | public class LinkedBlockingDequeTest ext
1021                          q.takeFirst();
1022                          threadShouldThrow();
1023                      } catch (InterruptedException success){
1024 <                    }  
1024 >                    }
1025                  }});
1026          t.start();
1027 <        try {
1028 <           Thread.sleep(SHORT_DELAY_MS);
1027 >        try {
1028 >           Thread.sleep(SHORT_DELAY_MS);
1029             t.interrupt();
1030             t.join();
1031          }
# Line 1047 | Line 1047 | public class LinkedBlockingDequeTest ext
1047              assertNull(q.pollFirst(0, TimeUnit.MILLISECONDS));
1048          } catch (InterruptedException e){
1049              unexpectedException();
1050 <        }  
1050 >        }
1051      }
1052  
1053      /**
# Line 1062 | Line 1062 | public class LinkedBlockingDequeTest ext
1062              assertNull(q.pollFirst(SHORT_DELAY_MS, TimeUnit.MILLISECONDS));
1063          } catch (InterruptedException e){
1064              unexpectedException();
1065 <        }  
1065 >        }
1066      }
1067  
1068      /**
# Line 1079 | Line 1079 | public class LinkedBlockingDequeTest ext
1079                          }
1080                          threadAssertNull(q.pollFirst(SHORT_DELAY_MS, TimeUnit.MILLISECONDS));
1081                      } catch (InterruptedException success){
1082 <                    }  
1082 >                    }
1083                  }});
1084          t.start();
1085 <        try {
1086 <           Thread.sleep(SHORT_DELAY_MS);
1085 >        try {
1086 >           Thread.sleep(SHORT_DELAY_MS);
1087             t.interrupt();
1088             t.join();
1089          }
# Line 1105 | Line 1105 | public class LinkedBlockingDequeTest ext
1105                          q.pollFirst(LONG_DELAY_MS, TimeUnit.MILLISECONDS);
1106                          q.pollFirst(LONG_DELAY_MS, TimeUnit.MILLISECONDS);
1107                          threadShouldThrow();
1108 <                    } catch (InterruptedException success) { }                
1108 >                    } catch (InterruptedException success) { }
1109                  }
1110              });
1111          try {
# Line 1117 | Line 1117 | public class LinkedBlockingDequeTest ext
1117          } catch (Exception e){
1118              unexpectedException();
1119          }
1120 <    }  
1120 >    }
1121  
1122      /**
1123       * putLast(null) throws NPE
# Line 1127 | Line 1127 | public class LinkedBlockingDequeTest ext
1127              LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
1128              q.putLast(null);
1129              shouldThrow();
1130 <        }
1130 >        }
1131          catch (NullPointerException success){
1132 <        }  
1132 >        }
1133          catch (InterruptedException ie) {
1134              unexpectedException();
1135          }
# Line 1170 | Line 1170 | public class LinkedBlockingDequeTest ext
1170                          threadShouldThrow();
1171                      } catch (InterruptedException ie){
1172                          threadAssertEquals(added, SIZE);
1173 <                    }  
1173 >                    }
1174                  }});
1175          t.start();
1176 <        try {
1177 <           Thread.sleep(SHORT_DELAY_MS);
1176 >        try {
1177 >           Thread.sleep(SHORT_DELAY_MS);
1178             t.interrupt();
1179             t.join();
1180          }
# Line 1233 | Line 1233 | public class LinkedBlockingDequeTest ext
1233                      } catch (InterruptedException success){}
1234                  }
1235              });
1236 <        
1236 >
1237          try {
1238              t.start();
1239              Thread.sleep(SMALL_DELAY_MS);
# Line 1255 | Line 1255 | public class LinkedBlockingDequeTest ext
1255              }
1256          } catch (InterruptedException e){
1257              unexpectedException();
1258 <        }  
1258 >        }
1259      }
1260  
1261      /**
# Line 1268 | Line 1268 | public class LinkedBlockingDequeTest ext
1268                      try {
1269                          q.takeLast();
1270                          threadShouldThrow();
1271 <                    } catch (InterruptedException success){ }                
1271 >                    } catch (InterruptedException success){ }
1272                  }
1273              });
1274          try {
# Line 1295 | Line 1295 | public class LinkedBlockingDequeTest ext
1295                          q.takeLast();
1296                          threadShouldThrow();
1297                      } catch (InterruptedException success){
1298 <                    }  
1298 >                    }
1299                  }});
1300          t.start();
1301 <        try {
1302 <           Thread.sleep(SHORT_DELAY_MS);
1301 >        try {
1302 >           Thread.sleep(SHORT_DELAY_MS);
1303             t.interrupt();
1304             t.join();
1305          }
# Line 1321 | Line 1321 | public class LinkedBlockingDequeTest ext
1321              assertNull(q.pollLast(0, TimeUnit.MILLISECONDS));
1322          } catch (InterruptedException e){
1323              unexpectedException();
1324 <        }  
1324 >        }
1325      }
1326  
1327      /**
# Line 1336 | Line 1336 | public class LinkedBlockingDequeTest ext
1336              assertNull(q.pollLast(SHORT_DELAY_MS, TimeUnit.MILLISECONDS));
1337          } catch (InterruptedException e){
1338              unexpectedException();
1339 <        }  
1339 >        }
1340      }
1341  
1342      /**
# Line 1353 | Line 1353 | public class LinkedBlockingDequeTest ext
1353                          }
1354                          threadAssertNull(q.pollLast(SHORT_DELAY_MS, TimeUnit.MILLISECONDS));
1355                      } catch (InterruptedException success){
1356 <                    }  
1356 >                    }
1357                  }});
1358          t.start();
1359 <        try {
1360 <           Thread.sleep(SHORT_DELAY_MS);
1359 >        try {
1360 >           Thread.sleep(SHORT_DELAY_MS);
1361             t.interrupt();
1362             t.join();
1363          }
# Line 1379 | Line 1379 | public class LinkedBlockingDequeTest ext
1379                          q.poll(LONG_DELAY_MS, TimeUnit.MILLISECONDS);
1380                          q.poll(LONG_DELAY_MS, TimeUnit.MILLISECONDS);
1381                          threadShouldThrow();
1382 <                    } catch (InterruptedException success) { }                
1382 >                    } catch (InterruptedException success) { }
1383                  }
1384              });
1385          try {
# Line 1391 | Line 1391 | public class LinkedBlockingDequeTest ext
1391          } catch (Exception e){
1392              unexpectedException();
1393          }
1394 <    }  
1394 >    }
1395  
1396  
1397      /**
# Line 1424 | Line 1424 | public class LinkedBlockingDequeTest ext
1424          }
1425          assertTrue(q.isEmpty());
1426      }
1427 <        
1427 >
1428      /**
1429       * contains(x) reports true when elements added but not yet removed
1430       */
# Line 1513 | Line 1513 | public class LinkedBlockingDequeTest ext
1513              assertEquals(o[i], q.take());
1514          } catch (InterruptedException e){
1515              unexpectedException();
1516 <        }    
1516 >        }
1517      }
1518  
1519      /**
# Line 1528 | Line 1528 | public class LinkedBlockingDequeTest ext
1528                  assertEquals(ints[i], q.take());
1529          } catch (InterruptedException e){
1530              unexpectedException();
1531 <        }    
1531 >        }
1532      }
1533  
1534      /**
# Line 1553 | Line 1553 | public class LinkedBlockingDequeTest ext
1553          } catch(ArrayStoreException  success){}
1554      }
1555  
1556 <    
1556 >
1557      /**
1558       * iterator iterates through all elements
1559       */
# Line 1566 | Line 1566 | public class LinkedBlockingDequeTest ext
1566              }
1567          } catch (InterruptedException e){
1568              unexpectedException();
1569 <        }    
1569 >        }
1570      }
1571  
1572      /**
# Line 1581 | Line 1581 | public class LinkedBlockingDequeTest ext
1581          Iterator it = q.iterator();
1582          it.next();
1583          it.remove();
1584 <        
1584 >
1585          it = q.iterator();
1586          assertEquals(it.next(), one);
1587          assertEquals(it.next(), three);
# Line 1660 | Line 1660 | public class LinkedBlockingDequeTest ext
1660                  int i = ((Integer)(it.next())).intValue();
1661                  assertEquals(++k, i);
1662              }
1663 <            
1663 >
1664              assertEquals(3, k);
1665              q.remove();
1666              q.remove();
# Line 1700 | Line 1700 | public class LinkedBlockingDequeTest ext
1700          for (int i = 0; i < SIZE; ++i) {
1701              assertTrue(s.indexOf(String.valueOf(i)) >= 0);
1702          }
1703 <    }        
1703 >    }
1704  
1705  
1706      /**
# Line 1735 | Line 1735 | public class LinkedBlockingDequeTest ext
1735                  }
1736              }
1737          });
1738 <        
1738 >
1739          joinPool(executor);
1740      }
1741  
# Line 1769 | Line 1769 | public class LinkedBlockingDequeTest ext
1769                  }
1770              }
1771          });
1772 <        
1772 >
1773          joinPool(executor);
1774      }
1775  
# Line 1789 | Line 1789 | public class LinkedBlockingDequeTest ext
1789              ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin));
1790              LinkedBlockingDeque r = (LinkedBlockingDeque)in.readObject();
1791              assertEquals(q.size(), r.size());
1792 <            while (!q.isEmpty())
1792 >            while (!q.isEmpty())
1793                  assertEquals(q.remove(), r.remove());
1794          } catch(Exception e){
1795              unexpectedException();
# Line 1798 | Line 1798 | public class LinkedBlockingDequeTest ext
1798  
1799      /**
1800       * drainTo(null) throws NPE
1801 <     */
1801 >     */
1802      public void testDrainToNull() {
1803          LinkedBlockingDeque q = populatedDeque(SIZE);
1804          try {
# Line 1810 | Line 1810 | public class LinkedBlockingDequeTest ext
1810  
1811      /**
1812       * drainTo(this) throws IAE
1813 <     */
1813 >     */
1814      public void testDrainToSelf() {
1815          LinkedBlockingDeque q = populatedDeque(SIZE);
1816          try {
# Line 1822 | Line 1822 | public class LinkedBlockingDequeTest ext
1822  
1823      /**
1824       * drainTo(c) empties deque into another collection c
1825 <     */
1825 >     */
1826      public void testDrainTo() {
1827          LinkedBlockingDeque q = populatedDeque(SIZE);
1828          ArrayList l = new ArrayList();
1829          q.drainTo(l);
1830          assertEquals(q.size(), 0);
1831          assertEquals(l.size(), SIZE);
1832 <        for (int i = 0; i < SIZE; ++i)
1832 >        for (int i = 0; i < SIZE; ++i)
1833              assertEquals(l.get(i), new Integer(i));
1834          q.add(zero);
1835          q.add(one);
# Line 1840 | Line 1840 | public class LinkedBlockingDequeTest ext
1840          q.drainTo(l);
1841          assertEquals(q.size(), 0);
1842          assertEquals(l.size(), 2);
1843 <        for (int i = 0; i < 2; ++i)
1843 >        for (int i = 0; i < 2; ++i)
1844              assertEquals(l.get(i), new Integer(i));
1845      }
1846  
1847      /**
1848       * drainTo empties full deque, unblocking a waiting put.
1849 <     */
1849 >     */
1850      public void testDrainToWithActivePut() {
1851          final LinkedBlockingDeque q = populatedDeque(SIZE);
1852          Thread t = new Thread(new Runnable() {
1853                  public void run() {
1854                      try {
1855                          q.put(new Integer(SIZE+1));
1856 <                    } catch (InterruptedException ie){
1856 >                    } catch (InterruptedException ie){
1857                          threadUnexpectedException();
1858                      }
1859                  }
# Line 1863 | Line 1863 | public class LinkedBlockingDequeTest ext
1863              ArrayList l = new ArrayList();
1864              q.drainTo(l);
1865              assertTrue(l.size() >= SIZE);
1866 <            for (int i = 0; i < SIZE; ++i)
1866 >            for (int i = 0; i < SIZE; ++i)
1867                  assertEquals(l.get(i), new Integer(i));
1868              t.join();
1869              assertTrue(q.size() + l.size() >= SIZE);
# Line 1874 | Line 1874 | public class LinkedBlockingDequeTest ext
1874  
1875      /**
1876       * drainTo(null, n) throws NPE
1877 <     */
1877 >     */
1878      public void testDrainToNullN() {
1879          LinkedBlockingDeque q = populatedDeque(SIZE);
1880          try {
# Line 1886 | Line 1886 | public class LinkedBlockingDequeTest ext
1886  
1887      /**
1888       * drainTo(this, n) throws IAE
1889 <     */
1889 >     */
1890      public void testDrainToSelfN() {
1891          LinkedBlockingDeque q = populatedDeque(SIZE);
1892          try {
# Line 1898 | Line 1898 | public class LinkedBlockingDequeTest ext
1898  
1899      /**
1900       * drainTo(c, n) empties first max {n, size} elements of deque into c
1901 <     */
1901 >     */
1902      public void testDrainToN() {
1903          LinkedBlockingDeque q = new LinkedBlockingDeque();
1904          for (int i = 0; i < SIZE + 2; ++i) {
# Line 1909 | Line 1909 | public class LinkedBlockingDequeTest ext
1909              int k = (i < SIZE)? i : SIZE;
1910              assertEquals(l.size(), k);
1911              assertEquals(q.size(), SIZE-k);
1912 <            for (int j = 0; j < k; ++j)
1912 >            for (int j = 0; j < k; ++j)
1913                  assertEquals(l.get(j), new Integer(j));
1914              while (q.poll() != null) ;
1915          }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines