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.4 by dl, Sat Sep 20 18:20:08 2003 UTC vs.
Revision 1.5 by dl, Thu Sep 25 11:02:41 2003 UTC

# Line 37 | Line 37 | public class LinkedBlockingQueueTest ext
37      }
38  
39      /**
40 <     *
40 >     * A new queue has the indicated capacity, or Integer.MAX_VALUE if
41 >     * none given
42       */
43      public void testConstructor1() {
44          assertEquals(SIZE, new LinkedBlockingQueue(SIZE).remainingCapacity());
45 +        assertEquals(Integer.MAX_VALUE, new LinkedBlockingQueue().remainingCapacity());
46      }
47  
48      /**
49 <     *
49 >     * Constructor throws IAE if  capacity argument nonpositive
50       */
51      public void testConstructor2() {
52          try {
# Line 55 | Line 57 | public class LinkedBlockingQueueTest ext
57      }
58  
59      /**
60 <     *
60 >     * Initializing from null Collection throws NPE
61       */
62      public void testConstructor3() {
61
63          try {
64              LinkedBlockingQueue q = new LinkedBlockingQueue(null);
65              shouldThrow();
# Line 67 | Line 68 | public class LinkedBlockingQueueTest ext
68      }
69  
70      /**
71 <     *
71 >     * Initializing from Collection of null elements throws NPE
72       */
73      public void testConstructor4() {
74          try {
# Line 79 | Line 80 | public class LinkedBlockingQueueTest ext
80      }
81  
82      /**
83 <     *
83 >     * Initializing from Collection with some null elements throws NPE
84       */
85      public void testConstructor5() {
86          try {
# Line 93 | Line 94 | public class LinkedBlockingQueueTest ext
94      }
95  
96      /**
97 <     *
97 >     * Queue contains all elements of collection used to initialize
98       */
99      public void testConstructor6() {
100          try {
# Line 108 | Line 109 | public class LinkedBlockingQueueTest ext
109      }
110  
111      /**
112 <     *
112 >     * Queue transitions from empty to full when elements added
113       */
114      public void testEmptyFull() {
115          LinkedBlockingQueue q = new LinkedBlockingQueue(2);
# Line 123 | Line 124 | public class LinkedBlockingQueueTest ext
124      }
125  
126      /**
127 <     *
127 >     * remainingCapacity decreases on add, increases on remove
128       */
129      public void testRemainingCapacity() {
130          LinkedBlockingQueue q = populatedQueue(SIZE);
# Line 140 | Line 141 | public class LinkedBlockingQueueTest ext
141      }
142  
143      /**
144 <     *
144 >     * offer(null) throws NPE
145       */
146      public void testOfferNull() {
147          try {
# Line 151 | Line 152 | public class LinkedBlockingQueueTest ext
152      }
153  
154      /**
155 <     *
155 >     * Offer succeeds if not full; fails if full
156       */
157      public void testOffer() {
158          LinkedBlockingQueue q = new LinkedBlockingQueue(1);
# Line 160 | Line 161 | public class LinkedBlockingQueueTest ext
161      }
162  
163      /**
164 <     *
164 >     * add succeeds if not full; throws ISE if full
165       */
166      public void testAdd() {
167          try {
# Line 175 | Line 176 | public class LinkedBlockingQueueTest ext
176      }
177  
178      /**
179 <     *
179 >     * addAll(null) throws NPE
180       */
181      public void testAddAll1() {
182          try {
# Line 186 | Line 187 | public class LinkedBlockingQueueTest ext
187          catch (NullPointerException success) {}
188      }
189      /**
190 <     *
190 >     * addAll of a collection with null elements throws NPE
191       */
192      public void testAddAll2() {
193          try {
# Line 198 | Line 199 | public class LinkedBlockingQueueTest ext
199          catch (NullPointerException success) {}
200      }
201      /**
202 <     *
202 >     * addAll of a collection with any null elements throws NPE after
203 >     * possibly adding some elements
204       */
205      public void testAddAll3() {
206          try {
# Line 212 | Line 214 | public class LinkedBlockingQueueTest ext
214          catch (NullPointerException success) {}
215      }
216      /**
217 <     *
217 >     * addAll throws ISE if not enough room
218       */
219      public void testAddAll4() {
220          try {
# Line 226 | Line 228 | public class LinkedBlockingQueueTest ext
228          catch (IllegalStateException success) {}
229      }
230      /**
231 <     *
231 >     * Queue contains all elements, in traversal order, of successful addAll
232       */
233      public void testAddAll5() {
234          try {
# Line 244 | Line 246 | public class LinkedBlockingQueueTest ext
246      }
247  
248      /**
249 <     *
249 >     * put(null) throws NPE
250       */
251       public void testPutNull() {
252          try {
# Line 260 | Line 262 | public class LinkedBlockingQueueTest ext
262       }
263  
264      /**
265 <     *
265 >     * all elements successfully put are contained
266       */
267       public void testPut() {
268           try {
# Line 278 | Line 280 | public class LinkedBlockingQueueTest ext
280      }
281  
282      /**
283 <     *
283 >     * put blocks interruptibly if full
284       */
285      public void testBlockingPut() {
286          Thread t = new Thread(new Runnable() {
# Line 308 | Line 310 | public class LinkedBlockingQueueTest ext
310      }
311  
312      /**
313 <     *
313 >     * put blocks waiting for take when full
314       */
315      public void testPutWithTake() {
316          final LinkedBlockingQueue q = new LinkedBlockingQueue(2);
# Line 342 | Line 344 | public class LinkedBlockingQueueTest ext
344      }
345  
346      /**
347 <     *
347 >     * timed offer times out if full and elements not taken
348       */
349      public void testTimedOffer() {
350          final LinkedBlockingQueue q = new LinkedBlockingQueue(2);
# Line 369 | Line 371 | public class LinkedBlockingQueueTest ext
371      }
372  
373      /**
374 <     *
374 >     * take retrieves elements in FIFO order
375       */
376      public void testTake() {
377          try {
# Line 383 | Line 385 | public class LinkedBlockingQueueTest ext
385      }
386  
387      /**
388 <     *
388 >     * take blocks interruptibly when empty
389       */
390      public void testTakeFromEmpty() {
391          final LinkedBlockingQueue q = new LinkedBlockingQueue(2);
# Line 406 | Line 408 | public class LinkedBlockingQueueTest ext
408      }
409  
410      /**
411 <     *
411 >     * Take removes existing elements until empty, then blocks interruptibly
412       */
413      public void testBlockingTake() {
414          Thread t = new Thread(new Runnable() {
# Line 434 | Line 436 | public class LinkedBlockingQueueTest ext
436  
437  
438      /**
439 <     *
439 >     * poll succeeds unless empty
440       */
441      public void testPoll() {
442          LinkedBlockingQueue q = populatedQueue(SIZE);
# Line 445 | Line 447 | public class LinkedBlockingQueueTest ext
447      }
448  
449      /**
450 <     *
450 >     * timed pool with zero timeout succeeds when non-empty, else times out
451       */
452      public void testTimedPoll0() {
453          try {
# Line 460 | Line 462 | public class LinkedBlockingQueueTest ext
462      }
463  
464      /**
465 <     *
465 >     * timed pool with nonzero timeout succeeds when non-empty, else times out
466       */
467      public void testTimedPoll() {
468          try {
# Line 475 | Line 477 | public class LinkedBlockingQueueTest ext
477      }
478  
479      /**
480 <     *
480 >     * Interrupted timed poll throws InterruptedException instead of
481 >     * returning timeout status
482       */
483      public void testInterruptedTimedPoll() {
484          Thread t = new Thread(new Runnable() {
# Line 501 | Line 504 | public class LinkedBlockingQueueTest ext
504      }
505  
506      /**
507 <     *
507 >     *  timed poll before a delayed offer fails; after offer succeeds;
508 >     *  on interruption throws
509       */
510      public void testTimedPollWithOffer() {
511          final LinkedBlockingQueue q = new LinkedBlockingQueue(2);
# Line 526 | Line 530 | public class LinkedBlockingQueueTest ext
530          }
531      }  
532  
529
533      /**
534 <     *
534 >     * peek returns next element, or null if empty
535       */
536      public void testPeek() {
537          LinkedBlockingQueue q = populatedQueue(SIZE);
# Line 542 | Line 545 | public class LinkedBlockingQueueTest ext
545      }
546  
547      /**
548 <     *
548 >     * element returns next element, or throws NSEE if empty
549       */
550      public void testElement() {
551          LinkedBlockingQueue q = populatedQueue(SIZE);
# Line 558 | Line 561 | public class LinkedBlockingQueueTest ext
561      }
562  
563      /**
564 <     *
564 >     * remove removes next element, or throws NSEE if empty
565       */
566      public void testRemove() {
567          LinkedBlockingQueue q = populatedQueue(SIZE);
# Line 573 | Line 576 | public class LinkedBlockingQueueTest ext
576      }
577  
578      /**
579 <     *
579 >     * remove(x) removes x and returns true if present
580       */
581      public void testRemoveElement() {
582          LinkedBlockingQueue q = populatedQueue(SIZE);
# Line 588 | Line 591 | public class LinkedBlockingQueueTest ext
591      }
592          
593      /**
594 <     *
594 >     * contains(x) reports true when elements added but not yet removed
595       */
596      public void testContains() {
597          LinkedBlockingQueue q = populatedQueue(SIZE);
# Line 600 | Line 603 | public class LinkedBlockingQueueTest ext
603      }
604  
605      /**
606 <     *
606 >     * clear removes all elements
607       */
608      public void testClear() {
609          LinkedBlockingQueue q = populatedQueue(SIZE);
# Line 615 | Line 618 | public class LinkedBlockingQueueTest ext
618      }
619  
620      /**
621 <     *
621 >     * containsAll(c) is true when c contains a subset of elements
622       */
623      public void testContainsAll() {
624          LinkedBlockingQueue q = populatedQueue(SIZE);
# Line 629 | Line 632 | public class LinkedBlockingQueueTest ext
632      }
633  
634      /**
635 <     *
635 >     * retainAll(c) retains only those elements of c and reports true if changed
636       */
637      public void testRetainAll() {
638          LinkedBlockingQueue q = populatedQueue(SIZE);
# Line 648 | Line 651 | public class LinkedBlockingQueueTest ext
651      }
652  
653      /**
654 <     *
654 >     * removeAll(c) removes only those elements of c and reports true if changed
655       */
656      public void testRemoveAll() {
657          for (int i = 1; i < SIZE; ++i) {
# Line 663 | Line 666 | public class LinkedBlockingQueueTest ext
666          }
667      }
668  
666
669      /**
670 <     *
670 >     * toArray contains all elements
671       */
672      public void testToArray() {
673          LinkedBlockingQueue q = populatedQueue(SIZE);
# Line 679 | Line 681 | public class LinkedBlockingQueueTest ext
681      }
682  
683      /**
684 <     *
684 >     * toArray(a) contains all elements
685       */
686      public void testToArray2() {
687          LinkedBlockingQueue q = populatedQueue(SIZE);
# Line 694 | Line 696 | public class LinkedBlockingQueueTest ext
696      }
697      
698      /**
699 <     *
699 >     * iterator iterates through all elements
700       */
701      public void testIterator() {
702          LinkedBlockingQueue q = populatedQueue(SIZE);
# Line 709 | Line 711 | public class LinkedBlockingQueueTest ext
711      }
712  
713      /**
714 <     *
714 >     * iterator.remove removes current element
715       */
716 <    public void testIteratorOrdering() {
715 <
716 >    public void testIteratorRemove () {
717          final LinkedBlockingQueue q = new LinkedBlockingQueue(3);
718 +        q.add(two);
719 +        q.add(one);
720 +        q.add(three);
721  
722 +        Iterator it = q.iterator();
723 +        it.next();
724 +        it.remove();
725 +        
726 +        it = q.iterator();
727 +        assertEquals(it.next(), one);
728 +        assertEquals(it.next(), three);
729 +        assertFalse(it.hasNext());
730 +    }
731 +
732 +
733 +    /**
734 +     * iterator ordering is FIFO
735 +     */
736 +    public void testIteratorOrdering() {
737 +        final LinkedBlockingQueue q = new LinkedBlockingQueue(3);
738          q.add(one);
739          q.add(two);
740          q.add(three);
721
741          assertEquals(0, q.remainingCapacity());
723
742          int k = 0;
743          for (Iterator it = q.iterator(); it.hasNext();) {
744              int i = ((Integer)(it.next())).intValue();
745              assertEquals(++k, i);
746          }
729
747          assertEquals(3, k);
748      }
749  
750      /**
751 <     *
751 >     * Modifications do not cause iterators to fail
752       */
753      public void testWeaklyConsistentIteration () {
737
754          final LinkedBlockingQueue q = new LinkedBlockingQueue(3);
739
755          q.add(one);
756          q.add(two);
757          q.add(three);
743
758          try {
759              for (Iterator it = q.iterator(); it.hasNext();) {
760                  q.remove();
# Line 750 | Line 764 | public class LinkedBlockingQueueTest ext
764          catch (ConcurrentModificationException e) {
765              unexpectedException();
766          }
753
767          assertEquals(0, q.size());
768      }
769  
770  
771      /**
772 <     *
772 >     * toString contains toStrings of elements
773       */
774      public void testToString() {
775          LinkedBlockingQueue q = populatedQueue(SIZE);
# Line 768 | Line 781 | public class LinkedBlockingQueueTest ext
781  
782  
783      /**
784 <     *
784 >     * offer transfers elements across Executor tasks
785       */
786      public void testOfferInExecutor() {
774
787          final LinkedBlockingQueue q = new LinkedBlockingQueue(2);
776
788          q.add(one);
789          q.add(two);
779
790          ExecutorService executor = Executors.newFixedThreadPool(2);
781
791          executor.execute(new Runnable() {
792              public void run() {
793                  threadAssertFalse(q.offer(three));
# Line 805 | Line 814 | public class LinkedBlockingQueueTest ext
814          });
815          
816          joinPool(executor);
808
817      }
818  
819      /**
820 <     *
820 >     * poll retrieves elements across Executor threads
821       */
822      public void testPollInExecutor() {
815
823          final LinkedBlockingQueue q = new LinkedBlockingQueue(2);
817
824          ExecutorService executor = Executors.newFixedThreadPool(2);
819
825          executor.execute(new Runnable() {
826              public void run() {
827                  threadAssertNull(q.poll());
# Line 846 | Line 851 | public class LinkedBlockingQueueTest ext
851      }
852  
853      /**
854 <     *
854 >     * A deserialized serialized queue has same elements in same order
855       */
856      public void testSerialization() {
857          LinkedBlockingQueue q = populatedQueue(SIZE);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines