6 |
|
* Pat Fisher, Mike Judd. |
7 |
|
*/ |
8 |
|
|
9 |
– |
import junit.framework.*; |
9 |
|
import java.util.concurrent.atomic.AtomicIntegerFieldUpdater; |
10 |
|
|
11 |
+ |
import junit.framework.Test; |
12 |
+ |
import junit.framework.TestSuite; |
13 |
+ |
|
14 |
|
public class AtomicIntegerFieldUpdaterTest extends JSR166TestCase { |
15 |
|
volatile int x = 0; |
16 |
|
int w; |
17 |
|
long z; |
18 |
|
public static void main(String[] args) { |
19 |
< |
junit.textui.TestRunner.run(suite()); |
19 |
> |
main(suite(), args); |
20 |
|
} |
21 |
|
public static Test suite() { |
22 |
|
return new TestSuite(AtomicIntegerFieldUpdaterTest.class); |
34 |
|
try { |
35 |
|
updaterFor("y"); |
36 |
|
shouldThrow(); |
37 |
< |
} catch (RuntimeException success) {} |
37 |
> |
} catch (RuntimeException success) { |
38 |
> |
assertNotNull(success.getCause()); |
39 |
> |
} |
40 |
|
} |
41 |
|
|
42 |
|
/** |
43 |
< |
* construction with field not of given type throws RuntimeException |
43 |
> |
* construction with field not of given type throws IllegalArgumentException |
44 |
|
*/ |
45 |
|
public void testConstructor2() { |
46 |
|
try { |
47 |
|
updaterFor("z"); |
48 |
|
shouldThrow(); |
49 |
< |
} catch (RuntimeException success) {} |
49 |
> |
} catch (IllegalArgumentException success) {} |
50 |
|
} |
51 |
|
|
52 |
|
/** |
53 |
< |
* construction with non-volatile field throws RuntimeException |
53 |
> |
* construction with non-volatile field throws IllegalArgumentException |
54 |
|
*/ |
55 |
|
public void testConstructor3() { |
56 |
|
try { |
57 |
|
updaterFor("w"); |
58 |
|
shouldThrow(); |
59 |
< |
} catch (RuntimeException success) {} |
59 |
> |
} catch (IllegalArgumentException success) {} |
60 |
|
} |
61 |
|
|
62 |
|
/** |
133 |
|
AtomicIntegerFieldUpdater<AtomicIntegerFieldUpdaterTest> a; |
134 |
|
a = updaterFor("x"); |
135 |
|
x = 1; |
136 |
< |
while (!a.weakCompareAndSet(this, 1, 2)); |
137 |
< |
while (!a.weakCompareAndSet(this, 2, -4)); |
136 |
> |
do {} while (!a.weakCompareAndSet(this, 1, 2)); |
137 |
> |
do {} while (!a.weakCompareAndSet(this, 2, -4)); |
138 |
|
assertEquals(-4, a.get(this)); |
139 |
< |
while (!a.weakCompareAndSet(this, -4, 7)); |
139 |
> |
do {} while (!a.weakCompareAndSet(this, -4, 7)); |
140 |
|
assertEquals(7, a.get(this)); |
141 |
|
} |
142 |
|
|