--- jsr166/src/test/tck/AtomicLongArrayTest.java 2011/08/10 07:14:48 1.25 +++ jsr166/src/test/tck/AtomicLongArrayTest.java 2015/02/22 04:34:44 1.30 @@ -6,10 +6,12 @@ * 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()); @@ -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) {} } @@ -161,10 +163,10 @@ public class AtomicLongArrayTest extends 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,8 +273,6 @@ public class AtomicLongArrayTest extends } } - static final long COUNTDOWN = 100000; - class Counter extends CheckedRunnable { final AtomicLongArray aa; volatile long counts; @@ -301,8 +301,9 @@ 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); @@ -311,7 +312,7 @@ public class AtomicLongArrayTest extends t2.start(); t1.join(); t2.join(); - assertEquals(c1.counts+c2.counts, SIZE * COUNTDOWN); + assertEquals(c1.counts+c2.counts, SIZE * countdown); } /** @@ -322,7 +323,7 @@ public class AtomicLongArrayTest extends for (int i = 0; i < SIZE; i++) x.set(i, -i); AtomicLongArray y = serialClone(x); - assertTrue(x != y); + assertNotSame(x, y); assertEquals(x.length(), y.length()); for (int i = 0; i < SIZE; i++) { assertEquals(x.get(i), y.get(i));