7 |
|
|
8 |
|
import junit.framework.*; |
9 |
|
import java.util.concurrent.atomic.*; |
10 |
+ |
import java.io.*; |
11 |
|
|
12 |
|
public class AtomicLongArrayTest extends TestCase |
13 |
|
{ |
145 |
|
} |
146 |
|
} |
147 |
|
|
148 |
+ |
public void testSerialization() { |
149 |
+ |
AtomicLongArray l = new AtomicLongArray(N); |
150 |
+ |
for (int i = 0; i < N; ++i) |
151 |
+ |
l.set(i, -i); |
152 |
+ |
|
153 |
+ |
try { |
154 |
+ |
ByteArrayOutputStream bout = new ByteArrayOutputStream(10000); |
155 |
+ |
ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout)); |
156 |
+ |
out.writeObject(l); |
157 |
+ |
out.close(); |
158 |
+ |
|
159 |
+ |
ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray()); |
160 |
+ |
ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin)); |
161 |
+ |
AtomicLongArray r = (AtomicLongArray) in.readObject(); |
162 |
+ |
for (int i = 0; i < N; ++i) { |
163 |
+ |
assertEquals(l.get(i), r.get(i)); |
164 |
+ |
} |
165 |
+ |
} catch(Exception e){ |
166 |
+ |
e.printStackTrace(); |
167 |
+ |
fail("unexpected exception"); |
168 |
+ |
} |
169 |
+ |
} |
170 |
+ |
|
171 |
+ |
|
172 |
|
} |