7 |
|
*/ |
8 |
|
|
9 |
|
import junit.framework.*; |
10 |
< |
import java.util.concurrent.atomic.*; |
11 |
< |
import java.io.*; |
10 |
> |
import java.util.concurrent.atomic.AtomicLong; |
11 |
|
|
12 |
|
public class AtomicLongTest extends JSR166TestCase { |
13 |
|
public static void main(String[] args) { |
194 |
|
* a deserialized serialized atomic holds same value |
195 |
|
*/ |
196 |
|
public void testSerialization() throws Exception { |
197 |
< |
AtomicLong l = new AtomicLong(); |
198 |
< |
|
199 |
< |
l.set(-22); |
200 |
< |
ByteArrayOutputStream bout = new ByteArrayOutputStream(10000); |
201 |
< |
ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout)); |
202 |
< |
out.writeObject(l); |
203 |
< |
out.close(); |
204 |
< |
|
206 |
< |
ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray()); |
207 |
< |
ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin)); |
208 |
< |
AtomicLong r = (AtomicLong) in.readObject(); |
209 |
< |
assertEquals(l.get(), r.get()); |
197 |
> |
AtomicLong x = new AtomicLong(); |
198 |
> |
AtomicLong y = serialClone(x); |
199 |
> |
assertTrue(x != y); |
200 |
> |
x.set(-22); |
201 |
> |
AtomicLong z = serialClone(x); |
202 |
> |
assertEquals(-22, x.get()); |
203 |
> |
assertEquals(0, y.get()); |
204 |
> |
assertEquals(-22, z.get()); |
205 |
|
} |
206 |
|
|
207 |
|
/** |