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

Comparing jsr166/src/test/tck/AtomicIntegerArrayTest.java (file contents):
Revision 1.14 by jsr166, Tue Nov 17 02:37:16 2009 UTC vs.
Revision 1.20 by jsr166, Tue Mar 15 19:47:06 2011 UTC

# Line 1 | Line 1
1   /*
2   * Written by Doug Lea with assistance from members of JCP JSR-166
3   * Expert Group and released to the public domain, as explained at
4 < * http://creativecommons.org/licenses/publicdomain
4 > * http://creativecommons.org/publicdomain/zero/1.0/
5   * Other contributors include Andrew Wright, Jeffrey Hayes,
6   * Pat Fisher, Mike Judd.
7   */
# Line 13 | Line 13 | import java.util.*;
13  
14   public class AtomicIntegerArrayTest extends JSR166TestCase {
15  
16 <    public static void main (String[] args) {
17 <        junit.textui.TestRunner.run (suite());
16 >    public static void main(String[] args) {
17 >        junit.textui.TestRunner.run(suite());
18      }
19      public static Test suite() {
20          return new TestSuite(AtomicIntegerArrayTest.class);
# Line 120 | Line 120 | public class AtomicIntegerArrayTest exte
120              assertTrue(ai.compareAndSet(i, 2,-4));
121              assertEquals(-4,ai.get(i));
122              assertFalse(ai.compareAndSet(i, -5,7));
123 <            assertFalse((7 == ai.get(i)));
123 >            assertEquals(-4,ai.get(i));
124              assertTrue(ai.compareAndSet(i, -4,7));
125              assertEquals(7,ai.get(i));
126          }
# Line 133 | Line 133 | public class AtomicIntegerArrayTest exte
133      public void testCompareAndSetInMultipleThreads() throws Exception {
134          final AtomicIntegerArray a = new AtomicIntegerArray(1);
135          a.set(0, 1);
136 <        Thread t = new Thread(new Runnable() {
137 <                public void run() {
138 <                    while (!a.compareAndSet(0, 2, 3)) Thread.yield();
139 <                }});
136 >        Thread t = new Thread(new CheckedRunnable() {
137 >            public void realRun() {
138 >                while (!a.compareAndSet(0, 2, 3))
139 >                    Thread.yield();
140 >            }});
141  
142          t.start();
143          assertTrue(a.compareAndSet(0, 1, 2));
# Line 162 | Line 163 | public class AtomicIntegerArrayTest exte
163      }
164  
165      /**
166 <     *  getAndSet returns previous value and sets to given value at given index
166 >     * getAndSet returns previous value and sets to given value at given index
167       */
168      public void testGetAndSet() {
169          AtomicIntegerArray ai = new AtomicIntegerArray(SIZE);
# Line 175 | Line 176 | public class AtomicIntegerArrayTest exte
176      }
177  
178      /**
179 <     *  getAndAdd returns previous value and adds given value
179 >     * getAndAdd returns previous value and adds given value
180       */
181      public void testGetAndAdd() {
182          AtomicIntegerArray ai = new AtomicIntegerArray(SIZE);
# Line 219 | Line 220 | public class AtomicIntegerArrayTest exte
220      }
221  
222      /**
223 <     *  addAndGet adds given value to current, and returns current value
223 >     * addAndGet adds given value to current, and returns current value
224       */
225      public void testAddAndGet() {
226          AtomicIntegerArray ai = new AtomicIntegerArray(SIZE);
# Line 247 | Line 248 | public class AtomicIntegerArrayTest exte
248      }
249  
250      /**
251 <     *  incrementAndGet increments and returns current value
251 >     * incrementAndGet increments and returns current value
252       */
253      public void testIncrementAndGet() {
254          AtomicIntegerArray ai = new AtomicIntegerArray(SIZE);
# Line 265 | Line 266 | public class AtomicIntegerArrayTest exte
266  
267      static final int COUNTDOWN = 100000;
268  
269 <    class Counter implements Runnable {
269 >    class Counter extends CheckedRunnable {
270          final AtomicIntegerArray ai;
271          volatile int counts;
272          Counter(AtomicIntegerArray a) { ai = a; }
273 <        public void run() {
273 >        public void realRun() {
274              for (;;) {
275                  boolean done = true;
276                  for (int i = 0; i < ai.length(); ++i) {
277                      int v = ai.get(i);
278 <                    threadAssertTrue(v >= 0);
278 >                    assertTrue(v >= 0);
279                      if (v != 0) {
280                          done = false;
281                          if (ai.compareAndSet(i, v, v-1))

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines