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.27 by jsr166, Thu May 30 03:28:55 2013 UTC vs.
Revision 1.32 by jsr166, Sat Apr 25 04:55:30 2015 UTC

# Line 6 | Line 6
6   * Pat Fisher, Mike Judd.
7   */
8  
9 import junit.framework.*;
9   import java.util.Arrays;
10   import java.util.concurrent.atomic.AtomicIntegerArray;
11  
12 + import junit.framework.Test;
13 + import junit.framework.TestSuite;
14 +
15   public class AtomicIntegerArrayTest extends JSR166TestCase {
16  
17      public static void main(String[] args) {
18 <        junit.textui.TestRunner.run(suite());
18 >        main(suite(), args);
19      }
20      public static Test suite() {
21          return new TestSuite(AtomicIntegerArrayTest.class);
# Line 34 | Line 36 | public class AtomicIntegerArrayTest exte
36      public void testConstructor2NPE() {
37          try {
38              int[] a = null;
39 <            AtomicIntegerArray aa = new AtomicIntegerArray(a);
39 >            new AtomicIntegerArray(a);
40              shouldThrow();
41          } catch (NullPointerException success) {}
42      }
# Line 162 | Line 164 | public class AtomicIntegerArrayTest exte
164          AtomicIntegerArray aa = new AtomicIntegerArray(SIZE);
165          for (int i = 0; i < SIZE; i++) {
166              aa.set(i, 1);
167 <            while (!aa.weakCompareAndSet(i, 1, 2));
168 <            while (!aa.weakCompareAndSet(i, 2, -4));
167 >            do {} while (!aa.weakCompareAndSet(i, 1, 2));
168 >            do {} while (!aa.weakCompareAndSet(i, 2, -4));
169              assertEquals(-4, aa.get(i));
170 <            while (!aa.weakCompareAndSet(i, -4, 7));
170 >            do {} while (!aa.weakCompareAndSet(i, -4, 7));
171              assertEquals(7, aa.get(i));
172          }
173      }
# Line 272 | Line 274 | public class AtomicIntegerArrayTest exte
274          }
275      }
276  
275    static final int COUNTDOWN = 100000;
276
277      class Counter extends CheckedRunnable {
278          final AtomicIntegerArray aa;
279          volatile int counts;
# Line 302 | Line 302 | public class AtomicIntegerArrayTest exte
302       */
303      public void testCountingInMultipleThreads() throws InterruptedException {
304          final AtomicIntegerArray aa = new AtomicIntegerArray(SIZE);
305 +        int countdown = 10000;
306          for (int i = 0; i < SIZE; i++)
307 <            aa.set(i, COUNTDOWN);
307 >            aa.set(i, countdown);
308          Counter c1 = new Counter(aa);
309          Counter c2 = new Counter(aa);
310          Thread t1 = new Thread(c1);
# Line 312 | Line 313 | public class AtomicIntegerArrayTest exte
313          t2.start();
314          t1.join();
315          t2.join();
316 <        assertEquals(c1.counts+c2.counts, SIZE * COUNTDOWN);
316 >        assertEquals(c1.counts+c2.counts, SIZE * countdown);
317      }
318  
319      /**

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines