28 |
|
try{ |
29 |
|
AtomicReferenceFieldUpdater<AtomicReferenceFieldUpdaterTest, Integer> |
30 |
|
a = AtomicReferenceFieldUpdater.newUpdater |
31 |
< |
(getClass(), Integer.class, "y"); |
31 |
> |
(AtomicReferenceFieldUpdaterTest.class, Integer.class, "y"); |
32 |
|
shouldThrow(); |
33 |
|
} |
34 |
|
catch (RuntimeException rt) {} |
42 |
|
try{ |
43 |
|
AtomicReferenceFieldUpdater<AtomicReferenceFieldUpdaterTest, Integer> |
44 |
|
a = AtomicReferenceFieldUpdater.newUpdater |
45 |
< |
(getClass(), Integer.class, "z"); |
45 |
> |
(AtomicReferenceFieldUpdaterTest.class, Integer.class, "z"); |
46 |
|
shouldThrow(); |
47 |
|
} |
48 |
|
catch (RuntimeException rt) {} |
55 |
|
try{ |
56 |
|
AtomicReferenceFieldUpdater<AtomicReferenceFieldUpdaterTest, Integer> |
57 |
|
a = AtomicReferenceFieldUpdater.newUpdater |
58 |
< |
(getClass(), Integer.class, "w"); |
58 |
> |
(AtomicReferenceFieldUpdaterTest.class, Integer.class, "w"); |
59 |
|
shouldThrow(); |
60 |
|
} |
61 |
|
catch (RuntimeException rt) {} |
65 |
|
* get returns the last value set or assigned |
66 |
|
*/ |
67 |
|
public void testGetSet(){ |
68 |
< |
AtomicReferenceFieldUpdater<AtomicReferenceFieldUpdaterTest, Integer>a = AtomicReferenceFieldUpdater.newUpdater(getClass(), Integer.class, "x"); |
68 |
> |
AtomicReferenceFieldUpdater<AtomicReferenceFieldUpdaterTest, Integer>a = AtomicReferenceFieldUpdater.newUpdater(AtomicReferenceFieldUpdaterTest.class, Integer.class, "x"); |
69 |
|
x = one; |
70 |
|
assertEquals(one,a.get(this)); |
71 |
|
a.set(this,two); |
78 |
|
* compareAndSet succeeds in changing value if equal to expected else fails |
79 |
|
*/ |
80 |
|
public void testCompareAndSet(){ |
81 |
< |
AtomicReferenceFieldUpdater<AtomicReferenceFieldUpdaterTest, Integer>a = AtomicReferenceFieldUpdater.newUpdater(getClass(), Integer.class, "x"); |
81 |
> |
AtomicReferenceFieldUpdater<AtomicReferenceFieldUpdaterTest, Integer>a = AtomicReferenceFieldUpdater.newUpdater(AtomicReferenceFieldUpdaterTest.class, Integer.class, "x"); |
82 |
|
x = one; |
83 |
|
assertTrue(a.compareAndSet(this,one,two)); |
84 |
|
assertTrue(a.compareAndSet(this,two,m4)); |
95 |
|
*/ |
96 |
|
public void testCompareAndSetInMultipleThreads() { |
97 |
|
x = one; |
98 |
< |
final AtomicReferenceFieldUpdater<AtomicReferenceFieldUpdaterTest, Integer>a = AtomicReferenceFieldUpdater.newUpdater(getClass(), Integer.class, "x"); |
98 |
> |
final AtomicReferenceFieldUpdater<AtomicReferenceFieldUpdaterTest, Integer>a = AtomicReferenceFieldUpdater.newUpdater(AtomicReferenceFieldUpdaterTest.class, Integer.class, "x"); |
99 |
|
|
100 |
|
Thread t = new Thread(new Runnable() { |
101 |
|
public void run() { |
118 |
|
* to expected |
119 |
|
*/ |
120 |
|
public void testWeakCompareAndSet(){ |
121 |
< |
AtomicReferenceFieldUpdater<AtomicReferenceFieldUpdaterTest, Integer>a = AtomicReferenceFieldUpdater.newUpdater(getClass(), Integer.class, "x"); |
121 |
> |
AtomicReferenceFieldUpdater<AtomicReferenceFieldUpdaterTest, Integer>a = AtomicReferenceFieldUpdater.newUpdater(AtomicReferenceFieldUpdaterTest.class, Integer.class, "x"); |
122 |
|
x = one; |
123 |
|
while(!a.weakCompareAndSet(this,one,two)); |
124 |
|
while(!a.weakCompareAndSet(this,two,m4)); |
131 |
|
* getAndSet returns previous value and sets to given value |
132 |
|
*/ |
133 |
|
public void testGetAndSet(){ |
134 |
< |
AtomicReferenceFieldUpdater<AtomicReferenceFieldUpdaterTest, Integer>a = AtomicReferenceFieldUpdater.newUpdater(getClass(), Integer.class, "x"); |
134 |
> |
AtomicReferenceFieldUpdater<AtomicReferenceFieldUpdaterTest, Integer>a = AtomicReferenceFieldUpdater.newUpdater(AtomicReferenceFieldUpdaterTest.class, Integer.class, "x"); |
135 |
|
x = one; |
136 |
|
assertEquals(one,a.getAndSet(this, zero)); |
137 |
|
assertEquals(zero,a.getAndSet(this,m10)); |