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.25 by jsr166, Sat Oct 9 19:30:35 2010 UTC vs.
Revision 1.32 by jsr166, Fri Nov 5 00:17:22 2010 UTC

# Line 38 | Line 38 | public class LinkedBlockingDequeTest ext
38       * Create a deque of given size containing consecutive
39       * Integers 0 ... n.
40       */
41 <    private LinkedBlockingDeque populatedDeque(int n) {
42 <        LinkedBlockingDeque q = new LinkedBlockingDeque(n);
41 >    private LinkedBlockingDeque<Integer> populatedDeque(int n) {
42 >        LinkedBlockingDeque<Integer> q =
43 >            new LinkedBlockingDeque<Integer>(n);
44          assertTrue(q.isEmpty());
45          for (int i = 0; i < n; i++)
46              assertTrue(q.offer(new Integer(i)));
# Line 682 | Line 683 | public class LinkedBlockingDequeTest ext
683      }
684  
685      /**
685     * take blocks interruptibly when empty
686     */
687    public void testTakeFromEmpty() throws InterruptedException {
688        final LinkedBlockingDeque q = new LinkedBlockingDeque(2);
689        Thread t = new ThreadShouldThrow(InterruptedException.class) {
690            public void realRun() throws InterruptedException {
691                q.take();
692            }};
693
694        t.start();
695        Thread.sleep(SHORT_DELAY_MS);
696        t.interrupt();
697        t.join();
698    }
699
700    /**
686       * Take removes existing elements until empty, then blocks interruptibly
687       */
688      public void testBlockingTake() throws InterruptedException {
# Line 1310 | Line 1295 | public class LinkedBlockingDequeTest ext
1295      }
1296  
1297      /**
1298 <     * toArray contains all elements
1298 >     * toArray contains all elements in FIFO order
1299       */
1300      public void testToArray() throws InterruptedException{
1301          LinkedBlockingDeque q = populatedDeque(SIZE);
1302          Object[] o = q.toArray();
1303          for (int i = 0; i < o.length; i++)
1304 <            assertEquals(o[i], q.take());
1304 >            assertSame(o[i], q.poll());
1305      }
1306  
1307      /**
1308 <     * toArray(a) contains all elements
1308 >     * toArray(a) contains all elements in FIFO order
1309       */
1310 <    public void testToArray2() throws InterruptedException {
1311 <        LinkedBlockingDeque q = populatedDeque(SIZE);
1310 >    public void testToArray2() {
1311 >        LinkedBlockingDeque<Integer> q = populatedDeque(SIZE);
1312          Integer[] ints = new Integer[SIZE];
1313 <        ints = (Integer[])q.toArray(ints);
1313 >        Integer[] array = q.toArray(ints);
1314 >        assertSame(ints, array);
1315          for (int i = 0; i < ints.length; i++)
1316 <            assertEquals(ints[i], q.take());
1316 >            assertSame(ints[i], q.remove());
1317      }
1318  
1319      /**
1320 <     * toArray(null) throws NPE
1320 >     * toArray(null) throws NullPointerException
1321       */
1322 <    public void testToArray_BadArg() {
1322 >    public void testToArray_NullArg() {
1323          LinkedBlockingDeque q = populatedDeque(SIZE);
1324          try {
1325 <            Object o[] = q.toArray(null);
1325 >            q.toArray(null);
1326              shouldThrow();
1327          } catch (NullPointerException success) {}
1328      }
1329  
1330      /**
1331 <     * toArray with incompatible array type throws CCE
1331 >     * toArray(incompatible array type) throws ArrayStoreException
1332       */
1333      public void testToArray1_BadArg() {
1334          LinkedBlockingDeque q = populatedDeque(SIZE);
1335          try {
1336 <            Object o[] = q.toArray(new String[10]);
1336 >            q.toArray(new String[10]);
1337              shouldThrow();
1338          } catch (ArrayStoreException success) {}
1339      }
# Line 1645 | Line 1631 | public class LinkedBlockingDequeTest ext
1631      }
1632  
1633      /**
1634 <     * drainTo(c, n) empties first max {n, size} elements of deque into c
1634 >     * drainTo(c, n) empties first min(n, size) elements of queue into c
1635       */
1636      public void testDrainToN() {
1637          LinkedBlockingDeque q = new LinkedBlockingDeque();
# Line 1654 | Line 1640 | public class LinkedBlockingDequeTest ext
1640                  assertTrue(q.offer(new Integer(j)));
1641              ArrayList l = new ArrayList();
1642              q.drainTo(l, i);
1643 <            int k = (i < SIZE)? i : SIZE;
1643 >            int k = (i < SIZE) ? i : SIZE;
1644              assertEquals(l.size(), k);
1645              assertEquals(q.size(), SIZE-k);
1646              for (int j = 0; j < k; ++j)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines