--- jsr166/src/test/tck/AtomicReferenceArray9Test.java 2016/06/17 19:00:48 1.1 +++ jsr166/src/test/tck/AtomicReferenceArray9Test.java 2019/02/22 19:27:47 1.4 @@ -4,7 +4,6 @@ * http://creativecommons.org/publicdomain/zero/1.0/ */ -import java.util.Arrays; import java.util.concurrent.atomic.AtomicReferenceArray; import junit.framework.Test; @@ -25,7 +24,8 @@ public class AtomicReferenceArray9Test e AtomicReferenceArray aa = new AtomicReferenceArray<>(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), @@ -35,12 +35,10 @@ public class AtomicReferenceArray9Test e () -> aa.compareAndExchange(j, null, null), () -> aa.compareAndExchangeAcquire(j, null, null), () -> aa.compareAndExchangeRelease(j, null, null), + () -> aa.weakCompareAndSetPlain(j, null, null), () -> aa.weakCompareAndSetVolatile(j, null, null), () -> aa.weakCompareAndSetAcquire(j, null, null), - () -> aa.weakCompareAndSetRelease(j, null, null), - }; - - assertThrows(IndexOutOfBoundsException.class, tasks); + () -> aa.weakCompareAndSetRelease(j, null, null)); } } @@ -187,6 +185,22 @@ public class AtomicReferenceArray9Test e assertEquals(seven, aa.get(i)); } } + + /** + * repeated weakCompareAndSetPlain succeeds in changing value when equal + * to expected + */ + public void testWeakCompareAndSetPlain() { + AtomicReferenceArray aa = new AtomicReferenceArray<>(SIZE); + for (int i = 0; i < SIZE; i++) { + aa.set(i, one); + do {} while (!aa.weakCompareAndSetPlain(i, one, two)); + do {} while (!aa.weakCompareAndSetPlain(i, two, m4)); + assertEquals(m4, aa.get(i)); + do {} while (!aa.weakCompareAndSetPlain(i, m4, seven)); + assertEquals(seven, aa.get(i)); + } + } /** * repeated weakCompareAndSetVolatile succeeds in changing value when equal