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.25 by jsr166, Wed Aug 10 07:14:48 2011 UTC vs.
Revision 1.38 by dl, Tue Jan 26 13:33:05 2021 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.AtomicLongArray;
11  
12 + import junit.framework.Test;
13 + import junit.framework.TestSuite;
14 +
15   public class AtomicLongArrayTest extends JSR166TestCase {
16      public static void main(String[] args) {
17 <        junit.textui.TestRunner.run(suite());
17 >        main(suite(), args);
18      }
19      public static Test suite() {
20          return new TestSuite(AtomicLongArrayTest.class);
# Line 33 | Line 35 | public class AtomicLongArrayTest extends
35      public void testConstructor2NPE() {
36          try {
37              long[] a = null;
38 <            AtomicLongArray aa = new AtomicLongArray(a);
38 >            new AtomicLongArray(a);
39              shouldThrow();
40          } catch (NullPointerException success) {}
41      }
# Line 52 | Line 54 | public class AtomicLongArrayTest extends
54      /**
55       * get and set for out of bound indices throw IndexOutOfBoundsException
56       */
57 +    @SuppressWarnings("deprecation")
58      public void testIndexing() {
59          AtomicLongArray aa = new AtomicLongArray(SIZE);
60          for (int index : new int[] { -1, SIZE }) {
# Line 157 | Line 160 | public class AtomicLongArrayTest extends
160       * repeated weakCompareAndSet succeeds in changing value when equal
161       * to expected
162       */
163 +    @SuppressWarnings("deprecation")
164      public void testWeakCompareAndSet() {
165          AtomicLongArray aa = new AtomicLongArray(SIZE);
166          for (int i = 0; i < SIZE; i++) {
167              aa.set(i, 1);
168 <            while (!aa.weakCompareAndSet(i, 1, 2));
169 <            while (!aa.weakCompareAndSet(i, 2, -4));
168 >            do {} while (!aa.weakCompareAndSet(i, 1, 2));
169 >            do {} while (!aa.weakCompareAndSet(i, 2, -4));
170              assertEquals(-4, aa.get(i));
171 <            while (!aa.weakCompareAndSet(i, -4, 7));
171 >            do {} while (!aa.weakCompareAndSet(i, -4, 7));
172              assertEquals(7, aa.get(i));
173          }
174      }
# Line 271 | Line 275 | public class AtomicLongArrayTest extends
275          }
276      }
277  
274    static final long COUNTDOWN = 100000;
275
278      class Counter extends CheckedRunnable {
279          final AtomicLongArray aa;
280 <        volatile long counts;
280 >        int decs;
281          Counter(AtomicLongArray a) { aa = a; }
282          public void realRun() {
283              for (;;) {
# Line 285 | Line 287 | public class AtomicLongArrayTest extends
287                      assertTrue(v >= 0);
288                      if (v != 0) {
289                          done = false;
290 <                        if (aa.compareAndSet(i, v, v-1))
291 <                            ++counts;
290 >                        if (aa.compareAndSet(i, v, v - 1))
291 >                            decs++;
292                      }
293                  }
294                  if (done)
# Line 301 | Line 303 | public class AtomicLongArrayTest extends
303       */
304      public void testCountingInMultipleThreads() throws InterruptedException {
305          final AtomicLongArray aa = new AtomicLongArray(SIZE);
306 +        long countdown = 10000;
307          for (int i = 0; i < SIZE; i++)
308 <            aa.set(i, COUNTDOWN);
308 >            aa.set(i, countdown);
309          Counter c1 = new Counter(aa);
310          Counter c2 = new Counter(aa);
311 <        Thread t1 = new Thread(c1);
312 <        Thread t2 = new Thread(c2);
310 <        t1.start();
311 <        t2.start();
311 >        Thread t1 = newStartedThread(c1);
312 >        Thread t2 = newStartedThread(c2);
313          t1.join();
314          t2.join();
315 <        assertEquals(c1.counts+c2.counts, SIZE * COUNTDOWN);
315 >        assertEquals(c1.decs + c2.decs, SIZE * countdown);
316      }
317  
318      /**
319 <     * a deserialized serialized array holds same values
319 >     * a deserialized/reserialized array holds same values in same order
320       */
321      public void testSerialization() throws Exception {
322          AtomicLongArray x = new AtomicLongArray(SIZE);
323          for (int i = 0; i < SIZE; i++)
324              x.set(i, -i);
325          AtomicLongArray y = serialClone(x);
326 <        assertTrue(x != y);
326 >        assertNotSame(x, y);
327          assertEquals(x.length(), y.length());
328          for (int i = 0; i < SIZE; i++) {
329              assertEquals(x.get(i), y.get(i));

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines