7 |
|
|
8 |
|
import junit.framework.*; |
9 |
|
import java.util.concurrent.atomic.*; |
10 |
+ |
import java.io.*; |
11 |
|
|
12 |
|
public class AtomicLongTest extends TestCase { |
13 |
|
public static void main (String[] args) { |
116 |
|
assertEquals(1,ai.get()); |
117 |
|
} |
118 |
|
|
119 |
+ |
public void testSerialization() { |
120 |
+ |
AtomicLong l = new AtomicLong(); |
121 |
+ |
|
122 |
+ |
try { |
123 |
+ |
l.set(-22); |
124 |
+ |
ByteArrayOutputStream bout = new ByteArrayOutputStream(10000); |
125 |
+ |
ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout)); |
126 |
+ |
out.writeObject(l); |
127 |
+ |
out.close(); |
128 |
+ |
|
129 |
+ |
ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray()); |
130 |
+ |
ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin)); |
131 |
+ |
AtomicLong r = (AtomicLong) in.readObject(); |
132 |
+ |
assertEquals(l.get(), r.get()); |
133 |
+ |
} catch(Exception e){ |
134 |
+ |
e.printStackTrace(); |
135 |
+ |
fail("unexpected exception"); |
136 |
+ |
} |
137 |
+ |
} |
138 |
|
|
139 |
|
} |