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.14 by jsr166, Sat Nov 21 02:07:27 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 {
199 >        Thread t = new Thread(new CheckedInterruptedRunnable() {
200 >            public void realRun() throws InterruptedException {
201                  threadAssertFalse(q.offer(new Object(), SHORT_DELAY_MS, MILLISECONDS));
202                  q.offer(new Object(), LONG_DELAY_MS, MILLISECONDS);
203              }});
# 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 {
339 >        Thread t = new Thread(new CheckedInterruptedRunnable() {
340 >            public void realRun() throws InterruptedException {
341                  SynchronousQueue q = new SynchronousQueue();
342                  q.poll(SMALL_DELAY_MS, MILLISECONDS);
343              }});
# 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 {
357 >        Thread t = new Thread(new CheckedRunnable() {
358 >            public void realRun() throws InterruptedException {
359                  threadAssertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS));
360                  assertSame(zero, q.poll(LONG_DELAY_MS, MILLISECONDS));
361                  try {
# 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 {
397 >        Thread t = new Thread(new CheckedRunnable() {
398 >            public void realRun() throws InterruptedException {
399                  threadAssertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS));
400                  assertSame(zero, q.poll(LONG_DELAY_MS, MILLISECONDS));
401                  try {
# 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 440 | Line 440 | public class SynchronousQueueTest extend
440              q.remove();
441              shouldThrow();
442          } catch (NoSuchElementException success) {
443 <        }
443 >        }
444      }
445  
446      /**
# Line 508 | Line 508 | public class SynchronousQueueTest extend
508       */
509      public void testToArray() {
510          SynchronousQueue q = new SynchronousQueue();
511 <        Object[] o = q.toArray();
511 >        Object[] o = q.toArray();
512          assertEquals(o.length, 0);
513      }
514  
# Line 517 | Line 517 | public class SynchronousQueueTest extend
517       */
518      public void testToArray2() {
519          SynchronousQueue q = new SynchronousQueue();
520 <        Integer[] ints = new Integer[1];
520 >        Integer[] ints = new Integer[1];
521          assertNull(ints[0]);
522      }
523  
# Line 525 | Line 525 | public class SynchronousQueueTest extend
525       * toArray(null) throws NPE
526       */
527      public void testToArray_BadArg() {
528 <        try {
528 >        try {
529              SynchronousQueue q = new SynchronousQueue();
530 <            Object o[] = q.toArray(null);
531 <            shouldThrow();
532 <        } catch (NullPointerException success) {}
530 >            Object o[] = q.toArray(null);
531 >            shouldThrow();
532 >        } catch (NullPointerException success) {}
533      }
534  
535  
# Line 538 | Line 538 | public class SynchronousQueueTest extend
538       */
539      public void testIterator() {
540          SynchronousQueue q = new SynchronousQueue();
541 <        Iterator it = q.iterator();
541 >        Iterator it = q.iterator();
542          assertFalse(it.hasNext());
543          try {
544              Object x = it.next();
# Line 551 | Line 551 | public class SynchronousQueueTest extend
551       */
552      public void testIteratorRemove() {
553          SynchronousQueue q = new SynchronousQueue();
554 <        Iterator it = q.iterator();
554 >        Iterator it = q.iterator();
555          try {
556              it.remove();
557              shouldThrow();
# Line 577 | Line 577 | public class SynchronousQueueTest extend
577          final Integer one = new Integer(1);
578  
579          executor.execute(new CheckedRunnable() {
580 <            public void realRun() throws InterruptedException {
580 >            public void realRun() throws InterruptedException {
581                  threadAssertFalse(q.offer(one));
582                  threadAssertTrue(q.offer(one, MEDIUM_DELAY_MS, MILLISECONDS));
583                  threadAssertEquals(0, q.remainingCapacity());
584              }});
585  
586          executor.execute(new CheckedRunnable() {
587 <            public void realRun() throws InterruptedException {
587 >            public void realRun() throws InterruptedException {
588                  Thread.sleep(SMALL_DELAY_MS);
589                  threadAssertEquals(one, q.take());
590              }});
# Line 600 | Line 600 | public class SynchronousQueueTest extend
600          final SynchronousQueue q = new SynchronousQueue();
601          ExecutorService executor = Executors.newFixedThreadPool(2);
602          executor.execute(new CheckedRunnable() {
603 <            public void realRun() throws InterruptedException {
603 >            public void realRun() throws InterruptedException {
604                  threadAssertNull(q.poll());
605                  threadAssertTrue(null != q.poll(MEDIUM_DELAY_MS, MILLISECONDS));
606                  threadAssertTrue(q.isEmpty());
607              }});
608  
609          executor.execute(new CheckedRunnable() {
610 <            public void realRun() throws InterruptedException {
610 >            public void realRun() throws InterruptedException {
611                  Thread.sleep(SMALL_DELAY_MS);
612                  q.put(new Integer(1));
613              }});
# Line 671 | Line 671 | public class SynchronousQueueTest extend
671       */
672      public void testDrainToWithActivePut() throws InterruptedException {
673          final SynchronousQueue q = new SynchronousQueue();
674 <        Thread t = new Thread(new CheckedRunnable() {
675 <            public void realRun() throws InterruptedException {
674 >        Thread t = new Thread(new CheckedRunnable() {
675 >            public void realRun() throws InterruptedException {
676                  q.put(new Integer(1));
677              }});
678  
# Line 715 | Line 715 | public class SynchronousQueueTest extend
715       */
716      public void testDrainToN() throws InterruptedException {
717          final SynchronousQueue q = new SynchronousQueue();
718 <        Thread t1 = new Thread(new CheckedRunnable() {
719 <            public void realRun() throws InterruptedException {
718 >        Thread t1 = new Thread(new CheckedRunnable() {
719 >            public void realRun() throws InterruptedException {
720                  q.put(one);
721              }});
722  
723 <        Thread t2 = new Thread(new CheckedRunnable() {
724 <            public void realRun() throws InterruptedException {
723 >        Thread t2 = new Thread(new CheckedRunnable() {
724 >            public void realRun() throws InterruptedException {
725                  q.put(two);
726              }});
727  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines