ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/tck/AtomicLongFieldUpdaterTest.java
(Generate patch)

Comparing jsr166/src/test/tck/AtomicLongFieldUpdaterTest.java (file contents):
Revision 1.4 by dl, Thu Sep 25 11:02:41 2003 UTC vs.
Revision 1.8 by dl, Tue Jan 20 20:20:56 2004 UTC

# Line 1 | Line 1
1   /*
2 < * Written by members of JCP JSR-166 Expert Group and released to the
3 < * public domain. Use, modify, and redistribute this code in any way
4 < * without acknowledgement. Other contributors include Andrew Wright,
5 < * Jeffrey Hayes, Pat Fischer, Mike Judd.
2 > * Written by Doug Lea with assistance from members of JCP JSR-166
3 > * Expert Group and released to the public domain, as explained at
4 > * http://creativecommons.org/licenses/publicdomain
5 > * Other contributors include Andrew Wright, Jeffrey Hayes,
6 > * Pat Fisher, Mike Judd.
7   */
8  
9   import java.util.concurrent.atomic.*;
# Line 22 | Line 23 | public class AtomicLongFieldUpdaterTest
23      }
24  
25      /**
26 <     * Contruction with non-existent field throws RuntimeException
26 >     * Construction with non-existent field throws RuntimeException
27       */
28      public void testConstructor(){
29          try{
30              AtomicLongFieldUpdater<AtomicLongFieldUpdaterTest>
31                  a = AtomicLongFieldUpdater.newUpdater
32 <                (getClass(), "y");
32 >                (AtomicLongFieldUpdaterTest.class, "y");
33              shouldThrow();
34          }
35          catch (RuntimeException rt) {}
# Line 41 | Line 42 | public class AtomicLongFieldUpdaterTest
42          try{
43              AtomicLongFieldUpdater<AtomicLongFieldUpdaterTest>
44                  a = AtomicLongFieldUpdater.newUpdater
45 <                (getClass(), "z");
45 >                (AtomicLongFieldUpdaterTest.class, "z");
46              shouldThrow();
47          }
48          catch (RuntimeException rt) {}
# Line 54 | Line 55 | public class AtomicLongFieldUpdaterTest
55          try{
56              AtomicLongFieldUpdater<AtomicLongFieldUpdaterTest>
57                  a = AtomicLongFieldUpdater.newUpdater
58 <                (getClass(), "w");
58 >                (AtomicLongFieldUpdaterTest.class, "w");
59              shouldThrow();
60          }
61  
# Line 65 | Line 66 | public class AtomicLongFieldUpdaterTest
66       *  get returns the last value set or assigned
67       */
68      public void testGetSet(){
69 <        AtomicLongFieldUpdater<AtomicLongFieldUpdaterTest> a = AtomicLongFieldUpdater.newUpdater(getClass(), "x");
69 >        AtomicLongFieldUpdater<AtomicLongFieldUpdaterTest> a;
70 >        try {
71 >            a = AtomicLongFieldUpdater.newUpdater(AtomicLongFieldUpdaterTest.class, "x");
72 >        } catch (RuntimeException ok) {
73 >            return;
74 >        }
75          x = 1;
76          assertEquals(1,a.get(this));
77          a.set(this,2);
# Line 78 | Line 84 | public class AtomicLongFieldUpdaterTest
84       * compareAndSet succeeds in changing value if equal to expected else fails
85       */
86      public void testCompareAndSet(){
87 <        AtomicLongFieldUpdater<AtomicLongFieldUpdaterTest> a = AtomicLongFieldUpdater.newUpdater(getClass(), "x");
87 >        AtomicLongFieldUpdater<AtomicLongFieldUpdaterTest> a;
88 >        try {
89 >            a = AtomicLongFieldUpdater.newUpdater(AtomicLongFieldUpdaterTest.class, "x");
90 >        } catch (RuntimeException ok) {
91 >            return;
92 >        }
93          x = 1;
94          assertTrue(a.compareAndSet(this,1,2));
95          assertTrue(a.compareAndSet(this,2,-4));
# Line 96 | Line 107 | public class AtomicLongFieldUpdaterTest
107       */
108      public void testCompareAndSetInMultipleThreads() {
109          x = 1;
110 <        final AtomicLongFieldUpdater<AtomicLongFieldUpdaterTest>a = AtomicLongFieldUpdater.newUpdater(getClass(), "x");
110 >        final AtomicLongFieldUpdater<AtomicLongFieldUpdaterTest>a;
111 >        try {
112 >            a = AtomicLongFieldUpdater.newUpdater(AtomicLongFieldUpdaterTest.class, "x");
113 >        } catch (RuntimeException ok) {
114 >            return;
115 >        }
116  
117          Thread t = new Thread(new Runnable() {
118                  public void run() {
# Line 119 | Line 135 | public class AtomicLongFieldUpdaterTest
135       * to expected
136       */
137      public void testWeakCompareAndSet(){
138 <        AtomicLongFieldUpdater<AtomicLongFieldUpdaterTest> a = AtomicLongFieldUpdater.newUpdater(getClass(), "x");
138 >        AtomicLongFieldUpdater<AtomicLongFieldUpdaterTest> a;
139 >        try {
140 >            a = AtomicLongFieldUpdater.newUpdater(AtomicLongFieldUpdaterTest.class, "x");
141 >        } catch (RuntimeException ok) {
142 >            return;
143 >        }
144          x = 1;
145          while(!a.weakCompareAndSet(this,1,2));
146          while(!a.weakCompareAndSet(this,2,-4));
# Line 132 | Line 153 | public class AtomicLongFieldUpdaterTest
153       *  getAndSet returns previous value and sets to given value
154       */
155      public void testGetAndSet(){
156 <        AtomicLongFieldUpdater<AtomicLongFieldUpdaterTest> a = AtomicLongFieldUpdater.newUpdater(getClass(), "x");
156 >        AtomicLongFieldUpdater<AtomicLongFieldUpdaterTest> a;
157 >        try {
158 >            a = AtomicLongFieldUpdater.newUpdater(AtomicLongFieldUpdaterTest.class, "x");
159 >        } catch (RuntimeException ok) {
160 >            return;
161 >        }
162          x = 1;
163          assertEquals(1,a.getAndSet(this, 0));
164          assertEquals(0,a.getAndSet(this,-10));
# Line 143 | Line 169 | public class AtomicLongFieldUpdaterTest
169       * getAndAdd returns previous value and adds given value
170       */
171      public void testGetAndAdd(){
172 <        AtomicLongFieldUpdater<AtomicLongFieldUpdaterTest> a = AtomicLongFieldUpdater.newUpdater(getClass(), "x");
172 >        AtomicLongFieldUpdater<AtomicLongFieldUpdaterTest> a;
173 >        try {
174 >            a = AtomicLongFieldUpdater.newUpdater(AtomicLongFieldUpdaterTest.class, "x");
175 >        } catch (RuntimeException ok) {
176 >            return;
177 >        }
178          x = 1;
179          assertEquals(1,a.getAndAdd(this,2));
180          assertEquals(3,a.get(this));
# Line 155 | Line 186 | public class AtomicLongFieldUpdaterTest
186       * getAndDecrement returns previous value and decrements
187       */
188      public void testGetAndDecrement(){
189 <        AtomicLongFieldUpdater<AtomicLongFieldUpdaterTest> a = AtomicLongFieldUpdater.newUpdater(getClass(), "x");
189 >        AtomicLongFieldUpdater<AtomicLongFieldUpdaterTest> a;
190 >        try {
191 >            a = AtomicLongFieldUpdater.newUpdater(AtomicLongFieldUpdaterTest.class, "x");
192 >        } catch (RuntimeException ok) {
193 >            return;
194 >        }
195          x = 1;
196          assertEquals(1,a.getAndDecrement(this));
197          assertEquals(0,a.getAndDecrement(this));
# Line 166 | Line 202 | public class AtomicLongFieldUpdaterTest
202       * getAndIncrement returns previous value and increments
203       */
204      public void testGetAndIncrement(){
205 <        AtomicLongFieldUpdater<AtomicLongFieldUpdaterTest> a = AtomicLongFieldUpdater.newUpdater(getClass(), "x");
205 >        AtomicLongFieldUpdater<AtomicLongFieldUpdaterTest> a;
206 >        try {
207 >            a = AtomicLongFieldUpdater.newUpdater(AtomicLongFieldUpdaterTest.class, "x");
208 >        } catch (RuntimeException ok) {
209 >            return;
210 >        }
211          x = 1;
212          assertEquals(1,a.getAndIncrement(this));
213          assertEquals(2,a.get(this));
# Line 181 | Line 222 | public class AtomicLongFieldUpdaterTest
222       * addAndGet adds given value to current, and returns current value
223       */
224      public void testAddAndGet(){
225 <        AtomicLongFieldUpdater<AtomicLongFieldUpdaterTest> a = AtomicLongFieldUpdater.newUpdater(getClass(), "x");
225 >        AtomicLongFieldUpdater<AtomicLongFieldUpdaterTest> a;
226 >        try {
227 >            a = AtomicLongFieldUpdater.newUpdater(AtomicLongFieldUpdaterTest.class, "x");
228 >        } catch (RuntimeException ok) {
229 >            return;
230 >        }
231          x = 1;
232          assertEquals(3,a.addAndGet(this,2));
233          assertEquals(3,a.get(this));
# Line 193 | Line 239 | public class AtomicLongFieldUpdaterTest
239       *  decrementAndGet decrements and returns current value
240       */
241      public void testDecrementAndGet(){
242 <        AtomicLongFieldUpdater<AtomicLongFieldUpdaterTest> a = AtomicLongFieldUpdater.newUpdater(getClass(), "x");
242 >        AtomicLongFieldUpdater<AtomicLongFieldUpdaterTest> a;
243 >        try {
244 >            a = AtomicLongFieldUpdater.newUpdater(AtomicLongFieldUpdaterTest.class, "x");
245 >        } catch (RuntimeException ok) {
246 >            return;
247 >        }
248          x = 1;
249          assertEquals(0,a.decrementAndGet(this));
250          assertEquals(-1,a.decrementAndGet(this));
# Line 205 | Line 256 | public class AtomicLongFieldUpdaterTest
256       * incrementAndGet increments and returns current value
257       */
258      public void testIncrementAndGet(){
259 <        AtomicLongFieldUpdater<AtomicLongFieldUpdaterTest> a = AtomicLongFieldUpdater.newUpdater(getClass(), "x");
259 >        AtomicLongFieldUpdater<AtomicLongFieldUpdaterTest> a;
260 >        try {
261 >            a = AtomicLongFieldUpdater.newUpdater(AtomicLongFieldUpdaterTest.class, "x");
262 >        } catch (RuntimeException ok) {
263 >            return;
264 >        }
265          x = 1;
266          assertEquals(2,a.incrementAndGet(this));
267          assertEquals(2,a.get(this));

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines