7 |
|
*/ |
8 |
|
|
9 |
|
import junit.framework.*; |
10 |
< |
import java.util.concurrent.atomic.*; |
11 |
< |
import java.io.*; |
10 |
> |
import java.util.concurrent.atomic.AtomicReference; |
11 |
|
|
12 |
|
public class AtomicReferenceTest extends JSR166TestCase { |
13 |
|
public static void main(String[] args) { |
117 |
|
* a deserialized serialized atomic holds same value |
118 |
|
*/ |
119 |
|
public void testSerialization() throws Exception { |
120 |
< |
AtomicReference l = new AtomicReference(); |
121 |
< |
|
122 |
< |
l.set(one); |
123 |
< |
ByteArrayOutputStream bout = new ByteArrayOutputStream(10000); |
124 |
< |
ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout)); |
125 |
< |
out.writeObject(l); |
126 |
< |
out.close(); |
127 |
< |
|
129 |
< |
ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray()); |
130 |
< |
ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin)); |
131 |
< |
AtomicReference r = (AtomicReference) in.readObject(); |
132 |
< |
assertEquals(l.get(), r.get()); |
120 |
> |
AtomicReference x = new AtomicReference(); |
121 |
> |
AtomicReference y = serialClone(x); |
122 |
> |
assertTrue(x != y); |
123 |
> |
x.set(one); |
124 |
> |
AtomicReference z = serialClone(x); |
125 |
> |
assertEquals(one, x.get()); |
126 |
> |
assertEquals(null, y.get()); |
127 |
> |
assertEquals(one, z.get()); |
128 |
|
} |
129 |
|
|
130 |
|
/** |