--- jsr166/src/test/tck/AtomicLongArrayTest.java 2009/11/17 06:58:50 1.14 +++ jsr166/src/test/tck/AtomicLongArrayTest.java 2011/05/31 16:16:23 1.21 @@ -1,19 +1,18 @@ /* * Written by Doug Lea with assistance from members of JCP JSR-166 * Expert Group and released to the public domain, as explained at - * http://creativecommons.org/licenses/publicdomain + * http://creativecommons.org/publicdomain/zero/1.0/ * Other contributors include Andrew Wright, Jeffrey Hayes, * Pat Fisher, Mike Judd. */ import junit.framework.*; -import java.util.concurrent.atomic.*; -import java.io.*; -import java.util.*; +import java.util.Arrays; +import java.util.concurrent.atomic.AtomicLongArray; public class AtomicLongArrayTest extends JSR166TestCase { - public static void main (String[] args) { - junit.textui.TestRunner.run (suite()); + public static void main(String[] args) { + junit.textui.TestRunner.run(suite()); } public static Test suite() { return new TestSuite(AtomicLongArrayTest.class); @@ -118,7 +117,7 @@ public class AtomicLongArrayTest extends assertTrue(ai.compareAndSet(i, 2,-4)); assertEquals(-4,ai.get(i)); assertFalse(ai.compareAndSet(i, -5,7)); - assertFalse((7 == ai.get(i))); + assertEquals(-4,ai.get(i)); assertTrue(ai.compareAndSet(i, -4,7)); assertEquals(7,ai.get(i)); } @@ -161,7 +160,7 @@ public class AtomicLongArrayTest extends } /** - * getAndSet returns previous value and sets to given value at given index + * getAndSet returns previous value and sets to given value at given index */ public void testGetAndSet() { AtomicLongArray ai = new AtomicLongArray(SIZE); @@ -174,7 +173,7 @@ public class AtomicLongArrayTest extends } /** - * getAndAdd returns previous value and adds given value + * getAndAdd returns previous value and adds given value */ public void testGetAndAdd() { AtomicLongArray ai = new AtomicLongArray(SIZE); @@ -218,7 +217,7 @@ public class AtomicLongArrayTest extends } /** - * addAndGet adds given value to current, and returns current value + * addAndGet adds given value to current, and returns current value */ public void testAddAndGet() { AtomicLongArray ai = new AtomicLongArray(SIZE); @@ -264,16 +263,16 @@ public class AtomicLongArrayTest extends static final long COUNTDOWN = 100000; - class Counter implements Runnable { + class Counter extends CheckedRunnable { final AtomicLongArray ai; volatile long counts; Counter(AtomicLongArray a) { ai = a; } - public void run() { + public void realRun() { for (;;) { boolean done = true; for (int i = 0; i < ai.length(); ++i) { long v = ai.get(i); - threadAssertTrue(v >= 0); + assertTrue(v >= 0); if (v != 0) { done = false; if (ai.compareAndSet(i, v, v-1)) @@ -309,20 +308,14 @@ public class AtomicLongArrayTest extends * a deserialized serialized array holds same values */ public void testSerialization() throws Exception { - AtomicLongArray l = new AtomicLongArray(SIZE); + AtomicLongArray x = new AtomicLongArray(SIZE); for (int i = 0; i < SIZE; ++i) - l.set(i, -i); - - ByteArrayOutputStream bout = new ByteArrayOutputStream(10000); - ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout)); - out.writeObject(l); - out.close(); - - ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray()); - ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin)); - AtomicLongArray r = (AtomicLongArray) in.readObject(); + x.set(i, -i); + AtomicLongArray y = serialClone(x); + assertTrue(x != y); + assertEquals(x.length(), y.length()); for (int i = 0; i < SIZE; ++i) { - assertEquals(l.get(i), r.get(i)); + assertEquals(x.get(i), y.get(i)); } } @@ -335,5 +328,4 @@ public class AtomicLongArrayTest extends assertEquals(Arrays.toString(a), ai.toString()); } - }