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