7 |
|
*/ |
8 |
|
|
9 |
|
import junit.framework.*; |
10 |
< |
import java.util.concurrent.atomic.*; |
11 |
< |
import java.io.*; |
12 |
< |
import java.util.*; |
10 |
> |
import java.util.Arrays; |
11 |
> |
import java.util.concurrent.atomic.AtomicReferenceArray; |
12 |
|
|
13 |
|
public class AtomicReferenceArrayTest extends JSR166TestCase { |
14 |
|
public static void main(String[] args) { |
177 |
|
* a deserialized serialized array holds same values |
178 |
|
*/ |
179 |
|
public void testSerialization() throws Exception { |
180 |
< |
AtomicReferenceArray l = new AtomicReferenceArray(SIZE); |
181 |
< |
for (int i = 0; i < SIZE; ++i) { |
182 |
< |
l.set(i, new Integer(-i)); |
183 |
< |
} |
184 |
< |
|
185 |
< |
ByteArrayOutputStream bout = new ByteArrayOutputStream(10000); |
186 |
< |
ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout)); |
187 |
< |
out.writeObject(l); |
188 |
< |
out.close(); |
190 |
< |
|
191 |
< |
ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray()); |
192 |
< |
ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin)); |
193 |
< |
AtomicReferenceArray r = (AtomicReferenceArray) in.readObject(); |
194 |
< |
assertEquals(l.length(), r.length()); |
195 |
< |
for (int i = 0; i < SIZE; ++i) { |
196 |
< |
assertEquals(r.get(i), l.get(i)); |
180 |
> |
AtomicReferenceArray x = new AtomicReferenceArray(SIZE); |
181 |
> |
for (int i = 0; i < SIZE; i++) { |
182 |
> |
x.set(i, new Integer(-i)); |
183 |
> |
} |
184 |
> |
AtomicReferenceArray y = serialClone(x); |
185 |
> |
assertTrue(x != y); |
186 |
> |
assertEquals(x.length(), y.length()); |
187 |
> |
for (int i = 0; i < SIZE; i++) { |
188 |
> |
assertEquals(x.get(i), y.get(i)); |
189 |
|
} |
190 |
|
} |
191 |
|
|