6 |
|
* Pat Fisher, Mike Judd. |
7 |
|
*/ |
8 |
|
|
9 |
< |
import junit.framework.*; |
10 |
< |
import java.util.Arrays; |
9 |
> |
import static java.util.concurrent.TimeUnit.MILLISECONDS; |
10 |
> |
|
11 |
|
import java.util.ArrayList; |
12 |
+ |
import java.util.Arrays; |
13 |
+ |
import java.util.Collection; |
14 |
|
import java.util.Iterator; |
15 |
|
import java.util.NoSuchElementException; |
16 |
|
import java.util.concurrent.BlockingQueue; |
20 |
|
import java.util.concurrent.Executors; |
21 |
|
import java.util.concurrent.ExecutorService; |
22 |
|
import java.util.concurrent.TimeUnit; |
23 |
< |
import static java.util.concurrent.TimeUnit.MILLISECONDS; |
23 |
> |
|
24 |
> |
import junit.framework.Test; |
25 |
|
|
26 |
|
public class DelayQueueTest extends JSR166TestCase { |
27 |
|
|
126 |
|
private DelayQueue<PDelay> populatedQueue(int n) { |
127 |
|
DelayQueue<PDelay> q = new DelayQueue<PDelay>(); |
128 |
|
assertTrue(q.isEmpty()); |
129 |
< |
for (int i = n-1; i >= 0; i-=2) |
129 |
> |
for (int i = n-1; i >= 0; i -= 2) |
130 |
|
assertTrue(q.offer(new PDelay(i))); |
131 |
< |
for (int i = (n & 1); i < n; i+=2) |
131 |
> |
for (int i = (n & 1); i < n; i += 2) |
132 |
|
assertTrue(q.offer(new PDelay(i))); |
133 |
|
assertFalse(q.isEmpty()); |
134 |
|
assertEquals(NOCAP, q.remainingCapacity()); |
289 |
|
public void testPut() { |
290 |
|
DelayQueue q = new DelayQueue(); |
291 |
|
for (int i = 0; i < SIZE; ++i) { |
292 |
< |
PDelay I = new PDelay(i); |
293 |
< |
q.put(I); |
294 |
< |
assertTrue(q.contains(I)); |
292 |
> |
PDelay x = new PDelay(i); |
293 |
> |
q.put(x); |
294 |
> |
assertTrue(q.contains(x)); |
295 |
|
} |
296 |
|
assertEquals(SIZE, q.size()); |
297 |
|
} |
561 |
|
assertTrue(q.removeAll(p)); |
562 |
|
assertEquals(SIZE-i, q.size()); |
563 |
|
for (int j = 0; j < i; ++j) { |
564 |
< |
PDelay I = (PDelay)(p.remove()); |
565 |
< |
assertFalse(q.contains(I)); |
564 |
> |
PDelay x = (PDelay)(p.remove()); |
565 |
> |
assertFalse(q.contains(x)); |
566 |
|
} |
567 |
|
} |
568 |
|
} |
654 |
|
public void realRun() throws InterruptedException { |
655 |
|
assertNull(q.poll()); |
656 |
|
threadsStarted.await(); |
657 |
< |
assertTrue(null != q.poll(LONG_DELAY_MS, MILLISECONDS)); |
657 |
> |
assertNotNull(q.poll(LONG_DELAY_MS, MILLISECONDS)); |
658 |
|
checkEmpty(q); |
659 |
|
}}); |
660 |
|
|
774 |
|
} |
775 |
|
} |
776 |
|
|
777 |
+ |
/** |
778 |
+ |
* remove(null), contains(null) always return false |
779 |
+ |
*/ |
780 |
+ |
public void testNeverContainsNull() { |
781 |
+ |
Collection<?> q = populatedQueue(SIZE); |
782 |
+ |
assertFalse(q.contains(null)); |
783 |
+ |
assertFalse(q.remove(null)); |
784 |
+ |
} |
785 |
|
} |