--- jsr166/src/test/tck/SynchronousQueueTest.java 2009/11/21 02:07:27 1.14 +++ jsr166/src/test/tck/SynchronousQueueTest.java 2010/08/25 00:07:03 1.21 @@ -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() { @@ -169,23 +169,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); + assertTrue(added == 1); } }}); t.start(); Thread.sleep(SHORT_DELAY_MS); - q.take(); + assertEquals(0, q.take()); Thread.sleep(SHORT_DELAY_MS); t.interrupt(); t.join(); @@ -198,7 +193,7 @@ public class SynchronousQueueTest extend final SynchronousQueue q = new SynchronousQueue(); 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); }}); @@ -251,23 +246,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); + assertTrue(added == 1); } }}); t.start(); Thread.sleep(SHORT_DELAY_MS); - q.take(); + assertEquals(0, q.take()); Thread.sleep(SHORT_DELAY_MS); t.interrupt(); t.join(); @@ -280,7 +270,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); }}); @@ -336,9 +326,9 @@ public class SynchronousQueueTest extend * returning timeout status */ public void testInterruptedTimedPoll() throws InterruptedException { + final SynchronousQueue q = new SynchronousQueue(); Thread t = new Thread(new CheckedInterruptedRunnable() { public void realRun() throws InterruptedException { - SynchronousQueue q = new SynchronousQueue(); q.poll(SMALL_DELAY_MS, MILLISECONDS); }}); @@ -356,11 +346,11 @@ public class SynchronousQueueTest extend final SynchronousQueue q = new SynchronousQueue(); Thread t = new Thread(new CheckedRunnable() { public void realRun() throws InterruptedException { - threadAssertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS)); + assertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS)); assertSame(zero, q.poll(LONG_DELAY_MS, MILLISECONDS)); try { q.poll(LONG_DELAY_MS, MILLISECONDS); - threadShouldThrow(); + shouldThrow(); } catch (InterruptedException success) {} }}); @@ -396,7 +386,7 @@ public class SynchronousQueueTest extend final SynchronousQueue q = new SynchronousQueue(true); Thread t = new Thread(new CheckedRunnable() { public void realRun() throws InterruptedException { - threadAssertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS)); + assertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS)); assertSame(zero, q.poll(LONG_DELAY_MS, MILLISECONDS)); try { q.poll(LONG_DELAY_MS, MILLISECONDS); @@ -439,8 +429,7 @@ public class SynchronousQueueTest extend try { q.remove(); shouldThrow(); - } catch (NoSuchElementException success) { - } + } catch (NoSuchElementException success) {} } /** @@ -525,8 +514,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) {} @@ -574,23 +563,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); - } /** @@ -601,15 +588,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); @@ -706,8 +693,7 @@ public class SynchronousQueueTest extend try { q.drainTo(q, 0); shouldThrow(); - } catch (IllegalArgumentException success) { - } + } catch (IllegalArgumentException success) {} } /**