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

Comparing jsr166/src/test/tck/AtomicIntegerArray9Test.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 25 | Line 25 | public class AtomicIntegerArray9Test ext
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),
# Line 35 | Line 37 | public class AtomicIntegerArray9Test ext
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  
# Line 187 | Line 187 | public class AtomicIntegerArray9Test ext
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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines