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.Comparator; |
15 |
|
import java.util.Iterator; |
16 |
|
import java.util.NoSuchElementException; |
17 |
|
import java.util.Queue; |
17 |
– |
import java.util.concurrent.PriorityBlockingQueue; |
18 |
|
import java.util.concurrent.BlockingQueue; |
19 |
|
import java.util.concurrent.CountDownLatch; |
20 |
|
import java.util.concurrent.Executors; |
21 |
|
import java.util.concurrent.ExecutorService; |
22 |
< |
import static java.util.concurrent.TimeUnit.MILLISECONDS; |
22 |
> |
import java.util.concurrent.PriorityBlockingQueue; |
23 |
> |
|
24 |
> |
import junit.framework.Test; |
25 |
|
|
26 |
|
public class PriorityBlockingQueueTest extends JSR166TestCase { |
27 |
|
|
57 |
|
} |
58 |
|
|
59 |
|
/** |
60 |
< |
* Creates a queue of given size containing consecutive |
60 |
> |
* Returns a new queue of given size containing consecutive |
61 |
|
* Integers 0 ... n. |
62 |
|
*/ |
63 |
|
private PriorityBlockingQueue<Integer> populatedQueue(int n) { |
64 |
|
PriorityBlockingQueue<Integer> q = |
65 |
|
new PriorityBlockingQueue<Integer>(n); |
66 |
|
assertTrue(q.isEmpty()); |
67 |
< |
for (int i = n-1; i >= 0; i-=2) |
67 |
> |
for (int i = n-1; i >= 0; i -= 2) |
68 |
|
assertTrue(q.offer(new Integer(i))); |
69 |
< |
for (int i = (n & 1); i < n; i+=2) |
69 |
> |
for (int i = (n & 1); i < n; i += 2) |
70 |
|
assertTrue(q.offer(new Integer(i))); |
71 |
|
assertFalse(q.isEmpty()); |
72 |
|
assertEquals(NOCAP, q.remainingCapacity()); |
266 |
|
public void testPut() { |
267 |
|
PriorityBlockingQueue q = new PriorityBlockingQueue(SIZE); |
268 |
|
for (int i = 0; i < SIZE; ++i) { |
269 |
< |
Integer I = new Integer(i); |
270 |
< |
q.put(I); |
271 |
< |
assertTrue(q.contains(I)); |
269 |
> |
Integer x = new Integer(i); |
270 |
> |
q.put(x); |
271 |
> |
assertTrue(q.contains(x)); |
272 |
|
} |
273 |
|
assertEquals(SIZE, q.size()); |
274 |
|
} |
530 |
|
assertTrue(q.removeAll(p)); |
531 |
|
assertEquals(SIZE-i, q.size()); |
532 |
|
for (int j = 0; j < i; ++j) { |
533 |
< |
Integer I = (Integer)(p.remove()); |
534 |
< |
assertFalse(q.contains(I)); |
533 |
> |
Integer x = (Integer)(p.remove()); |
534 |
> |
assertFalse(q.contains(x)); |
535 |
|
} |
536 |
|
} |
537 |
|
} |
646 |
|
Queue x = populatedQueue(SIZE); |
647 |
|
Queue y = serialClone(x); |
648 |
|
|
649 |
< |
assertTrue(x != y); |
649 |
> |
assertNotSame(x, y); |
650 |
|
assertEquals(x.size(), y.size()); |
651 |
|
while (!x.isEmpty()) { |
652 |
|
assertFalse(y.isEmpty()); |
714 |
|
assertEquals(SIZE-k, q.size()); |
715 |
|
for (int j = 0; j < k; ++j) |
716 |
|
assertEquals(l.get(j), new Integer(j)); |
717 |
< |
while (q.poll() != null) ; |
717 |
> |
do {} while (q.poll() != null); |
718 |
> |
} |
719 |
> |
} |
720 |
> |
|
721 |
> |
/** |
722 |
> |
* remove(null), contains(null) always return false |
723 |
> |
*/ |
724 |
> |
public void testNeverContainsNull() { |
725 |
> |
Collection<?>[] qs = { |
726 |
> |
new PriorityBlockingQueue<Object>(), |
727 |
> |
populatedQueue(2), |
728 |
> |
}; |
729 |
> |
|
730 |
> |
for (Collection<?> q : qs) { |
731 |
> |
assertFalse(q.contains(null)); |
732 |
> |
assertFalse(q.remove(null)); |
733 |
|
} |
734 |
|
} |
735 |
|
|