--- jsr166/src/test/tck/AtomicLongArrayTest.java 2009/12/01 09:56:28 1.15 +++ jsr166/src/test/tck/AtomicLongArrayTest.java 2011/06/10 19:45:01 1.22 @@ -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); @@ -43,7 +42,7 @@ public class AtomicLongArrayTest extends * constructor with array is of same size and has all elements */ public void testConstructor2() { - long[] a = { 17L, 3L, -42L, 99L, -7L}; + long[] a = { 17L, 3L, -42L, 99L, -7L }; AtomicLongArray ai = new AtomicLongArray(a); assertEquals(a.length, ai.length()); for (int i = 0; i < a.length; ++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)); } } @@ -330,10 +323,9 @@ public class AtomicLongArrayTest extends * toString returns current value. */ public void testToString() { - long[] a = { 17, 3, -42, 99, -7}; + long[] a = { 17, 3, -42, 99, -7 }; AtomicLongArray ai = new AtomicLongArray(a); assertEquals(Arrays.toString(a), ai.toString()); } - }