8 |
|
import junit.framework.*; |
9 |
|
import java.util.*; |
10 |
|
import java.util.concurrent.*; |
11 |
+ |
import java.io.*; |
12 |
|
|
13 |
|
public class ArrayBlockingQueueTest extends TestCase { |
14 |
|
|
500 |
|
assertTrue(q.remove(new Integer(i))); |
501 |
|
assertFalse(q.remove(new Integer(i+1))); |
502 |
|
} |
503 |
< |
assert(q.isEmpty()); |
503 |
> |
assertTrue(q.isEmpty()); |
504 |
|
} |
505 |
|
|
506 |
|
public void testContains(){ |
723 |
|
|
724 |
|
} |
725 |
|
|
726 |
+ |
public void testSerialization() { |
727 |
+ |
ArrayBlockingQueue q = fullQueue(N); |
728 |
+ |
|
729 |
+ |
try { |
730 |
+ |
ByteArrayOutputStream bout = new ByteArrayOutputStream(10000); |
731 |
+ |
ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout)); |
732 |
+ |
out.writeObject(q); |
733 |
+ |
out.close(); |
734 |
+ |
|
735 |
+ |
ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray()); |
736 |
+ |
ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin)); |
737 |
+ |
ArrayBlockingQueue r = (ArrayBlockingQueue)in.readObject(); |
738 |
+ |
assertEquals(q.size(), r.size()); |
739 |
+ |
while (!q.isEmpty()) |
740 |
+ |
assertEquals(q.remove(), r.remove()); |
741 |
+ |
} catch(Exception e){ |
742 |
+ |
fail("unexpected exception"); |
743 |
+ |
} |
744 |
+ |
} |
745 |
+ |
|
746 |
+ |
|
747 |
|
} |