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.3 by dl, Sat Sep 20 18:20:07 2003 UTC vs.
Revision 1.4 by dl, Thu Sep 25 11:02:41 2003 UTC

# Line 11 | Line 11 | import java.util.*;
11  
12   public class AtomicLongFieldUpdaterTest extends JSR166TestCase {
13      volatile long x = 0;
14 <    long z;
15 <    int w;
14 >    int z;
15 >    long w;
16  
17      public static void main(String[] args){
18          junit.textui.TestRunner.run(suite());
19      }
20
21  
20      public static Test suite() {
21          return new TestSuite(AtomicLongFieldUpdaterTest.class);
22      }
23  
24      /**
25 <     *
25 >     * Contruction with non-existent field throws RuntimeException
26       */
27      public void testConstructor(){
28          try{
# Line 37 | Line 35 | public class AtomicLongFieldUpdaterTest
35      }
36  
37      /**
38 <     *
38 >     * construction with field not of given type throws RuntimeException
39       */
40      public void testConstructor2(){
41          try{
# Line 50 | Line 48 | public class AtomicLongFieldUpdaterTest
48      }
49  
50      /**
51 <     *
51 >     * construction with non-volatile field throws RuntimeException
52       */
53      public void testConstructor3(){
54          try{
# Line 64 | Line 62 | public class AtomicLongFieldUpdaterTest
62      }
63  
64      /**
65 <     *
65 >     *  get returns the last value set or assigned
66       */
67      public void testGetSet(){
68          AtomicLongFieldUpdater<AtomicLongFieldUpdaterTest> a = AtomicLongFieldUpdater.newUpdater(getClass(), "x");
# Line 77 | Line 75 | public class AtomicLongFieldUpdaterTest
75          
76      }
77      /**
78 <     *
78 >     * compareAndSet succeeds in changing value if equal to expected else fails
79       */
80      public void testCompareAndSet(){
81          AtomicLongFieldUpdater<AtomicLongFieldUpdaterTest> a = AtomicLongFieldUpdater.newUpdater(getClass(), "x");
# Line 91 | Line 89 | public class AtomicLongFieldUpdaterTest
89          assertEquals(7,a.get(this));
90      }
91  
92 +
93 +    /**
94 +     * compareAndSet in one thread enables another waiting for value
95 +     * to succeed
96 +     */
97 +    public void testCompareAndSetInMultipleThreads() {
98 +        x = 1;
99 +        final AtomicLongFieldUpdater<AtomicLongFieldUpdaterTest>a = AtomicLongFieldUpdater.newUpdater(getClass(), "x");
100 +
101 +        Thread t = new Thread(new Runnable() {
102 +                public void run() {
103 +                    while(!a.compareAndSet(AtomicLongFieldUpdaterTest.this, 2, 3)) Thread.yield();
104 +                }});
105 +        try {
106 +            t.start();
107 +            assertTrue(a.compareAndSet(this, 1, 2));
108 +            t.join(LONG_DELAY_MS);
109 +            assertFalse(t.isAlive());
110 +            assertEquals(a.get(this), 3);
111 +        }
112 +        catch(Exception e) {
113 +            unexpectedException();
114 +        }
115 +    }
116 +
117      /**
118 <     *
118 >     * repeated weakCompareAndSet succeeds in changing value when equal
119 >     * to expected
120       */
121      public void testWeakCompareAndSet(){
122          AtomicLongFieldUpdater<AtomicLongFieldUpdaterTest> a = AtomicLongFieldUpdater.newUpdater(getClass(), "x");
# Line 105 | Line 129 | public class AtomicLongFieldUpdaterTest
129      }
130  
131      /**
132 <     *
132 >     *  getAndSet returns previous value and sets to given value
133       */
134      public void testGetAndSet(){
135          AtomicLongFieldUpdater<AtomicLongFieldUpdaterTest> a = AtomicLongFieldUpdater.newUpdater(getClass(), "x");
# Line 116 | Line 140 | public class AtomicLongFieldUpdaterTest
140      }
141  
142      /**
143 <     *
143 >     * getAndAdd returns previous value and adds given value
144       */
145      public void testGetAndAdd(){
146          AtomicLongFieldUpdater<AtomicLongFieldUpdaterTest> a = AtomicLongFieldUpdater.newUpdater(getClass(), "x");
# Line 128 | Line 152 | public class AtomicLongFieldUpdaterTest
152      }
153  
154      /**
155 <     *
155 >     * getAndDecrement returns previous value and decrements
156       */
157      public void testGetAndDecrement(){
158          AtomicLongFieldUpdater<AtomicLongFieldUpdaterTest> a = AtomicLongFieldUpdater.newUpdater(getClass(), "x");
# Line 139 | Line 163 | public class AtomicLongFieldUpdaterTest
163      }
164  
165      /**
166 <     *
166 >     * getAndIncrement returns previous value and increments
167       */
168      public void testGetAndIncrement(){
169          AtomicLongFieldUpdater<AtomicLongFieldUpdaterTest> a = AtomicLongFieldUpdater.newUpdater(getClass(), "x");
# Line 154 | Line 178 | public class AtomicLongFieldUpdaterTest
178      }
179  
180      /**
181 <     *
181 >     * addAndGet adds given value to current, and returns current value
182       */
183      public void testAddAndGet(){
184          AtomicLongFieldUpdater<AtomicLongFieldUpdaterTest> a = AtomicLongFieldUpdater.newUpdater(getClass(), "x");
# Line 166 | Line 190 | public class AtomicLongFieldUpdaterTest
190      }
191  
192      /**
193 <     *
193 >     *  decrementAndGet decrements and returns current value
194       */
195      public void testDecrementAndGet(){
196          AtomicLongFieldUpdater<AtomicLongFieldUpdaterTest> a = AtomicLongFieldUpdater.newUpdater(getClass(), "x");
# Line 178 | Line 202 | public class AtomicLongFieldUpdaterTest
202      }
203  
204      /**
205 <     *
205 >     * incrementAndGet increments and returns current value
206       */
207      public void testIncrementAndGet(){
208          AtomicLongFieldUpdater<AtomicLongFieldUpdaterTest> a = AtomicLongFieldUpdater.newUpdater(getClass(), "x");

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines