--- jsr166/src/test/tck/AtomicReferenceTest.java 2003/08/31 19:24:53 1.1 +++ jsr166/src/test/tck/AtomicReferenceTest.java 2003/09/07 20:39:11 1.2 @@ -7,6 +7,7 @@ import junit.framework.*; import java.util.concurrent.atomic.*; +import java.io.*; public class AtomicReferenceTest extends TestCase { public static void main (String[] args) { @@ -71,5 +72,25 @@ public class AtomicReferenceTest extends assertEquals(m10,ai.getAndSet(one)); } + public void testSerialization() { + AtomicReference l = new AtomicReference(); + + try { + l.set(one); + ByteArrayOutputStream bout = new ByteArrayOutputStream(10000); + ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout)); + out.writeObject(l); + out.close(); + + ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray()); + ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin)); + AtomicReference r = (AtomicReference) in.readObject(); + assertEquals(l.get(), r.get()); + } catch(Exception e){ + e.printStackTrace(); + fail("unexpected exception"); + } + } + }