6 |
|
* Pat Fisher, Mike Judd. |
7 |
|
*/ |
8 |
|
|
9 |
– |
import junit.framework.*; |
9 |
|
import java.util.Arrays; |
10 |
|
import java.util.concurrent.atomic.AtomicIntegerArray; |
11 |
|
|
12 |
+ |
import junit.framework.Test; |
13 |
+ |
import junit.framework.TestSuite; |
14 |
+ |
|
15 |
|
public class AtomicIntegerArrayTest extends JSR166TestCase { |
16 |
|
|
17 |
|
public static void main(String[] args) { |
274 |
|
} |
275 |
|
} |
276 |
|
|
275 |
– |
static final int COUNTDOWN = 100000; |
276 |
– |
|
277 |
|
class Counter extends CheckedRunnable { |
278 |
|
final AtomicIntegerArray aa; |
279 |
|
volatile int counts; |
302 |
|
*/ |
303 |
|
public void testCountingInMultipleThreads() throws InterruptedException { |
304 |
|
final AtomicIntegerArray aa = new AtomicIntegerArray(SIZE); |
305 |
+ |
int countdown = 10000; |
306 |
|
for (int i = 0; i < SIZE; i++) |
307 |
< |
aa.set(i, COUNTDOWN); |
307 |
> |
aa.set(i, countdown); |
308 |
|
Counter c1 = new Counter(aa); |
309 |
|
Counter c2 = new Counter(aa); |
310 |
|
Thread t1 = new Thread(c1); |
313 |
|
t2.start(); |
314 |
|
t1.join(); |
315 |
|
t2.join(); |
316 |
< |
assertEquals(c1.counts+c2.counts, SIZE * COUNTDOWN); |
316 |
> |
assertEquals(c1.counts+c2.counts, SIZE * countdown); |
317 |
|
} |
318 |
|
|
319 |
|
/** |
324 |
|
for (int i = 0; i < SIZE; i++) |
325 |
|
x.set(i, -i); |
326 |
|
AtomicIntegerArray y = serialClone(x); |
327 |
< |
assertTrue(x != y); |
327 |
> |
assertNotSame(x, y); |
328 |
|
assertEquals(x.length(), y.length()); |
329 |
|
for (int i = 0; i < SIZE; i++) { |
330 |
|
assertEquals(x.get(i), y.get(i)); |