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.23 by jsr166, Thu Sep 16 00:52:49 2010 UTC vs.
Revision 1.27 by jsr166, Thu Oct 28 17:57:26 2010 UTC

# Line 14 | Line 14 | import java.io.*;
14  
15   public class SynchronousQueueTest extends JSR166TestCase {
16  
17 +    public static class Fair extends BlockingQueueTest {
18 +        protected BlockingQueue emptyCollection() {
19 +            return new SynchronousQueue(true);
20 +        }
21 +    }
22 +
23 +    public static class NonFair extends BlockingQueueTest {
24 +        protected BlockingQueue emptyCollection() {
25 +            return new SynchronousQueue(false);
26 +        }
27 +    }
28 +
29      public static void main(String[] args) {
30          junit.textui.TestRunner.run(suite());
31      }
32  
33      public static Test suite() {
34 <        return new TestSuite(SynchronousQueueTest.class);
34 >        return newTestSuite(SynchronousQueueTest.class,
35 >                            new Fair().testSuite(),
36 >                            new NonFair().testSuite());
37      }
38  
39      /**
# Line 204 | Line 218 | public class SynchronousQueueTest extend
218          t.join();
219      }
220  
207
208    /**
209     * take blocks interruptibly when empty
210     */
211    public void testTakeFromEmpty() throws InterruptedException {
212        final SynchronousQueue q = new SynchronousQueue();
213        Thread t = new Thread(new CheckedInterruptedRunnable() {
214            public void realRun() throws InterruptedException {
215                q.take();
216            }});
217
218        t.start();
219        Thread.sleep(SHORT_DELAY_MS);
220        t.interrupt();
221        t.join();
222    }
223
224
221      /**
222       * put blocks interruptibly if no active taker
223       */
# Line 340 | Line 336 | public class SynchronousQueueTest extend
336      }
337  
338      /**
343     *  timed poll before a delayed offer fails; after offer succeeds;
344     *  on interruption throws
345     */
346    public void testTimedPollWithOffer() throws InterruptedException {
347        final SynchronousQueue q = new SynchronousQueue();
348        Thread t = new Thread(new CheckedRunnable() {
349            public void realRun() throws InterruptedException {
350                assertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS));
351                assertSame(zero, q.poll(LONG_DELAY_MS, MILLISECONDS));
352                try {
353                    q.poll(LONG_DELAY_MS, MILLISECONDS);
354                    shouldThrow();
355                } catch (InterruptedException success) {}
356            }});
357
358        t.start();
359        Thread.sleep(SMALL_DELAY_MS);
360        assertTrue(q.offer(zero, SHORT_DELAY_MS, MILLISECONDS));
361        t.interrupt();
362        t.join();
363    }
364
365    /**
339       * Interrupted timed poll throws InterruptedException instead of
340       * returning timeout status
341       */
# Line 380 | Line 353 | public class SynchronousQueueTest extend
353      }
354  
355      /**
356 <     *  timed poll before a delayed offer fails; after offer succeeds;
357 <     *  on interruption throws
356 >     * timed poll before a delayed offer fails; after offer succeeds;
357 >     * on interruption throws
358       */
359      public void testFairTimedPollWithOffer() throws InterruptedException {
360          final SynchronousQueue q = new SynchronousQueue(true);
361          Thread t = new Thread(new CheckedRunnable() {
362              public void realRun() throws InterruptedException {
390                assertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS));
391                assertSame(zero, q.poll(LONG_DELAY_MS, MILLISECONDS));
363                  try {
364 +                    assertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS));
365 +                    assertSame(zero, q.poll(LONG_DELAY_MS, MILLISECONDS));
366                      q.poll(LONG_DELAY_MS, MILLISECONDS);
367                      threadShouldThrow();
368                  } catch (InterruptedException success) {}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines