ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/tck/ArrayBlockingQueueTest.java
(Generate patch)

Comparing jsr166/src/test/tck/ArrayBlockingQueueTest.java (file contents):
Revision 1.48 by jsr166, Mon May 30 22:43:20 2011 UTC vs.
Revision 1.50 by jsr166, Fri Jul 15 18:49:31 2011 UTC

# Line 12 | Line 12 | import java.util.ArrayList;
12   import java.util.Collection;
13   import java.util.Iterator;
14   import java.util.NoSuchElementException;
15 + import java.util.Queue;
16   import java.util.concurrent.ArrayBlockingQueue;
17   import java.util.concurrent.BlockingQueue;
18   import java.util.concurrent.CountDownLatch;
19   import java.util.concurrent.Executors;
20   import java.util.concurrent.ExecutorService;
21   import static java.util.concurrent.TimeUnit.MILLISECONDS;
21 import java.io.*;
22  
23   public class ArrayBlockingQueueTest extends JSR166TestCase {
24  
25      public static class Fair extends BlockingQueueTest {
26          protected BlockingQueue emptyCollection() {
27 <            return new ArrayBlockingQueue(20, true);
27 >            return new ArrayBlockingQueue(SIZE, true);
28          }
29      }
30  
31      public static class NonFair extends BlockingQueueTest {
32          protected BlockingQueue emptyCollection() {
33 <            return new ArrayBlockingQueue(20, false);
33 >            return new ArrayBlockingQueue(SIZE, false);
34          }
35      }
36  
# Line 515 | Line 515 | public class ArrayBlockingQueueTest exte
515      }
516  
517      /**
518     * remove(x) removes x and returns true if present
519     */
520    public void testRemoveElement() {
521        ArrayBlockingQueue q = populatedQueue(SIZE);
522        for (int i = 1; i < SIZE; i+=2) {
523            assertTrue(q.remove(new Integer(i)));
524        }
525        for (int i = 0; i < SIZE; i+=2) {
526            assertTrue(q.remove(new Integer(i)));
527            assertFalse(q.remove(new Integer(i+1)));
528        }
529        assertTrue(q.isEmpty());
530    }
531
532    /**
518       * contains(x) reports true when elements added but not yet removed
519       */
520      public void testContains() {
# Line 768 | Line 753 | public class ArrayBlockingQueueTest exte
753       * A deserialized serialized queue has same elements in same order
754       */
755      public void testSerialization() throws Exception {
756 <        ArrayBlockingQueue q = populatedQueue(SIZE);
756 >        Queue x = populatedQueue(SIZE);
757 >        Queue y = serialClone(x);
758  
759 <        ByteArrayOutputStream bout = new ByteArrayOutputStream(10000);
760 <        ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout));
761 <        out.writeObject(q);
762 <        out.close();
763 <
764 <        ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
765 <        ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin));
766 <        ArrayBlockingQueue r = (ArrayBlockingQueue)in.readObject();
767 <        assertEquals(q.size(), r.size());
782 <        while (!q.isEmpty())
783 <            assertEquals(q.remove(), r.remove());
759 >        assertTrue(x != y);
760 >        assertEquals(x.size(), y.size());
761 >        assertEquals(x.toString(), y.toString());
762 >        assertTrue(Arrays.equals(x.toArray(), y.toArray()));
763 >        while (!x.isEmpty()) {
764 >            assertFalse(y.isEmpty());
765 >            assertEquals(x.remove(), y.remove());
766 >        }
767 >        assertTrue(y.isEmpty());
768      }
769  
770      /**

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines