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.25 by jsr166, Tue Apr 2 04:11:28 2013 UTC vs.
Revision 1.33 by jsr166, Wed Sep 20 00:41:13 2017 UTC

# Line 6 | Line 6
6   * Pat Fisher, Mike Judd.
7   */
8  
9 import junit.framework.*;
9   import java.util.concurrent.atomic.AtomicLongFieldUpdater;
10  
11 + import junit.framework.Test;
12 + import junit.framework.TestSuite;
13 +
14   public class AtomicLongFieldUpdaterTest extends JSR166TestCase {
15      volatile long x = 0;
16 <    int z;
16 >    protected volatile long protectedField;
17 >    private volatile long privateField;
18      long w;
19 <
19 >    float z;
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(AtomicLongFieldUpdaterTest.class);
# Line 34 | Line 37 | public class AtomicLongFieldUpdaterTest
37              updaterFor("y");
38              shouldThrow();
39          } catch (RuntimeException success) {
40 <            assertTrue(success.getCause() != null);
40 >            assertNotNull(success.getCause());
41          }
42      }
43  
# Line 59 | Line 62 | public class AtomicLongFieldUpdaterTest
62      }
63  
64      /**
65 +     * construction using private field from subclass throws RuntimeException
66 +     */
67 +    public void testPrivateFieldInSubclass() {
68 +        new NonNestmates.AtomicLongFieldUpdaterTestSubclass()
69 +            .checkPrivateAccess();
70 +    }
71 +
72 +    /**
73 +     * construction from unrelated class; package access is allowed,
74 +     * private access is not
75 +     */
76 +    public void testUnrelatedClassAccess() {
77 +        new NonNestmates().checkPackageAccess(this);
78 +        new NonNestmates().checkPrivateAccess(this);
79 +    }
80 +
81 +    /**
82       * get returns the last value set or assigned
83       */
84      public void testGetSet() {
# Line 103 | Line 123 | public class AtomicLongFieldUpdaterTest
123      }
124  
125      /**
126 +     * compareAndSet succeeds in changing protected field value if
127 +     * equal to expected else fails
128 +     */
129 +    public void testCompareAndSetProtected() {
130 +        AtomicLongFieldUpdater<AtomicLongFieldUpdaterTest> a;
131 +        a = updaterFor("protectedField");
132 +        protectedField = 1;
133 +        assertTrue(a.compareAndSet(this, 1, 2));
134 +        assertTrue(a.compareAndSet(this, 2, -4));
135 +        assertEquals(-4, a.get(this));
136 +        assertFalse(a.compareAndSet(this, -5, 7));
137 +        assertEquals(-4, a.get(this));
138 +        assertTrue(a.compareAndSet(this, -4, 7));
139 +        assertEquals(7, a.get(this));
140 +    }
141 +
142 +    /**
143 +     * compareAndSet succeeds in changing protected field value if
144 +     * equal to expected else fails
145 +     */
146 +    public void testCompareAndSetProtectedInSubclass() {
147 +        NonNestmates.AtomicLongFieldUpdaterTestSubclass s =
148 +            new NonNestmates.AtomicLongFieldUpdaterTestSubclass();
149 +        s.checkCompareAndSetProtectedSub();
150 +    }
151 +
152 +    /**
153       * compareAndSet in one thread enables another waiting for value
154       * to succeed
155       */
# Line 132 | Line 179 | public class AtomicLongFieldUpdaterTest
179          AtomicLongFieldUpdater<AtomicLongFieldUpdaterTest> a;
180          a = updaterFor("x");
181          x = 1;
182 <        while (!a.weakCompareAndSet(this, 1, 2));
183 <        while (!a.weakCompareAndSet(this, 2, -4));
182 >        do {} while (!a.weakCompareAndSet(this, 1, 2));
183 >        do {} while (!a.weakCompareAndSet(this, 2, -4));
184          assertEquals(-4, a.get(this));
185 <        while (!a.weakCompareAndSet(this, -4, 7));
185 >        do {} while (!a.weakCompareAndSet(this, -4, 7));
186          assertEquals(7, a.get(this));
187      }
188  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines