--- jsr166/src/test/tck/DelayQueueTest.java 2010/09/29 12:33:48 1.34 +++ jsr166/src/test/tck/DelayQueueTest.java 2010/10/19 00:41:14 1.38 @@ -484,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)); + + barrier.await(); + assertSame(pdelay, q.poll(MEDIUM_DELAY_MS, MILLISECONDS)); + + Thread.currentThread().interrupt(); try { - assertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS)); - assertSame(pdelay, q.poll(LONG_DELAY_MS, MILLISECONDS)); - 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(); } @@ -762,24 +775,20 @@ public class DelayQueueTest extends JSR1 * Delayed actions do not occur until their delay elapses */ public void testDelay() throws InterruptedException { - DelayQueue q = new DelayQueue(); - NanoDelay[] elements = new NanoDelay[SIZE]; - for (int i = 0; i < SIZE; ++i) { - elements[i] = new NanoDelay(1000000000L + 1000000L * (SIZE - i)); - } - for (int i = 0; i < SIZE; ++i) { - q.add(elements[i]); - } + DelayQueue q = new DelayQueue(); + for (int i = 0; i < SIZE; ++i) + q.add(new NanoDelay(1000000L * (SIZE - i))); long last = 0; for (int i = 0; i < SIZE; ++i) { - NanoDelay e = (NanoDelay)(q.take()); + NanoDelay e = q.take(); long tt = e.getTriggerTime(); - assertTrue(tt <= System.nanoTime()); + assertTrue(System.nanoTime() - tt >= 0); if (i != 0) assertTrue(tt >= last); last = tt; } + assertTrue(q.isEmpty()); } /** @@ -901,7 +910,7 @@ public class DelayQueueTest extends JSR1 } /** - * drainTo(c, n) empties first max {n, size} elements of queue into c + * drainTo(c, n) empties first min(n, size) elements of queue into c */ public void testDrainToN() { for (int i = 0; i < SIZE + 2; ++i) {