7 |
|
|
8 |
|
import junit.framework.*; |
9 |
|
import java.util.concurrent.atomic.*; |
10 |
+ |
import java.io.*; |
11 |
|
|
12 |
< |
public class AtomicReferenceTest extends TestCase { |
12 |
> |
public class AtomicReferenceTest extends JSR166TestCase { |
13 |
|
public static void main (String[] args) { |
14 |
|
junit.textui.TestRunner.run (suite()); |
15 |
|
} |
17 |
|
return new TestSuite(AtomicReferenceTest.class); |
18 |
|
} |
19 |
|
|
19 |
– |
static final Integer zero = new Integer(0); |
20 |
– |
static final Integer one = new Integer(1); |
21 |
– |
static final Integer two = new Integer(2); |
22 |
– |
static final Integer m3 = new Integer(-3); |
23 |
– |
static final Integer m4 = new Integer(-4); |
24 |
– |
static final Integer m5 = new Integer(-5); |
25 |
– |
static final Integer seven = new Integer(7); |
26 |
– |
static final Integer m10 = new Integer(-10); |
27 |
– |
|
20 |
|
public void testConstructor(){ |
21 |
|
AtomicReference ai = new AtomicReference(one); |
22 |
|
assertEquals(one,ai.get()); |
63 |
|
assertEquals(m10,ai.getAndSet(one)); |
64 |
|
} |
65 |
|
|
66 |
+ |
public void testSerialization() { |
67 |
+ |
AtomicReference l = new AtomicReference(); |
68 |
+ |
|
69 |
+ |
try { |
70 |
+ |
l.set(one); |
71 |
+ |
ByteArrayOutputStream bout = new ByteArrayOutputStream(10000); |
72 |
+ |
ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout)); |
73 |
+ |
out.writeObject(l); |
74 |
+ |
out.close(); |
75 |
+ |
|
76 |
+ |
ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray()); |
77 |
+ |
ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin)); |
78 |
+ |
AtomicReference r = (AtomicReference) in.readObject(); |
79 |
+ |
assertEquals(l.get(), r.get()); |
80 |
+ |
} catch(Exception e){ |
81 |
+ |
e.printStackTrace(); |
82 |
+ |
fail("unexpected exception"); |
83 |
+ |
} |
84 |
+ |
} |
85 |
+ |
|
86 |
|
} |
87 |
|
|