8 |
|
import junit.framework.*; |
9 |
|
import java.util.*; |
10 |
|
import java.util.concurrent.*; |
11 |
+ |
import java.io.*; |
12 |
|
|
13 |
|
public class CopyOnWriteArraySetTest extends TestCase{ |
14 |
|
|
237 |
|
}catch(ArrayStoreException e){} |
238 |
|
} |
239 |
|
|
240 |
+ |
public void testSerialization() { |
241 |
+ |
CopyOnWriteArraySet q = fullSet(10); |
242 |
+ |
|
243 |
+ |
try { |
244 |
+ |
ByteArrayOutputStream bout = new ByteArrayOutputStream(10000); |
245 |
+ |
ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout)); |
246 |
+ |
out.writeObject(q); |
247 |
+ |
out.close(); |
248 |
+ |
|
249 |
+ |
ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray()); |
250 |
+ |
ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin)); |
251 |
+ |
CopyOnWriteArraySet r = (CopyOnWriteArraySet)in.readObject(); |
252 |
+ |
assertEquals(q.size(), r.size()); |
253 |
+ |
assertTrue(q.equals(r)); |
254 |
+ |
assertTrue(r.equals(q)); |
255 |
+ |
} catch(Exception e){ |
256 |
+ |
e.printStackTrace(); |
257 |
+ |
fail("unexpected exception"); |
258 |
+ |
} |
259 |
+ |
} |
260 |
+ |
|
261 |
|
} |