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

Comparing jsr166/src/test/tck/AtomicReferenceFieldUpdaterTest.java (file contents):
Revision 1.29 by jsr166, Thu May 30 03:28:55 2013 UTC vs.
Revision 1.33 by jsr166, Sat Apr 25 04:55:30 2015 UTC

# Line 6 | Line 6
6   * Pat Fisher, Mike Judd.
7   */
8  
9 import junit.framework.*;
9   import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;
10  
11 + import junit.framework.Test;
12 + import junit.framework.TestSuite;
13 +
14   public class AtomicReferenceFieldUpdaterTest extends JSR166TestCase {
15      volatile Integer x = null;
16      Object z;
# Line 16 | Line 18 | public class AtomicReferenceFieldUpdater
18      volatile int i;
19  
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(AtomicReferenceFieldUpdaterTest.class);
# Line 73 | Line 75 | public class AtomicReferenceFieldUpdater
75       * get returns the last value set or assigned
76       */
77      public void testGetSet() {
78 <        AtomicReferenceFieldUpdater<AtomicReferenceFieldUpdaterTest, Integer>a;
78 >        AtomicReferenceFieldUpdater<AtomicReferenceFieldUpdaterTest, Integer> a;
79          a = updaterFor("x");
80          x = one;
81          assertSame(one, a.get(this));
# Line 87 | Line 89 | public class AtomicReferenceFieldUpdater
89       * get returns the last value lazySet by same thread
90       */
91      public void testGetLazySet() {
92 <        AtomicReferenceFieldUpdater<AtomicReferenceFieldUpdaterTest, Integer>a;
92 >        AtomicReferenceFieldUpdater<AtomicReferenceFieldUpdaterTest, Integer> a;
93          a = updaterFor("x");
94          x = one;
95          assertSame(one, a.get(this));
# Line 101 | Line 103 | public class AtomicReferenceFieldUpdater
103       * compareAndSet succeeds in changing value if equal to expected else fails
104       */
105      public void testCompareAndSet() {
106 <        AtomicReferenceFieldUpdater<AtomicReferenceFieldUpdaterTest, Integer>a;
106 >        AtomicReferenceFieldUpdater<AtomicReferenceFieldUpdaterTest, Integer> a;
107          a = updaterFor("x");
108          x = one;
109          assertTrue(a.compareAndSet(this, one, two));
# Line 119 | Line 121 | public class AtomicReferenceFieldUpdater
121       */
122      public void testCompareAndSetInMultipleThreads() throws Exception {
123          x = one;
124 <        final AtomicReferenceFieldUpdater<AtomicReferenceFieldUpdaterTest, Integer>a;
124 >        final AtomicReferenceFieldUpdater<AtomicReferenceFieldUpdaterTest, Integer> a;
125          a = updaterFor("x");
126  
127          Thread t = new Thread(new CheckedRunnable() {
# Line 140 | Line 142 | public class AtomicReferenceFieldUpdater
142       * to expected
143       */
144      public void testWeakCompareAndSet() {
145 <        AtomicReferenceFieldUpdater<AtomicReferenceFieldUpdaterTest, Integer>a;
145 >        AtomicReferenceFieldUpdater<AtomicReferenceFieldUpdaterTest, Integer> a;
146          a = updaterFor("x");
147          x = one;
148 <        while (!a.weakCompareAndSet(this, one, two));
149 <        while (!a.weakCompareAndSet(this, two, m4));
148 >        do {} while (!a.weakCompareAndSet(this, one, two));
149 >        do {} while (!a.weakCompareAndSet(this, two, m4));
150          assertSame(m4, a.get(this));
151 <        while (!a.weakCompareAndSet(this, m4, seven));
151 >        do {} while (!a.weakCompareAndSet(this, m4, seven));
152          assertSame(seven, a.get(this));
153      }
154  
# Line 154 | Line 156 | public class AtomicReferenceFieldUpdater
156       * getAndSet returns previous value and sets to given value
157       */
158      public void testGetAndSet() {
159 <        AtomicReferenceFieldUpdater<AtomicReferenceFieldUpdaterTest, Integer>a;
159 >        AtomicReferenceFieldUpdater<AtomicReferenceFieldUpdaterTest, Integer> a;
160          a = updaterFor("x");
161          x = one;
162          assertSame(one, a.getAndSet(this, zero));

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines