1 |
|
/* |
2 |
|
* Written by Doug Lea with assistance from members of JCP JSR-166 |
3 |
|
* Expert Group and released to the public domain, as explained at |
4 |
< |
* http://creativecommons.org/licenses/publicdomain |
4 |
> |
* http://creativecommons.org/publicdomain/zero/1.0/ |
5 |
|
* Other contributors include Andrew Wright, Jeffrey Hayes, |
6 |
|
* Pat Fisher, Mike Judd. |
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.AtomicIntegerArray; |
12 |
|
|
13 |
|
public class AtomicIntegerArrayTest extends JSR166TestCase { |
14 |
|
|
15 |
< |
public static void main (String[] args) { |
16 |
< |
junit.textui.TestRunner.run (suite()); |
15 |
> |
public static void main(String[] args) { |
16 |
> |
junit.textui.TestRunner.run(suite()); |
17 |
|
} |
18 |
|
public static Test suite() { |
19 |
|
return new TestSuite(AtomicIntegerArrayTest.class); |
20 |
|
} |
21 |
|
|
23 |
– |
|
22 |
|
/** |
23 |
|
* constructor creates array of given size with all elements zero |
24 |
|
*/ |
25 |
|
public void testConstructor() { |
26 |
< |
AtomicIntegerArray ai = new AtomicIntegerArray(SIZE); |
27 |
< |
for (int i = 0; i < SIZE; ++i) |
28 |
< |
assertEquals(0,ai.get(i)); |
26 |
> |
AtomicIntegerArray aa = new AtomicIntegerArray(SIZE); |
27 |
> |
for (int i = 0; i < SIZE; i++) |
28 |
> |
assertEquals(0, aa.get(i)); |
29 |
|
} |
30 |
|
|
31 |
|
/** |
34 |
|
public void testConstructor2NPE() { |
35 |
|
try { |
36 |
|
int[] a = null; |
37 |
< |
AtomicIntegerArray ai = new AtomicIntegerArray(a); |
37 |
> |
AtomicIntegerArray aa = new AtomicIntegerArray(a); |
38 |
|
shouldThrow(); |
39 |
|
} catch (NullPointerException success) {} |
40 |
|
} |
43 |
|
* constructor with array is of same size and has all elements |
44 |
|
*/ |
45 |
|
public void testConstructor2() { |
46 |
< |
int[] a = { 17, 3, -42, 99, -7}; |
47 |
< |
AtomicIntegerArray ai = new AtomicIntegerArray(a); |
48 |
< |
assertEquals(a.length, ai.length()); |
49 |
< |
for (int i = 0; i < a.length; ++i) |
50 |
< |
assertEquals(a[i], ai.get(i)); |
46 |
> |
int[] a = { 17, 3, -42, 99, -7 }; |
47 |
> |
AtomicIntegerArray aa = new AtomicIntegerArray(a); |
48 |
> |
assertEquals(a.length, aa.length()); |
49 |
> |
for (int i = 0; i < a.length; i++) |
50 |
> |
assertEquals(a[i], aa.get(i)); |
51 |
|
} |
52 |
|
|
53 |
|
/** |
54 |
|
* get and set for out of bound indices throw IndexOutOfBoundsException |
55 |
|
*/ |
56 |
|
public void testIndexing() { |
57 |
< |
AtomicIntegerArray ai = new AtomicIntegerArray(SIZE); |
58 |
< |
try { |
59 |
< |
ai.get(SIZE); |
60 |
< |
shouldThrow(); |
61 |
< |
} catch (IndexOutOfBoundsException success) { |
62 |
< |
} |
63 |
< |
try { |
64 |
< |
ai.get(-1); |
65 |
< |
shouldThrow(); |
66 |
< |
} catch (IndexOutOfBoundsException success) { |
67 |
< |
} |
68 |
< |
try { |
69 |
< |
ai.set(SIZE, 0); |
70 |
< |
shouldThrow(); |
71 |
< |
} catch (IndexOutOfBoundsException success) { |
72 |
< |
} |
73 |
< |
try { |
74 |
< |
ai.set(-1, 0); |
75 |
< |
shouldThrow(); |
76 |
< |
} catch (IndexOutOfBoundsException success) { |
57 |
> |
AtomicIntegerArray aa = new AtomicIntegerArray(SIZE); |
58 |
> |
for (int index : new int[] { -1, SIZE }) { |
59 |
> |
try { |
60 |
> |
aa.get(index); |
61 |
> |
shouldThrow(); |
62 |
> |
} catch (IndexOutOfBoundsException success) {} |
63 |
> |
try { |
64 |
> |
aa.set(index, 1); |
65 |
> |
shouldThrow(); |
66 |
> |
} catch (IndexOutOfBoundsException success) {} |
67 |
> |
try { |
68 |
> |
aa.lazySet(index, 1); |
69 |
> |
shouldThrow(); |
70 |
> |
} catch (IndexOutOfBoundsException success) {} |
71 |
> |
try { |
72 |
> |
aa.compareAndSet(index, 1, 2); |
73 |
> |
shouldThrow(); |
74 |
> |
} catch (IndexOutOfBoundsException success) {} |
75 |
> |
try { |
76 |
> |
aa.weakCompareAndSet(index, 1, 2); |
77 |
> |
shouldThrow(); |
78 |
> |
} catch (IndexOutOfBoundsException success) {} |
79 |
> |
try { |
80 |
> |
aa.getAndAdd(index, 1); |
81 |
> |
shouldThrow(); |
82 |
> |
} catch (IndexOutOfBoundsException success) {} |
83 |
> |
try { |
84 |
> |
aa.addAndGet(index, 1); |
85 |
> |
shouldThrow(); |
86 |
> |
} catch (IndexOutOfBoundsException success) {} |
87 |
|
} |
88 |
|
} |
89 |
|
|
91 |
|
* get returns the last value set at index |
92 |
|
*/ |
93 |
|
public void testGetSet() { |
94 |
< |
AtomicIntegerArray ai = new AtomicIntegerArray(SIZE); |
95 |
< |
for (int i = 0; i < SIZE; ++i) { |
96 |
< |
ai.set(i, 1); |
97 |
< |
assertEquals(1,ai.get(i)); |
98 |
< |
ai.set(i, 2); |
99 |
< |
assertEquals(2,ai.get(i)); |
100 |
< |
ai.set(i, -3); |
101 |
< |
assertEquals(-3,ai.get(i)); |
94 |
> |
AtomicIntegerArray aa = new AtomicIntegerArray(SIZE); |
95 |
> |
for (int i = 0; i < SIZE; i++) { |
96 |
> |
aa.set(i, 1); |
97 |
> |
assertEquals(1, aa.get(i)); |
98 |
> |
aa.set(i, 2); |
99 |
> |
assertEquals(2, aa.get(i)); |
100 |
> |
aa.set(i, -3); |
101 |
> |
assertEquals(-3, aa.get(i)); |
102 |
|
} |
103 |
|
} |
104 |
|
|
106 |
|
* get returns the last value lazySet at index by same thread |
107 |
|
*/ |
108 |
|
public void testGetLazySet() { |
109 |
< |
AtomicIntegerArray ai = new AtomicIntegerArray(SIZE); |
110 |
< |
for (int i = 0; i < SIZE; ++i) { |
111 |
< |
ai.lazySet(i, 1); |
112 |
< |
assertEquals(1,ai.get(i)); |
113 |
< |
ai.lazySet(i, 2); |
114 |
< |
assertEquals(2,ai.get(i)); |
115 |
< |
ai.lazySet(i, -3); |
116 |
< |
assertEquals(-3,ai.get(i)); |
109 |
> |
AtomicIntegerArray aa = new AtomicIntegerArray(SIZE); |
110 |
> |
for (int i = 0; i < SIZE; i++) { |
111 |
> |
aa.lazySet(i, 1); |
112 |
> |
assertEquals(1, aa.get(i)); |
113 |
> |
aa.lazySet(i, 2); |
114 |
> |
assertEquals(2, aa.get(i)); |
115 |
> |
aa.lazySet(i, -3); |
116 |
> |
assertEquals(-3, aa.get(i)); |
117 |
|
} |
118 |
|
} |
119 |
|
|
121 |
|
* compareAndSet succeeds in changing value if equal to expected else fails |
122 |
|
*/ |
123 |
|
public void testCompareAndSet() { |
124 |
< |
AtomicIntegerArray ai = new AtomicIntegerArray(SIZE); |
125 |
< |
for (int i = 0; i < SIZE; ++i) { |
126 |
< |
ai.set(i, 1); |
127 |
< |
assertTrue(ai.compareAndSet(i, 1,2)); |
128 |
< |
assertTrue(ai.compareAndSet(i, 2,-4)); |
129 |
< |
assertEquals(-4,ai.get(i)); |
130 |
< |
assertFalse(ai.compareAndSet(i, -5,7)); |
131 |
< |
assertFalse((7 == ai.get(i))); |
132 |
< |
assertTrue(ai.compareAndSet(i, -4,7)); |
133 |
< |
assertEquals(7,ai.get(i)); |
124 |
> |
AtomicIntegerArray aa = new AtomicIntegerArray(SIZE); |
125 |
> |
for (int i = 0; i < SIZE; i++) { |
126 |
> |
aa.set(i, 1); |
127 |
> |
assertTrue(aa.compareAndSet(i, 1, 2)); |
128 |
> |
assertTrue(aa.compareAndSet(i, 2, -4)); |
129 |
> |
assertEquals(-4, aa.get(i)); |
130 |
> |
assertFalse(aa.compareAndSet(i, -5, 7)); |
131 |
> |
assertEquals(-4, aa.get(i)); |
132 |
> |
assertTrue(aa.compareAndSet(i, -4, 7)); |
133 |
> |
assertEquals(7, aa.get(i)); |
134 |
|
} |
135 |
|
} |
136 |
|
|
151 |
|
assertTrue(a.compareAndSet(0, 1, 2)); |
152 |
|
t.join(LONG_DELAY_MS); |
153 |
|
assertFalse(t.isAlive()); |
154 |
< |
assertEquals(a.get(0), 3); |
154 |
> |
assertEquals(3, a.get(0)); |
155 |
|
} |
156 |
|
|
157 |
|
/** |
159 |
|
* to expected |
160 |
|
*/ |
161 |
|
public void testWeakCompareAndSet() { |
162 |
< |
AtomicIntegerArray ai = new AtomicIntegerArray(SIZE); |
163 |
< |
for (int i = 0; i < SIZE; ++i) { |
164 |
< |
ai.set(i, 1); |
165 |
< |
while (!ai.weakCompareAndSet(i, 1,2)); |
166 |
< |
while (!ai.weakCompareAndSet(i, 2,-4)); |
167 |
< |
assertEquals(-4,ai.get(i)); |
168 |
< |
while (!ai.weakCompareAndSet(i, -4,7)); |
169 |
< |
assertEquals(7,ai.get(i)); |
162 |
> |
AtomicIntegerArray aa = new AtomicIntegerArray(SIZE); |
163 |
> |
for (int i = 0; i < SIZE; i++) { |
164 |
> |
aa.set(i, 1); |
165 |
> |
while (!aa.weakCompareAndSet(i, 1, 2)); |
166 |
> |
while (!aa.weakCompareAndSet(i, 2, -4)); |
167 |
> |
assertEquals(-4, aa.get(i)); |
168 |
> |
while (!aa.weakCompareAndSet(i, -4, 7)); |
169 |
> |
assertEquals(7, aa.get(i)); |
170 |
|
} |
171 |
|
} |
172 |
|
|
173 |
|
/** |
174 |
< |
* getAndSet returns previous value and sets to given value at given index |
174 |
> |
* getAndSet returns previous value and sets to given value at given index |
175 |
|
*/ |
176 |
|
public void testGetAndSet() { |
177 |
< |
AtomicIntegerArray ai = new AtomicIntegerArray(SIZE); |
178 |
< |
for (int i = 0; i < SIZE; ++i) { |
179 |
< |
ai.set(i, 1); |
180 |
< |
assertEquals(1,ai.getAndSet(i,0)); |
181 |
< |
assertEquals(0,ai.getAndSet(i,-10)); |
182 |
< |
assertEquals(-10,ai.getAndSet(i,1)); |
177 |
> |
AtomicIntegerArray aa = new AtomicIntegerArray(SIZE); |
178 |
> |
for (int i = 0; i < SIZE; i++) { |
179 |
> |
aa.set(i, 1); |
180 |
> |
assertEquals(1, aa.getAndSet(i, 0)); |
181 |
> |
assertEquals(0, aa.getAndSet(i, -10)); |
182 |
> |
assertEquals(-10, aa.getAndSet(i, 1)); |
183 |
|
} |
184 |
|
} |
185 |
|
|
186 |
|
/** |
187 |
< |
* getAndAdd returns previous value and adds given value |
187 |
> |
* getAndAdd returns previous value and adds given value |
188 |
|
*/ |
189 |
|
public void testGetAndAdd() { |
190 |
< |
AtomicIntegerArray ai = new AtomicIntegerArray(SIZE); |
191 |
< |
for (int i = 0; i < SIZE; ++i) { |
192 |
< |
ai.set(i, 1); |
193 |
< |
assertEquals(1,ai.getAndAdd(i,2)); |
194 |
< |
assertEquals(3,ai.get(i)); |
195 |
< |
assertEquals(3,ai.getAndAdd(i,-4)); |
196 |
< |
assertEquals(-1,ai.get(i)); |
190 |
> |
AtomicIntegerArray aa = new AtomicIntegerArray(SIZE); |
191 |
> |
for (int i = 0; i < SIZE; i++) { |
192 |
> |
aa.set(i, 1); |
193 |
> |
assertEquals(1, aa.getAndAdd(i, 2)); |
194 |
> |
assertEquals(3, aa.get(i)); |
195 |
> |
assertEquals(3, aa.getAndAdd(i, -4)); |
196 |
> |
assertEquals(-1, aa.get(i)); |
197 |
|
} |
198 |
|
} |
199 |
|
|
201 |
|
* getAndDecrement returns previous value and decrements |
202 |
|
*/ |
203 |
|
public void testGetAndDecrement() { |
204 |
< |
AtomicIntegerArray ai = new AtomicIntegerArray(SIZE); |
205 |
< |
for (int i = 0; i < SIZE; ++i) { |
206 |
< |
ai.set(i, 1); |
207 |
< |
assertEquals(1,ai.getAndDecrement(i)); |
208 |
< |
assertEquals(0,ai.getAndDecrement(i)); |
209 |
< |
assertEquals(-1,ai.getAndDecrement(i)); |
204 |
> |
AtomicIntegerArray aa = new AtomicIntegerArray(SIZE); |
205 |
> |
for (int i = 0; i < SIZE; i++) { |
206 |
> |
aa.set(i, 1); |
207 |
> |
assertEquals(1, aa.getAndDecrement(i)); |
208 |
> |
assertEquals(0, aa.getAndDecrement(i)); |
209 |
> |
assertEquals(-1, aa.getAndDecrement(i)); |
210 |
|
} |
211 |
|
} |
212 |
|
|
214 |
|
* getAndIncrement returns previous value and increments |
215 |
|
*/ |
216 |
|
public void testGetAndIncrement() { |
217 |
< |
AtomicIntegerArray ai = new AtomicIntegerArray(SIZE); |
218 |
< |
for (int i = 0; i < SIZE; ++i) { |
219 |
< |
ai.set(i, 1); |
220 |
< |
assertEquals(1,ai.getAndIncrement(i)); |
221 |
< |
assertEquals(2,ai.get(i)); |
222 |
< |
ai.set(i,-2); |
223 |
< |
assertEquals(-2,ai.getAndIncrement(i)); |
224 |
< |
assertEquals(-1,ai.getAndIncrement(i)); |
225 |
< |
assertEquals(0,ai.getAndIncrement(i)); |
226 |
< |
assertEquals(1,ai.get(i)); |
217 |
> |
AtomicIntegerArray aa = new AtomicIntegerArray(SIZE); |
218 |
> |
for (int i = 0; i < SIZE; i++) { |
219 |
> |
aa.set(i, 1); |
220 |
> |
assertEquals(1, aa.getAndIncrement(i)); |
221 |
> |
assertEquals(2, aa.get(i)); |
222 |
> |
aa.set(i, -2); |
223 |
> |
assertEquals(-2, aa.getAndIncrement(i)); |
224 |
> |
assertEquals(-1, aa.getAndIncrement(i)); |
225 |
> |
assertEquals(0, aa.getAndIncrement(i)); |
226 |
> |
assertEquals(1, aa.get(i)); |
227 |
|
} |
228 |
|
} |
229 |
|
|
230 |
|
/** |
231 |
< |
* addAndGet adds given value to current, and returns current value |
231 |
> |
* addAndGet adds given value to current, and returns current value |
232 |
|
*/ |
233 |
|
public void testAddAndGet() { |
234 |
< |
AtomicIntegerArray ai = new AtomicIntegerArray(SIZE); |
235 |
< |
for (int i = 0; i < SIZE; ++i) { |
236 |
< |
ai.set(i, 1); |
237 |
< |
assertEquals(3,ai.addAndGet(i,2)); |
238 |
< |
assertEquals(3,ai.get(i)); |
239 |
< |
assertEquals(-1,ai.addAndGet(i,-4)); |
240 |
< |
assertEquals(-1,ai.get(i)); |
234 |
> |
AtomicIntegerArray aa = new AtomicIntegerArray(SIZE); |
235 |
> |
for (int i = 0; i < SIZE; i++) { |
236 |
> |
aa.set(i, 1); |
237 |
> |
assertEquals(3, aa.addAndGet(i, 2)); |
238 |
> |
assertEquals(3, aa.get(i)); |
239 |
> |
assertEquals(-1, aa.addAndGet(i, -4)); |
240 |
> |
assertEquals(-1, aa.get(i)); |
241 |
|
} |
242 |
|
} |
243 |
|
|
245 |
|
* decrementAndGet decrements and returns current value |
246 |
|
*/ |
247 |
|
public void testDecrementAndGet() { |
248 |
< |
AtomicIntegerArray ai = new AtomicIntegerArray(SIZE); |
249 |
< |
for (int i = 0; i < SIZE; ++i) { |
250 |
< |
ai.set(i, 1); |
251 |
< |
assertEquals(0,ai.decrementAndGet(i)); |
252 |
< |
assertEquals(-1,ai.decrementAndGet(i)); |
253 |
< |
assertEquals(-2,ai.decrementAndGet(i)); |
254 |
< |
assertEquals(-2,ai.get(i)); |
248 |
> |
AtomicIntegerArray aa = new AtomicIntegerArray(SIZE); |
249 |
> |
for (int i = 0; i < SIZE; i++) { |
250 |
> |
aa.set(i, 1); |
251 |
> |
assertEquals(0, aa.decrementAndGet(i)); |
252 |
> |
assertEquals(-1, aa.decrementAndGet(i)); |
253 |
> |
assertEquals(-2, aa.decrementAndGet(i)); |
254 |
> |
assertEquals(-2, aa.get(i)); |
255 |
|
} |
256 |
|
} |
257 |
|
|
258 |
|
/** |
259 |
< |
* incrementAndGet increments and returns current value |
259 |
> |
* incrementAndGet increments and returns current value |
260 |
|
*/ |
261 |
|
public void testIncrementAndGet() { |
262 |
< |
AtomicIntegerArray ai = new AtomicIntegerArray(SIZE); |
263 |
< |
for (int i = 0; i < SIZE; ++i) { |
264 |
< |
ai.set(i, 1); |
265 |
< |
assertEquals(2,ai.incrementAndGet(i)); |
266 |
< |
assertEquals(2,ai.get(i)); |
267 |
< |
ai.set(i, -2); |
268 |
< |
assertEquals(-1,ai.incrementAndGet(i)); |
269 |
< |
assertEquals(0,ai.incrementAndGet(i)); |
270 |
< |
assertEquals(1,ai.incrementAndGet(i)); |
271 |
< |
assertEquals(1,ai.get(i)); |
262 |
> |
AtomicIntegerArray aa = new AtomicIntegerArray(SIZE); |
263 |
> |
for (int i = 0; i < SIZE; i++) { |
264 |
> |
aa.set(i, 1); |
265 |
> |
assertEquals(2, aa.incrementAndGet(i)); |
266 |
> |
assertEquals(2, aa.get(i)); |
267 |
> |
aa.set(i, -2); |
268 |
> |
assertEquals(-1, aa.incrementAndGet(i)); |
269 |
> |
assertEquals(0, aa.incrementAndGet(i)); |
270 |
> |
assertEquals(1, aa.incrementAndGet(i)); |
271 |
> |
assertEquals(1, aa.get(i)); |
272 |
|
} |
273 |
|
} |
274 |
|
|
275 |
< |
static final int COUNTDOWN = 100000; |
276 |
< |
|
269 |
< |
class Counter implements Runnable { |
270 |
< |
final AtomicIntegerArray ai; |
275 |
> |
class Counter extends CheckedRunnable { |
276 |
> |
final AtomicIntegerArray aa; |
277 |
|
volatile int counts; |
278 |
< |
Counter(AtomicIntegerArray a) { ai = a; } |
279 |
< |
public void run() { |
278 |
> |
Counter(AtomicIntegerArray a) { aa = a; } |
279 |
> |
public void realRun() { |
280 |
|
for (;;) { |
281 |
|
boolean done = true; |
282 |
< |
for (int i = 0; i < ai.length(); ++i) { |
283 |
< |
int v = ai.get(i); |
284 |
< |
threadAssertTrue(v >= 0); |
282 |
> |
for (int i = 0; i < aa.length(); i++) { |
283 |
> |
int v = aa.get(i); |
284 |
> |
assertTrue(v >= 0); |
285 |
|
if (v != 0) { |
286 |
|
done = false; |
287 |
< |
if (ai.compareAndSet(i, v, v-1)) |
287 |
> |
if (aa.compareAndSet(i, v, v-1)) |
288 |
|
++counts; |
289 |
|
} |
290 |
|
} |
299 |
|
* update a number of times equal to total count |
300 |
|
*/ |
301 |
|
public void testCountingInMultipleThreads() throws InterruptedException { |
302 |
< |
final AtomicIntegerArray ai = new AtomicIntegerArray(SIZE); |
303 |
< |
for (int i = 0; i < SIZE; ++i) |
304 |
< |
ai.set(i, COUNTDOWN); |
305 |
< |
Counter c1 = new Counter(ai); |
306 |
< |
Counter c2 = new Counter(ai); |
302 |
> |
final AtomicIntegerArray aa = new AtomicIntegerArray(SIZE); |
303 |
> |
int countdown = 10000; |
304 |
> |
for (int i = 0; i < SIZE; i++) |
305 |
> |
aa.set(i, countdown); |
306 |
> |
Counter c1 = new Counter(aa); |
307 |
> |
Counter c2 = new Counter(aa); |
308 |
|
Thread t1 = new Thread(c1); |
309 |
|
Thread t2 = new Thread(c2); |
310 |
|
t1.start(); |
311 |
|
t2.start(); |
312 |
|
t1.join(); |
313 |
|
t2.join(); |
314 |
< |
assertEquals(c1.counts+c2.counts, SIZE * COUNTDOWN); |
314 |
> |
assertEquals(c1.counts+c2.counts, SIZE * countdown); |
315 |
|
} |
316 |
|
|
310 |
– |
|
317 |
|
/** |
318 |
|
* a deserialized serialized array holds same values |
319 |
|
*/ |
320 |
|
public void testSerialization() throws Exception { |
321 |
< |
AtomicIntegerArray l = new AtomicIntegerArray(SIZE); |
322 |
< |
for (int i = 0; i < SIZE; ++i) |
323 |
< |
l.set(i, -i); |
324 |
< |
|
325 |
< |
ByteArrayOutputStream bout = new ByteArrayOutputStream(10000); |
326 |
< |
ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout)); |
327 |
< |
out.writeObject(l); |
328 |
< |
out.close(); |
323 |
< |
|
324 |
< |
ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray()); |
325 |
< |
ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin)); |
326 |
< |
AtomicIntegerArray r = (AtomicIntegerArray) in.readObject(); |
327 |
< |
for (int i = 0; i < SIZE; ++i) { |
328 |
< |
assertEquals(l.get(i), r.get(i)); |
321 |
> |
AtomicIntegerArray x = new AtomicIntegerArray(SIZE); |
322 |
> |
for (int i = 0; i < SIZE; i++) |
323 |
> |
x.set(i, -i); |
324 |
> |
AtomicIntegerArray y = serialClone(x); |
325 |
> |
assertNotSame(x, y); |
326 |
> |
assertEquals(x.length(), y.length()); |
327 |
> |
for (int i = 0; i < SIZE; i++) { |
328 |
> |
assertEquals(x.get(i), y.get(i)); |
329 |
|
} |
330 |
|
} |
331 |
|
|
332 |
– |
|
332 |
|
/** |
333 |
|
* toString returns current value. |
334 |
|
*/ |
335 |
|
public void testToString() { |
336 |
< |
int[] a = { 17, 3, -42, 99, -7}; |
337 |
< |
AtomicIntegerArray ai = new AtomicIntegerArray(a); |
338 |
< |
assertEquals(Arrays.toString(a), ai.toString()); |
336 |
> |
int[] a = { 17, 3, -42, 99, -7 }; |
337 |
> |
AtomicIntegerArray aa = new AtomicIntegerArray(a); |
338 |
> |
assertEquals(Arrays.toString(a), aa.toString()); |
339 |
|
} |
340 |
|
|
341 |
|
} |