--- jsr166/src/test/tck/DelayQueueTest.java 2015/10/04 18:49:02 1.75 +++ jsr166/src/test/tck/DelayQueueTest.java 2021/01/26 13:33:05 1.94 @@ -39,25 +39,28 @@ public class DelayQueueTest extends JSR1 } public static Test suite() { + class Implementation implements CollectionImplementation { + public Class klazz() { return DelayQueue.class; } + public Collection emptyCollection() { return new DelayQueue(); } + public Object makeElement(int i) { return new PDelay(i); } + public boolean isConcurrent() { return true; } + public boolean permitsNulls() { return false; } + } return newTestSuite(DelayQueueTest.class, - new Generic().testSuite()); + new Generic().testSuite(), + CollectionTest.testSuite(new Implementation())); } /** - * A delayed implementation for testing. - * Most tests use Pseudodelays, where delays are all elapsed + * A fake Delayed implementation for testing. + * Most tests use PDelays, where delays are all elapsed * (so, no blocking solely for delays) but are still ordered */ static class PDelay implements Delayed { - int pseudodelay; - PDelay(int i) { pseudodelay = i; } - public int compareTo(PDelay other) { - int a = this.pseudodelay; - int b = other.pseudodelay; - return (a < b) ? -1 : (a > b) ? 1 : 0; - } + final int pseudodelay; + PDelay(int pseudodelay) { this.pseudodelay = pseudodelay; } public int compareTo(Delayed y) { - return compareTo((PDelay)y); + return Integer.compare(this.pseudodelay, ((PDelay)y).pseudodelay); } public boolean equals(Object other) { return (other instanceof PDelay) && @@ -66,7 +69,7 @@ public class DelayQueueTest extends JSR1 // suppress [overrides] javac warning public int hashCode() { return pseudodelay; } public long getDelay(TimeUnit ignore) { - return Integer.MIN_VALUE + pseudodelay; + return (long) Integer.MIN_VALUE + pseudodelay; } public String toString() { return String.valueOf(pseudodelay); @@ -77,27 +80,18 @@ public class DelayQueueTest extends JSR1 * Delayed implementation that actually delays */ static class NanoDelay implements Delayed { - long trigger; + final long trigger; NanoDelay(long i) { trigger = System.nanoTime() + i; } - public int compareTo(NanoDelay y) { - long i = trigger; - long j = y.trigger; - if (i < j) return -1; - if (i > j) return 1; - return 0; - } public int compareTo(Delayed y) { - return compareTo((NanoDelay)y); + return Long.compare(trigger, ((NanoDelay)y).trigger); } public boolean equals(Object other) { - return equals((NanoDelay)other); - } - public boolean equals(NanoDelay other) { - return other.trigger == trigger; + return (other instanceof NanoDelay) && + this.trigger == ((NanoDelay)other).trigger; } // suppress [overrides] javac warning @@ -119,18 +113,19 @@ public class DelayQueueTest extends JSR1 /** * Returns a new queue of given size containing consecutive - * PDelays 0 ... n. + * PDelays 0 ... n - 1. */ - private DelayQueue populatedQueue(int n) { - DelayQueue q = new DelayQueue(); + private static DelayQueue populatedQueue(int n) { + DelayQueue q = new DelayQueue<>(); assertTrue(q.isEmpty()); for (int i = n - 1; i >= 0; i -= 2) assertTrue(q.offer(new PDelay(i))); for (int i = (n & 1); i < n; i += 2) assertTrue(q.offer(new PDelay(i))); assertFalse(q.isEmpty()); - assertEquals(Integer.MAX_VALUE, q.remainingCapacity()); - assertEquals(n, q.size()); + mustEqual(Integer.MAX_VALUE, q.remainingCapacity()); + mustEqual(n, q.size()); + mustEqual(new PDelay(0), q.peek()); return q; } @@ -138,7 +133,7 @@ public class DelayQueueTest extends JSR1 * A new queue has unbounded capacity */ public void testConstructor1() { - assertEquals(Integer.MAX_VALUE, new DelayQueue().remainingCapacity()); + mustEqual(Integer.MAX_VALUE, new DelayQueue().remainingCapacity()); } /** @@ -146,7 +141,7 @@ public class DelayQueueTest extends JSR1 */ public void testConstructor3() { try { - new DelayQueue(null); + new DelayQueue(null); shouldThrow(); } catch (NullPointerException success) {} } @@ -156,7 +151,7 @@ public class DelayQueueTest extends JSR1 */ public void testConstructor4() { try { - new DelayQueue(Arrays.asList(new PDelay[SIZE])); + new DelayQueue(Arrays.asList(new PDelay[SIZE])); shouldThrow(); } catch (NullPointerException success) {} } @@ -169,7 +164,7 @@ public class DelayQueueTest extends JSR1 for (int i = 0; i < SIZE - 1; ++i) a[i] = new PDelay(i); try { - new DelayQueue(Arrays.asList(a)); + new DelayQueue(Arrays.asList(a)); shouldThrow(); } catch (NullPointerException success) {} } @@ -178,21 +173,21 @@ public class DelayQueueTest extends JSR1 * Queue contains all elements of collection used to initialize */ public void testConstructor6() { - PDelay[] ints = new PDelay[SIZE]; + PDelay[] items = new PDelay[SIZE]; for (int i = 0; i < SIZE; ++i) - ints[i] = new PDelay(i); - DelayQueue q = new DelayQueue(Arrays.asList(ints)); + items[i] = new PDelay(i); + DelayQueue q = new DelayQueue(Arrays.asList(items)); for (int i = 0; i < SIZE; ++i) - assertEquals(ints[i], q.poll()); + mustEqual(items[i], q.poll()); } /** * isEmpty is true before add, false after */ public void testEmpty() { - DelayQueue q = new DelayQueue(); + DelayQueue q = new DelayQueue(); assertTrue(q.isEmpty()); - assertEquals(Integer.MAX_VALUE, q.remainingCapacity()); + mustEqual(Integer.MAX_VALUE, q.remainingCapacity()); q.add(new PDelay(1)); assertFalse(q.isEmpty()); q.add(new PDelay(2)); @@ -205,15 +200,15 @@ public class DelayQueueTest extends JSR1 * remainingCapacity() always returns Integer.MAX_VALUE */ public void testRemainingCapacity() { - BlockingQueue q = populatedQueue(SIZE); + BlockingQueue q = populatedQueue(SIZE); for (int i = 0; i < SIZE; ++i) { - assertEquals(Integer.MAX_VALUE, q.remainingCapacity()); - assertEquals(SIZE - i, q.size()); + mustEqual(Integer.MAX_VALUE, q.remainingCapacity()); + mustEqual(SIZE - i, q.size()); assertTrue(q.remove() instanceof PDelay); } for (int i = 0; i < SIZE; ++i) { - assertEquals(Integer.MAX_VALUE, q.remainingCapacity()); - assertEquals(i, q.size()); + mustEqual(Integer.MAX_VALUE, q.remainingCapacity()); + mustEqual(i, q.size()); assertTrue(q.add(new PDelay(i))); } } @@ -222,7 +217,7 @@ public class DelayQueueTest extends JSR1 * offer non-null succeeds */ public void testOffer() { - DelayQueue q = new DelayQueue(); + DelayQueue q = new DelayQueue(); assertTrue(q.offer(new PDelay(0))); assertTrue(q.offer(new PDelay(1))); } @@ -231,18 +226,18 @@ public class DelayQueueTest extends JSR1 * add succeeds */ public void testAdd() { - DelayQueue q = new DelayQueue(); + DelayQueue q = new DelayQueue(); for (int i = 0; i < SIZE; ++i) { - assertEquals(i, q.size()); + mustEqual(i, q.size()); assertTrue(q.add(new PDelay(i))); } } /** - * addAll(this) throws IAE + * addAll(this) throws IllegalArgumentException */ public void testAddAllSelf() { - DelayQueue q = populatedQueue(SIZE); + DelayQueue q = populatedQueue(SIZE); try { q.addAll(q); shouldThrow(); @@ -254,7 +249,7 @@ public class DelayQueueTest extends JSR1 * possibly adding some elements */ public void testAddAll3() { - DelayQueue q = new DelayQueue(); + DelayQueue q = new DelayQueue(); PDelay[] a = new PDelay[SIZE]; for (int i = 0; i < SIZE - 1; ++i) a[i] = new PDelay(i); @@ -269,34 +264,34 @@ public class DelayQueueTest extends JSR1 */ public void testAddAll5() { PDelay[] empty = new PDelay[0]; - PDelay[] ints = new PDelay[SIZE]; + PDelay[] items = new PDelay[SIZE]; for (int i = SIZE - 1; i >= 0; --i) - ints[i] = new PDelay(i); - DelayQueue q = new DelayQueue(); + items[i] = new PDelay(i); + DelayQueue q = new DelayQueue(); assertFalse(q.addAll(Arrays.asList(empty))); - assertTrue(q.addAll(Arrays.asList(ints))); + assertTrue(q.addAll(Arrays.asList(items))); for (int i = 0; i < SIZE; ++i) - assertEquals(ints[i], q.poll()); + mustEqual(items[i], q.poll()); } /** * all elements successfully put are contained */ public void testPut() { - DelayQueue q = new DelayQueue(); + DelayQueue q = new DelayQueue(); for (int i = 0; i < SIZE; ++i) { PDelay x = new PDelay(i); q.put(x); assertTrue(q.contains(x)); } - assertEquals(SIZE, q.size()); + mustEqual(SIZE, q.size()); } /** * put doesn't block waiting for take */ public void testPutWithTake() throws InterruptedException { - final DelayQueue q = new DelayQueue(); + final DelayQueue q = new DelayQueue(); Thread t = newStartedThread(new CheckedRunnable() { public void realRun() { q.put(new PDelay(0)); @@ -306,14 +301,14 @@ public class DelayQueueTest extends JSR1 }}); awaitTermination(t); - assertEquals(4, q.size()); + mustEqual(4, q.size()); } /** - * timed offer does not time out + * Queue is unbounded, so timed offer never times out */ public void testTimedOffer() throws InterruptedException { - final DelayQueue q = new DelayQueue(); + final DelayQueue q = new DelayQueue(); Thread t = newStartedThread(new CheckedRunnable() { public void realRun() throws InterruptedException { q.put(new PDelay(0)); @@ -329,9 +324,9 @@ public class DelayQueueTest extends JSR1 * take retrieves elements in priority order */ public void testTake() throws InterruptedException { - DelayQueue q = populatedQueue(SIZE); + DelayQueue q = populatedQueue(SIZE); for (int i = 0; i < SIZE; ++i) { - assertEquals(new PDelay(i), q.take()); + mustEqual(new PDelay(i), q.take()); } } @@ -339,13 +334,12 @@ public class DelayQueueTest extends JSR1 * Take removes existing elements until empty, then blocks interruptibly */ public void testBlockingTake() throws InterruptedException { - final DelayQueue q = populatedQueue(SIZE); + final DelayQueue q = populatedQueue(SIZE); final CountDownLatch pleaseInterrupt = new CountDownLatch(1); Thread t = newStartedThread(new CheckedRunnable() { public void realRun() throws InterruptedException { - for (int i = 0; i < SIZE; ++i) { - assertEquals(new PDelay(i), ((PDelay)q.take())); - } + for (int i = 0; i < SIZE; i++) + mustEqual(new PDelay(i), q.take()); Thread.currentThread().interrupt(); try { @@ -363,7 +357,7 @@ public class DelayQueueTest extends JSR1 }}); await(pleaseInterrupt); - assertThreadStaysAlive(t); + if (randomBoolean()) assertThreadBlocks(t, Thread.State.WAITING); t.interrupt(); awaitTermination(t); } @@ -372,9 +366,9 @@ public class DelayQueueTest extends JSR1 * poll succeeds unless empty */ public void testPoll() { - DelayQueue q = populatedQueue(SIZE); + DelayQueue q = populatedQueue(SIZE); for (int i = 0; i < SIZE; ++i) { - assertEquals(new PDelay(i), q.poll()); + mustEqual(new PDelay(i), q.poll()); } assertNull(q.poll()); } @@ -383,9 +377,9 @@ public class DelayQueueTest extends JSR1 * timed poll with zero timeout succeeds when non-empty, else times out */ public void testTimedPoll0() throws InterruptedException { - DelayQueue q = populatedQueue(SIZE); + DelayQueue q = populatedQueue(SIZE); for (int i = 0; i < SIZE; ++i) { - assertEquals(new PDelay(i), q.poll(0, MILLISECONDS)); + mustEqual(new PDelay(i), q.poll(0, MILLISECONDS)); } assertNull(q.poll(0, MILLISECONDS)); } @@ -394,10 +388,10 @@ public class DelayQueueTest extends JSR1 * timed poll with nonzero timeout succeeds when non-empty, else times out */ public void testTimedPoll() throws InterruptedException { - DelayQueue q = populatedQueue(SIZE); + DelayQueue q = populatedQueue(SIZE); for (int i = 0; i < SIZE; ++i) { long startTime = System.nanoTime(); - assertEquals(new PDelay(i), q.poll(LONG_DELAY_MS, MILLISECONDS)); + mustEqual(new PDelay(i), q.poll(LONG_DELAY_MS, MILLISECONDS)); assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS); } long startTime = System.nanoTime(); @@ -412,42 +406,43 @@ public class DelayQueueTest extends JSR1 */ public void testInterruptedTimedPoll() throws InterruptedException { final CountDownLatch pleaseInterrupt = new CountDownLatch(1); + final DelayQueue q = populatedQueue(SIZE); Thread t = newStartedThread(new CheckedRunnable() { public void realRun() throws InterruptedException { - DelayQueue q = populatedQueue(SIZE); - for (int i = 0; i < SIZE; ++i) { - assertEquals(new PDelay(i), ((PDelay)q.poll(SHORT_DELAY_MS, MILLISECONDS))); - } + for (int i = 0; i < SIZE; i++) + mustEqual(new PDelay(i), + q.poll(LONG_DELAY_MS, MILLISECONDS)); Thread.currentThread().interrupt(); try { - q.poll(LONG_DELAY_MS, MILLISECONDS); + q.poll(randomTimeout(), randomTimeUnit()); shouldThrow(); } catch (InterruptedException success) {} assertFalse(Thread.interrupted()); pleaseInterrupt.countDown(); try { - q.poll(LONG_DELAY_MS, MILLISECONDS); + q.poll(LONGER_DELAY_MS, MILLISECONDS); shouldThrow(); } catch (InterruptedException success) {} assertFalse(Thread.interrupted()); }}); await(pleaseInterrupt); - assertThreadStaysAlive(t); + if (randomBoolean()) assertThreadBlocks(t, Thread.State.TIMED_WAITING); t.interrupt(); awaitTermination(t); + checkEmpty(q); } /** * peek returns next element, or null if empty */ public void testPeek() { - DelayQueue q = populatedQueue(SIZE); + DelayQueue q = populatedQueue(SIZE); for (int i = 0; i < SIZE; ++i) { - assertEquals(new PDelay(i), q.peek()); - assertEquals(new PDelay(i), q.poll()); + mustEqual(new PDelay(i), q.peek()); + mustEqual(new PDelay(i), q.poll()); if (q.isEmpty()) assertNull(q.peek()); else @@ -460,9 +455,9 @@ public class DelayQueueTest extends JSR1 * element returns next element, or throws NSEE if empty */ public void testElement() { - DelayQueue q = populatedQueue(SIZE); + DelayQueue q = populatedQueue(SIZE); for (int i = 0; i < SIZE; ++i) { - assertEquals(new PDelay(i), q.element()); + mustEqual(new PDelay(i), q.element()); q.poll(); } try { @@ -475,9 +470,9 @@ public class DelayQueueTest extends JSR1 * remove removes next element, or throws NSEE if empty */ public void testRemove() { - DelayQueue q = populatedQueue(SIZE); + DelayQueue q = populatedQueue(SIZE); for (int i = 0; i < SIZE; ++i) { - assertEquals(new PDelay(i), q.remove()); + mustEqual(new PDelay(i), q.remove()); } try { q.remove(); @@ -489,7 +484,7 @@ public class DelayQueueTest extends JSR1 * contains(x) reports true when elements added but not yet removed */ public void testContains() { - DelayQueue q = populatedQueue(SIZE); + DelayQueue q = populatedQueue(SIZE); for (int i = 0; i < SIZE; ++i) { assertTrue(q.contains(new PDelay(i))); q.poll(); @@ -501,11 +496,11 @@ public class DelayQueueTest extends JSR1 * clear removes all elements */ public void testClear() { - DelayQueue q = populatedQueue(SIZE); + DelayQueue q = populatedQueue(SIZE); q.clear(); assertTrue(q.isEmpty()); - assertEquals(0, q.size()); - assertEquals(Integer.MAX_VALUE, q.remainingCapacity()); + mustEqual(0, q.size()); + mustEqual(Integer.MAX_VALUE, q.remainingCapacity()); PDelay x = new PDelay(1); q.add(x); assertFalse(q.isEmpty()); @@ -518,8 +513,8 @@ public class DelayQueueTest extends JSR1 * containsAll(c) is true when c contains a subset of elements */ public void testContainsAll() { - DelayQueue q = populatedQueue(SIZE); - DelayQueue p = new DelayQueue(); + DelayQueue q = populatedQueue(SIZE); + DelayQueue p = new DelayQueue(); for (int i = 0; i < SIZE; ++i) { assertTrue(q.containsAll(p)); assertFalse(p.containsAll(q)); @@ -532,8 +527,8 @@ public class DelayQueueTest extends JSR1 * retainAll(c) retains only those elements of c and reports true if changed */ public void testRetainAll() { - DelayQueue q = populatedQueue(SIZE); - DelayQueue p = populatedQueue(SIZE); + DelayQueue q = populatedQueue(SIZE); + DelayQueue p = populatedQueue(SIZE); for (int i = 0; i < SIZE; ++i) { boolean changed = q.retainAll(p); if (i == 0) @@ -542,7 +537,7 @@ public class DelayQueueTest extends JSR1 assertTrue(changed); assertTrue(q.containsAll(p)); - assertEquals(SIZE - i, q.size()); + mustEqual(SIZE - i, q.size()); p.remove(); } } @@ -552,13 +547,12 @@ public class DelayQueueTest extends JSR1 */ public void testRemoveAll() { for (int i = 1; i < SIZE; ++i) { - DelayQueue q = populatedQueue(SIZE); - DelayQueue p = populatedQueue(i); + DelayQueue q = populatedQueue(SIZE); + DelayQueue p = populatedQueue(i); assertTrue(q.removeAll(p)); - assertEquals(SIZE - i, q.size()); + mustEqual(SIZE - i, q.size()); for (int j = 0; j < i; ++j) { - PDelay x = (PDelay)(p.remove()); - assertFalse(q.contains(x)); + assertFalse(q.contains(p.remove())); } } } @@ -567,11 +561,13 @@ public class DelayQueueTest extends JSR1 * toArray contains all elements */ public void testToArray() throws InterruptedException { - DelayQueue q = populatedQueue(SIZE); - Object[] o = q.toArray(); - Arrays.sort(o); - for (int i = 0; i < o.length; i++) - assertSame(o[i], q.take()); + DelayQueue q = populatedQueue(SIZE); + Object[] a = q.toArray(); + assertSame(Object[].class, a.getClass()); + Arrays.sort(a); + for (Object o : a) + assertSame(o, q.take()); + assertTrue(q.isEmpty()); } /** @@ -579,19 +575,20 @@ public class DelayQueueTest extends JSR1 */ public void testToArray2() { DelayQueue q = populatedQueue(SIZE); - PDelay[] ints = new PDelay[SIZE]; - PDelay[] array = q.toArray(ints); - assertSame(ints, array); - Arrays.sort(ints); - for (int i = 0; i < ints.length; i++) - assertSame(ints[i], q.remove()); + PDelay[] items = new PDelay[SIZE]; + PDelay[] array = q.toArray(items); + assertSame(items, array); + Arrays.sort(items); + for (PDelay o : items) + assertSame(o, q.remove()); + assertTrue(q.isEmpty()); } /** * toArray(incompatible array type) throws ArrayStoreException */ public void testToArray1_BadArg() { - DelayQueue q = populatedQueue(SIZE); + DelayQueue q = populatedQueue(SIZE); try { q.toArray(new String[10]); shouldThrow(); @@ -602,14 +599,14 @@ public class DelayQueueTest extends JSR1 * iterator iterates through all elements */ public void testIterator() { - DelayQueue q = populatedQueue(SIZE); + DelayQueue q = populatedQueue(SIZE); int i = 0; - Iterator it = q.iterator(); + Iterator it = q.iterator(); while (it.hasNext()) { assertTrue(q.contains(it.next())); ++i; } - assertEquals(i, SIZE); + mustEqual(i, SIZE); assertIteratorExhausted(it); } @@ -617,23 +614,23 @@ public class DelayQueueTest extends JSR1 * iterator of empty collection has no elements */ public void testEmptyIterator() { - assertIteratorExhausted(new DelayQueue().iterator()); + assertIteratorExhausted(new DelayQueue().iterator()); } /** * iterator.remove removes current element */ public void testIteratorRemove() { - final DelayQueue q = new DelayQueue(); + final DelayQueue q = new DelayQueue(); q.add(new PDelay(2)); q.add(new PDelay(1)); q.add(new PDelay(3)); - Iterator it = q.iterator(); + Iterator it = q.iterator(); it.next(); it.remove(); it = q.iterator(); - assertEquals(new PDelay(2), it.next()); - assertEquals(new PDelay(3), it.next()); + mustEqual(new PDelay(2), it.next()); + mustEqual(new PDelay(3), it.next()); assertFalse(it.hasNext()); } @@ -641,7 +638,7 @@ public class DelayQueueTest extends JSR1 * toString contains toStrings of elements */ public void testToString() { - DelayQueue q = populatedQueue(SIZE); + DelayQueue q = populatedQueue(SIZE); String s = q.toString(); for (Object e : q) assertTrue(s.contains(e.toString())); @@ -651,7 +648,7 @@ public class DelayQueueTest extends JSR1 * timed poll transfers elements across Executor tasks */ public void testPollInExecutor() { - final DelayQueue q = new DelayQueue(); + final DelayQueue q = new DelayQueue(); final CheckedBarrier threadsStarted = new CheckedBarrier(2); final ExecutorService executor = Executors.newFixedThreadPool(2); try (PoolCleaner cleaner = cleaner(executor)) { @@ -675,7 +672,7 @@ public class DelayQueueTest extends JSR1 * Delayed actions do not occur until their delay elapses */ public void testDelay() throws InterruptedException { - DelayQueue q = new DelayQueue(); + DelayQueue q = new DelayQueue<>(); for (int i = 0; i < SIZE; ++i) q.add(new NanoDelay(1000000L * (SIZE - i))); @@ -695,7 +692,7 @@ public class DelayQueueTest extends JSR1 * peek of a non-empty queue returns non-null even if not expired */ public void testPeekDelayed() { - DelayQueue q = new DelayQueue(); + DelayQueue q = new DelayQueue(); q.add(new NanoDelay(Long.MAX_VALUE)); assertNotNull(q.peek()); } @@ -704,7 +701,7 @@ public class DelayQueueTest extends JSR1 * poll of a non-empty queue returns null if no expired elements. */ public void testPollDelayed() { - DelayQueue q = new DelayQueue(); + DelayQueue q = new DelayQueue(); q.add(new NanoDelay(Long.MAX_VALUE)); assertNull(q.poll()); } @@ -713,26 +710,28 @@ public class DelayQueueTest extends JSR1 * timed poll of a non-empty queue returns null if no expired elements. */ public void testTimedPollDelayed() throws InterruptedException { - DelayQueue q = new DelayQueue(); + DelayQueue q = new DelayQueue(); q.add(new NanoDelay(LONG_DELAY_MS * 1000000L)); + long startTime = System.nanoTime(); assertNull(q.poll(timeoutMillis(), MILLISECONDS)); + assertTrue(millisElapsedSince(startTime) >= timeoutMillis()); } /** * drainTo(c) empties queue into another collection c */ public void testDrainTo() { - DelayQueue q = new DelayQueue(); + DelayQueue q = new DelayQueue(); PDelay[] elems = new PDelay[SIZE]; for (int i = 0; i < SIZE; ++i) { elems[i] = new PDelay(i); q.add(elems[i]); } - ArrayList l = new ArrayList(); + ArrayList l = new ArrayList(); q.drainTo(l); - assertEquals(0, q.size()); + mustEqual(0, q.size()); for (int i = 0; i < SIZE; ++i) - assertEquals(elems[i], l.get(i)); + mustEqual(elems[i], l.get(i)); q.add(elems[0]); q.add(elems[1]); assertFalse(q.isEmpty()); @@ -740,24 +739,24 @@ public class DelayQueueTest extends JSR1 assertTrue(q.contains(elems[1])); l.clear(); q.drainTo(l); - assertEquals(0, q.size()); - assertEquals(2, l.size()); + mustEqual(0, q.size()); + mustEqual(2, l.size()); for (int i = 0; i < 2; ++i) - assertEquals(elems[i], l.get(i)); + mustEqual(elems[i], l.get(i)); } /** * drainTo empties queue */ public void testDrainToWithActivePut() throws InterruptedException { - final DelayQueue q = populatedQueue(SIZE); + final DelayQueue q = populatedQueue(SIZE); Thread t = new Thread(new CheckedRunnable() { public void realRun() { q.put(new PDelay(SIZE + 1)); }}); t.start(); - ArrayList l = new ArrayList(); + ArrayList l = new ArrayList(); q.drainTo(l); assertTrue(l.size() >= SIZE); t.join(); @@ -769,12 +768,12 @@ public class DelayQueueTest extends JSR1 */ public void testDrainToN() { for (int i = 0; i < SIZE + 2; ++i) { - DelayQueue q = populatedQueue(SIZE); - ArrayList l = new ArrayList(); + DelayQueue q = populatedQueue(SIZE); + ArrayList l = new ArrayList(); q.drainTo(l, i); int k = (i < SIZE) ? i : SIZE; - assertEquals(SIZE - k, q.size()); - assertEquals(k, l.size()); + mustEqual(SIZE - k, q.size()); + mustEqual(k, l.size()); } }