ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/tck/AtomicLongArray9Test.java
(Generate patch)

Comparing jsr166/src/test/tck/AtomicLongArray9Test.java (file contents):
Revision 1.2 by jsr166, Wed Aug 24 22:22:39 2016 UTC vs.
Revision 1.4 by jsr166, Fri Feb 22 19:27:47 2019 UTC

# Line 24 | Line 24 | public class AtomicLongArray9Test extend
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),
# Line 34 | Line 35 | public class AtomicLongArray9Test extend
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  
# Line 186 | Line 185 | public class AtomicLongArray9Test extend
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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines