6 |
|
* Pat Fisher, Mike Judd. |
7 |
|
*/ |
8 |
|
|
9 |
– |
import junit.framework.*; |
9 |
|
import java.util.concurrent.atomic.AtomicReference; |
10 |
|
|
11 |
+ |
import junit.framework.Test; |
12 |
+ |
import junit.framework.TestSuite; |
13 |
+ |
|
14 |
|
public class AtomicReferenceTest extends JSR166TestCase { |
15 |
|
public static void main(String[] args) { |
16 |
|
junit.textui.TestRunner.run(suite()); |
98 |
|
*/ |
99 |
|
public void testWeakCompareAndSet() { |
100 |
|
AtomicReference ai = new AtomicReference(one); |
101 |
< |
while (!ai.weakCompareAndSet(one, two)); |
102 |
< |
while (!ai.weakCompareAndSet(two, m4)); |
101 |
> |
do {} while (!ai.weakCompareAndSet(one, two)); |
102 |
> |
do {} while (!ai.weakCompareAndSet(two, m4)); |
103 |
|
assertSame(m4, ai.get()); |
104 |
< |
while (!ai.weakCompareAndSet(m4, seven)); |
104 |
> |
do {} while (!ai.weakCompareAndSet(m4, seven)); |
105 |
|
assertSame(seven, ai.get()); |
106 |
|
} |
107 |
|
|
121 |
|
public void testSerialization() throws Exception { |
122 |
|
AtomicReference x = new AtomicReference(); |
123 |
|
AtomicReference y = serialClone(x); |
124 |
< |
assertTrue(x != y); |
124 |
> |
assertNotSame(x, y); |
125 |
|
x.set(one); |
126 |
|
AtomicReference z = serialClone(x); |
127 |
+ |
assertNotSame(y, z); |
128 |
|
assertEquals(one, x.get()); |
129 |
|
assertEquals(null, y.get()); |
130 |
|
assertEquals(one, z.get()); |