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.ArrayBlockingQueue; |
17 |
|
import java.util.concurrent.BlockingQueue; |
18 |
|
import java.util.concurrent.CountDownLatch; |
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 ArrayBlockingQueueTest extends JSR166TestCase { |
24 |
|
|
768 |
|
* A deserialized serialized queue has same elements in same order |
769 |
|
*/ |
770 |
|
public void testSerialization() throws Exception { |
771 |
< |
ArrayBlockingQueue q = populatedQueue(SIZE); |
771 |
> |
Queue x = populatedQueue(SIZE); |
772 |
> |
Queue y = serialClone(x); |
773 |
|
|
774 |
< |
ByteArrayOutputStream bout = new ByteArrayOutputStream(10000); |
775 |
< |
ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout)); |
776 |
< |
out.writeObject(q); |
777 |
< |
out.close(); |
778 |
< |
|
779 |
< |
ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray()); |
780 |
< |
ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin)); |
781 |
< |
ArrayBlockingQueue r = (ArrayBlockingQueue)in.readObject(); |
782 |
< |
assertEquals(q.size(), r.size()); |
782 |
< |
while (!q.isEmpty()) |
783 |
< |
assertEquals(q.remove(), r.remove()); |
774 |
> |
assertTrue(x != y); |
775 |
> |
assertEquals(x.size(), y.size()); |
776 |
> |
assertEquals(x.toString(), y.toString()); |
777 |
> |
assertTrue(Arrays.equals(x.toArray(), y.toArray())); |
778 |
> |
while (!x.isEmpty()) { |
779 |
> |
assertFalse(y.isEmpty()); |
780 |
> |
assertEquals(x.remove(), y.remove()); |
781 |
> |
} |
782 |
> |
assertTrue(y.isEmpty()); |
783 |
|
} |
784 |
|
|
785 |
|
/** |