--- jsr166/src/test/tck/SynchronousQueueTest.java 2010/08/25 00:07:03 1.21 +++ jsr166/src/test/tck/SynchronousQueueTest.java 2010/10/28 17:57:26 1.27 @@ -14,12 +14,26 @@ import java.io.*; public class SynchronousQueueTest extends JSR166TestCase { + public static class Fair extends BlockingQueueTest { + protected BlockingQueue emptyCollection() { + return new SynchronousQueue(true); + } + } + + public static class NonFair extends BlockingQueueTest { + protected BlockingQueue emptyCollection() { + return new SynchronousQueue(false); + } + } + public static void main(String[] args) { junit.textui.TestRunner.run(suite()); } public static Test suite() { - return new TestSuite(SynchronousQueueTest.class); + return newTestSuite(SynchronousQueueTest.class, + new Fair().testSuite(), + new NonFair().testSuite()); } /** @@ -119,6 +133,7 @@ public class SynchronousQueueTest extend shouldThrow(); } catch (NullPointerException success) {} } + /** * addAll throws ISE if no active taker */ @@ -174,7 +189,7 @@ public class SynchronousQueueTest extend ++added; } } catch (InterruptedException success) { - assertTrue(added == 1); + assertEquals(1, added); } }}); @@ -203,24 +218,6 @@ public class SynchronousQueueTest extend t.join(); } - - /** - * take blocks interruptibly when empty - */ - public void testTakeFromEmpty() throws InterruptedException { - final SynchronousQueue q = new SynchronousQueue(); - Thread t = new Thread(new CheckedInterruptedRunnable() { - public void realRun() throws InterruptedException { - q.take(); - }}); - - t.start(); - Thread.sleep(SHORT_DELAY_MS); - t.interrupt(); - t.join(); - } - - /** * put blocks interruptibly if no active taker */ @@ -251,7 +248,7 @@ public class SynchronousQueueTest extend ++added; } } catch (InterruptedException success) { - assertTrue(added == 1); + assertEquals(1, added); } }}); @@ -339,29 +336,6 @@ public class SynchronousQueueTest extend } /** - * timed poll before a delayed offer fails; after offer succeeds; - * on interruption throws - */ - public void testTimedPollWithOffer() throws InterruptedException { - final SynchronousQueue q = new SynchronousQueue(); - Thread t = new Thread(new CheckedRunnable() { - public void realRun() throws InterruptedException { - assertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS)); - assertSame(zero, q.poll(LONG_DELAY_MS, MILLISECONDS)); - try { - q.poll(LONG_DELAY_MS, MILLISECONDS); - shouldThrow(); - } catch (InterruptedException success) {} - }}); - - t.start(); - Thread.sleep(SMALL_DELAY_MS); - assertTrue(q.offer(zero, SHORT_DELAY_MS, MILLISECONDS)); - t.interrupt(); - t.join(); - } - - /** * Interrupted timed poll throws InterruptedException instead of * returning timeout status */ @@ -379,16 +353,16 @@ public class SynchronousQueueTest extend } /** - * timed poll before a delayed offer fails; after offer succeeds; - * on interruption throws + * timed poll before a delayed offer fails; after offer succeeds; + * on interruption throws */ public void testFairTimedPollWithOffer() throws InterruptedException { final SynchronousQueue q = new SynchronousQueue(true); Thread t = new Thread(new CheckedRunnable() { public void realRun() throws InterruptedException { - assertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS)); - assertSame(zero, q.poll(LONG_DELAY_MS, MILLISECONDS)); try { + assertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS)); + assertSame(zero, q.poll(LONG_DELAY_MS, MILLISECONDS)); q.poll(LONG_DELAY_MS, MILLISECONDS); threadShouldThrow(); } catch (InterruptedException success) {} @@ -716,9 +690,9 @@ public class SynchronousQueueTest extend ArrayList l = new ArrayList(); Thread.sleep(SHORT_DELAY_MS); q.drainTo(l, 1); - assertTrue(l.size() == 1); + assertEquals(1, l.size()); q.drainTo(l, 1); - assertTrue(l.size() == 2); + assertEquals(2, l.size()); assertTrue(l.contains(one)); assertTrue(l.contains(two)); t1.join();