7 |
|
|
8 |
|
import junit.framework.*; |
9 |
|
import java.util.concurrent.atomic.*; |
10 |
+ |
import java.io.*; |
11 |
|
|
12 |
|
public class AtomicBooleanTest extends TestCase { |
13 |
|
public static void main (String[] args) { |
66 |
|
assertEquals(true,ai.get()); |
67 |
|
} |
68 |
|
|
69 |
+ |
public void testSerialization() { |
70 |
+ |
AtomicBoolean l = new AtomicBoolean(); |
71 |
+ |
|
72 |
+ |
try { |
73 |
+ |
l.set(true); |
74 |
+ |
ByteArrayOutputStream bout = new ByteArrayOutputStream(10000); |
75 |
+ |
ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout)); |
76 |
+ |
out.writeObject(l); |
77 |
+ |
out.close(); |
78 |
+ |
|
79 |
+ |
ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray()); |
80 |
+ |
ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin)); |
81 |
+ |
AtomicBoolean r = (AtomicBoolean) in.readObject(); |
82 |
+ |
assertEquals(l.get(), r.get()); |
83 |
+ |
} catch(Exception e){ |
84 |
+ |
e.printStackTrace(); |
85 |
+ |
fail("unexpected exception"); |
86 |
+ |
} |
87 |
+ |
} |
88 |
+ |
|
89 |
|
|
90 |
|
} |