13 |
|
|
14 |
|
public class AtomicIntegerFieldUpdaterTest extends JSR166TestCase { |
15 |
|
volatile int x = 0; |
16 |
+ |
protected volatile int protectedField; |
17 |
+ |
private volatile int privateField; |
18 |
|
int w; |
19 |
< |
long z; |
19 |
> |
float z; |
20 |
|
public static void main(String[] args) { |
21 |
< |
junit.textui.TestRunner.run(suite()); |
21 |
> |
main(suite(), args); |
22 |
|
} |
23 |
|
public static Test suite() { |
24 |
|
return new TestSuite(AtomicIntegerFieldUpdaterTest.class); |
62 |
|
} |
63 |
|
|
64 |
|
/** |
65 |
+ |
* construction using private field from subclass throws RuntimeException |
66 |
+ |
*/ |
67 |
+ |
public void testPrivateFieldInSubclass() { |
68 |
+ |
new NonNestmates.AtomicIntegerFieldUpdaterTestSubclass() |
69 |
+ |
.checkPrivateAccess(); |
70 |
+ |
} |
71 |
+ |
|
72 |
+ |
/** |
73 |
+ |
* construction from unrelated class; package access is allowed, |
74 |
+ |
* private access is not |
75 |
+ |
*/ |
76 |
+ |
public void testUnrelatedClassAccess() { |
77 |
+ |
new NonNestmates().checkPackageAccess(this); |
78 |
+ |
new NonNestmates().checkPrivateAccess(this); |
79 |
+ |
} |
80 |
+ |
|
81 |
+ |
/** |
82 |
|
* get returns the last value set or assigned |
83 |
|
*/ |
84 |
|
public void testGetSet() { |
123 |
|
} |
124 |
|
|
125 |
|
/** |
126 |
+ |
* compareAndSet succeeds in changing protected field value if |
127 |
+ |
* equal to expected else fails |
128 |
+ |
*/ |
129 |
+ |
public void testCompareAndSetProtected() { |
130 |
+ |
AtomicIntegerFieldUpdater<AtomicIntegerFieldUpdaterTest> a; |
131 |
+ |
a = updaterFor("protectedField"); |
132 |
+ |
protectedField = 1; |
133 |
+ |
assertTrue(a.compareAndSet(this, 1, 2)); |
134 |
+ |
assertTrue(a.compareAndSet(this, 2, -4)); |
135 |
+ |
assertEquals(-4, a.get(this)); |
136 |
+ |
assertFalse(a.compareAndSet(this, -5, 7)); |
137 |
+ |
assertEquals(-4, a.get(this)); |
138 |
+ |
assertTrue(a.compareAndSet(this, -4, 7)); |
139 |
+ |
assertEquals(7, a.get(this)); |
140 |
+ |
} |
141 |
+ |
|
142 |
+ |
/** |
143 |
+ |
* compareAndSet succeeds in changing protected field value if |
144 |
+ |
* equal to expected else fails |
145 |
+ |
*/ |
146 |
+ |
public void testCompareAndSetProtectedInSubclass() { |
147 |
+ |
NonNestmates.AtomicIntegerFieldUpdaterTestSubclass s = |
148 |
+ |
new NonNestmates.AtomicIntegerFieldUpdaterTestSubclass(); |
149 |
+ |
s.checkCompareAndSetProtectedSub(); |
150 |
+ |
} |
151 |
+ |
|
152 |
+ |
/** |
153 |
|
* compareAndSet in one thread enables another waiting for value |
154 |
|
* to succeed |
155 |
|
*/ |