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

Comparing jsr166/src/test/tck/AtomicLongArrayTest.java (file contents):
Revision 1.13 by jsr166, Tue Nov 17 02:48:16 2009 UTC vs.
Revision 1.19 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 12 | Line 12 | import java.io.*;
12   import java.util.*;
13  
14   public class AtomicLongArrayTest extends JSR166TestCase {
15 <    public static void main (String[] args) {
16 <        junit.textui.TestRunner.run (suite());
15 >    public static void main(String[] args) {
16 >        junit.textui.TestRunner.run(suite());
17      }
18      public static Test suite() {
19          return new TestSuite(AtomicLongArrayTest.class);
# Line 118 | Line 118 | public class AtomicLongArrayTest extends
118              assertTrue(ai.compareAndSet(i, 2,-4));
119              assertEquals(-4,ai.get(i));
120              assertFalse(ai.compareAndSet(i, -5,7));
121 <            assertFalse((7 == ai.get(i)));
121 >            assertEquals(-4,ai.get(i));
122              assertTrue(ai.compareAndSet(i, -4,7));
123              assertEquals(7,ai.get(i));
124          }
# Line 131 | Line 131 | public class AtomicLongArrayTest extends
131      public void testCompareAndSetInMultipleThreads() throws InterruptedException {
132          final AtomicLongArray a = new AtomicLongArray(1);
133          a.set(0, 1);
134 <        Thread t = new Thread(new Runnable() {
135 <                public void run() {
136 <                    while (!a.compareAndSet(0, 2, 3)) Thread.yield();
137 <                }});
134 >        Thread t = new Thread(new CheckedRunnable() {
135 >            public void realRun() {
136 >                while (!a.compareAndSet(0, 2, 3))
137 >                    Thread.yield();
138 >            }});
139  
140          t.start();
141          assertTrue(a.compareAndSet(0, 1, 2));
# Line 160 | Line 161 | public class AtomicLongArrayTest extends
161      }
162  
163      /**
164 <     *  getAndSet returns previous value and sets to given value at given index
164 >     * getAndSet returns previous value and sets to given value at given index
165       */
166      public void testGetAndSet() {
167          AtomicLongArray ai = new AtomicLongArray(SIZE);
# Line 173 | Line 174 | public class AtomicLongArrayTest extends
174      }
175  
176      /**
177 <     *  getAndAdd returns previous value and adds given value
177 >     * getAndAdd returns previous value and adds given value
178       */
179      public void testGetAndAdd() {
180          AtomicLongArray ai = new AtomicLongArray(SIZE);
# Line 217 | Line 218 | public class AtomicLongArrayTest extends
218      }
219  
220      /**
221 <     *  addAndGet adds given value to current, and returns current value
221 >     * addAndGet adds given value to current, and returns current value
222       */
223      public void testAddAndGet() {
224          AtomicLongArray ai = new AtomicLongArray(SIZE);
# Line 263 | Line 264 | public class AtomicLongArrayTest extends
264  
265      static final long COUNTDOWN = 100000;
266  
267 <    class Counter implements Runnable {
267 >    class Counter extends CheckedRunnable {
268          final AtomicLongArray ai;
269          volatile long counts;
270          Counter(AtomicLongArray a) { ai = a; }
271 <        public void run() {
271 >        public void realRun() {
272              for (;;) {
273                  boolean done = true;
274                  for (int i = 0; i < ai.length(); ++i) {
275                      long v = ai.get(i);
276 <                    threadAssertTrue(v >= 0);
276 >                    assertTrue(v >= 0);
277                      if (v != 0) {
278                          done = false;
279                          if (ai.compareAndSet(i, v, v-1))

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines