13 |
|
|
14 |
|
public class AtomicReferenceFieldUpdaterTest extends JSR166TestCase { |
15 |
|
volatile Integer x = null; |
16 |
+ |
protected volatile Integer protectedField; |
17 |
+ |
private volatile Integer privateField; |
18 |
|
Object z; |
19 |
|
Integer w; |
20 |
|
volatile int i; |
26 |
|
return new TestSuite(AtomicReferenceFieldUpdaterTest.class); |
27 |
|
} |
28 |
|
|
29 |
< |
AtomicReferenceFieldUpdater<AtomicReferenceFieldUpdaterTest, Integer> updaterFor(String fieldName) { |
29 |
> |
static AtomicReferenceFieldUpdater<AtomicReferenceFieldUpdaterTest, Integer> updaterFor(String fieldName) { |
30 |
|
return AtomicReferenceFieldUpdater.newUpdater |
31 |
|
(AtomicReferenceFieldUpdaterTest.class, Integer.class, fieldName); |
32 |
|
} |
74 |
|
} |
75 |
|
|
76 |
|
/** |
77 |
+ |
* construction using private field from subclass throws RuntimeException |
78 |
+ |
*/ |
79 |
+ |
public void testPrivateFieldInSubclass() { |
80 |
+ |
new NonNestmates.AtomicReferenceFieldUpdaterTestSubclass() |
81 |
+ |
.checkPrivateAccess(); |
82 |
+ |
} |
83 |
+ |
|
84 |
+ |
/** |
85 |
+ |
* construction from unrelated class; package access is allowed, |
86 |
+ |
* private access is not |
87 |
+ |
*/ |
88 |
+ |
public void testUnrelatedClassAccess() { |
89 |
+ |
new NonNestmates().checkPackageAccess(this); |
90 |
+ |
new NonNestmates().checkPrivateAccess(this); |
91 |
+ |
} |
92 |
+ |
|
93 |
+ |
/** |
94 |
|
* get returns the last value set or assigned |
95 |
|
*/ |
96 |
|
public void testGetSet() { |
119 |
|
} |
120 |
|
|
121 |
|
/** |
122 |
< |
* compareAndSet succeeds in changing value if equal to expected else fails |
122 |
> |
* compareAndSet succeeds in changing value if same as expected else fails |
123 |
|
*/ |
124 |
|
public void testCompareAndSet() { |
125 |
|
AtomicReferenceFieldUpdater<AtomicReferenceFieldUpdaterTest, Integer> a; |
129 |
|
assertTrue(a.compareAndSet(this, two, m4)); |
130 |
|
assertSame(m4, a.get(this)); |
131 |
|
assertFalse(a.compareAndSet(this, m5, seven)); |
132 |
< |
assertFalse(seven == a.get(this)); |
132 |
> |
assertNotSame(seven, a.get(this)); |
133 |
|
assertTrue(a.compareAndSet(this, m4, seven)); |
134 |
|
assertSame(seven, a.get(this)); |
135 |
|
} |
136 |
|
|
137 |
|
/** |
138 |
+ |
* compareAndSet succeeds in changing protected field value if |
139 |
+ |
* same as expected else fails |
140 |
+ |
*/ |
141 |
+ |
public void testCompareAndSetProtectedInSubclass() { |
142 |
+ |
new NonNestmates.AtomicReferenceFieldUpdaterTestSubclass() |
143 |
+ |
.checkCompareAndSetProtectedSub(); |
144 |
+ |
} |
145 |
+ |
|
146 |
+ |
/** |
147 |
|
* compareAndSet in one thread enables another waiting for value |
148 |
|
* to succeed |
149 |
|
*/ |
166 |
|
} |
167 |
|
|
168 |
|
/** |
169 |
< |
* repeated weakCompareAndSet succeeds in changing value when equal |
142 |
< |
* to expected |
169 |
> |
* repeated weakCompareAndSet succeeds in changing value when same as expected |
170 |
|
*/ |
171 |
|
public void testWeakCompareAndSet() { |
172 |
|
AtomicReferenceFieldUpdater<AtomicReferenceFieldUpdaterTest, Integer> a; |