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

# Line 35 | Line 35 | public class ArrayBlockingQueueTest exte
35      }
36  
37      /**
38 <     *
38 >     * A new queue has the indicated capacity
39       */
40      public void testConstructor1() {
41          assertEquals(SIZE, new ArrayBlockingQueue(SIZE).remainingCapacity());
42      }
43  
44      /**
45 <     *
45 >     * Constructor throws IAE if  capacity argument nonpositive
46       */
47      public void testConstructor2() {
48          try {
# Line 53 | Line 53 | public class ArrayBlockingQueueTest exte
53      }
54  
55      /**
56 <     *
56 >     * Initializing from null Collection throws NPE
57       */
58      public void testConstructor3() {
59
59          try {
60              ArrayBlockingQueue q = new ArrayBlockingQueue(1, true, null);
61              shouldThrow();
# Line 65 | Line 64 | public class ArrayBlockingQueueTest exte
64      }
65  
66      /**
67 <     *
67 >     * Initializing from Collection of null elements throws NPE
68       */
69      public void testConstructor4() {
70          try {
# Line 77 | Line 76 | public class ArrayBlockingQueueTest exte
76      }
77  
78      /**
79 <     *
79 >     * Initializing from Collection with some null elements throws NPE
80       */
81      public void testConstructor5() {
82          try {
# Line 91 | Line 90 | public class ArrayBlockingQueueTest exte
90      }
91  
92      /**
93 <     *
93 >     * Initializing from too large collection throws IAE
94       */
95      public void testConstructor6() {
96          try {
# Line 105 | Line 104 | public class ArrayBlockingQueueTest exte
104      }
105  
106      /**
107 <     *
107 >     * Queue contains all elements of collection used to initialize
108       */
109      public void testConstructor7() {
110          try {
# Line 120 | Line 119 | public class ArrayBlockingQueueTest exte
119      }
120  
121      /**
122 <     *
122 >     * Queue transitions from empty to full when elements added
123       */
124      public void testEmptyFull() {
125          ArrayBlockingQueue q = new ArrayBlockingQueue(2);
# Line 135 | Line 134 | public class ArrayBlockingQueueTest exte
134      }
135  
136      /**
137 <     *
137 >     * remainingCapacity decreases on add, increases on remove
138       */
139      public void testRemainingCapacity() {
140          ArrayBlockingQueue q = populatedQueue(SIZE);
# Line 152 | Line 151 | public class ArrayBlockingQueueTest exte
151      }
152  
153      /**
154 <     *
154 >     *  offer(null) throws NPE
155       */
156      public void testOfferNull() {
157          try {
# Line 163 | Line 162 | public class ArrayBlockingQueueTest exte
162      }
163  
164      /**
165 <     *
165 >     * Offer succeeds if not full; fails if full
166       */
167      public void testOffer() {
168          ArrayBlockingQueue q = new ArrayBlockingQueue(1);
# Line 172 | Line 171 | public class ArrayBlockingQueueTest exte
171      }
172  
173      /**
174 <     *
174 >     * add succeeds if not full; throws ISE if full
175       */
176      public void testAdd() {
177          try {
# Line 187 | Line 186 | public class ArrayBlockingQueueTest exte
186      }
187  
188      /**
189 <     *
189 >     *  addAll(null) throws NPE
190       */
191      public void testAddAll1() {
192          try {
# Line 198 | Line 197 | public class ArrayBlockingQueueTest exte
197          catch (NullPointerException success) {}
198      }
199      /**
200 <     *
200 >     *  addAll of a collection with null elements throws NPE
201       */
202      public void testAddAll2() {
203          try {
# Line 210 | Line 209 | public class ArrayBlockingQueueTest exte
209          catch (NullPointerException success) {}
210      }
211      /**
212 <     *
212 >     * addAll of a collection with any null elements throws NPE after
213 >     * possibly adding some elements
214       */
215      public void testAddAll3() {
216          try {
# Line 224 | Line 224 | public class ArrayBlockingQueueTest exte
224          catch (NullPointerException success) {}
225      }
226      /**
227 <     *
227 >     * addAll throws ISE if not enough room
228       */
229      public void testAddAll4() {
230          try {
# Line 238 | Line 238 | public class ArrayBlockingQueueTest exte
238          catch (IllegalStateException success) {}
239      }
240      /**
241 <     *
241 >     * Queue contains all elements, in traversal order, of successful addAll
242       */
243      public void testAddAll5() {
244          try {
# Line 256 | Line 256 | public class ArrayBlockingQueueTest exte
256      }
257  
258      /**
259 <     *
259 >     *  put(null) throws NPE
260       */
261       public void testPutNull() {
262          try {
# Line 272 | Line 272 | public class ArrayBlockingQueueTest exte
272       }
273  
274      /**
275 <     *
275 >     * all elements successfully put are contained
276       */
277       public void testPut() {
278           try {
# Line 290 | Line 290 | public class ArrayBlockingQueueTest exte
290      }
291  
292      /**
293 <     *
293 >     * put blocks interruptibly if full
294       */
295      public void testBlockingPut() {
296          Thread t = new Thread(new Runnable() {
# Line 320 | Line 320 | public class ArrayBlockingQueueTest exte
320      }
321  
322      /**
323 <     *
323 >     * put blocks waiting for take when full
324       */
325      public void testPutWithTake() {
326          final ArrayBlockingQueue q = new ArrayBlockingQueue(2);
# Line 354 | Line 354 | public class ArrayBlockingQueueTest exte
354      }
355  
356      /**
357 <     *
357 >     * timed offer times out if full and elements not taken
358       */
359      public void testTimedOffer() {
360          final ArrayBlockingQueue q = new ArrayBlockingQueue(2);
# Line 381 | Line 381 | public class ArrayBlockingQueueTest exte
381      }
382  
383      /**
384 <     *
384 >     * take retrieves elements in FIFO order
385       */
386      public void testTake() {
387          try {
# Line 395 | Line 395 | public class ArrayBlockingQueueTest exte
395      }
396  
397      /**
398 <     *
398 >     * take blocks interruptibly when empty
399       */
400      public void testTakeFromEmpty() {
401          final ArrayBlockingQueue q = new ArrayBlockingQueue(2);
# Line 418 | Line 418 | public class ArrayBlockingQueueTest exte
418      }
419  
420      /**
421 <     *
421 >     * Take removes existing elements until empty, then blocks interruptibly
422       */
423      public void testBlockingTake() {
424          Thread t = new Thread(new Runnable() {
# Line 446 | Line 446 | public class ArrayBlockingQueueTest exte
446  
447  
448      /**
449 <     *
449 >     * poll succeeds unless empty
450       */
451      public void testPoll() {
452          ArrayBlockingQueue q = populatedQueue(SIZE);
# Line 457 | Line 457 | public class ArrayBlockingQueueTest exte
457      }
458  
459      /**
460 <     *
460 >     * timed pool with zero timeout succeeds when non-empty, else times out
461       */
462      public void testTimedPoll0() {
463          try {
# Line 472 | Line 472 | public class ArrayBlockingQueueTest exte
472      }
473  
474      /**
475 <     *
475 >     * timed pool with nonzero timeout succeeds when non-empty, else times out
476       */
477      public void testTimedPoll() {
478          try {
# Line 487 | Line 487 | public class ArrayBlockingQueueTest exte
487      }
488  
489      /**
490 <     *
490 >     * Interrupted timed poll throws InterruptedException instead of
491 >     * returning timeout status
492       */
493      public void testInterruptedTimedPoll() {
494          Thread t = new Thread(new Runnable() {
# Line 513 | Line 514 | public class ArrayBlockingQueueTest exte
514      }
515  
516      /**
517 <     *
517 >     *  timed poll before a delayed offer fails; after offer succeeds;
518 >     *  on interruption throws
519       */
520      public void testTimedPollWithOffer() {
521          final ArrayBlockingQueue q = new ArrayBlockingQueue(2);
# Line 540 | Line 542 | public class ArrayBlockingQueueTest exte
542  
543  
544      /**
545 <     *
545 >     * peek returns next element, or null if empty
546       */
547      public void testPeek() {
548          ArrayBlockingQueue q = populatedQueue(SIZE);
# Line 554 | Line 556 | public class ArrayBlockingQueueTest exte
556      }
557  
558      /**
559 <     *
559 >     * element returns next element, or throws NSEE if empty
560       */
561      public void testElement() {
562          ArrayBlockingQueue q = populatedQueue(SIZE);
# Line 570 | Line 572 | public class ArrayBlockingQueueTest exte
572      }
573  
574      /**
575 <     *
575 >     * remove removes next element, or throws NSEE if empty
576       */
577      public void testRemove() {
578          ArrayBlockingQueue q = populatedQueue(SIZE);
# Line 585 | Line 587 | public class ArrayBlockingQueueTest exte
587      }
588  
589      /**
590 <     *
590 >     * remove(x) removes x and returns true if present
591       */
592      public void testRemoveElement() {
593          ArrayBlockingQueue q = populatedQueue(SIZE);
# Line 600 | Line 602 | public class ArrayBlockingQueueTest exte
602      }
603          
604      /**
605 <     *
605 >     * contains(x) reports true when elements added but not yet removed
606       */
607      public void testContains() {
608          ArrayBlockingQueue q = populatedQueue(SIZE);
# Line 612 | Line 614 | public class ArrayBlockingQueueTest exte
614      }
615  
616      /**
617 <     *
617 >     * clear removes all elements
618       */
619      public void testClear() {
620          ArrayBlockingQueue q = populatedQueue(SIZE);
# Line 627 | Line 629 | public class ArrayBlockingQueueTest exte
629      }
630  
631      /**
632 <     *
632 >     * containsAll(c) is true when c contains a subset of elements
633       */
634      public void testContainsAll() {
635          ArrayBlockingQueue q = populatedQueue(SIZE);
# Line 641 | Line 643 | public class ArrayBlockingQueueTest exte
643      }
644  
645      /**
646 <     *
646 >     * retainAll(c) retains only those elements of c and reports true if changed
647       */
648      public void testRetainAll() {
649          ArrayBlockingQueue q = populatedQueue(SIZE);
# Line 660 | Line 662 | public class ArrayBlockingQueueTest exte
662      }
663  
664      /**
665 <     *
665 >     * removeAll(c) removes only those elements of c and reports true if changed
666       */
667      public void testRemoveAll() {
668          for (int i = 1; i < SIZE; ++i) {
# Line 675 | Line 677 | public class ArrayBlockingQueueTest exte
677          }
678      }
679  
678
680      /**
681 <     *
681 >     *  toArray contains all elements
682       */
683      public void testToArray() {
684          ArrayBlockingQueue q = populatedQueue(SIZE);
# Line 691 | Line 692 | public class ArrayBlockingQueueTest exte
692      }
693  
694      /**
695 <     *
695 >     * toArray(a) contains all elements
696       */
697      public void testToArray2() {
698          ArrayBlockingQueue q = populatedQueue(SIZE);
# Line 706 | Line 707 | public class ArrayBlockingQueueTest exte
707      }
708      
709      /**
710 <     *
710 >     * iterator iterates through all elements
711       */
712      public void testIterator() {
713          ArrayBlockingQueue q = populatedQueue(SIZE);
# Line 721 | Line 722 | public class ArrayBlockingQueueTest exte
722      }
723  
724      /**
725 <     *
725 >     * iterator.remove removes current element
726 >     */
727 >    public void testIteratorRemove () {
728 >        final ArrayBlockingQueue q = new ArrayBlockingQueue(3);
729 >        q.add(two);
730 >        q.add(one);
731 >        q.add(three);
732 >
733 >        Iterator it = q.iterator();
734 >        it.next();
735 >        it.remove();
736 >        
737 >        it = q.iterator();
738 >        assertEquals(it.next(), one);
739 >        assertEquals(it.next(), three);
740 >        assertFalse(it.hasNext());
741 >    }
742 >
743 >    /**
744 >     * iterator ordering is FIFO
745       */
746      public void testIteratorOrdering() {
747          final ArrayBlockingQueue q = new ArrayBlockingQueue(3);
# Line 740 | Line 760 | public class ArrayBlockingQueueTest exte
760      }
761  
762      /**
763 <     *
763 >     * Modifications do not cause iterators to fail
764       */
765      public void testWeaklyConsistentIteration () {
766          final ArrayBlockingQueue q = new ArrayBlockingQueue(3);
# Line 756 | Line 776 | public class ArrayBlockingQueueTest exte
776          catch (ConcurrentModificationException e) {
777              unexpectedException();
778          }
759
779          assertEquals(0, q.size());
780      }
781  
782  
783      /**
784 <     *
784 >     * toString contains toStrings of elements
785       */
786      public void testToString() {
787          ArrayBlockingQueue q = populatedQueue(SIZE);
# Line 774 | Line 793 | public class ArrayBlockingQueueTest exte
793  
794  
795      /**
796 <     *
796 >     * offer transfers elements across Executor tasks
797       */
798      public void testOfferInExecutor() {
780
799          final ArrayBlockingQueue q = new ArrayBlockingQueue(2);
782
800          q.add(one);
801          q.add(two);
785
802          ExecutorService executor = Executors.newFixedThreadPool(2);
787
803          executor.execute(new Runnable() {
804              public void run() {
805                  threadAssertFalse(q.offer(three));
# Line 815 | Line 830 | public class ArrayBlockingQueueTest exte
830      }
831  
832      /**
833 <     *
833 >     * poll retrieves elements across Executor threads
834       */
835      public void testPollInExecutor() {
821
836          final ArrayBlockingQueue q = new ArrayBlockingQueue(2);
823
837          ExecutorService executor = Executors.newFixedThreadPool(2);
825
838          executor.execute(new Runnable() {
839              public void run() {
840                  threadAssertNull(q.poll());
# Line 849 | Line 861 | public class ArrayBlockingQueueTest exte
861          });
862          
863          joinPool(executor);
852
864      }
865  
866      /**
867 <     *
867 >     * A deserialized serialized queue has same elements in same order
868       */
869      public void testSerialization() {
870          ArrayBlockingQueue q = populatedQueue(SIZE);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines