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