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

Comparing jsr166/src/test/tck/PriorityBlockingQueueTest.java (file contents):
Revision 1.5 by dl, Sat Sep 20 18:20:08 2003 UTC vs.
Revision 1.6 by dl, Thu Sep 25 11:02:41 2003 UTC

# Line 14 | Line 14 | public class PriorityBlockingQueueTest e
14      public static void main(String[] args) {
15          junit.textui.TestRunner.run (suite());  
16      }
17
17      public static Test suite() {
18          return new TestSuite(PriorityBlockingQueueTest.class);
19      }
# Line 32 | Line 31 | public class PriorityBlockingQueueTest e
31          }
32      }
33  
35
34      /**
35       * Create a queue of given size containing consecutive
36       * Integers 0 ... n.
# Line 51 | Line 49 | public class PriorityBlockingQueueTest e
49      }
50  
51      /**
52 <     *
52 >     * A new queue has unbounded capacity
53       */
54      public void testConstructor1() {
55          assertEquals(NOCAP, new PriorityBlockingQueue(SIZE).remainingCapacity());
56      }
57  
58      /**
59 <     *
59 >     * Constructor throws IAE if  capacity argument nonpositive
60       */
61      public void testConstructor2() {
62          try {
# Line 69 | Line 67 | public class PriorityBlockingQueueTest e
67      }
68  
69      /**
70 <     *
70 >     * Initializing from null Collection throws NPE
71       */
72      public void testConstructor3() {
75
73          try {
74              PriorityBlockingQueue q = new PriorityBlockingQueue(null);
75              shouldThrow();
# Line 81 | Line 78 | public class PriorityBlockingQueueTest e
78      }
79  
80      /**
81 <     *
81 >     * Initializing from Collection of null elements throws NPE
82       */
83      public void testConstructor4() {
84          try {
# Line 93 | Line 90 | public class PriorityBlockingQueueTest e
90      }
91  
92      /**
93 <     *
93 >     * Initializing from Collection with some null elements throws NPE
94       */
95      public void testConstructor5() {
96          try {
# Line 107 | Line 104 | public class PriorityBlockingQueueTest e
104      }
105  
106      /**
107 <     *
107 >     * Queue contains all elements of collection used to initialize
108       */
109      public void testConstructor6() {
110          try {
# Line 122 | Line 119 | public class PriorityBlockingQueueTest e
119      }
120  
121      /**
122 <     *
122 >     * The comparator used in constructor is used
123       */
124      public void testConstructor7() {
125          try {
# Line 140 | Line 137 | public class PriorityBlockingQueueTest e
137      }
138  
139      /**
140 <     *
140 >     * isEmpty is true before add, false after
141       */
142      public void testEmpty() {
143          PriorityBlockingQueue q = new PriorityBlockingQueue(2);
144          assertTrue(q.isEmpty());
145          assertEquals(NOCAP, q.remainingCapacity());
146 <        q.add(new Integer(1));
146 >        q.add(one);
147          assertFalse(q.isEmpty());
148 <        q.add(new Integer(2));
148 >        q.add(two);
149          q.remove();
150          q.remove();
151          assertTrue(q.isEmpty());
152      }
153  
154      /**
155 <     *
155 >     * remainingCapacity does not change when elementa added or removed,
156 >     * but size does
157       */
158      public void testRemainingCapacity() {
159          PriorityBlockingQueue q = populatedQueue(SIZE);
# Line 172 | Line 170 | public class PriorityBlockingQueueTest e
170      }
171  
172      /**
173 <     *
173 >     * offer(null) throws NPE
174       */
175      public void testOfferNull() {
176          try {
# Line 183 | Line 181 | public class PriorityBlockingQueueTest e
181      }
182  
183      /**
184 <     *
184 >     * Offer of comparable element succeeds
185       */
186      public void testOffer() {
187          PriorityBlockingQueue q = new PriorityBlockingQueue(1);
188 <        assertTrue(q.offer(new Integer(0)));
189 <        assertTrue(q.offer(new Integer(1)));
188 >        assertTrue(q.offer(zero));
189 >        assertTrue(q.offer(one));
190      }
191  
192      /**
193 <     *
193 >     * Offer of non-Comparable throws CCE
194       */
195      public void testOfferNonComparable() {
196          try {
# Line 206 | Line 204 | public class PriorityBlockingQueueTest e
204      }
205  
206      /**
207 <     *
207 >     * add of comparable succeeds
208       */
209      public void testAdd() {
210          PriorityBlockingQueue q = new PriorityBlockingQueue(SIZE);
# Line 217 | Line 215 | public class PriorityBlockingQueueTest e
215      }
216  
217      /**
218 <     *
218 >     * addAll(null) throws NPE
219       */
220      public void testAddAll1() {
221          try {
# Line 228 | Line 226 | public class PriorityBlockingQueueTest e
226          catch (NullPointerException success) {}
227      }
228      /**
229 <     *
229 >     * addAll of a collection with null elements throws NPE
230       */
231      public void testAddAll2() {
232          try {
# Line 240 | Line 238 | public class PriorityBlockingQueueTest e
238          catch (NullPointerException success) {}
239      }
240      /**
241 <     *
241 >     * addAll of a collection with any null elements throws NPE after
242 >     * possibly adding some elements
243       */
244      public void testAddAll3() {
245          try {
# Line 255 | Line 254 | public class PriorityBlockingQueueTest e
254      }
255  
256      /**
257 <     *
257 >     * Queue contains all elements of successful addAll
258       */
259      public void testAddAll5() {
260          try {
# Line 273 | Line 272 | public class PriorityBlockingQueueTest e
272      }
273  
274      /**
275 <     *
275 >     * put(null) throws NPE
276       */
277       public void testPutNull() {
278          try {
# Line 286 | Line 285 | public class PriorityBlockingQueueTest e
285       }
286  
287      /**
288 <     *
288 >     * all elements successfully put are contained
289       */
290       public void testPut() {
291           try {
# Line 303 | Line 302 | public class PriorityBlockingQueueTest e
302      }
303  
304      /**
305 <     *
305 >     * put doesn't block waiting for take
306       */
307      public void testPutWithTake() {
308          final PriorityBlockingQueue q = new PriorityBlockingQueue(2);
# Line 336 | Line 335 | public class PriorityBlockingQueueTest e
335      }
336  
337      /**
338 <     *
338 >     * timed offer does not time out
339       */
340      public void testTimedOffer() {
341          final PriorityBlockingQueue q = new PriorityBlockingQueue(2);
# Line 362 | Line 361 | public class PriorityBlockingQueueTest e
361      }
362  
363      /**
364 <     *
364 >     * take retrieves elements in priority order
365       */
366      public void testTake() {
367          try {
# Line 376 | Line 375 | public class PriorityBlockingQueueTest e
375      }
376  
377      /**
378 <     *
378 >     * take blocks interruptibly when empty
379       */
380      public void testTakeFromEmpty() {
381          final PriorityBlockingQueue q = new PriorityBlockingQueue(2);
# Line 399 | Line 398 | public class PriorityBlockingQueueTest e
398      }
399  
400      /**
401 <     *
401 >     * Take removes existing elements until empty, then blocks interruptibly
402       */
403      public void testBlockingTake() {
404          Thread t = new Thread(new Runnable() {
# Line 427 | Line 426 | public class PriorityBlockingQueueTest e
426  
427  
428      /**
429 <     *
429 >     * poll succeeds unless empty
430       */
431      public void testPoll() {
432          PriorityBlockingQueue q = populatedQueue(SIZE);
# Line 438 | Line 437 | public class PriorityBlockingQueueTest e
437      }
438  
439      /**
440 <     *
440 >     * timed pool with zero timeout succeeds when non-empty, else times out
441       */
442      public void testTimedPoll0() {
443          try {
# Line 453 | Line 452 | public class PriorityBlockingQueueTest e
452      }
453  
454      /**
455 <     *
455 >     * timed pool with nonzero timeout succeeds when non-empty, else times out
456       */
457      public void testTimedPoll() {
458          try {
# Line 468 | Line 467 | public class PriorityBlockingQueueTest e
467      }
468  
469      /**
470 <     *
470 >     * Interrupted timed poll throws InterruptedException instead of
471 >     * returning timeout status
472       */
473      public void testInterruptedTimedPoll() {
474          Thread t = new Thread(new Runnable() {
# Line 494 | Line 494 | public class PriorityBlockingQueueTest e
494      }
495  
496      /**
497 <     *
497 >     *  timed poll before a delayed offer fails; after offer succeeds;
498 >     *  on interruption throws
499       */
500      public void testTimedPollWithOffer() {
501          final PriorityBlockingQueue q = new PriorityBlockingQueue(2);
# Line 521 | Line 522 | public class PriorityBlockingQueueTest e
522  
523  
524      /**
525 <     *
525 >     * peek returns next element, or null if empty
526       */
527      public void testPeek() {
528          PriorityBlockingQueue q = populatedQueue(SIZE);
# Line 535 | Line 536 | public class PriorityBlockingQueueTest e
536      }
537  
538      /**
539 <     *
539 >     * element returns next element, or throws NSEE if empty
540       */
541      public void testElement() {
542          PriorityBlockingQueue q = populatedQueue(SIZE);
# Line 551 | Line 552 | public class PriorityBlockingQueueTest e
552      }
553  
554      /**
555 <     *
555 >     * remove removes next element, or throws NSEE if empty
556       */
557      public void testRemove() {
558          PriorityBlockingQueue q = populatedQueue(SIZE);
# Line 566 | Line 567 | public class PriorityBlockingQueueTest e
567      }
568  
569      /**
570 <     *
570 >     * remove(x) removes x and returns true if present
571       */
572      public void testRemoveElement() {
573          PriorityBlockingQueue q = populatedQueue(SIZE);
# Line 581 | Line 582 | public class PriorityBlockingQueueTest e
582      }
583          
584      /**
585 <     *
585 >     * contains(x) reports true when elements added but not yet removed
586       */
587      public void testContains() {
588          PriorityBlockingQueue q = populatedQueue(SIZE);
# Line 593 | Line 594 | public class PriorityBlockingQueueTest e
594      }
595  
596      /**
597 <     *
597 >     * clear removes all elements
598       */
599      public void testClear() {
600          PriorityBlockingQueue q = populatedQueue(SIZE);
# Line 608 | Line 609 | public class PriorityBlockingQueueTest e
609      }
610  
611      /**
612 <     *
612 >     * containsAll(c) is true when c contains a subset of elements
613       */
614      public void testContainsAll() {
615          PriorityBlockingQueue q = populatedQueue(SIZE);
# Line 622 | Line 623 | public class PriorityBlockingQueueTest e
623      }
624  
625      /**
626 <     *
626 >     * retainAll(c) retains only those elements of c and reports true if changed
627       */
628      public void testRetainAll() {
629          PriorityBlockingQueue q = populatedQueue(SIZE);
# Line 641 | Line 642 | public class PriorityBlockingQueueTest e
642      }
643  
644      /**
645 <     *
645 >     * removeAll(c) removes only those elements of c and reports true if changed
646       */
647      public void testRemoveAll() {
648          for (int i = 1; i < SIZE; ++i) {
# Line 657 | Line 658 | public class PriorityBlockingQueueTest e
658      }
659  
660      /**
661 <     *
661 >     *  toArray contains all elements
662       */
663      public void testToArray() {
664          PriorityBlockingQueue q = populatedQueue(SIZE);
# Line 672 | Line 673 | public class PriorityBlockingQueueTest e
673      }
674  
675      /**
676 <     *
676 >     * toArray(a) contains all elements
677       */
678      public void testToArray2() {
679          PriorityBlockingQueue q = populatedQueue(SIZE);
# Line 688 | Line 689 | public class PriorityBlockingQueueTest e
689      }
690      
691      /**
692 <     *
692 >     * iterator iterates through all elements
693       */
694      public void testIterator() {
695          PriorityBlockingQueue q = populatedQueue(SIZE);
# Line 702 | Line 703 | public class PriorityBlockingQueueTest e
703      }
704  
705      /**
706 <     *
706 >     * iterator.remove removes current element
707       */
708      public void testIteratorRemove () {
709          final PriorityBlockingQueue q = new PriorityBlockingQueue(3);
# Line 722 | Line 723 | public class PriorityBlockingQueueTest e
723  
724  
725      /**
726 <     *
726 >     * toString contains toStrings of elements
727       */
728      public void testToString() {
729          PriorityBlockingQueue q = populatedQueue(SIZE);
# Line 733 | Line 734 | public class PriorityBlockingQueueTest e
734      }        
735  
736      /**
737 <     *
737 >     * offer transfers elements across Executor tasks
738       */
739      public void testPollInExecutor() {
739
740          final PriorityBlockingQueue q = new PriorityBlockingQueue(2);
741
741          ExecutorService executor = Executors.newFixedThreadPool(2);
743
742          executor.execute(new Runnable() {
743              public void run() {
744                  threadAssertNull(q.poll());
# Line 767 | Line 765 | public class PriorityBlockingQueueTest e
765          });
766          
767          joinPool(executor);
770
768      }
769  
770      /**
771 <     *
771 >     * A deserialized serialized queue has same elements
772       */
773      public void testSerialization() {
774          PriorityBlockingQueue q = populatedQueue(SIZE);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines