--- jsr166/src/test/tck/AtomicLongArray9Test.java 2016/08/24 22:22:39 1.2 +++ jsr166/src/test/tck/AtomicLongArray9Test.java 2019/02/22 19:27:47 1.4 @@ -24,7 +24,8 @@ public class AtomicLongArray9Test extend AtomicLongArray aa = new AtomicLongArray(SIZE); for (int index : new int[] { -1, SIZE }) { final int j = index; - final Runnable[] tasks = { + assertThrows( + IndexOutOfBoundsException.class, () -> aa.getPlain(j), () -> aa.getOpaque(j), () -> aa.getAcquire(j), @@ -34,12 +35,10 @@ public class AtomicLongArray9Test extend () -> aa.compareAndExchange(j, 1, 2), () -> aa.compareAndExchangeAcquire(j, 1, 2), () -> aa.compareAndExchangeRelease(j, 1, 2), + () -> aa.weakCompareAndSetPlain(j, 1, 2), () -> aa.weakCompareAndSetVolatile(j, 1, 2), () -> aa.weakCompareAndSetAcquire(j, 1, 2), - () -> aa.weakCompareAndSetRelease(j, 1, 2), - }; - - assertThrows(IndexOutOfBoundsException.class, tasks); + () -> aa.weakCompareAndSetRelease(j, 1, 2)); } } @@ -186,6 +185,22 @@ public class AtomicLongArray9Test extend assertEquals(7, aa.get(i)); } } + + /** + * repeated weakCompareAndSetPlain succeeds in changing value when equal + * to expected + */ + public void testWeakCompareAndSetPlain() { + AtomicLongArray aa = new AtomicLongArray(SIZE); + for (int i = 0; i < SIZE; i++) { + aa.set(i, 1); + do {} while (!aa.weakCompareAndSetPlain(i, 1, 2)); + do {} while (!aa.weakCompareAndSetPlain(i, 2, -4)); + assertEquals(-4, aa.get(i)); + do {} while (!aa.weakCompareAndSetPlain(i, -4, 7)); + assertEquals(7, aa.get(i)); + } + } /** * repeated weakCompareAndSetVolatile succeeds in changing value when equal