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

Comparing jsr166/src/test/tck/AtomicIntegerTest.java (file contents):
Revision 1.4 by dl, Sat Sep 20 18:20:07 2003 UTC vs.
Revision 1.5 by dl, Thu Sep 25 11:02:41 2003 UTC

# Line 18 | Line 18 | public class AtomicIntegerTest extends J
18      }
19  
20      /**
21 <     *
21 >     * constructor initializes to given value
22       */
23      public void testConstructor(){
24          AtomicInteger ai = new AtomicInteger(1);
# Line 26 | Line 26 | public class AtomicIntegerTest extends J
26      }
27  
28      /**
29 <     *
29 >     * default constructed intializes to zero
30       */
31      public void testConstructor2(){
32          AtomicInteger ai = new AtomicInteger();
# Line 34 | Line 34 | public class AtomicIntegerTest extends J
34      }
35  
36      /**
37 <     *
37 >     * get returns the last value set
38       */
39      public void testGetSet(){
40          AtomicInteger ai = new AtomicInteger(1);
# Line 46 | Line 46 | public class AtomicIntegerTest extends J
46          
47      }
48      /**
49 <     *
49 >     * compareAndSet succeeds in changing value if equal to expected else fails
50       */
51      public void testCompareAndSet(){
52          AtomicInteger ai = new AtomicInteger(1);
# Line 60 | Line 60 | public class AtomicIntegerTest extends J
60      }
61  
62      /**
63 <     *
63 >     * compareAndSet in one thread enables another waiting for value
64 >     * to succeed
65 >     */
66 >    public void testCompareAndSetInMultipleThreads() {
67 >        final AtomicInteger ai = new AtomicInteger(1);
68 >        Thread t = new Thread(new Runnable() {
69 >                public void run() {
70 >                    while(!ai.compareAndSet(2, 3)) Thread.yield();
71 >                }});
72 >        try {
73 >            t.start();
74 >            assertTrue(ai.compareAndSet(1, 2));
75 >            t.join(LONG_DELAY_MS);
76 >            assertFalse(t.isAlive());
77 >            assertEquals(ai.get(), 3);
78 >        }
79 >        catch(Exception e) {
80 >            unexpectedException();
81 >        }
82 >    }
83 >
84 >    /**
85 >     * repeated weakCompareAndSet succeeds in changing value when equal
86 >     * to expected
87       */
88      public void testWeakCompareAndSet(){
89          AtomicInteger ai = new AtomicInteger(1);
# Line 72 | Line 95 | public class AtomicIntegerTest extends J
95      }
96  
97      /**
98 <     *
98 >     * getAndSet returns previous value and sets to given value
99       */
100      public void testGetAndSet(){
101          AtomicInteger ai = new AtomicInteger(1);
# Line 82 | Line 105 | public class AtomicIntegerTest extends J
105      }
106  
107      /**
108 <     *
108 >     * getAndAdd returns previous value and adds given value
109       */
110      public void testGetAndAdd(){
111          AtomicInteger ai = new AtomicInteger(1);
# Line 93 | Line 116 | public class AtomicIntegerTest extends J
116      }
117  
118      /**
119 <     *
119 >     * getAndDecrement returns previous value and decrements
120       */
121      public void testGetAndDecrement(){
122          AtomicInteger ai = new AtomicInteger(1);
# Line 103 | Line 126 | public class AtomicIntegerTest extends J
126      }
127  
128      /**
129 <     *
129 >     * getAndIncrement returns previous value and increments
130       */
131      public void testGetAndIncrement(){
132          AtomicInteger ai = new AtomicInteger(1);
# Line 117 | Line 140 | public class AtomicIntegerTest extends J
140      }
141  
142      /**
143 <     *
143 >     * addAndGet adds given value to current, and returns current value
144       */
145      public void testAddAndGet(){
146          AtomicInteger ai = new AtomicInteger(1);
# Line 128 | Line 151 | public class AtomicIntegerTest extends J
151      }
152  
153      /**
154 <     *
154 >     * decrementAndGet decrements and returns current value
155       */
156      public void testDecrementAndGet(){
157          AtomicInteger ai = new AtomicInteger(1);
# Line 139 | Line 162 | public class AtomicIntegerTest extends J
162      }
163  
164      /**
165 <     *
165 >     * incrementAndGet increments and returns current value
166       */
167      public void testIncrementAndGet(){
168          AtomicInteger ai = new AtomicInteger(1);
# Line 153 | Line 176 | public class AtomicIntegerTest extends J
176      }
177  
178      /**
179 <     *
179 >     * a deserialized serialized atomic holds same value
180       */
181      public void testSerialization() {
182          AtomicInteger l = new AtomicInteger();

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines