8 |
|
import junit.framework.*; |
9 |
|
import java.util.*; |
10 |
|
import java.util.concurrent.*; |
11 |
+ |
import java.io.*; |
12 |
|
|
13 |
|
public class LinkedBlockingQueueTest extends TestCase { |
14 |
|
|
489 |
|
assertTrue(q.remove(new Integer(i))); |
490 |
|
assertFalse(q.remove(new Integer(i+1))); |
491 |
|
} |
492 |
< |
assert(q.isEmpty()); |
492 |
> |
assertTrue(q.isEmpty()); |
493 |
|
} |
494 |
|
|
495 |
|
public void testContains(){ |
712 |
|
|
713 |
|
} |
714 |
|
|
715 |
+ |
public void testSerialization() { |
716 |
+ |
LinkedBlockingQueue q = fullQueue(N); |
717 |
+ |
|
718 |
+ |
try { |
719 |
+ |
ByteArrayOutputStream bout = new ByteArrayOutputStream(10000); |
720 |
+ |
ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout)); |
721 |
+ |
out.writeObject(q); |
722 |
+ |
out.close(); |
723 |
+ |
|
724 |
+ |
ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray()); |
725 |
+ |
ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin)); |
726 |
+ |
LinkedBlockingQueue r = (LinkedBlockingQueue)in.readObject(); |
727 |
+ |
assertEquals(q.size(), r.size()); |
728 |
+ |
while (!q.isEmpty()) |
729 |
+ |
assertEquals(q.remove(), r.remove()); |
730 |
+ |
} catch(Exception e){ |
731 |
+ |
e.printStackTrace(); |
732 |
+ |
fail("unexpected exception"); |
733 |
+ |
} |
734 |
+ |
} |
735 |
+ |
|
736 |
|
} |