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

Comparing jsr166/src/test/tck/DelayQueueTest.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 22 | Line 22 | public class DelayQueueTest extends JSR1
22  
23      /**
24       * A delayed implmentation for testing.
25 <     * Most Q/BQ tests use Pseudodelays, where delays are all elapsed
25 >     * Most  tests use Pseudodelays, where delays are all elapsed
26       * (so, no blocking solely for delays) but are still ordered
27       */
28      static class PDelay implements Delayed {
# Line 129 | Line 129 | public class DelayQueueTest extends JSR1
129      }
130  
131      /**
132 <     *
132 >     * A new queue has unbounded capacity
133       */
134      public void testConstructor1() {
135          assertEquals(NOCAP, new DelayQueue().remainingCapacity());
136      }
137  
138      /**
139 <     *
139 >     * Initializing from null Collection throws NPE
140       */
141      public void testConstructor3() {
142          try {
# Line 147 | Line 147 | public class DelayQueueTest extends JSR1
147      }
148  
149      /**
150 <     *
150 >     * Initializing from Collection of null elements throws NPE
151       */
152      public void testConstructor4() {
153          try {
# Line 159 | Line 159 | public class DelayQueueTest extends JSR1
159      }
160  
161      /**
162 <     *
162 >     * Initializing from Collection with some null elements throws NPE
163       */
164      public void testConstructor5() {
165          try {
# Line 173 | Line 173 | public class DelayQueueTest extends JSR1
173      }
174  
175      /**
176 <     *
176 >     * Queue contains all elements of collection used to initialize
177       */
178      public void testConstructor6() {
179          try {
# Line 188 | Line 188 | public class DelayQueueTest extends JSR1
188      }
189  
190      /**
191 <     *
191 >     * isEmpty is true before add, false after
192       */
193      public void testEmpty() {
194          DelayQueue q = new DelayQueue();
# Line 203 | Line 203 | public class DelayQueueTest extends JSR1
203      }
204  
205      /**
206 <     *
206 >     * remainingCapacity does not change when elementa added or removed,
207 >     * but size does
208       */
209      public void testRemainingCapacity() {
210          DelayQueue q = populatedQueue(SIZE);
# Line 220 | Line 221 | public class DelayQueueTest extends JSR1
221      }
222  
223      /**
224 <     *
224 >     * offer(null) throws NPE
225       */
226      public void testOfferNull() {
227          try {
# Line 231 | Line 232 | public class DelayQueueTest extends JSR1
232      }
233  
234      /**
235 <     *
235 >     * offer non-null succeeds
236       */
237      public void testOffer() {
238          DelayQueue q = new DelayQueue();
# Line 240 | Line 241 | public class DelayQueueTest extends JSR1
241      }
242  
243      /**
244 <     *
244 >     * add succeeds
245       */
246      public void testAdd() {
247          DelayQueue q = new DelayQueue();
# Line 251 | Line 252 | public class DelayQueueTest extends JSR1
252      }
253  
254      /**
255 <     *
255 >     * addAll(null) throws NPE
256       */
257      public void testAddAll1() {
258          try {
# Line 262 | Line 263 | public class DelayQueueTest extends JSR1
263          catch (NullPointerException success) {}
264      }
265      /**
266 <     *
266 >     * addAll of a collection with null elements throws NPE
267       */
268      public void testAddAll2() {
269          try {
# Line 274 | Line 275 | public class DelayQueueTest extends JSR1
275          catch (NullPointerException success) {}
276      }
277      /**
278 <     *
278 >     * addAll of a collection with any null elements throws NPE after
279 >     * possibly adding some elements
280       */
281      public void testAddAll3() {
282          try {
# Line 289 | Line 291 | public class DelayQueueTest extends JSR1
291      }
292  
293      /**
294 <     *
294 >     * Queue contains all elements of successful addAll
295       */
296      public void testAddAll5() {
297          try {
# Line 307 | Line 309 | public class DelayQueueTest extends JSR1
309      }
310  
311      /**
312 <     *
312 >     * put(null) throws NPE
313       */
314       public void testPutNull() {
315          try {
# Line 320 | Line 322 | public class DelayQueueTest extends JSR1
322       }
323  
324      /**
325 <     *
325 >     * all elements successfully put are contained
326       */
327       public void testPut() {
328           try {
# Line 337 | Line 339 | public class DelayQueueTest extends JSR1
339      }
340  
341      /**
342 <     *
342 >     * put doesn't block waiting for take
343       */
344      public void testPutWithTake() {
345          final DelayQueue q = new DelayQueue();
# Line 370 | Line 372 | public class DelayQueueTest extends JSR1
372      }
373  
374      /**
375 <     *
375 >     * timed offer does not time out
376       */
377      public void testTimedOffer() {
378          final DelayQueue q = new DelayQueue();
# Line 396 | Line 398 | public class DelayQueueTest extends JSR1
398      }
399  
400      /**
401 <     *
401 >     * take retrieves elements in priority order
402       */
403      public void testTake() {
404          try {
# Line 410 | Line 412 | public class DelayQueueTest extends JSR1
412      }
413  
414      /**
415 <     *
415 >     * take blocks interruptibly when empty
416       */
417      public void testTakeFromEmpty() {
418          final DelayQueue q = new DelayQueue();
# Line 433 | Line 435 | public class DelayQueueTest extends JSR1
435      }
436  
437      /**
438 <     *
438 >     * Take removes existing elements until empty, then blocks interruptibly
439       */
440      public void testBlockingTake() {
441          Thread t = new Thread(new Runnable() {
# Line 461 | Line 463 | public class DelayQueueTest extends JSR1
463  
464  
465      /**
466 <     *
466 >     * poll succeeds unless empty
467       */
468      public void testPoll() {
469          DelayQueue q = populatedQueue(SIZE);
# Line 472 | Line 474 | public class DelayQueueTest extends JSR1
474      }
475  
476      /**
477 <     *
477 >     * timed pool with zero timeout succeeds when non-empty, else times out
478       */
479      public void testTimedPoll0() {
480          try {
# Line 487 | Line 489 | public class DelayQueueTest extends JSR1
489      }
490  
491      /**
492 <     *
492 >     * timed pool with nonzero timeout succeeds when non-empty, else times out
493       */
494      public void testTimedPoll() {
495          try {
# Line 502 | Line 504 | public class DelayQueueTest extends JSR1
504      }
505  
506      /**
507 <     *
507 >     * Interrupted timed poll throws InterruptedException instead of
508 >     * returning timeout status
509       */
510      public void testInterruptedTimedPoll() {
511          Thread t = new Thread(new Runnable() {
# Line 528 | Line 531 | public class DelayQueueTest extends JSR1
531      }
532  
533      /**
534 <     *
534 >     *  timed poll before a delayed offer fails; after offer succeeds;
535 >     *  on interruption throws
536       */
537      public void testTimedPollWithOffer() {
538          final DelayQueue q = new DelayQueue();
# Line 555 | Line 559 | public class DelayQueueTest extends JSR1
559  
560  
561      /**
562 <     *
562 >     * peek returns next element, or null if empty
563       */
564      public void testPeek() {
565          DelayQueue q = populatedQueue(SIZE);
# Line 569 | Line 573 | public class DelayQueueTest extends JSR1
573      }
574  
575      /**
576 <     *
576 >     * element returns next element, or throws NSEE if empty
577       */
578      public void testElement() {
579          DelayQueue q = populatedQueue(SIZE);
# Line 585 | Line 589 | public class DelayQueueTest extends JSR1
589      }
590  
591      /**
592 <     *
592 >     * remove removes next element, or throws NSEE if empty
593       */
594      public void testRemove() {
595          DelayQueue q = populatedQueue(SIZE);
# Line 600 | Line 604 | public class DelayQueueTest extends JSR1
604      }
605  
606      /**
607 <     *
607 >     * remove(x) removes x and returns true if present
608       */
609      public void testRemoveElement() {
610          DelayQueue q = populatedQueue(SIZE);
# Line 615 | Line 619 | public class DelayQueueTest extends JSR1
619      }
620          
621      /**
622 <     *
622 >     * contains(x) reports true when elements added but not yet removed
623       */
624      public void testContains() {
625          DelayQueue q = populatedQueue(SIZE);
# Line 627 | Line 631 | public class DelayQueueTest extends JSR1
631      }
632  
633      /**
634 <     *
634 >     * clear removes all elements
635       */
636      public void testClear() {
637          DelayQueue q = populatedQueue(SIZE);
# Line 642 | Line 646 | public class DelayQueueTest extends JSR1
646      }
647  
648      /**
649 <     *
649 >     * containsAll(c) is true when c contains a subset of elements
650       */
651      public void testContainsAll() {
652          DelayQueue q = populatedQueue(SIZE);
# Line 656 | Line 660 | public class DelayQueueTest extends JSR1
660      }
661  
662      /**
663 <     *
663 >     * retainAll(c) retains only those elements of c and reports true if changed
664       */
665      public void testRetainAll() {
666          DelayQueue q = populatedQueue(SIZE);
# Line 675 | Line 679 | public class DelayQueueTest extends JSR1
679      }
680  
681      /**
682 <     *
682 >     * removeAll(c) removes only those elements of c and reports true if changed
683       */
684      public void testRemoveAll() {
685          for (int i = 1; i < SIZE; ++i) {
# Line 691 | Line 695 | public class DelayQueueTest extends JSR1
695      }
696  
697      /**
698 <     *
698 >     * toArray contains all elements
699       */
700      public void testToArray() {
701          DelayQueue q = populatedQueue(SIZE);
# Line 706 | Line 710 | public class DelayQueueTest extends JSR1
710      }
711  
712      /**
713 <     *
713 >     * toArray(a) contains all elements
714       */
715      public void testToArray2() {
716          DelayQueue q = populatedQueue(SIZE);
# Line 722 | Line 726 | public class DelayQueueTest extends JSR1
726      }
727      
728      /**
729 <     *
729 >     * iterator iterates through all elements
730       */
731      public void testIterator() {
732          DelayQueue q = populatedQueue(SIZE);
# Line 736 | Line 740 | public class DelayQueueTest extends JSR1
740      }
741  
742      /**
743 <     *
743 >     * iterator.remove removes current element
744       */
745      public void testIteratorRemove () {
742
746          final DelayQueue q = new DelayQueue();
744
747          q.add(new PDelay(2));
748          q.add(new PDelay(1));
749          q.add(new PDelay(3));
748
750          Iterator it = q.iterator();
751          it.next();
752          it.remove();
752
753          it = q.iterator();
754          assertEquals(it.next(), new PDelay(2));
755          assertEquals(it.next(), new PDelay(3));
# Line 758 | Line 758 | public class DelayQueueTest extends JSR1
758  
759  
760      /**
761 <     *
761 >     * toString contains toStrings of elements
762       */
763      public void testToString() {
764          DelayQueue q = populatedQueue(SIZE);
# Line 769 | Line 769 | public class DelayQueueTest extends JSR1
769      }        
770  
771      /**
772 <     *
772 >     * offer transfers elements across Executor tasks
773       */
774      public void testPollInExecutor() {
775
775          final DelayQueue q = new DelayQueue();
777
776          ExecutorService executor = Executors.newFixedThreadPool(2);
779
777          executor.execute(new Runnable() {
778              public void run() {
779                  threadAssertNull(q.poll());
# Line 801 | Line 798 | public class DelayQueueTest extends JSR1
798                  }
799              }
800          });
804        
801          joinPool(executor);
802  
803      }
804  
805  
806      /**
807 <     *
807 >     * Dekayed actions do not occur until their delay elapses
808       */
809      public void testDelay() {
810          DelayQueue q = new DelayQueue();

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines