12 |
|
import java.util.Collection; |
13 |
|
import java.util.Iterator; |
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.LinkedBlockingQueue; |
19 |
|
import java.util.concurrent.Executors; |
20 |
|
import java.util.concurrent.ExecutorService; |
21 |
|
import static java.util.concurrent.TimeUnit.MILLISECONDS; |
21 |
– |
import java.io.*; |
22 |
|
|
23 |
|
public class LinkedBlockingQueueTest extends JSR166TestCase { |
24 |
|
|
773 |
|
* A deserialized serialized queue has same elements in same order |
774 |
|
*/ |
775 |
|
public void testSerialization() throws Exception { |
776 |
< |
LinkedBlockingQueue q = populatedQueue(SIZE); |
776 |
> |
Queue x = populatedQueue(SIZE); |
777 |
> |
Queue y = serialClone(x); |
778 |
|
|
779 |
< |
ByteArrayOutputStream bout = new ByteArrayOutputStream(10000); |
780 |
< |
ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout)); |
781 |
< |
out.writeObject(q); |
782 |
< |
out.close(); |
783 |
< |
|
784 |
< |
ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray()); |
785 |
< |
ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin)); |
786 |
< |
LinkedBlockingQueue r = (LinkedBlockingQueue)in.readObject(); |
787 |
< |
assertEquals(q.size(), r.size()); |
787 |
< |
while (!q.isEmpty()) |
788 |
< |
assertEquals(q.remove(), r.remove()); |
779 |
> |
assertTrue(x != y); |
780 |
> |
assertEquals(x.size(), y.size()); |
781 |
> |
assertEquals(x.toString(), y.toString()); |
782 |
> |
assertTrue(Arrays.equals(x.toArray(), y.toArray())); |
783 |
> |
while (!x.isEmpty()) { |
784 |
> |
assertFalse(y.isEmpty()); |
785 |
> |
assertEquals(x.remove(), y.remove()); |
786 |
> |
} |
787 |
> |
assertTrue(y.isEmpty()); |
788 |
|
} |
789 |
|
|
790 |
|
/** |