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