--- jsr166/src/test/tck/SynchronousQueueTest.java 2009/12/01 09:48:12 1.20 +++ jsr166/src/test/tck/SynchronousQueueTest.java 2010/10/06 07:49:23 1.25 @@ -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()); + 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); } }}); @@ -251,7 +266,7 @@ public class SynchronousQueueTest extend ++added; } } catch (InterruptedException success) { - assertTrue(added == 1); + assertEquals(1, added); } }}); @@ -339,29 +354,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 */ @@ -386,9 +378,9 @@ public class SynchronousQueueTest extend 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 +708,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();