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.Random; |
16 |
> |
import java.util.concurrent.ConcurrentLinkedDeque; |
17 |
|
|
18 |
|
public class ConcurrentLinkedDequeTest extends JSR166TestCase { |
19 |
|
|
847 |
|
* A deserialized serialized deque has same elements in same order |
848 |
|
*/ |
849 |
|
public void testSerialization() throws Exception { |
850 |
< |
ConcurrentLinkedDeque q = populatedDeque(SIZE); |
851 |
< |
ByteArrayOutputStream bout = new ByteArrayOutputStream(10000); |
852 |
< |
ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout)); |
853 |
< |
out.writeObject(q); |
854 |
< |
out.close(); |
855 |
< |
|
856 |
< |
ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray()); |
857 |
< |
ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin)); |
858 |
< |
ConcurrentLinkedDeque r = (ConcurrentLinkedDeque)in.readObject(); |
859 |
< |
assertEquals(q.size(), r.size()); |
860 |
< |
while (!q.isEmpty()) |
861 |
< |
assertEquals(q.remove(), r.remove()); |
850 |
> |
Queue x = populatedDeque(SIZE); |
851 |
> |
Queue y = serialClone(x); |
852 |
> |
|
853 |
> |
assertTrue(x != y); |
854 |
> |
assertEquals(x.size(), y.size()); |
855 |
> |
assertEquals(x.toString(), y.toString()); |
856 |
> |
assertTrue(Arrays.equals(x.toArray(), y.toArray())); |
857 |
> |
while (!x.isEmpty()) { |
858 |
> |
assertFalse(y.isEmpty()); |
859 |
> |
assertEquals(x.remove(), y.remove()); |
860 |
> |
} |
861 |
> |
assertTrue(y.isEmpty()); |
862 |
|
} |
863 |
|
|
864 |
|
} |