25 |
|
AtomicIntegerArray aa = new AtomicIntegerArray(SIZE); |
26 |
|
for (int index : new int[] { -1, SIZE }) { |
27 |
|
final int j = index; |
28 |
< |
final Runnable[] tasks = { |
28 |
> |
|
29 |
> |
assertThrows( |
30 |
> |
IndexOutOfBoundsException.class, |
31 |
|
() -> aa.getPlain(j), |
32 |
|
() -> aa.getOpaque(j), |
33 |
|
() -> aa.getAcquire(j), |
37 |
|
() -> aa.compareAndExchange(j, 1, 2), |
38 |
|
() -> aa.compareAndExchangeAcquire(j, 1, 2), |
39 |
|
() -> aa.compareAndExchangeRelease(j, 1, 2), |
40 |
+ |
() -> aa.weakCompareAndSetPlain(j, 1, 2), |
41 |
|
() -> aa.weakCompareAndSetVolatile(j, 1, 2), |
42 |
|
() -> aa.weakCompareAndSetAcquire(j, 1, 2), |
43 |
< |
() -> aa.weakCompareAndSetRelease(j, 1, 2), |
41 |
< |
}; |
42 |
< |
|
43 |
< |
assertThrows(IndexOutOfBoundsException.class, tasks); |
43 |
> |
() -> aa.weakCompareAndSetRelease(j, 1, 2)); |
44 |
|
} |
45 |
|
} |
46 |
|
|
187 |
|
assertEquals(7, aa.get(i)); |
188 |
|
} |
189 |
|
} |
190 |
+ |
|
191 |
+ |
/** |
192 |
+ |
* repeated weakCompareAndSetPlain succeeds in changing value when equal |
193 |
+ |
* to expected |
194 |
+ |
*/ |
195 |
+ |
public void testWeakCompareAndSetPlain() { |
196 |
+ |
AtomicIntegerArray aa = new AtomicIntegerArray(SIZE); |
197 |
+ |
for (int i = 0; i < SIZE; i++) { |
198 |
+ |
aa.set(i, 1); |
199 |
+ |
do {} while (!aa.weakCompareAndSetPlain(i, 1, 2)); |
200 |
+ |
do {} while (!aa.weakCompareAndSetPlain(i, 2, -4)); |
201 |
+ |
assertEquals(-4, aa.get(i)); |
202 |
+ |
do {} while (!aa.weakCompareAndSetPlain(i, -4, 7)); |
203 |
+ |
assertEquals(7, aa.get(i)); |
204 |
+ |
} |
205 |
+ |
} |
206 |
|
|
207 |
|
/** |
208 |
|
* repeated weakCompareAndSetVolatile succeeds in changing value when equal |