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.6 by dl, Sat Dec 27 19:26:43 2003 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 28 | Line 29 | public class AtomicLongFieldUpdaterTest
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 = AtomicLongFieldUpdater.newUpdater(AtomicLongFieldUpdaterTest.class, "x");
70          x = 1;
71          assertEquals(1,a.get(this));
72          a.set(this,2);
# Line 78 | Line 79 | public class AtomicLongFieldUpdaterTest
79       * compareAndSet succeeds in changing value if equal to expected else fails
80       */
81      public void testCompareAndSet(){
82 <        AtomicLongFieldUpdater<AtomicLongFieldUpdaterTest> a = AtomicLongFieldUpdater.newUpdater(getClass(), "x");
82 >        AtomicLongFieldUpdater<AtomicLongFieldUpdaterTest> a = AtomicLongFieldUpdater.newUpdater(AtomicLongFieldUpdaterTest.class, "x");
83          x = 1;
84          assertTrue(a.compareAndSet(this,1,2));
85          assertTrue(a.compareAndSet(this,2,-4));
# Line 96 | Line 97 | public class AtomicLongFieldUpdaterTest
97       */
98      public void testCompareAndSetInMultipleThreads() {
99          x = 1;
100 <        final AtomicLongFieldUpdater<AtomicLongFieldUpdaterTest>a = AtomicLongFieldUpdater.newUpdater(getClass(), "x");
100 >        final AtomicLongFieldUpdater<AtomicLongFieldUpdaterTest>a = AtomicLongFieldUpdater.newUpdater(AtomicLongFieldUpdaterTest.class, "x");
101  
102          Thread t = new Thread(new Runnable() {
103                  public void run() {
# Line 119 | Line 120 | public class AtomicLongFieldUpdaterTest
120       * to expected
121       */
122      public void testWeakCompareAndSet(){
123 <        AtomicLongFieldUpdater<AtomicLongFieldUpdaterTest> a = AtomicLongFieldUpdater.newUpdater(getClass(), "x");
123 >        AtomicLongFieldUpdater<AtomicLongFieldUpdaterTest> a = AtomicLongFieldUpdater.newUpdater(AtomicLongFieldUpdaterTest.class, "x");
124          x = 1;
125          while(!a.weakCompareAndSet(this,1,2));
126          while(!a.weakCompareAndSet(this,2,-4));
# Line 132 | Line 133 | public class AtomicLongFieldUpdaterTest
133       *  getAndSet returns previous value and sets to given value
134       */
135      public void testGetAndSet(){
136 <        AtomicLongFieldUpdater<AtomicLongFieldUpdaterTest> a = AtomicLongFieldUpdater.newUpdater(getClass(), "x");
136 >        AtomicLongFieldUpdater<AtomicLongFieldUpdaterTest> a = AtomicLongFieldUpdater.newUpdater(AtomicLongFieldUpdaterTest.class, "x");
137          x = 1;
138          assertEquals(1,a.getAndSet(this, 0));
139          assertEquals(0,a.getAndSet(this,-10));
# Line 143 | Line 144 | public class AtomicLongFieldUpdaterTest
144       * getAndAdd returns previous value and adds given value
145       */
146      public void testGetAndAdd(){
147 <        AtomicLongFieldUpdater<AtomicLongFieldUpdaterTest> a = AtomicLongFieldUpdater.newUpdater(getClass(), "x");
147 >        AtomicLongFieldUpdater<AtomicLongFieldUpdaterTest> a = AtomicLongFieldUpdater.newUpdater(AtomicLongFieldUpdaterTest.class, "x");
148          x = 1;
149          assertEquals(1,a.getAndAdd(this,2));
150          assertEquals(3,a.get(this));
# Line 155 | Line 156 | public class AtomicLongFieldUpdaterTest
156       * getAndDecrement returns previous value and decrements
157       */
158      public void testGetAndDecrement(){
159 <        AtomicLongFieldUpdater<AtomicLongFieldUpdaterTest> a = AtomicLongFieldUpdater.newUpdater(getClass(), "x");
159 >        AtomicLongFieldUpdater<AtomicLongFieldUpdaterTest> a = AtomicLongFieldUpdater.newUpdater(AtomicLongFieldUpdaterTest.class, "x");
160          x = 1;
161          assertEquals(1,a.getAndDecrement(this));
162          assertEquals(0,a.getAndDecrement(this));
# Line 166 | Line 167 | public class AtomicLongFieldUpdaterTest
167       * getAndIncrement returns previous value and increments
168       */
169      public void testGetAndIncrement(){
170 <        AtomicLongFieldUpdater<AtomicLongFieldUpdaterTest> a = AtomicLongFieldUpdater.newUpdater(getClass(), "x");
170 >        AtomicLongFieldUpdater<AtomicLongFieldUpdaterTest> a = AtomicLongFieldUpdater.newUpdater(AtomicLongFieldUpdaterTest.class, "x");
171          x = 1;
172          assertEquals(1,a.getAndIncrement(this));
173          assertEquals(2,a.get(this));
# Line 181 | Line 182 | public class AtomicLongFieldUpdaterTest
182       * addAndGet adds given value to current, and returns current value
183       */
184      public void testAddAndGet(){
185 <        AtomicLongFieldUpdater<AtomicLongFieldUpdaterTest> a = AtomicLongFieldUpdater.newUpdater(getClass(), "x");
185 >        AtomicLongFieldUpdater<AtomicLongFieldUpdaterTest> a = AtomicLongFieldUpdater.newUpdater(AtomicLongFieldUpdaterTest.class, "x");
186          x = 1;
187          assertEquals(3,a.addAndGet(this,2));
188          assertEquals(3,a.get(this));
# Line 193 | Line 194 | public class AtomicLongFieldUpdaterTest
194       *  decrementAndGet decrements and returns current value
195       */
196      public void testDecrementAndGet(){
197 <        AtomicLongFieldUpdater<AtomicLongFieldUpdaterTest> a = AtomicLongFieldUpdater.newUpdater(getClass(), "x");
197 >        AtomicLongFieldUpdater<AtomicLongFieldUpdaterTest> a = AtomicLongFieldUpdater.newUpdater(AtomicLongFieldUpdaterTest.class, "x");
198          x = 1;
199          assertEquals(0,a.decrementAndGet(this));
200          assertEquals(-1,a.decrementAndGet(this));
# Line 205 | Line 206 | public class AtomicLongFieldUpdaterTest
206       * incrementAndGet increments and returns current value
207       */
208      public void testIncrementAndGet(){
209 <        AtomicLongFieldUpdater<AtomicLongFieldUpdaterTest> a = AtomicLongFieldUpdater.newUpdater(getClass(), "x");
209 >        AtomicLongFieldUpdater<AtomicLongFieldUpdaterTest> a = AtomicLongFieldUpdater.newUpdater(AtomicLongFieldUpdaterTest.class, "x");
210          x = 1;
211          assertEquals(2,a.incrementAndGet(this));
212          assertEquals(2,a.get(this));

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines