--- jsr166/src/test/tck/SynchronousQueueTest.java 2009/11/21 22:00:46 1.17 +++ jsr166/src/test/tck/SynchronousQueueTest.java 2010/09/29 12:33:48 1.24 @@ -15,7 +15,7 @@ import java.io.*; public class SynchronousQueueTest extends JSR166TestCase { public static void main(String[] args) { - junit.textui.TestRunner.run (suite()); + junit.textui.TestRunner.run(suite()); } public static Test suite() { @@ -119,6 +119,7 @@ public class SynchronousQueueTest extend shouldThrow(); } catch (NullPointerException success) {} } + /** * addAll throws ISE if no active taker */ @@ -169,23 +170,18 @@ public class SynchronousQueueTest extend public void realRun() throws InterruptedException { int added = 0; try { - q.put(new Object()); - ++added; - q.put(new Object()); - ++added; - q.put(new Object()); - ++added; - q.put(new Object()); - ++added; - threadShouldThrow(); + while (true) { + q.put(added); + ++added; + } } catch (InterruptedException success) { - assertTrue(added >= 1); + assertEquals(1, added); } }}); t.start(); Thread.sleep(SHORT_DELAY_MS); - q.take(); + assertEquals(0, q.take()); Thread.sleep(SHORT_DELAY_MS); t.interrupt(); t.join(); @@ -251,23 +247,18 @@ public class SynchronousQueueTest extend public void realRun() throws InterruptedException { int added = 0; try { - q.put(new Object()); - ++added; - q.put(new Object()); - ++added; - q.put(new Object()); - ++added; - q.put(new Object()); - ++added; - threadShouldThrow(); + while (true) { + q.put(added); + ++added; + } } catch (InterruptedException success) { - assertTrue(added >= 1); + assertEquals(1, added); } }}); t.start(); Thread.sleep(SHORT_DELAY_MS); - q.take(); + assertEquals(0, q.take()); Thread.sleep(SHORT_DELAY_MS); t.interrupt(); t.join(); @@ -280,7 +271,7 @@ public class SynchronousQueueTest extend final SynchronousQueue q = new SynchronousQueue(true); Thread t = new Thread(new CheckedInterruptedRunnable() { public void realRun() throws InterruptedException { - threadAssertFalse(q.offer(new Object(), SHORT_DELAY_MS, MILLISECONDS)); + assertFalse(q.offer(new Object(), SHORT_DELAY_MS, MILLISECONDS)); q.offer(new Object(), LONG_DELAY_MS, MILLISECONDS); }}); @@ -356,9 +347,9 @@ public class SynchronousQueueTest extend 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 { + assertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS)); + assertSame(zero, q.poll(LONG_DELAY_MS, MILLISECONDS)); q.poll(LONG_DELAY_MS, MILLISECONDS); shouldThrow(); } catch (InterruptedException success) {} @@ -396,9 +387,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) {} @@ -524,8 +515,8 @@ public class SynchronousQueueTest extend * toArray(null) throws NPE */ public void testToArray_BadArg() { + SynchronousQueue q = new SynchronousQueue(); try { - SynchronousQueue q = new SynchronousQueue(); Object o[] = q.toArray(null); shouldThrow(); } catch (NullPointerException success) {} @@ -573,23 +564,21 @@ public class SynchronousQueueTest extend public void testOfferInExecutor() { final SynchronousQueue q = new SynchronousQueue(); ExecutorService executor = Executors.newFixedThreadPool(2); - final Integer one = new Integer(1); executor.execute(new CheckedRunnable() { public void realRun() throws InterruptedException { - threadAssertFalse(q.offer(one)); - threadAssertTrue(q.offer(one, MEDIUM_DELAY_MS, MILLISECONDS)); - threadAssertEquals(0, q.remainingCapacity()); + assertFalse(q.offer(one)); + assertTrue(q.offer(one, MEDIUM_DELAY_MS, MILLISECONDS)); + assertEquals(0, q.remainingCapacity()); }}); executor.execute(new CheckedRunnable() { public void realRun() throws InterruptedException { Thread.sleep(SMALL_DELAY_MS); - threadAssertEquals(one, q.take()); + assertSame(one, q.take()); }}); joinPool(executor); - } /** @@ -600,15 +589,15 @@ public class SynchronousQueueTest extend ExecutorService executor = Executors.newFixedThreadPool(2); executor.execute(new CheckedRunnable() { public void realRun() throws InterruptedException { - threadAssertNull(q.poll()); - threadAssertTrue(null != q.poll(MEDIUM_DELAY_MS, MILLISECONDS)); - threadAssertTrue(q.isEmpty()); + assertNull(q.poll()); + assertSame(one, q.poll(MEDIUM_DELAY_MS, MILLISECONDS)); + assertTrue(q.isEmpty()); }}); executor.execute(new CheckedRunnable() { public void realRun() throws InterruptedException { - Thread.sleep(SMALL_DELAY_MS); - q.put(new Integer(1)); + Thread.sleep(SHORT_DELAY_MS); + q.put(one); }}); joinPool(executor); @@ -728,9 +717,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();