6 |
|
* Pat Fisher, Mike Judd. |
7 |
|
*/ |
8 |
|
|
9 |
– |
import junit.framework.*; |
9 |
|
import java.util.concurrent.atomic.AtomicLong; |
10 |
|
|
11 |
+ |
import junit.framework.Test; |
12 |
+ |
import junit.framework.TestSuite; |
13 |
+ |
|
14 |
|
public class AtomicLongTest extends JSR166TestCase { |
15 |
|
public static void main(String[] args) { |
16 |
< |
junit.textui.TestRunner.run(suite()); |
16 |
> |
main(suite(), args); |
17 |
|
} |
18 |
|
public static Test suite() { |
19 |
|
return new TestSuite(AtomicLongTest.class); |
104 |
|
*/ |
105 |
|
public void testWeakCompareAndSet() { |
106 |
|
AtomicLong ai = new AtomicLong(1); |
107 |
< |
while (!ai.weakCompareAndSet(1, 2)); |
108 |
< |
while (!ai.weakCompareAndSet(2, -4)); |
107 |
> |
do {} while (!ai.weakCompareAndSet(1, 2)); |
108 |
> |
do {} while (!ai.weakCompareAndSet(2, -4)); |
109 |
|
assertEquals(-4, ai.get()); |
110 |
< |
while (!ai.weakCompareAndSet(-4, 7)); |
110 |
> |
do {} while (!ai.weakCompareAndSet(-4, 7)); |
111 |
|
assertEquals(7, ai.get()); |
112 |
|
} |
113 |
|
|
193 |
|
} |
194 |
|
|
195 |
|
/** |
196 |
< |
* a deserialized serialized atomic holds same value |
196 |
> |
* a deserialized/reserialized atomic holds same value |
197 |
|
*/ |
198 |
|
public void testSerialization() throws Exception { |
199 |
|
AtomicLong x = new AtomicLong(); |
200 |
|
AtomicLong y = serialClone(x); |
201 |
< |
assertTrue(x != y); |
201 |
> |
assertNotSame(x, y); |
202 |
|
x.set(-22); |
203 |
|
AtomicLong z = serialClone(x); |
204 |
+ |
assertNotSame(y, z); |
205 |
|
assertEquals(-22, x.get()); |
206 |
|
assertEquals(0, y.get()); |
207 |
|
assertEquals(-22, z.get()); |
213 |
|
public void testToString() { |
214 |
|
AtomicLong ai = new AtomicLong(); |
215 |
|
assertEquals("0", ai.toString()); |
216 |
< |
for (long i : VALUES) { |
217 |
< |
ai.set(i); |
218 |
< |
assertEquals(ai.toString(), Long.toString(i)); |
216 |
> |
for (long x : VALUES) { |
217 |
> |
ai.set(x); |
218 |
> |
assertEquals(Long.toString(x), ai.toString()); |
219 |
|
} |
220 |
|
} |
221 |
|
|