7 |
|
*/ |
8 |
|
|
9 |
|
import junit.framework.*; |
10 |
< |
import java.util.*; |
11 |
< |
import java.util.concurrent.*; |
12 |
< |
import java.io.*; |
10 |
> |
import java.util.Arrays; |
11 |
> |
import java.util.Collection; |
12 |
> |
import java.util.Iterator; |
13 |
> |
import java.util.NoSuchElementException; |
14 |
> |
import java.util.Queue; |
15 |
> |
import java.util.concurrent.ConcurrentLinkedQueue; |
16 |
|
|
17 |
|
public class ConcurrentLinkedQueueTest extends JSR166TestCase { |
18 |
|
|
25 |
|
} |
26 |
|
|
27 |
|
/** |
28 |
< |
* Create a queue of given size containing consecutive |
28 |
> |
* Returns a new queue of given size containing consecutive |
29 |
|
* Integers 0 ... n. |
30 |
|
*/ |
31 |
|
private ConcurrentLinkedQueue<Integer> populatedQueue(int n) { |
500 |
|
* A deserialized serialized queue has same elements in same order |
501 |
|
*/ |
502 |
|
public void testSerialization() throws Exception { |
503 |
< |
ConcurrentLinkedQueue q = populatedQueue(SIZE); |
504 |
< |
ByteArrayOutputStream bout = new ByteArrayOutputStream(10000); |
505 |
< |
ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout)); |
506 |
< |
out.writeObject(q); |
507 |
< |
out.close(); |
508 |
< |
|
509 |
< |
ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray()); |
510 |
< |
ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin)); |
511 |
< |
ConcurrentLinkedQueue r = (ConcurrentLinkedQueue)in.readObject(); |
512 |
< |
assertEquals(q.size(), r.size()); |
513 |
< |
while (!q.isEmpty()) |
514 |
< |
assertEquals(q.remove(), r.remove()); |
503 |
> |
Queue x = populatedQueue(SIZE); |
504 |
> |
Queue y = serialClone(x); |
505 |
> |
|
506 |
> |
assertNotSame(x, y); |
507 |
> |
assertEquals(x.size(), y.size()); |
508 |
> |
assertEquals(x.toString(), y.toString()); |
509 |
> |
assertTrue(Arrays.equals(x.toArray(), y.toArray())); |
510 |
> |
while (!x.isEmpty()) { |
511 |
> |
assertFalse(y.isEmpty()); |
512 |
> |
assertEquals(x.remove(), y.remove()); |
513 |
> |
} |
514 |
> |
assertTrue(y.isEmpty()); |
515 |
|
} |
516 |
|
|
517 |
+ |
/** |
518 |
+ |
* remove(null), contains(null) always return false |
519 |
+ |
*/ |
520 |
+ |
public void testNeverContainsNull() { |
521 |
+ |
Collection<?>[] qs = { |
522 |
+ |
new ConcurrentLinkedQueue<Object>(), |
523 |
+ |
populatedQueue(2), |
524 |
+ |
}; |
525 |
+ |
|
526 |
+ |
for (Collection<?> q : qs) { |
527 |
+ |
assertFalse(q.contains(null)); |
528 |
+ |
assertFalse(q.remove(null)); |
529 |
+ |
} |
530 |
+ |
} |
531 |
|
} |