ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/tck/AtomicReferenceArrayTest.java
(Generate patch)

Comparing jsr166/src/test/tck/AtomicReferenceArrayTest.java (file contents):
Revision 1.1 by dl, Sun Aug 31 19:24:53 2003 UTC vs.
Revision 1.2 by dl, Sun Sep 7 20:39:11 2003 UTC

# Line 7 | Line 7
7  
8   import junit.framework.*;
9   import java.util.concurrent.atomic.*;
10 + import java.io.*;
11  
12   public class AtomicReferenceArrayTest extends TestCase
13   {
# Line 83 | Line 84 | public class AtomicReferenceArrayTest ex
84          }
85      }
86  
87 +    public void testSerialization() {
88 +        AtomicReferenceArray l = new AtomicReferenceArray(10);
89 +        for (int i = 0; i < 10; ++i) {
90 +            l.set(i, new Integer(-i));
91 +        }
92 +
93 +        try {
94 +            ByteArrayOutputStream bout = new ByteArrayOutputStream(10000);
95 +            ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout));
96 +            out.writeObject(l);
97 +            out.close();
98 +
99 +            ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
100 +            ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin));
101 +            AtomicReferenceArray r = (AtomicReferenceArray) in.readObject();
102 +            assertEquals(l.length(), r.length());
103 +            for (int i = 0; i < 10; ++i) {
104 +                assertEquals(r.get(i), l.get(i));
105 +            }
106 +        } catch(Exception e){
107 +            e.printStackTrace();
108 +            fail("unexpected exception");
109 +        }
110 +    }
111  
112   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines