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.40 by jsr166, Mon May 30 22:43:20 2011 UTC vs.
Revision 1.43 by jsr166, Tue Oct 25 20:29:12 2011 UTC

# Line 10 | Line 10 | import java.util.ArrayList;
10   import java.util.Collection;
11   import java.util.Iterator;
12   import java.util.NoSuchElementException;
13 + import java.util.Queue;
14   import java.util.concurrent.BlockingDeque;
15   import java.util.concurrent.BlockingQueue;
16   import java.util.concurrent.CountDownLatch;
# Line 17 | Line 18 | import java.util.concurrent.Executors;
18   import java.util.concurrent.ExecutorService;
19   import java.util.concurrent.LinkedBlockingDeque;
20   import static java.util.concurrent.TimeUnit.MILLISECONDS;
20 import java.io.*;
21  
22   public class LinkedBlockingDequeTest extends JSR166TestCase {
23  
# Line 29 | Line 29 | public class LinkedBlockingDequeTest ext
29  
30      public static class Bounded extends BlockingQueueTest {
31          protected BlockingQueue emptyCollection() {
32 <            return new LinkedBlockingDeque(20);
32 >            return new LinkedBlockingDeque(SIZE);
33          }
34      }
35  
# Line 1400 | Line 1400 | public class LinkedBlockingDequeTest ext
1400      }
1401  
1402      /**
1403     * remove(x) removes x and returns true if present
1404     */
1405    public void testRemoveElement() {
1406        LinkedBlockingDeque q = populatedDeque(SIZE);
1407        for (int i = 1; i < SIZE; i+=2) {
1408            assertTrue(q.contains(i));
1409            assertTrue(q.remove(i));
1410            assertFalse(q.contains(i));
1411            assertTrue(q.contains(i-1));
1412        }
1413        for (int i = 0; i < SIZE; i+=2) {
1414            assertTrue(q.contains(i));
1415            assertTrue(q.remove(i));
1416            assertFalse(q.contains(i));
1417            assertFalse(q.remove(i+1));
1418            assertFalse(q.contains(i+1));
1419        }
1420        assertTrue(q.isEmpty());
1421    }
1422
1423    /**
1403       * contains(x) reports true when elements added but not yet removed
1404       */
1405      public void testContains() {
# Line 1500 | Line 1479 | public class LinkedBlockingDequeTest ext
1479      /**
1480       * toArray contains all elements in FIFO order
1481       */
1482 <    public void testToArray() throws InterruptedException{
1482 >    public void testToArray() throws InterruptedException {
1483          LinkedBlockingDeque q = populatedDeque(SIZE);
1484          Object[] o = q.toArray();
1485          for (int i = 0; i < o.length; i++)
# Line 1718 | Line 1697 | public class LinkedBlockingDequeTest ext
1697       * A deserialized serialized deque has same elements in same order
1698       */
1699      public void testSerialization() throws Exception {
1700 <        LinkedBlockingDeque q = populatedDeque(SIZE);
1700 >        Queue x = populatedDeque(SIZE);
1701 >        Queue y = serialClone(x);
1702  
1703 <        ByteArrayOutputStream bout = new ByteArrayOutputStream(10000);
1704 <        ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout));
1705 <        out.writeObject(q);
1706 <        out.close();
1707 <
1708 <        ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
1709 <        ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin));
1710 <        LinkedBlockingDeque r = (LinkedBlockingDeque)in.readObject();
1711 <        assertEquals(q.size(), r.size());
1732 <        while (!q.isEmpty())
1733 <            assertEquals(q.remove(), r.remove());
1703 >        assertTrue(x != y);
1704 >        assertEquals(x.size(), y.size());
1705 >        assertEquals(x.toString(), y.toString());
1706 >        assertTrue(Arrays.equals(x.toArray(), y.toArray()));
1707 >        while (!x.isEmpty()) {
1708 >            assertFalse(y.isEmpty());
1709 >            assertEquals(x.remove(), y.remove());
1710 >        }
1711 >        assertTrue(y.isEmpty());
1712      }
1713  
1714      /**

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines