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.37 by jsr166, Fri Aug 4 03:30:21 2017 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 161 | Line 163 | public class AtomicLongArrayTest extends
163          AtomicLongArray aa = new AtomicLongArray(SIZE);
164          for (int i = 0; i < SIZE; i++) {
165              aa.set(i, 1);
166 <            while (!aa.weakCompareAndSet(i, 1, 2));
167 <            while (!aa.weakCompareAndSet(i, 2, -4));
166 >            do {} while (!aa.weakCompareAndSet(i, 1, 2));
167 >            do {} while (!aa.weakCompareAndSet(i, 2, -4));
168              assertEquals(-4, aa.get(i));
169 <            while (!aa.weakCompareAndSet(i, -4, 7));
169 >            do {} while (!aa.weakCompareAndSet(i, -4, 7));
170              assertEquals(7, aa.get(i));
171          }
172      }
# Line 271 | Line 273 | public class AtomicLongArrayTest extends
273          }
274      }
275  
274    static final long COUNTDOWN = 100000;
275
276      class Counter extends CheckedRunnable {
277          final AtomicLongArray aa;
278 <        volatile long counts;
278 >        int decs;
279          Counter(AtomicLongArray a) { aa = a; }
280          public void realRun() {
281              for (;;) {
# Line 285 | Line 285 | public class AtomicLongArrayTest extends
285                      assertTrue(v >= 0);
286                      if (v != 0) {
287                          done = false;
288 <                        if (aa.compareAndSet(i, v, v-1))
289 <                            ++counts;
288 >                        if (aa.compareAndSet(i, v, v - 1))
289 >                            decs++;
290                      }
291                  }
292                  if (done)
# Line 301 | Line 301 | public class AtomicLongArrayTest extends
301       */
302      public void testCountingInMultipleThreads() throws InterruptedException {
303          final AtomicLongArray aa = new AtomicLongArray(SIZE);
304 +        long countdown = 10000;
305          for (int i = 0; i < SIZE; i++)
306 <            aa.set(i, COUNTDOWN);
306 >            aa.set(i, countdown);
307          Counter c1 = new Counter(aa);
308          Counter c2 = new Counter(aa);
309 <        Thread t1 = new Thread(c1);
310 <        Thread t2 = new Thread(c2);
310 <        t1.start();
311 <        t2.start();
309 >        Thread t1 = newStartedThread(c1);
310 >        Thread t2 = newStartedThread(c2);
311          t1.join();
312          t2.join();
313 <        assertEquals(c1.counts+c2.counts, SIZE * COUNTDOWN);
313 >        assertEquals(c1.decs + c2.decs, SIZE * countdown);
314      }
315  
316      /**
317 <     * a deserialized serialized array holds same values
317 >     * a deserialized/reserialized array holds same values in same order
318       */
319      public void testSerialization() throws Exception {
320          AtomicLongArray x = new AtomicLongArray(SIZE);
321          for (int i = 0; i < SIZE; i++)
322              x.set(i, -i);
323          AtomicLongArray y = serialClone(x);
324 <        assertTrue(x != y);
324 >        assertNotSame(x, y);
325          assertEquals(x.length(), y.length());
326          for (int i = 0; i < SIZE; i++) {
327              assertEquals(x.get(i), y.get(i));

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines