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.14 by jsr166, Mon Nov 16 05:30:07 2009 UTC vs.
Revision 1.15 by jsr166, Sat Nov 21 02:07:26 2009 UTC

# Line 14 | Line 14 | import java.io.*;
14   public class LinkedBlockingQueueTest extends JSR166TestCase {
15  
16      public static void main(String[] args) {
17 <        junit.textui.TestRunner.run (suite());
17 >        junit.textui.TestRunner.run (suite());
18      }
19  
20      public static Test suite() {
21 <        return new TestSuite(LinkedBlockingQueueTest.class);
21 >        return new TestSuite(LinkedBlockingQueueTest.class);
22      }
23  
24  
# Line 29 | Line 29 | public class LinkedBlockingQueueTest ext
29      private LinkedBlockingQueue populatedQueue(int n) {
30          LinkedBlockingQueue q = new LinkedBlockingQueue(n);
31          assertTrue(q.isEmpty());
32 <        for (int i = 0; i < n; i++)
33 <            assertTrue(q.offer(new Integer(i)));
32 >        for (int i = 0; i < n; i++)
33 >            assertTrue(q.offer(new Integer(i)));
34          assertFalse(q.isEmpty());
35          assertEquals(0, q.remainingCapacity());
36 <        assertEquals(n, q.size());
36 >        assertEquals(n, q.size());
37          return q;
38      }
39  
# Line 145 | Line 145 | public class LinkedBlockingQueueTest ext
145       * offer(null) throws NPE
146       */
147      public void testOfferNull() {
148 <        try {
148 >        try {
149              LinkedBlockingQueue q = new LinkedBlockingQueue(1);
150              q.offer(null);
151              shouldThrow();
# Line 156 | Line 156 | public class LinkedBlockingQueueTest ext
156       * add(null) throws NPE
157       */
158      public void testAddNull() {
159 <        try {
159 >        try {
160              LinkedBlockingQueue q = new LinkedBlockingQueue(1);
161              q.add(null);
162              shouldThrow();
# Line 176 | Line 176 | public class LinkedBlockingQueueTest ext
176       * add succeeds if not full; throws ISE if full
177       */
178      public void testAdd() {
179 <        try {
179 >        try {
180              LinkedBlockingQueue q = new LinkedBlockingQueue(SIZE);
181              for (int i = 0; i < SIZE; ++i) {
182                  assertTrue(q.add(new Integer(i)));
# Line 184 | Line 184 | public class LinkedBlockingQueueTest ext
184              assertEquals(0, q.remainingCapacity());
185              q.add(new Integer(SIZE));
186          } catch (IllegalStateException success) {
187 <        }
187 >        }
188      }
189  
190      /**
# Line 274 | Line 274 | public class LinkedBlockingQueueTest ext
274       * put(null) throws NPE
275       */
276       public void testPutNull() {
277 <        try {
277 >        try {
278              LinkedBlockingQueue q = new LinkedBlockingQueue(SIZE);
279              q.put(null);
280              shouldThrow();
281          }
282          catch (NullPointerException success) {
283 <        }
283 >        }
284          catch (InterruptedException ie) {
285 <            unexpectedException();
285 >            unexpectedException();
286          }
287       }
288  
# Line 300 | Line 300 | public class LinkedBlockingQueueTest ext
300               assertEquals(0, q.remainingCapacity());
301           }
302          catch (InterruptedException ie) {
303 <            unexpectedException();
303 >            unexpectedException();
304          }
305      }
306  
# Line 330 | Line 330 | public class LinkedBlockingQueueTest ext
330             t.join();
331          }
332          catch (InterruptedException ie) {
333 <            unexpectedException();
333 >            unexpectedException();
334          }
335      }
336  
# Line 351 | Line 351 | public class LinkedBlockingQueueTest ext
351                          ++added;
352                          q.put(new Object());
353                          ++added;
354 <                        threadShouldThrow();
354 >                        threadShouldThrow();
355                      } catch (InterruptedException e) {
356                          threadAssertTrue(added >= 2);
357                      }
# Line 380 | Line 380 | public class LinkedBlockingQueueTest ext
380                          q.put(new Object());
381                          threadAssertFalse(q.offer(new Object(), SHORT_DELAY_MS, TimeUnit.MILLISECONDS));
382                          q.offer(new Object(), LONG_DELAY_MS, TimeUnit.MILLISECONDS);
383 <                        threadShouldThrow();
383 >                        threadShouldThrow();
384                      } catch (InterruptedException success) {}
385                  }
386              });
# Line 399 | Line 399 | public class LinkedBlockingQueueTest ext
399       * take retrieves elements in FIFO order
400       */
401      public void testTake() {
402 <        try {
402 >        try {
403              LinkedBlockingQueue q = populatedQueue(SIZE);
404              for (int i = 0; i < SIZE; ++i) {
405                  assertEquals(i, ((Integer)q.take()).intValue());
406              }
407          } catch (InterruptedException e) {
408 <            unexpectedException();
409 <        }
408 >            unexpectedException();
409 >        }
410      }
411  
412      /**
# Line 418 | Line 418 | public class LinkedBlockingQueueTest ext
418                  public void run() {
419                      try {
420                          q.take();
421 <                        threadShouldThrow();
421 >                        threadShouldThrow();
422                      } catch (InterruptedException success) { }
423                  }
424              });
# Line 455 | Line 455 | public class LinkedBlockingQueueTest ext
455             t.join();
456          }
457          catch (InterruptedException ie) {
458 <            unexpectedException();
458 >            unexpectedException();
459          }
460      }
461  
# Line 468 | Line 468 | public class LinkedBlockingQueueTest ext
468          for (int i = 0; i < SIZE; ++i) {
469              assertEquals(i, ((Integer)q.poll()).intValue());
470          }
471 <        assertNull(q.poll());
471 >        assertNull(q.poll());
472      }
473  
474      /**
# Line 482 | Line 482 | public class LinkedBlockingQueueTest ext
482              }
483              assertNull(q.poll(0, TimeUnit.MILLISECONDS));
484          } catch (InterruptedException e) {
485 <            unexpectedException();
486 <        }
485 >            unexpectedException();
486 >        }
487      }
488  
489      /**
# Line 497 | Line 497 | public class LinkedBlockingQueueTest ext
497              }
498              assertNull(q.poll(SHORT_DELAY_MS, TimeUnit.MILLISECONDS));
499          } catch (InterruptedException e) {
500 <            unexpectedException();
501 <        }
500 >            unexpectedException();
501 >        }
502      }
503  
504      /**
# Line 524 | Line 524 | public class LinkedBlockingQueueTest ext
524             t.join();
525          }
526          catch (InterruptedException ie) {
527 <            unexpectedException();
527 >            unexpectedException();
528          }
529      }
530  
# Line 540 | Line 540 | public class LinkedBlockingQueueTest ext
540                          threadAssertNull(q.poll(SHORT_DELAY_MS, TimeUnit.MILLISECONDS));
541                          q.poll(LONG_DELAY_MS, TimeUnit.MILLISECONDS);
542                          q.poll(LONG_DELAY_MS, TimeUnit.MILLISECONDS);
543 <                        threadShouldThrow();
543 >                        threadShouldThrow();
544                      } catch (InterruptedException success) { }
545                  }
546              });
# Line 566 | Line 566 | public class LinkedBlockingQueueTest ext
566              assertTrue(q.peek() == null ||
567                         i != ((Integer)q.peek()).intValue());
568          }
569 <        assertNull(q.peek());
569 >        assertNull(q.peek());
570      }
571  
572      /**
# Line 597 | Line 597 | public class LinkedBlockingQueueTest ext
597              q.remove();
598              shouldThrow();
599          } catch (NoSuchElementException success) {
600 <        }
600 >        }
601      }
602  
603      /**
# Line 714 | Line 714 | public class LinkedBlockingQueueTest ext
714       */
715      public void testToArray() {
716          LinkedBlockingQueue q = populatedQueue(SIZE);
717 <        Object[] o = q.toArray();
718 <        try {
719 <        for (int i = 0; i < o.length; i++)
720 <            assertEquals(o[i], q.take());
721 <        } catch (InterruptedException e) {
722 <            unexpectedException();
723 <        }
717 >        Object[] o = q.toArray();
718 >        try {
719 >        for (int i = 0; i < o.length; i++)
720 >            assertEquals(o[i], q.take());
721 >        } catch (InterruptedException e) {
722 >            unexpectedException();
723 >        }
724      }
725  
726      /**
# Line 728 | Line 728 | public class LinkedBlockingQueueTest ext
728       */
729      public void testToArray2() {
730          LinkedBlockingQueue q = populatedQueue(SIZE);
731 <        Integer[] ints = new Integer[SIZE];
732 <        ints = (Integer[])q.toArray(ints);
733 <        try {
734 <            for (int i = 0; i < ints.length; i++)
735 <                assertEquals(ints[i], q.take());
736 <        } catch (InterruptedException e) {
737 <            unexpectedException();
738 <        }
731 >        Integer[] ints = new Integer[SIZE];
732 >        ints = (Integer[])q.toArray(ints);
733 >        try {
734 >            for (int i = 0; i < ints.length; i++)
735 >                assertEquals(ints[i], q.take());
736 >        } catch (InterruptedException e) {
737 >            unexpectedException();
738 >        }
739      }
740  
741      /**
742       * toArray(null) throws NPE
743       */
744      public void testToArray_BadArg() {
745 <        try {
745 >        try {
746              LinkedBlockingQueue q = populatedQueue(SIZE);
747 <            Object o[] = q.toArray(null);
748 <            shouldThrow();
749 <        } catch (NullPointerException success) {}
747 >            Object o[] = q.toArray(null);
748 >            shouldThrow();
749 >        } catch (NullPointerException success) {}
750      }
751  
752      /**
753       * toArray with incompatible array type throws CCE
754       */
755      public void testToArray1_BadArg() {
756 <        try {
756 >        try {
757              LinkedBlockingQueue q = populatedQueue(SIZE);
758 <            Object o[] = q.toArray(new String[10] );
759 <            shouldThrow();
760 <        } catch (ArrayStoreException  success) {}
758 >            Object o[] = q.toArray(new String[10] );
759 >            shouldThrow();
760 >        } catch (ArrayStoreException  success) {}
761      }
762  
763  
# Line 766 | Line 766 | public class LinkedBlockingQueueTest ext
766       */
767      public void testIterator() {
768          LinkedBlockingQueue q = populatedQueue(SIZE);
769 <        Iterator it = q.iterator();
770 <        try {
771 <            while (it.hasNext()) {
772 <                assertEquals(it.next(), q.take());
773 <            }
774 <        } catch (InterruptedException e) {
775 <            unexpectedException();
776 <        }
769 >        Iterator it = q.iterator();
770 >        try {
771 >            while (it.hasNext()) {
772 >                assertEquals(it.next(), q.take());
773 >            }
774 >        } catch (InterruptedException e) {
775 >            unexpectedException();
776 >        }
777      }
778  
779      /**

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines