--- jsr166/src/test/tck/DelayQueueTest.java 2009/12/01 06:39:23 1.28 +++ jsr166/src/test/tck/DelayQueueTest.java 2010/10/06 07:49:22 1.35 @@ -13,7 +13,7 @@ import java.util.concurrent.*; public class DelayQueueTest extends JSR166TestCase { public static void main(String[] args) { - junit.textui.TestRunner.run (suite()); + junit.textui.TestRunner.run(suite()); } public static Test suite() { @@ -191,7 +191,7 @@ public class DelayQueueTest extends JSR1 } /** - * remainingCapacity does not change when elementa added or removed, + * remainingCapacity does not change when elements added or removed, * but size does */ public void testRemainingCapacity() { @@ -284,6 +284,7 @@ public class DelayQueueTest extends JSR1 shouldThrow(); } catch (NullPointerException success) {} } + /** * addAll of a collection with any null elements throws NPE after * possibly adding some elements @@ -483,25 +484,38 @@ public class DelayQueueTest extends JSR1 } /** - * 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 testTimedPollWithOffer() throws InterruptedException { final DelayQueue q = new DelayQueue(); final PDelay pdelay = new PDelay(0); + final CheckedBarrier barrier = new CheckedBarrier(2); Thread t = new Thread(new CheckedRunnable() { public void realRun() throws InterruptedException { assertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS)); - assertSame(pdelay, q.poll(LONG_DELAY_MS, MILLISECONDS)); + + barrier.await(); + assertSame(pdelay, q.poll(MEDIUM_DELAY_MS, MILLISECONDS)); + + Thread.currentThread().interrupt(); try { - q.poll(LONG_DELAY_MS, MILLISECONDS); + q.poll(SHORT_DELAY_MS, MILLISECONDS); + shouldThrow(); + } catch (InterruptedException success) {} + + barrier.await(); + try { + q.poll(MEDIUM_DELAY_MS, MILLISECONDS); shouldThrow(); } catch (InterruptedException success) {} }}); t.start(); - Thread.sleep(SMALL_DELAY_MS); + barrier.await(); assertTrue(q.offer(pdelay, SHORT_DELAY_MS, MILLISECONDS)); + barrier.await(); + sleep(SHORT_DELAY_MS); t.interrupt(); t.join(); } @@ -708,7 +722,7 @@ public class DelayQueueTest extends JSR1 /** * iterator.remove removes current element */ - public void testIteratorRemove () { + public void testIteratorRemove() { final DelayQueue q = new DelayQueue(); q.add(new PDelay(2)); q.add(new PDelay(1)); @@ -754,7 +768,6 @@ public class DelayQueueTest extends JSR1 }}); joinPool(executor); - } @@ -788,7 +801,7 @@ public class DelayQueueTest extends JSR1 public void testPeekDelayed() { DelayQueue q = new DelayQueue(); q.add(new NanoDelay(Long.MAX_VALUE)); - assert(q.peek() != null); + assertNotNull(q.peek()); }