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

Comparing jsr166/src/test/tck/LinkedBlockingQueueTest.java (file contents):
Revision 1.44 by jsr166, Fri May 27 20:07:24 2011 UTC vs.
Revision 1.45 by jsr166, Mon May 30 22:43:20 2011 UTC

# Line 7 | Line 7
7   */
8  
9   import junit.framework.*;
10 < import java.util.*;
11 < import java.util.concurrent.*;
10 > import java.util.Arrays;
11 > import java.util.ArrayList;
12 > import java.util.Collection;
13 > import java.util.Iterator;
14 > import java.util.NoSuchElementException;
15 > import java.util.concurrent.BlockingQueue;
16 > import java.util.concurrent.CountDownLatch;
17 > import java.util.concurrent.LinkedBlockingQueue;
18 > import java.util.concurrent.Executors;
19 > import java.util.concurrent.ExecutorService;
20   import static java.util.concurrent.TimeUnit.MILLISECONDS;
21   import java.io.*;
22  
# Line 62 | Line 70 | public class LinkedBlockingQueueTest ext
70      }
71  
72      /**
73 <     * Constructor throws IAE if capacity argument nonpositive
73 >     * Constructor throws IllegalArgumentException if capacity argument nonpositive
74       */
75      public void testConstructor2() {
76          try {
77 <            LinkedBlockingQueue q = new LinkedBlockingQueue(0);
77 >            new LinkedBlockingQueue(0);
78              shouldThrow();
79          } catch (IllegalArgumentException success) {}
80      }
81  
82      /**
83 <     * Initializing from null Collection throws NPE
83 >     * Initializing from null Collection throws NullPointerException
84       */
85      public void testConstructor3() {
86          try {
87 <            LinkedBlockingQueue q = new LinkedBlockingQueue(null);
87 >            new LinkedBlockingQueue(null);
88              shouldThrow();
89          } catch (NullPointerException success) {}
90      }
91  
92      /**
93 <     * Initializing from Collection of null elements throws NPE
93 >     * Initializing from Collection of null elements throws NullPointerException
94       */
95      public void testConstructor4() {
96 +        Collection<Integer> elements = Arrays.asList(new Integer[SIZE]);
97          try {
98 <            Integer[] ints = new Integer[SIZE];
90 <            LinkedBlockingQueue q = new LinkedBlockingQueue(Arrays.asList(ints));
98 >            new LinkedBlockingQueue(elements);
99              shouldThrow();
100          } catch (NullPointerException success) {}
101      }
102  
103      /**
104 <     * Initializing from Collection with some null elements throws NPE
104 >     * Initializing from Collection with some null elements throws
105 >     * NullPointerException
106       */
107      public void testConstructor5() {
108 +        Integer[] ints = new Integer[SIZE];
109 +        for (int i = 0; i < SIZE-1; ++i)
110 +            ints[i] = new Integer(i);
111 +        Collection<Integer> elements = Arrays.asList(ints);
112          try {
113 <            Integer[] ints = new Integer[SIZE];
101 <            for (int i = 0; i < SIZE-1; ++i)
102 <                ints[i] = new Integer(i);
103 <            LinkedBlockingQueue q = new LinkedBlockingQueue(Arrays.asList(ints));
113 >            new LinkedBlockingQueue(elements);
114              shouldThrow();
115          } catch (NullPointerException success) {}
116      }
# Line 150 | Line 160 | public class LinkedBlockingQueueTest ext
160      }
161  
162      /**
153     * offer(null) throws NPE
154     */
155    public void testOfferNull() {
156        try {
157            LinkedBlockingQueue q = new LinkedBlockingQueue(1);
158            q.offer(null);
159            shouldThrow();
160        } catch (NullPointerException success) {}
161    }
162
163    /**
164     * add(null) throws NPE
165     */
166    public void testAddNull() {
167        try {
168            LinkedBlockingQueue q = new LinkedBlockingQueue(1);
169            q.add(null);
170            shouldThrow();
171        } catch (NullPointerException success) {}
172    }
173
174    /**
163       * Offer succeeds if not full; fails if full
164       */
165      public void testOffer() {
# Line 181 | Line 169 | public class LinkedBlockingQueueTest ext
169      }
170  
171      /**
172 <     * add succeeds if not full; throws ISE if full
172 >     * add succeeds if not full; throws IllegalStateException if full
173       */
174      public void testAdd() {
175 +        LinkedBlockingQueue q = new LinkedBlockingQueue(SIZE);
176 +        for (int i = 0; i < SIZE; ++i)
177 +            assertTrue(q.add(new Integer(i)));
178 +        assertEquals(0, q.remainingCapacity());
179          try {
188            LinkedBlockingQueue q = new LinkedBlockingQueue(SIZE);
189            for (int i = 0; i < SIZE; ++i) {
190                assertTrue(q.add(new Integer(i)));
191            }
192            assertEquals(0, q.remainingCapacity());
180              q.add(new Integer(SIZE));
181              shouldThrow();
182          } catch (IllegalStateException success) {}
183      }
184  
185      /**
186 <     * addAll(null) throws NPE
200 <     */
201 <    public void testAddAll1() {
202 <        try {
203 <            LinkedBlockingQueue q = new LinkedBlockingQueue(1);
204 <            q.addAll(null);
205 <            shouldThrow();
206 <        } catch (NullPointerException success) {}
207 <    }
208 <
209 <    /**
210 <     * addAll(this) throws IAE
186 >     * addAll(this) throws IllegalArgumentException
187       */
188      public void testAddAllSelf() {
189 +        LinkedBlockingQueue q = populatedQueue(SIZE);
190          try {
214            LinkedBlockingQueue q = populatedQueue(SIZE);
191              q.addAll(q);
192              shouldThrow();
193          } catch (IllegalArgumentException success) {}
194      }
195  
196      /**
221     * addAll of a collection with null elements throws NPE
222     */
223    public void testAddAll2() {
224        try {
225            LinkedBlockingQueue q = new LinkedBlockingQueue(SIZE);
226            Integer[] ints = new Integer[SIZE];
227            q.addAll(Arrays.asList(ints));
228            shouldThrow();
229        } catch (NullPointerException success) {}
230    }
231
232    /**
197       * addAll of a collection with any null elements throws NPE after
198       * possibly adding some elements
199       */
200      public void testAddAll3() {
201 +        LinkedBlockingQueue q = new LinkedBlockingQueue(SIZE);
202 +        Integer[] ints = new Integer[SIZE];
203 +        for (int i = 0; i < SIZE-1; ++i)
204 +            ints[i] = new Integer(i);
205 +        Collection<Integer> elements = Arrays.asList(ints);
206          try {
207 <            LinkedBlockingQueue q = new LinkedBlockingQueue(SIZE);
239 <            Integer[] ints = new Integer[SIZE];
240 <            for (int i = 0; i < SIZE-1; ++i)
241 <                ints[i] = new Integer(i);
242 <            q.addAll(Arrays.asList(ints));
207 >            q.addAll(elements);
208              shouldThrow();
209          } catch (NullPointerException success) {}
210      }
211  
212      /**
213 <     * addAll throws ISE if not enough room
213 >     * addAll throws IllegalStateException if not enough room
214       */
215      public void testAddAll4() {
216 +        LinkedBlockingQueue q = new LinkedBlockingQueue(SIZE - 1);
217 +        Integer[] ints = new Integer[SIZE];
218 +        for (int i = 0; i < SIZE; ++i)
219 +            ints[i] = new Integer(i);
220 +        Collection<Integer> elements = Arrays.asList(ints);
221          try {
222 <            LinkedBlockingQueue q = new LinkedBlockingQueue(1);
253 <            Integer[] ints = new Integer[SIZE];
254 <            for (int i = 0; i < SIZE; ++i)
255 <                ints[i] = new Integer(i);
256 <            q.addAll(Arrays.asList(ints));
222 >            q.addAll(elements);
223              shouldThrow();
224          } catch (IllegalStateException success) {}
225      }
# Line 274 | Line 240 | public class LinkedBlockingQueueTest ext
240      }
241  
242      /**
277     * put(null) throws NPE
278     */
279    public void testPutNull() throws InterruptedException {
280        try {
281            LinkedBlockingQueue q = new LinkedBlockingQueue(SIZE);
282            q.put(null);
283            shouldThrow();
284        } catch (NullPointerException success) {}
285    }
286
287    /**
243       * all elements successfully put are contained
244       */
245      public void testPut() throws InterruptedException {
# Line 682 | Line 637 | public class LinkedBlockingQueueTest ext
637      }
638  
639      /**
685     * toArray(null) throws NullPointerException
686     */
687    public void testToArray_NullArg() {
688        LinkedBlockingQueue q = populatedQueue(SIZE);
689        try {
690            q.toArray(null);
691            shouldThrow();
692        } catch (NullPointerException success) {}
693    }
694
695    /**
640       * toArray(incompatible array type) throws ArrayStoreException
641       */
642      public void testToArray1_BadArg() {
# Line 845 | Line 789 | public class LinkedBlockingQueueTest ext
789      }
790  
791      /**
848     * drainTo(null) throws NPE
849     */
850    public void testDrainToNull() {
851        LinkedBlockingQueue q = populatedQueue(SIZE);
852        try {
853            q.drainTo(null);
854            shouldThrow();
855        } catch (NullPointerException success) {}
856    }
857
858    /**
859     * drainTo(this) throws IAE
860     */
861    public void testDrainToSelf() {
862        LinkedBlockingQueue q = populatedQueue(SIZE);
863        try {
864            q.drainTo(q);
865            shouldThrow();
866        } catch (IllegalArgumentException success) {}
867    }
868
869    /**
792       * drainTo(c) empties queue into another collection c
793       */
794      public void testDrainTo() {
# Line 911 | Line 833 | public class LinkedBlockingQueueTest ext
833      }
834  
835      /**
914     * drainTo(null, n) throws NPE
915     */
916    public void testDrainToNullN() {
917        LinkedBlockingQueue q = populatedQueue(SIZE);
918        try {
919            q.drainTo(null, 0);
920            shouldThrow();
921        } catch (NullPointerException success) {}
922    }
923
924    /**
925     * drainTo(this, n) throws IAE
926     */
927    public void testDrainToSelfN() {
928        LinkedBlockingQueue q = populatedQueue(SIZE);
929        try {
930            q.drainTo(q, 0);
931            shouldThrow();
932        } catch (IllegalArgumentException success) {}
933    }
934
935    /**
836       * drainTo(c, n) empties first min(n, size) elements of queue into c
837       */
838      public void testDrainToN() {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines