7 |
|
|
8 |
|
import junit.framework.*; |
9 |
|
import java.util.concurrent.atomic.*; |
10 |
+ |
import java.io.*; |
11 |
|
|
12 |
|
public class AtomicReferenceArrayTest extends TestCase |
13 |
|
{ |
84 |
|
} |
85 |
|
} |
86 |
|
|
87 |
+ |
public void testSerialization() { |
88 |
+ |
AtomicReferenceArray l = new AtomicReferenceArray(10); |
89 |
+ |
for (int i = 0; i < 10; ++i) { |
90 |
+ |
l.set(i, new Integer(-i)); |
91 |
+ |
} |
92 |
+ |
|
93 |
+ |
try { |
94 |
+ |
ByteArrayOutputStream bout = new ByteArrayOutputStream(10000); |
95 |
+ |
ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout)); |
96 |
+ |
out.writeObject(l); |
97 |
+ |
out.close(); |
98 |
+ |
|
99 |
+ |
ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray()); |
100 |
+ |
ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin)); |
101 |
+ |
AtomicReferenceArray r = (AtomicReferenceArray) in.readObject(); |
102 |
+ |
assertEquals(l.length(), r.length()); |
103 |
+ |
for (int i = 0; i < 10; ++i) { |
104 |
+ |
assertEquals(r.get(i), l.get(i)); |
105 |
+ |
} |
106 |
+ |
} catch(Exception e){ |
107 |
+ |
e.printStackTrace(); |
108 |
+ |
fail("unexpected exception"); |
109 |
+ |
} |
110 |
+ |
} |
111 |
|
|
112 |
|
} |