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.13 by jsr166, Thu Nov 19 01:15:42 2009 UTC vs.
Revision 1.18 by jsr166, Sun Nov 22 18:57:17 2009 UTC

# Line 15 | Line 15 | import java.io.*;
15   public class SynchronousQueueTest extends JSR166TestCase {
16  
17      public static void main(String[] args) {
18 <        junit.textui.TestRunner.run (suite());
18 >        junit.textui.TestRunner.run (suite());
19      }
20  
21      public static Test suite() {
22 <        return new TestSuite(SynchronousQueueTest.class);
22 >        return new TestSuite(SynchronousQueueTest.class);
23      }
24  
25      /**
# Line 28 | Line 28 | public class SynchronousQueueTest extend
28      public void testEmptyFull() {
29          SynchronousQueue q = new SynchronousQueue();
30          assertTrue(q.isEmpty());
31 <        assertEquals(0, q.size());
31 >        assertEquals(0, q.size());
32          assertEquals(0, q.remainingCapacity());
33          assertFalse(q.offer(zero));
34      }
# Line 39 | Line 39 | public class SynchronousQueueTest extend
39      public void testFairEmptyFull() {
40          SynchronousQueue q = new SynchronousQueue(true);
41          assertTrue(q.isEmpty());
42 <        assertEquals(0, q.size());
42 >        assertEquals(0, q.size());
43          assertEquals(0, q.remainingCapacity());
44          assertFalse(q.offer(zero));
45      }
# Line 48 | Line 48 | public class SynchronousQueueTest extend
48       * offer(null) throws NPE
49       */
50      public void testOfferNull() {
51 <        try {
51 >        try {
52              SynchronousQueue q = new SynchronousQueue();
53              q.offer(null);
54              shouldThrow();
# Line 59 | Line 59 | public class SynchronousQueueTest extend
59       * add(null) throws NPE
60       */
61      public void testAddNull() {
62 <        try {
62 >        try {
63              SynchronousQueue q = new SynchronousQueue();
64              q.add(null);
65              shouldThrow();
# Line 78 | Line 78 | public class SynchronousQueueTest extend
78       * add throws ISE if no active taker
79       */
80      public void testAdd() {
81 <        try {
81 >        try {
82              SynchronousQueue q = new SynchronousQueue();
83              assertEquals(0, q.remainingCapacity());
84              q.add(one);
# Line 137 | Line 137 | public class SynchronousQueueTest extend
137       * put(null) throws NPE
138       */
139      public void testPutNull() throws InterruptedException {
140 <        try {
140 >        try {
141              SynchronousQueue q = new SynchronousQueue();
142              q.put(null);
143              shouldThrow();
# Line 148 | Line 148 | public class SynchronousQueueTest extend
148       * put blocks interruptibly if no active taker
149       */
150      public void testBlockingPut() throws InterruptedException {
151 <        Thread t = new Thread(new CheckedInterruptedRunnable() {
152 <            public void realRun() throws InterruptedException {
151 >        Thread t = new Thread(new CheckedInterruptedRunnable() {
152 >            public void realRun() throws InterruptedException {
153                  SynchronousQueue q = new SynchronousQueue();
154                  q.put(zero);
155              }});
# Line 165 | Line 165 | public class SynchronousQueueTest extend
165       */
166      public void testPutWithTake() throws InterruptedException {
167          final SynchronousQueue q = new SynchronousQueue();
168 <        Thread t = new Thread(new CheckedRunnable() {
169 <            public void realRun() throws InterruptedException {
168 >        Thread t = new Thread(new CheckedRunnable() {
169 >            public void realRun() throws InterruptedException {
170                  int added = 0;
171                  try {
172                      q.put(new Object());
# Line 196 | Line 196 | public class SynchronousQueueTest extend
196       */
197      public void testTimedOffer() throws InterruptedException {
198          final SynchronousQueue q = new SynchronousQueue();
199 <        Thread t = new Thread(new CheckedInterruptedRunnable() {
200 <            public void realRun() throws InterruptedException {
201 <                threadAssertFalse(q.offer(new Object(), SHORT_DELAY_MS, MILLISECONDS));
199 >        Thread t = new Thread(new CheckedInterruptedRunnable() {
200 >            public void realRun() throws InterruptedException {
201 >                assertFalse(q.offer(new Object(), SHORT_DELAY_MS, MILLISECONDS));
202                  q.offer(new Object(), LONG_DELAY_MS, MILLISECONDS);
203              }});
204  
# Line 214 | Line 214 | public class SynchronousQueueTest extend
214       */
215      public void testTakeFromEmpty() throws InterruptedException {
216          final SynchronousQueue q = new SynchronousQueue();
217 <        Thread t = new Thread(new CheckedInterruptedRunnable() {
218 <            public void realRun() throws InterruptedException {
217 >        Thread t = new Thread(new CheckedInterruptedRunnable() {
218 >            public void realRun() throws InterruptedException {
219                  q.take();
220              }});
221  
# Line 230 | Line 230 | public class SynchronousQueueTest extend
230       * put blocks interruptibly if no active taker
231       */
232      public void testFairBlockingPut() throws InterruptedException {
233 <        Thread t = new Thread(new CheckedInterruptedRunnable() {
234 <            public void realRun() throws InterruptedException {
233 >        Thread t = new Thread(new CheckedInterruptedRunnable() {
234 >            public void realRun() throws InterruptedException {
235                  SynchronousQueue q = new SynchronousQueue(true);
236                  q.put(zero);
237              }});
# Line 247 | Line 247 | public class SynchronousQueueTest extend
247       */
248      public void testFairPutWithTake() throws InterruptedException {
249          final SynchronousQueue q = new SynchronousQueue(true);
250 <        Thread t = new Thread(new CheckedRunnable() {
251 <            public void realRun() throws InterruptedException {
250 >        Thread t = new Thread(new CheckedRunnable() {
251 >            public void realRun() throws InterruptedException {
252                  int added = 0;
253                  try {
254                      q.put(new Object());
# Line 278 | Line 278 | public class SynchronousQueueTest extend
278       */
279      public void testFairTimedOffer() throws InterruptedException {
280          final SynchronousQueue q = new SynchronousQueue(true);
281 <        Thread t = new Thread(new CheckedInterruptedRunnable() {
282 <            public void realRun() throws InterruptedException {
281 >        Thread t = new Thread(new CheckedInterruptedRunnable() {
282 >            public void realRun() throws InterruptedException {
283                  threadAssertFalse(q.offer(new Object(), SHORT_DELAY_MS, MILLISECONDS));
284                  q.offer(new Object(), LONG_DELAY_MS, MILLISECONDS);
285              }});
# Line 296 | Line 296 | public class SynchronousQueueTest extend
296       */
297      public void testFairTakeFromEmpty() throws InterruptedException {
298          final SynchronousQueue q = new SynchronousQueue(true);
299 <        Thread t = new Thread(new CheckedInterruptedRunnable() {
300 <            public void realRun() throws InterruptedException {
299 >        Thread t = new Thread(new CheckedInterruptedRunnable() {
300 >            public void realRun() throws InterruptedException {
301                  q.take();
302              }});
303  
# Line 312 | Line 312 | public class SynchronousQueueTest extend
312       */
313      public void testPoll() {
314          SynchronousQueue q = new SynchronousQueue();
315 <        assertNull(q.poll());
315 >        assertNull(q.poll());
316      }
317  
318      /**
# Line 336 | Line 336 | public class SynchronousQueueTest extend
336       * returning timeout status
337       */
338      public void testInterruptedTimedPoll() throws InterruptedException {
339 <        Thread t = new Thread(new CheckedInterruptedRunnable() {
340 <            public void realRun() throws InterruptedException {
341 <                SynchronousQueue q = new SynchronousQueue();
339 >        final SynchronousQueue q = new SynchronousQueue();
340 >        Thread t = new Thread(new CheckedInterruptedRunnable() {
341 >            public void realRun() throws InterruptedException {
342                  q.poll(SMALL_DELAY_MS, MILLISECONDS);
343              }});
344  
# Line 354 | Line 354 | public class SynchronousQueueTest extend
354       */
355      public void testTimedPollWithOffer() throws InterruptedException {
356          final SynchronousQueue q = new SynchronousQueue();
357 <        Thread t = new Thread(new CheckedRunnable() {
358 <            public void realRun() throws InterruptedException {
359 <                threadAssertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS));
357 >        Thread t = new Thread(new CheckedRunnable() {
358 >            public void realRun() throws InterruptedException {
359 >                assertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS));
360                  assertSame(zero, q.poll(LONG_DELAY_MS, MILLISECONDS));
361                  try {
362                      q.poll(LONG_DELAY_MS, MILLISECONDS);
363 <                    threadShouldThrow();
363 >                    shouldThrow();
364                  } catch (InterruptedException success) {}
365              }});
366  
# Line 376 | Line 376 | public class SynchronousQueueTest extend
376       * returning timeout status
377       */
378      public void testFairInterruptedTimedPoll() throws InterruptedException {
379 <        Thread t = new Thread(new CheckedInterruptedRunnable() {
380 <            public void realRun() throws InterruptedException {
379 >        Thread t = new Thread(new CheckedInterruptedRunnable() {
380 >            public void realRun() throws InterruptedException {
381                  SynchronousQueue q = new SynchronousQueue(true);
382                  q.poll(SMALL_DELAY_MS, MILLISECONDS);
383              }});
# Line 394 | Line 394 | public class SynchronousQueueTest extend
394       */
395      public void testFairTimedPollWithOffer() throws InterruptedException {
396          final SynchronousQueue q = new SynchronousQueue(true);
397 <        Thread t = new Thread(new CheckedRunnable() {
398 <            public void realRun() throws InterruptedException {
399 <                threadAssertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS));
397 >        Thread t = new Thread(new CheckedRunnable() {
398 >            public void realRun() throws InterruptedException {
399 >                assertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS));
400                  assertSame(zero, q.poll(LONG_DELAY_MS, MILLISECONDS));
401                  try {
402                      q.poll(LONG_DELAY_MS, MILLISECONDS);
# Line 417 | Line 417 | public class SynchronousQueueTest extend
417       */
418      public void testPeek() {
419          SynchronousQueue q = new SynchronousQueue();
420 <        assertNull(q.peek());
420 >        assertNull(q.peek());
421      }
422  
423      /**
# Line 439 | Line 439 | public class SynchronousQueueTest extend
439          try {
440              q.remove();
441              shouldThrow();
442 <        } catch (NoSuchElementException success) {
443 <        }
442 >        } catch (NoSuchElementException success) {}
443      }
444  
445      /**
# Line 508 | Line 507 | public class SynchronousQueueTest extend
507       */
508      public void testToArray() {
509          SynchronousQueue q = new SynchronousQueue();
510 <        Object[] o = q.toArray();
510 >        Object[] o = q.toArray();
511          assertEquals(o.length, 0);
512      }
513  
# Line 517 | Line 516 | public class SynchronousQueueTest extend
516       */
517      public void testToArray2() {
518          SynchronousQueue q = new SynchronousQueue();
519 <        Integer[] ints = new Integer[1];
519 >        Integer[] ints = new Integer[1];
520          assertNull(ints[0]);
521      }
522  
# Line 525 | Line 524 | public class SynchronousQueueTest extend
524       * toArray(null) throws NPE
525       */
526      public void testToArray_BadArg() {
527 <        try {
528 <            SynchronousQueue q = new SynchronousQueue();
529 <            Object o[] = q.toArray(null);
530 <            shouldThrow();
531 <        } catch (NullPointerException success) {}
527 >        SynchronousQueue q = new SynchronousQueue();
528 >        try {
529 >            Object o[] = q.toArray(null);
530 >            shouldThrow();
531 >        } catch (NullPointerException success) {}
532      }
533  
534  
# Line 538 | Line 537 | public class SynchronousQueueTest extend
537       */
538      public void testIterator() {
539          SynchronousQueue q = new SynchronousQueue();
540 <        Iterator it = q.iterator();
540 >        Iterator it = q.iterator();
541          assertFalse(it.hasNext());
542          try {
543              Object x = it.next();
# Line 551 | Line 550 | public class SynchronousQueueTest extend
550       */
551      public void testIteratorRemove() {
552          SynchronousQueue q = new SynchronousQueue();
553 <        Iterator it = q.iterator();
553 >        Iterator it = q.iterator();
554          try {
555              it.remove();
556              shouldThrow();
# Line 577 | Line 576 | public class SynchronousQueueTest extend
576          final Integer one = new Integer(1);
577  
578          executor.execute(new CheckedRunnable() {
579 <            public void realRun() throws InterruptedException {
579 >            public void realRun() throws InterruptedException {
580                  threadAssertFalse(q.offer(one));
581                  threadAssertTrue(q.offer(one, MEDIUM_DELAY_MS, MILLISECONDS));
582                  threadAssertEquals(0, q.remainingCapacity());
583              }});
584  
585          executor.execute(new CheckedRunnable() {
586 <            public void realRun() throws InterruptedException {
586 >            public void realRun() throws InterruptedException {
587                  Thread.sleep(SMALL_DELAY_MS);
588                  threadAssertEquals(one, q.take());
589              }});
# Line 600 | Line 599 | public class SynchronousQueueTest extend
599          final SynchronousQueue q = new SynchronousQueue();
600          ExecutorService executor = Executors.newFixedThreadPool(2);
601          executor.execute(new CheckedRunnable() {
602 <            public void realRun() throws InterruptedException {
602 >            public void realRun() throws InterruptedException {
603                  threadAssertNull(q.poll());
604                  threadAssertTrue(null != q.poll(MEDIUM_DELAY_MS, MILLISECONDS));
605                  threadAssertTrue(q.isEmpty());
606              }});
607  
608          executor.execute(new CheckedRunnable() {
609 <            public void realRun() throws InterruptedException {
609 >            public void realRun() throws InterruptedException {
610                  Thread.sleep(SMALL_DELAY_MS);
611                  q.put(new Integer(1));
612              }});
# Line 671 | Line 670 | public class SynchronousQueueTest extend
670       */
671      public void testDrainToWithActivePut() throws InterruptedException {
672          final SynchronousQueue q = new SynchronousQueue();
673 <        Thread t = new Thread(new CheckedRunnable() {
674 <            public void realRun() throws InterruptedException {
673 >        Thread t = new Thread(new CheckedRunnable() {
674 >            public void realRun() throws InterruptedException {
675                  q.put(new Integer(1));
676              }});
677  
# Line 706 | Line 705 | public class SynchronousQueueTest extend
705          try {
706              q.drainTo(q, 0);
707              shouldThrow();
708 <        } catch (IllegalArgumentException success) {
710 <        }
708 >        } catch (IllegalArgumentException success) {}
709      }
710  
711      /**
# Line 715 | Line 713 | public class SynchronousQueueTest extend
713       */
714      public void testDrainToN() throws InterruptedException {
715          final SynchronousQueue q = new SynchronousQueue();
716 <        Thread t1 = new Thread(new CheckedRunnable() {
717 <            public void realRun() throws InterruptedException {
716 >        Thread t1 = new Thread(new CheckedRunnable() {
717 >            public void realRun() throws InterruptedException {
718                  q.put(one);
719              }});
720  
721 <        Thread t2 = new Thread(new CheckedRunnable() {
722 <            public void realRun() throws InterruptedException {
721 >        Thread t2 = new Thread(new CheckedRunnable() {
722 >            public void realRun() throws InterruptedException {
723                  q.put(two);
724              }});
725  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines