--- jsr166/src/test/tck/ArrayBlockingQueueTest.java 2009/12/01 06:03:49 1.27 +++ jsr166/src/test/tck/ArrayBlockingQueueTest.java 2010/11/03 07:54:52 1.38 @@ -14,11 +14,27 @@ import static java.util.concurrent.TimeU import java.io.*; public class ArrayBlockingQueueTest extends JSR166TestCase { + + public static class Fair extends BlockingQueueTest { + protected BlockingQueue emptyCollection() { + return new ArrayBlockingQueue(20, true); + } + } + + public static class NonFair extends BlockingQueueTest { + protected BlockingQueue emptyCollection() { + return new ArrayBlockingQueue(20, false); + } + } + public static void main(String[] args) { - junit.textui.TestRunner.run (suite()); + junit.textui.TestRunner.run(suite()); } + public static Test suite() { - return new TestSuite(ArrayBlockingQueueTest.class); + return newTestSuite(ArrayBlockingQueueTest.class, + new Fair().testSuite(), + new NonFair().testSuite()); } /** @@ -145,7 +161,7 @@ public class ArrayBlockingQueueTest exte } /** - * offer(null) throws NPE + * offer(null) throws NPE */ public void testOfferNull() { try { @@ -156,7 +172,7 @@ public class ArrayBlockingQueueTest exte } /** - * add(null) throws NPE + * add(null) throws NPE */ public void testAddNull() { try { @@ -191,7 +207,7 @@ public class ArrayBlockingQueueTest exte } /** - * addAll(null) throws NPE + * addAll(null) throws NPE */ public void testAddAll1() { try { @@ -214,7 +230,7 @@ public class ArrayBlockingQueueTest exte /** - * addAll of a collection with null elements throws NPE + * addAll of a collection with null elements throws NPE */ public void testAddAll2() { try { @@ -224,6 +240,7 @@ public class ArrayBlockingQueueTest exte shouldThrow(); } catch (NullPointerException success) {} } + /** * addAll of a collection with any null elements throws NPE after * possibly adding some elements @@ -238,6 +255,7 @@ public class ArrayBlockingQueueTest exte shouldThrow(); } catch (NullPointerException success) {} } + /** * addAll throws ISE if not enough room */ @@ -251,6 +269,7 @@ public class ArrayBlockingQueueTest exte shouldThrow(); } catch (IllegalStateException success) {} } + /** * Queue contains all elements, in traversal order, of successful addAll */ @@ -267,7 +286,7 @@ public class ArrayBlockingQueueTest exte } /** - * put(null) throws NPE + * put(null) throws NPE */ public void testPutNull() throws InterruptedException { try { @@ -374,22 +393,6 @@ public class ArrayBlockingQueueTest exte } /** - * take blocks interruptibly when empty - */ - public void testTakeFromEmpty() throws InterruptedException { - final ArrayBlockingQueue q = new ArrayBlockingQueue(2); - Thread t = new ThreadShouldThrow(InterruptedException.class) { - 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 { @@ -424,7 +427,7 @@ public class ArrayBlockingQueueTest exte } /** - * 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 { ArrayBlockingQueue q = populatedQueue(SIZE); @@ -435,7 +438,7 @@ public class ArrayBlockingQueueTest exte } /** - * 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 { ArrayBlockingQueue q = populatedQueue(SIZE); @@ -469,30 +472,6 @@ public class ArrayBlockingQueueTest exte } /** - * timed poll before a delayed offer fails; after offer succeeds; - * on interruption throws - */ - public void testTimedPollWithOffer() throws InterruptedException { - final ArrayBlockingQueue q = new ArrayBlockingQueue(2); - Thread t = new Thread(new CheckedRunnable() { - public void realRun() throws InterruptedException { - assertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS)); - assertSame(zero, q.poll(LONG_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() { @@ -628,7 +607,7 @@ public class ArrayBlockingQueueTest exte } /** - * toArray contains all elements + * toArray contains all elements */ public void testToArray() throws InterruptedException { ArrayBlockingQueue q = populatedQueue(SIZE); @@ -660,12 +639,12 @@ public class ArrayBlockingQueueTest exte } /** - * toArray with incompatible array type throws CCE + * toArray(incompatible array type) throws ArrayStoreException */ public void testToArray1_BadArg() { ArrayBlockingQueue q = populatedQueue(SIZE); try { - Object o[] = q.toArray(new String[10]); + q.toArray(new String[10]); shouldThrow(); } catch (ArrayStoreException success) {} } @@ -685,7 +664,7 @@ public class ArrayBlockingQueueTest exte /** * iterator.remove removes current element */ - public void testIteratorRemove () { + public void testIteratorRemove() { final ArrayBlockingQueue q = new ArrayBlockingQueue(3); q.add(two); q.add(one); @@ -696,8 +675,8 @@ public class ArrayBlockingQueueTest exte it.remove(); it = q.iterator(); - assertEquals(it.next(), one); - assertEquals(it.next(), three); + assertSame(it.next(), one); + assertSame(it.next(), three); assertFalse(it.hasNext()); } @@ -722,7 +701,7 @@ public class ArrayBlockingQueueTest exte /** * Modifications do not cause iterators to fail */ - public void testWeaklyConsistentIteration () { + public void testWeaklyConsistentIteration() { final ArrayBlockingQueue q = new ArrayBlockingQueue(3); q.add(one); q.add(two); @@ -769,7 +748,6 @@ public class ArrayBlockingQueueTest exte }}); joinPool(executor); - } /** @@ -902,7 +880,7 @@ public class ArrayBlockingQueueTest exte } /** - * 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() { ArrayBlockingQueue q = new ArrayBlockingQueue(SIZE*2); @@ -911,7 +889,7 @@ public class ArrayBlockingQueueTest exte 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)