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

Comparing jsr166/src/test/tck/SynchronousQueueTest.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 21 | Line 21 | public class SynchronousQueueTest extend
21      }
22  
23      /**
24 <     *
24 >     * A SynchronousQueue is both empty and full
25       */
26      public void testEmptyFull() {
27          SynchronousQueue q = new SynchronousQueue();
28          assertTrue(q.isEmpty());
29          assertEquals(0, q.size());
30          assertEquals(0, q.remainingCapacity());
31 <        assertFalse(q.offer(new Integer(3)));
31 >        assertFalse(q.offer(zero));
32      }
33  
34      /**
35 <     *
35 >     * offer(null) throws NPE
36       */
37      public void testOfferNull() {
38          try {
# Line 43 | Line 43 | public class SynchronousQueueTest extend
43      }
44  
45      /**
46 <     *
46 >     * offer fails if no active taker
47       */
48      public void testOffer() {
49          SynchronousQueue q = new SynchronousQueue();
50 <        assertFalse(q.offer(new Integer(1)));
50 >        assertFalse(q.offer(one));
51      }
52  
53      /**
54 <     *
54 >     * add throws ISE if no active taker
55       */
56      public void testAdd() {
57          try {
58              SynchronousQueue q = new SynchronousQueue();
59              assertEquals(0, q.remainingCapacity());
60 <            q.add(new Integer(0));
60 >            q.add(one);
61 >            shouldThrow();
62          } catch (IllegalStateException success){
63          }  
64      }
65  
66      /**
67 <     *
67 >     * addAll(null) throws NPE
68       */
69      public void testAddAll1() {
70          try {
# Line 74 | Line 75 | public class SynchronousQueueTest extend
75          catch (NullPointerException success) {}
76      }
77      /**
78 <     *
78 >     * addAll of a collection with null elements throws NPE
79       */
80      public void testAddAll2() {
81          try {
# Line 86 | Line 87 | public class SynchronousQueueTest extend
87          catch (NullPointerException success) {}
88      }
89      /**
90 <     *
90 >     * addAll throws ISE if no active taker
91       */
92      public void testAddAll4() {
93          try {
# Line 101 | Line 102 | public class SynchronousQueueTest extend
102      }
103  
104      /**
105 <     *
105 >     * put(null) throws NPE
106       */
107      public void testPutNull() {
108          try {
# Line 117 | Line 118 | public class SynchronousQueueTest extend
118       }
119  
120      /**
121 <     *
121 >     * put blocks interruptibly if no active taker
122       */
123      public void testBlockingPut() {
124          Thread t = new Thread(new Runnable() {
125                  public void run() {
126                      try {
127                          SynchronousQueue q = new SynchronousQueue();
128 <                        q.put(new Integer(0));
128 >                        q.put(zero);
129                          threadShouldThrow();
130                      } catch (InterruptedException ie){
131                      }  
# Line 141 | Line 142 | public class SynchronousQueueTest extend
142      }
143  
144      /**
145 <     *
145 >     * put blocks waiting for take
146       */
147      public void testPutWithTake() {
148          final SynchronousQueue q = new SynchronousQueue();
# Line 176 | Line 177 | public class SynchronousQueueTest extend
177      }
178  
179      /**
180 <     *
180 >     * timed offer times out if elements not taken
181       */
182      public void testTimedOffer() {
183          final SynchronousQueue q = new SynchronousQueue();
# Line 203 | Line 204 | public class SynchronousQueueTest extend
204  
205  
206      /**
207 <     *
207 >     * take blocks interruptibly when empty
208       */
209      public void testTakeFromEmpty() {
210          final SynchronousQueue q = new SynchronousQueue();
# Line 226 | Line 227 | public class SynchronousQueueTest extend
227      }
228  
229      /**
230 <     *
230 >     * poll fails unless active taker
231       */
232      public void testPoll() {
233          SynchronousQueue q = new SynchronousQueue();
# Line 234 | Line 235 | public class SynchronousQueueTest extend
235      }
236  
237      /**
238 <     *
238 >     * timed pool with zero timeout times out if no active taker
239       */
240      public void testTimedPoll0() {
241          try {
# Line 246 | Line 247 | public class SynchronousQueueTest extend
247      }
248  
249      /**
250 <     *
250 >     * timed pool with nonzero timeout times out if no active taker
251       */
252      public void testTimedPoll() {
253          try {
# Line 258 | Line 259 | public class SynchronousQueueTest extend
259      }
260  
261      /**
262 <     *
262 >     * Interrupted timed poll throws InterruptedException instead of
263 >     * returning timeout status
264       */
265      public void testInterruptedTimedPoll() {
266          Thread t = new Thread(new Runnable() {
# Line 281 | Line 283 | public class SynchronousQueueTest extend
283      }
284  
285      /**
286 <     *
286 >     *  timed poll before a delayed offer fails; after offer succeeds;
287 >     *  on interruption throws
288       */
289      public void testTimedPollWithOffer() {
290          final SynchronousQueue q = new SynchronousQueue();
# Line 298 | Line 301 | public class SynchronousQueueTest extend
301          try {
302              t.start();
303              Thread.sleep(SMALL_DELAY_MS);
304 <            assertTrue(q.offer(new Integer(0), SHORT_DELAY_MS, TimeUnit.MILLISECONDS));
304 >            assertTrue(q.offer(zero, SHORT_DELAY_MS, TimeUnit.MILLISECONDS));
305              t.interrupt();
306              t.join();
307          } catch (Exception e){
# Line 308 | Line 311 | public class SynchronousQueueTest extend
311  
312  
313      /**
314 <     *
314 >     * peek returns null
315       */
316      public void testPeek() {
317          SynchronousQueue q = new SynchronousQueue();
# Line 316 | Line 319 | public class SynchronousQueueTest extend
319      }
320  
321      /**
322 <     *
322 >     * element throws NSEE
323       */
324      public void testElement() {
325          SynchronousQueue q = new SynchronousQueue();
# Line 328 | Line 331 | public class SynchronousQueueTest extend
331      }
332  
333      /**
334 <     *
334 >     * remove throws NSEE if no active taker
335       */
336      public void testRemove() {
337          SynchronousQueue q = new SynchronousQueue();
# Line 340 | Line 343 | public class SynchronousQueueTest extend
343      }
344  
345      /**
346 <     *
346 >     * remove(x) returns false
347       */
348      public void testRemoveElement() {
349          SynchronousQueue q = new SynchronousQueue();
350 <        assertFalse(q.remove(new Integer(0)));
350 >        assertFalse(q.remove(zero));
351          assertTrue(q.isEmpty());
352      }
353          
354      /**
355 <     *
355 >     * contains returns false
356       */
357      public void testContains() {
358          SynchronousQueue q = new SynchronousQueue();
359 <        assertFalse(q.contains(new Integer(0)));
359 >        assertFalse(q.contains(zero));
360      }
361  
362      /**
363 <     *
363 >     * clear ensures isEmpty
364       */
365      public void testClear() {
366          SynchronousQueue q = new SynchronousQueue();
# Line 366 | Line 369 | public class SynchronousQueueTest extend
369      }
370  
371      /**
372 <     *
372 >     * containsAll returns false unless empty
373       */
374      public void testContainsAll() {
375          SynchronousQueue q = new SynchronousQueue();
376          Integer[] empty = new Integer[0];
377 <        Integer[] ints = new Integer[1]; ints[0] = new Integer(0);
377 >        assertTrue(q.containsAll(Arrays.asList(empty)));
378 >        Integer[] ints = new Integer[1]; ints[0] = zero;
379          assertFalse(q.containsAll(Arrays.asList(ints)));
380      }
381  
382      /**
383 <     *
383 >     * retainAll returns false
384       */
385      public void testRetainAll() {
386          SynchronousQueue q = new SynchronousQueue();
387          Integer[] empty = new Integer[0];
388 <        Integer[] ints = new Integer[1]; ints[0] = new Integer(0);
389 <        q.retainAll(Arrays.asList(ints));
390 <        assertFalse(q.containsAll(Arrays.asList(ints)));
388 >        assertFalse(q.retainAll(Arrays.asList(empty)));
389 >        Integer[] ints = new Integer[1]; ints[0] = zero;
390 >        assertFalse(q.retainAll(Arrays.asList(ints)));
391      }
392  
393      /**
394 <     *
394 >     * removeAll returns false
395       */
396      public void testRemoveAll() {
397          SynchronousQueue q = new SynchronousQueue();
398          Integer[] empty = new Integer[0];
399 <        Integer[] ints = new Integer[1]; ints[0] = new Integer(0);
400 <        q.removeAll(Arrays.asList(ints));
399 >        assertFalse(q.removeAll(Arrays.asList(empty)));
400 >        Integer[] ints = new Integer[1]; ints[0] = zero;
401          assertFalse(q.containsAll(Arrays.asList(ints)));
402      }
403  
404  
405      /**
406 <     *
406 >     * toArray is empty
407       */
408      public void testToArray() {
409          SynchronousQueue q = new SynchronousQueue();
# Line 408 | Line 412 | public class SynchronousQueueTest extend
412      }
413  
414      /**
415 <     *
415 >     * toArray(a) is nulled at position 0
416       */
417      public void testToArray2() {
418          SynchronousQueue q = new SynchronousQueue();
# Line 417 | Line 421 | public class SynchronousQueueTest extend
421      }
422      
423      /**
424 <     *
424 >     * iterator does not traverse any elements
425       */
426      public void testIterator() {
427          SynchronousQueue q = new SynchronousQueue();
# Line 431 | Line 435 | public class SynchronousQueueTest extend
435      }
436  
437      /**
438 <     *
438 >     * iterator remove throws ISE
439       */
440      public void testIteratorRemove() {
441          SynchronousQueue q = new SynchronousQueue();
# Line 444 | Line 448 | public class SynchronousQueueTest extend
448      }
449  
450      /**
451 <     *
451 >     * toString returns a non-null string
452       */
453      public void testToString() {
454          SynchronousQueue q = new SynchronousQueue();
455          String s = q.toString();
456 <        assertTrue(s != null);
456 >        assertNotNull(s);
457      }        
458  
459  
460      /**
461 <     *
461 >     * offer transfers elements across Executor tasks
462       */
463      public void testOfferInExecutor() {
464          final SynchronousQueue q = new SynchronousQueue();
# Line 491 | Line 495 | public class SynchronousQueueTest extend
495      }
496  
497      /**
498 <     *
498 >     * poll retrieves elements across Executor threads
499       */
500      public void testPollInExecutor() {
497
501          final SynchronousQueue q = new SynchronousQueue();
499
502          ExecutorService executor = Executors.newFixedThreadPool(2);
501
503          executor.execute(new Runnable() {
504              public void run() {
505                  threadAssertNull(q.poll());
# Line 525 | Line 526 | public class SynchronousQueueTest extend
526          });
527          
528          joinPool(executor);
528
529      }
530  
531      /**
532 <     *
532 >     * a deserialized serialized queue is usable
533       */
534      public void testSerialization() {
535          SynchronousQueue q = new SynchronousQueue();

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines