--- jsr166/src/test/tck/LinkedTransferQueueTest.java 2010/10/28 17:22:13 1.27 +++ jsr166/src/test/tck/LinkedTransferQueueTest.java 2010/10/28 22:20:47 1.30 @@ -274,21 +274,7 @@ public class LinkedTransferQueueTest ext } /** - * take blocks interruptibly when empty - */ - public void testTakeFromEmpty() throws InterruptedException { - final LinkedTransferQueue q = new LinkedTransferQueue(); - Thread t = newStartedThread(new CheckedInterruptedRunnable() { - public void realRun() throws InterruptedException { - q.take(); - }}); - Thread.sleep(SHORT_DELAY_MS); - t.interrupt(); - t.join(); - } - - /** - * Take removes existing elements until empty, then blocks interruptibly + * take removes existing elements until empty, then blocks interruptibly */ public void testBlockingTake() throws InterruptedException { final LinkedTransferQueue q = populatedQueue(SIZE); @@ -306,7 +292,7 @@ public class LinkedTransferQueueTest ext t.start(); Thread.sleep(SHORT_DELAY_MS); t.interrupt(); - t.join(); + awaitTermination(t, MEDIUM_DELAY_MS); checkEmpty(q); } @@ -323,7 +309,7 @@ public class LinkedTransferQueueTest ext } /** - * timed pool with zero timeout succeeds when non-empty, else times out + * timed poll with zero timeout succeeds when non-empty, else times out */ public void testTimedPoll0() throws InterruptedException { LinkedTransferQueue q = populatedQueue(SIZE); @@ -335,15 +321,14 @@ public class LinkedTransferQueueTest ext } /** - * timed pool with nonzero timeout succeeds when non-empty, else times out + * timed poll with nonzero timeout succeeds when non-empty, else times out */ public void testTimedPoll() throws InterruptedException { LinkedTransferQueue q = populatedQueue(SIZE); for (int i = 0; i < SIZE; ++i) { long t0 = System.nanoTime(); assertEquals(i, (int) q.poll(LONG_DELAY_MS, MILLISECONDS)); - long millisElapsed = (System.nanoTime() - t0)/(1024 * 1024); - assertTrue(millisElapsed < SMALL_DELAY_MS); + assertTrue(millisElapsedSince(t0) < SMALL_DELAY_MS); } assertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS)); checkEmpty(q); @@ -360,8 +345,7 @@ public class LinkedTransferQueueTest ext for (int i = 0; i < SIZE; ++i) { long t0 = System.nanoTime(); assertEquals(i, (int) q.poll(LONG_DELAY_MS, MILLISECONDS)); - long millisElapsed = (System.nanoTime() - t0)/(1024 * 1024); - assertTrue(millisElapsed < SMALL_DELAY_MS); + assertTrue(millisElapsedSince(t0) < SMALL_DELAY_MS); } try { q.poll(LONG_DELAY_MS, MILLISECONDS); @@ -371,7 +355,7 @@ public class LinkedTransferQueueTest ext Thread.sleep(SMALL_DELAY_MS); t.interrupt(); - t.join(); + awaitTermination(t, MEDIUM_DELAY_MS); checkEmpty(q); } @@ -781,7 +765,7 @@ public class LinkedTransferQueueTest ext for (int i = 0; i < SIZE; ++i) { assertEquals(l.get(i), i); } - t.join(); + awaitTermination(t, MEDIUM_DELAY_MS); assertTrue(q.size() + l.size() >= SIZE); } @@ -851,7 +835,7 @@ public class LinkedTransferQueueTest ext assertSame(one, q.poll(LONG_DELAY_MS, MILLISECONDS)); assertEquals(q.getWaitingConsumerCount(), 0); assertFalse(q.hasWaitingConsumer()); - t.join(); + awaitTermination(t, MEDIUM_DELAY_MS); } /** @@ -883,7 +867,7 @@ public class LinkedTransferQueueTest ext assertEquals(1, q.size()); assertEquals(SIZE, (int) q.poll()); assertTrue(q.isEmpty()); - t.join(); + awaitTermination(t, MEDIUM_DELAY_MS); } /** @@ -938,7 +922,7 @@ public class LinkedTransferQueueTest ext Thread.sleep(SHORT_DELAY_MS); assertTrue(q.offer(three)); assertSame(four, q.poll()); - t.join(); + awaitTermination(t, MEDIUM_DELAY_MS); } /** @@ -958,7 +942,7 @@ public class LinkedTransferQueueTest ext Thread.sleep(SHORT_DELAY_MS); assertEquals(SIZE, (int) q.take()); checkEmpty(q); - t.join(); + awaitTermination(t, MEDIUM_DELAY_MS); } /** @@ -1003,7 +987,7 @@ public class LinkedTransferQueueTest ext assertSame(hotPotato, q.poll(MEDIUM_DELAY_MS, MILLISECONDS)); checkEmpty(q); - t.join(); + awaitTermination(t, MEDIUM_DELAY_MS); } /** @@ -1026,7 +1010,7 @@ public class LinkedTransferQueueTest ext assertSame(q.take(), hotPotato); checkEmpty(q); - t.join(); + awaitTermination(t, MEDIUM_DELAY_MS); } /** @@ -1057,8 +1041,7 @@ public class LinkedTransferQueueTest ext long t0 = System.nanoTime(); assertFalse(q.tryTransfer(new Object(), SHORT_DELAY_MS, MILLISECONDS)); - long elapsed = NANOSECONDS.toMillis(System.nanoTime() - t0); - assertTrue(elapsed >= SHORT_DELAY_MS); + assertTrue(millisElapsedSince(t0) >= SHORT_DELAY_MS); }}); checkEmpty(q); @@ -1085,7 +1068,7 @@ public class LinkedTransferQueueTest ext assertSame(four, q.poll()); assertSame(five, q.poll()); checkEmpty(q); - t.join(); + awaitTermination(t, MEDIUM_DELAY_MS); } /**