--- jsr166/src/test/tck/DelayQueueTest.java 2009/11/21 10:29:50 1.21 +++ jsr166/src/test/tck/DelayQueueTest.java 2009/12/01 06:03:49 1.27 @@ -375,8 +375,8 @@ public class DelayQueueTest extends JSR1 public void realRun() throws InterruptedException { q.put(new PDelay(0)); q.put(new PDelay(0)); - threadAssertTrue(q.offer(new PDelay(0), SHORT_DELAY_MS, MILLISECONDS)); - threadAssertTrue(q.offer(new PDelay(0), LONG_DELAY_MS, MILLISECONDS)); + assertTrue(q.offer(new PDelay(0), SHORT_DELAY_MS, MILLISECONDS)); + assertTrue(q.offer(new PDelay(0), LONG_DELAY_MS, MILLISECONDS)); }}); t.start(); @@ -415,14 +415,17 @@ public class DelayQueueTest extends JSR1 * Take removes existing elements until empty, then blocks interruptibly */ public void testBlockingTake() throws InterruptedException { - Thread t = new ThreadShouldThrow(InterruptedException.class) { + final DelayQueue q = populatedQueue(SIZE); + Thread t = new Thread(new CheckedRunnable() { public void realRun() throws InterruptedException { - DelayQueue q = populatedQueue(SIZE); for (int i = 0; i < SIZE; ++i) { - threadAssertEquals(new PDelay(i), ((PDelay)q.take())); + assertEquals(new PDelay(i), ((PDelay)q.take())); } - q.take(); - }}; + try { + q.take(); + shouldThrow(); + } catch (InterruptedException success) {} + }}); t.start(); Thread.sleep(SHORT_DELAY_MS); @@ -476,7 +479,7 @@ public class DelayQueueTest extends JSR1 assertEquals(new PDelay(i), ((PDelay)q.poll(SHORT_DELAY_MS, MILLISECONDS))); } try { - q.poll(LONG_DELAY_MS, MILLISECONDS); + q.poll(SMALL_DELAY_MS, MILLISECONDS); shouldThrow(); } catch (InterruptedException success) {} }}); @@ -493,10 +496,11 @@ public class DelayQueueTest extends JSR1 */ public void testTimedPollWithOffer() throws InterruptedException { final DelayQueue q = new DelayQueue(); + final PDelay pdelay = new PDelay(0); Thread t = new Thread(new CheckedRunnable() { public void realRun() throws InterruptedException { assertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS)); - q.poll(LONG_DELAY_MS, MILLISECONDS); + assertSame(pdelay, q.poll(LONG_DELAY_MS, MILLISECONDS)); try { q.poll(LONG_DELAY_MS, MILLISECONDS); shouldThrow(); @@ -505,7 +509,7 @@ public class DelayQueueTest extends JSR1 t.start(); Thread.sleep(SMALL_DELAY_MS); - assertTrue(q.offer(new PDelay(0), SHORT_DELAY_MS, MILLISECONDS)); + assertTrue(q.offer(pdelay, SHORT_DELAY_MS, MILLISECONDS)); t.interrupt(); t.join(); } @@ -518,11 +522,11 @@ public class DelayQueueTest extends JSR1 DelayQueue q = populatedQueue(SIZE); for (int i = 0; i < SIZE; ++i) { assertEquals(new PDelay(i), ((PDelay)q.peek())); - q.poll(); + assertEquals(new PDelay(i), ((PDelay)q.poll())); if (q.isEmpty()) assertNull(q.peek()); else - assertTrue(i != ((PDelay)q.peek()).intValue()); + assertFalse(new PDelay(i).equals(q.peek())); } assertNull(q.peek()); } @@ -677,8 +681,8 @@ public class DelayQueueTest extends JSR1 * toArray(null) throws NPE */ public void testToArray_BadArg() { + DelayQueue q = populatedQueue(SIZE); try { - DelayQueue q = populatedQueue(SIZE); Object o[] = q.toArray(null); shouldThrow(); } catch (NullPointerException success) {} @@ -688,9 +692,9 @@ public class DelayQueueTest extends JSR1 * toArray with incompatible array type throws CCE */ public void testToArray1_BadArg() { + DelayQueue q = populatedQueue(SIZE); try { - DelayQueue q = populatedQueue(SIZE); - Object o[] = q.toArray(new String[10] ); + Object o[] = q.toArray(new String[10]); shouldThrow(); } catch (ArrayStoreException success) {} } @@ -746,9 +750,9 @@ public class DelayQueueTest extends JSR1 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()); + assertTrue(null != q.poll(MEDIUM_DELAY_MS, MILLISECONDS)); + assertTrue(q.isEmpty()); }}); executor.execute(new CheckedRunnable() {