--- jsr166/src/test/tck/PriorityBlockingQueueTest.java 2009/11/22 18:57:17 1.24 +++ jsr166/src/test/tck/PriorityBlockingQueueTest.java 2010/10/28 22:20:47 1.34 @@ -13,11 +13,27 @@ import static java.util.concurrent.TimeU import java.io.*; public class PriorityBlockingQueueTest extends JSR166TestCase { + + public static class Generic extends BlockingQueueTest { + protected BlockingQueue emptyCollection() { + return new PriorityBlockingQueue(); + } + } + + public static class InitialCapacity extends BlockingQueueTest { + protected BlockingQueue emptyCollection() { + return new PriorityBlockingQueue(20); + } + } + public static void main(String[] args) { - junit.textui.TestRunner.run (suite()); + junit.textui.TestRunner.run(suite()); } + public static Test suite() { - return new TestSuite(PriorityBlockingQueueTest.class); + return newTestSuite(PriorityBlockingQueueTest.class, + new Generic().testSuite(), + new InitialCapacity().testSuite()); } private static final int NOCAP = Integer.MAX_VALUE; @@ -245,6 +261,7 @@ public class PriorityBlockingQueueTest e shouldThrow(); } catch (NullPointerException success) {} } + /** * addAll of a collection with any null elements throws NPE after * possibly adding some elements @@ -349,22 +366,6 @@ public class PriorityBlockingQueueTest e } /** - * take blocks interruptibly when empty - */ - public void testTakeFromEmpty() throws InterruptedException { - final PriorityBlockingQueue q = new PriorityBlockingQueue(2); - Thread t = new Thread(new CheckedInterruptedRunnable() { - public void realRun() throws InterruptedException { - q.take(); - }}); - - t.start(); - Thread.sleep(SHORT_DELAY_MS); - t.interrupt(); - t.join(); - } - - /** * Take removes existing elements until empty, then blocks interruptibly */ public void testBlockingTake() throws InterruptedException { @@ -399,7 +400,7 @@ public class PriorityBlockingQueueTest e } /** - * 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 { PriorityBlockingQueue q = populatedQueue(SIZE); @@ -410,7 +411,7 @@ public class PriorityBlockingQueueTest e } /** - * 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 { PriorityBlockingQueue q = populatedQueue(SIZE); @@ -444,30 +445,6 @@ public class PriorityBlockingQueueTest e } /** - * timed poll before a delayed offer fails; after offer succeeds; - * on interruption throws - */ - public void testTimedPollWithOffer() throws InterruptedException { - final PriorityBlockingQueue q = new PriorityBlockingQueue(2); - Thread t = new Thread(new CheckedRunnable() { - public void realRun() throws InterruptedException { - assertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS)); - assertSame(zero, q.poll(MEDIUM_DELAY_MS, MILLISECONDS)); - try { - q.poll(LONG_DELAY_MS, MILLISECONDS); - shouldThrow(); - } catch (InterruptedException success) {} - }}); - - t.start(); - Thread.sleep(SMALL_DELAY_MS); - assertTrue(q.offer(zero, SHORT_DELAY_MS, MILLISECONDS)); - t.interrupt(); - t.join(); - } - - - /** * peek returns next element, or null if empty */ public void testPeek() { @@ -602,7 +579,7 @@ public class PriorityBlockingQueueTest e } /** - * toArray contains all elements + * toArray contains all elements */ public void testToArray() throws InterruptedException { PriorityBlockingQueue q = populatedQueue(SIZE); @@ -663,7 +640,7 @@ public class PriorityBlockingQueueTest e /** * iterator.remove removes current element */ - public void testIteratorRemove () { + public void testIteratorRemove() { final PriorityBlockingQueue q = new PriorityBlockingQueue(3); q.add(new Integer(2)); q.add(new Integer(1)); @@ -699,15 +676,15 @@ public class PriorityBlockingQueueTest e 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)); + q.put(one); }}); joinPool(executor); @@ -820,7 +797,7 @@ public class PriorityBlockingQueueTest e } /** - * 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() { PriorityBlockingQueue q = new PriorityBlockingQueue(SIZE*2); @@ -829,7 +806,7 @@ public class PriorityBlockingQueueTest e assertTrue(q.offer(new Integer(j))); ArrayList l = new ArrayList(); q.drainTo(l, i); - int k = (i < SIZE)? i : SIZE; + int k = (i < SIZE) ? i : SIZE; assertEquals(l.size(), k); assertEquals(q.size(), SIZE-k); for (int j = 0; j < k; ++j)