5 |
|
* Other contributors include John Vint |
6 |
|
*/ |
7 |
|
|
8 |
< |
import java.io.BufferedInputStream; |
9 |
< |
import java.io.BufferedOutputStream; |
10 |
< |
import java.io.ByteArrayInputStream; |
11 |
< |
import java.io.ByteArrayOutputStream; |
12 |
< |
import java.io.ObjectInputStream; |
13 |
< |
import java.io.ObjectOutputStream; |
14 |
< |
import java.util.ArrayList; |
8 |
> |
import junit.framework.*; |
9 |
|
import java.util.Arrays; |
10 |
+ |
import java.util.ArrayList; |
11 |
|
import java.util.Collection; |
12 |
|
import java.util.Iterator; |
13 |
|
import java.util.List; |
14 |
|
import java.util.NoSuchElementException; |
15 |
+ |
import java.util.Queue; |
16 |
|
import java.util.concurrent.BlockingQueue; |
17 |
|
import java.util.concurrent.CountDownLatch; |
18 |
|
import java.util.concurrent.Executors; |
20 |
|
import java.util.concurrent.LinkedTransferQueue; |
21 |
|
import static java.util.concurrent.TimeUnit.MILLISECONDS; |
22 |
|
import static java.util.concurrent.TimeUnit.NANOSECONDS; |
27 |
– |
import junit.framework.Test; |
28 |
– |
import junit.framework.TestSuite; |
23 |
|
|
24 |
|
@SuppressWarnings({"unchecked", "rawtypes"}) |
25 |
|
public class LinkedTransferQueueTest extends JSR166TestCase { |
643 |
|
* A deserialized serialized queue has same elements in same order |
644 |
|
*/ |
645 |
|
public void testSerialization() throws Exception { |
646 |
< |
LinkedTransferQueue q = populatedQueue(SIZE); |
646 |
> |
Queue x = populatedQueue(SIZE); |
647 |
> |
Queue y = serialClone(x); |
648 |
|
|
649 |
< |
ByteArrayOutputStream bout = new ByteArrayOutputStream(10000); |
650 |
< |
ObjectOutputStream out |
651 |
< |
= new ObjectOutputStream(new BufferedOutputStream(bout)); |
652 |
< |
out.writeObject(q); |
653 |
< |
out.close(); |
654 |
< |
|
655 |
< |
ByteArrayInputStream bin |
661 |
< |
= new ByteArrayInputStream(bout.toByteArray()); |
662 |
< |
ObjectInputStream in |
663 |
< |
= new ObjectInputStream(new BufferedInputStream(bin)); |
664 |
< |
LinkedTransferQueue r = (LinkedTransferQueue) in.readObject(); |
665 |
< |
|
666 |
< |
assertEquals(q.size(), r.size()); |
667 |
< |
assertEquals(q.toString(), r.toString()); |
668 |
< |
assertTrue(Arrays.equals(q.toArray(), r.toArray())); |
669 |
< |
while (!q.isEmpty()) { |
670 |
< |
assertEquals(q.remove(), r.remove()); |
649 |
> |
assertTrue(x != y); |
650 |
> |
assertEquals(x.size(), y.size()); |
651 |
> |
assertEquals(x.toString(), y.toString()); |
652 |
> |
assertTrue(Arrays.equals(x.toArray(), y.toArray())); |
653 |
> |
while (!x.isEmpty()) { |
654 |
> |
assertFalse(y.isEmpty()); |
655 |
> |
assertEquals(x.remove(), y.remove()); |
656 |
|
} |
657 |
+ |
assertTrue(y.isEmpty()); |
658 |
|
} |
659 |
|
|
660 |
|
/** |