12 |
|
import java.util.*; |
13 |
|
|
14 |
|
public class AtomicLongArrayTest extends JSR166TestCase { |
15 |
< |
public static void main (String[] args) { |
16 |
< |
junit.textui.TestRunner.run (suite()); |
15 |
> |
public static void main(String[] args) { |
16 |
> |
junit.textui.TestRunner.run(suite()); |
17 |
|
} |
18 |
|
public static Test suite() { |
19 |
|
return new TestSuite(AtomicLongArrayTest.class); |
118 |
|
assertTrue(ai.compareAndSet(i, 2,-4)); |
119 |
|
assertEquals(-4,ai.get(i)); |
120 |
|
assertFalse(ai.compareAndSet(i, -5,7)); |
121 |
< |
assertFalse((7 == ai.get(i))); |
121 |
> |
assertEquals(-4,ai.get(i)); |
122 |
|
assertTrue(ai.compareAndSet(i, -4,7)); |
123 |
|
assertEquals(7,ai.get(i)); |
124 |
|
} |
131 |
|
public void testCompareAndSetInMultipleThreads() throws InterruptedException { |
132 |
|
final AtomicLongArray a = new AtomicLongArray(1); |
133 |
|
a.set(0, 1); |
134 |
< |
Thread t = new Thread(new Runnable() { |
135 |
< |
public void run() { |
136 |
< |
while (!a.compareAndSet(0, 2, 3)) Thread.yield(); |
137 |
< |
}}); |
134 |
> |
Thread t = new Thread(new CheckedRunnable() { |
135 |
> |
public void realRun() { |
136 |
> |
while (!a.compareAndSet(0, 2, 3)) |
137 |
> |
Thread.yield(); |
138 |
> |
}}); |
139 |
|
|
140 |
|
t.start(); |
141 |
|
assertTrue(a.compareAndSet(0, 1, 2)); |