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