--- jsr166/src/test/tck/AtomicLongArrayTest.java 2013/05/30 03:28:55 1.26 +++ jsr166/src/test/tck/AtomicLongArrayTest.java 2021/01/26 13:33:05 1.38 @@ -6,13 +6,15 @@ * Pat Fisher, Mike Judd. */ -import junit.framework.*; import java.util.Arrays; import java.util.concurrent.atomic.AtomicLongArray; +import junit.framework.Test; +import junit.framework.TestSuite; + public class AtomicLongArrayTest extends JSR166TestCase { public static void main(String[] args) { - junit.textui.TestRunner.run(suite()); + main(suite(), args); } public static Test suite() { return new TestSuite(AtomicLongArrayTest.class); @@ -33,7 +35,7 @@ public class AtomicLongArrayTest extends public void testConstructor2NPE() { try { long[] a = null; - AtomicLongArray aa = new AtomicLongArray(a); + new AtomicLongArray(a); shouldThrow(); } catch (NullPointerException success) {} } @@ -52,6 +54,7 @@ public class AtomicLongArrayTest extends /** * get and set for out of bound indices throw IndexOutOfBoundsException */ + @SuppressWarnings("deprecation") public void testIndexing() { AtomicLongArray aa = new AtomicLongArray(SIZE); for (int index : new int[] { -1, SIZE }) { @@ -157,14 +160,15 @@ public class AtomicLongArrayTest extends * repeated weakCompareAndSet succeeds in changing value when equal * to expected */ + @SuppressWarnings("deprecation") public void testWeakCompareAndSet() { AtomicLongArray aa = new AtomicLongArray(SIZE); for (int i = 0; i < SIZE; i++) { aa.set(i, 1); - while (!aa.weakCompareAndSet(i, 1, 2)); - while (!aa.weakCompareAndSet(i, 2, -4)); + do {} while (!aa.weakCompareAndSet(i, 1, 2)); + do {} while (!aa.weakCompareAndSet(i, 2, -4)); assertEquals(-4, aa.get(i)); - while (!aa.weakCompareAndSet(i, -4, 7)); + do {} while (!aa.weakCompareAndSet(i, -4, 7)); assertEquals(7, aa.get(i)); } } @@ -271,11 +275,9 @@ public class AtomicLongArrayTest extends } } - static final long COUNTDOWN = 100000; - class Counter extends CheckedRunnable { final AtomicLongArray aa; - volatile long counts; + int decs; Counter(AtomicLongArray a) { aa = a; } public void realRun() { for (;;) { @@ -285,8 +287,8 @@ public class AtomicLongArrayTest extends assertTrue(v >= 0); if (v != 0) { done = false; - if (aa.compareAndSet(i, v, v-1)) - ++counts; + if (aa.compareAndSet(i, v, v - 1)) + decs++; } } if (done) @@ -301,21 +303,20 @@ public class AtomicLongArrayTest extends */ public void testCountingInMultipleThreads() throws InterruptedException { final AtomicLongArray aa = new AtomicLongArray(SIZE); + long countdown = 10000; for (int i = 0; i < SIZE; i++) - aa.set(i, COUNTDOWN); + aa.set(i, countdown); Counter c1 = new Counter(aa); Counter c2 = new Counter(aa); - Thread t1 = new Thread(c1); - Thread t2 = new Thread(c2); - t1.start(); - t2.start(); + Thread t1 = newStartedThread(c1); + Thread t2 = newStartedThread(c2); t1.join(); t2.join(); - assertEquals(c1.counts+c2.counts, SIZE * COUNTDOWN); + assertEquals(c1.decs + c2.decs, SIZE * countdown); } /** - * a deserialized serialized array holds same values + * a deserialized/reserialized array holds same values in same order */ public void testSerialization() throws Exception { AtomicLongArray x = new AtomicLongArray(SIZE);