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); |
102 |
|
* repeated weakCompareAndSet succeeds in changing value when equal |
103 |
|
* to expected |
104 |
|
*/ |
105 |
+ |
@SuppressWarnings("deprecation") |
106 |
|
public void testWeakCompareAndSet() { |
107 |
|
AtomicLong ai = new AtomicLong(1); |
108 |
< |
while (!ai.weakCompareAndSet(1, 2)); |
109 |
< |
while (!ai.weakCompareAndSet(2, -4)); |
108 |
> |
do {} while (!ai.weakCompareAndSet(1, 2)); |
109 |
> |
do {} while (!ai.weakCompareAndSet(2, -4)); |
110 |
|
assertEquals(-4, ai.get()); |
111 |
< |
while (!ai.weakCompareAndSet(-4, 7)); |
111 |
> |
do {} while (!ai.weakCompareAndSet(-4, 7)); |
112 |
|
assertEquals(7, ai.get()); |
113 |
|
} |
114 |
|
|
194 |
|
} |
195 |
|
|
196 |
|
/** |
197 |
< |
* a deserialized serialized atomic holds same value |
197 |
> |
* a deserialized/reserialized atomic holds same value |
198 |
|
*/ |
199 |
|
public void testSerialization() throws Exception { |
200 |
|
AtomicLong x = new AtomicLong(); |
201 |
|
AtomicLong y = serialClone(x); |
202 |
< |
assertTrue(x != y); |
202 |
> |
assertNotSame(x, y); |
203 |
|
x.set(-22); |
204 |
|
AtomicLong z = serialClone(x); |
205 |
+ |
assertNotSame(y, z); |
206 |
|
assertEquals(-22, x.get()); |
207 |
|
assertEquals(0, y.get()); |
208 |
|
assertEquals(-22, z.get()); |
214 |
|
public void testToString() { |
215 |
|
AtomicLong ai = new AtomicLong(); |
216 |
|
assertEquals("0", ai.toString()); |
217 |
< |
for (long i : VALUES) { |
218 |
< |
ai.set(i); |
219 |
< |
assertEquals(ai.toString(), Long.toString(i)); |
217 |
> |
for (long x : VALUES) { |
218 |
> |
ai.set(x); |
219 |
> |
assertEquals(Long.toString(x), ai.toString()); |
220 |
|
} |
221 |
|
} |
222 |
|
|