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

Comparing jsr166/src/test/tck/AtomicLongArrayTest.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 AtomicLongArrayTest extends
18      }
19  
20      /**
21 <     *
21 >     * constructor creates array of given size with all elements zero
22       */
23      public void testConstructor(){
24          AtomicLongArray ai = new AtomicLongArray(SIZE);
# Line 27 | Line 27 | public class AtomicLongArrayTest extends
27      }
28  
29      /**
30 <     *
30 >     * get and set for out of bound indices throw IndexOutOfBoundsException
31 >     */
32 >    public void testIndexing(){
33 >        AtomicLongArray ai = new AtomicLongArray(SIZE);
34 >        try {
35 >            ai.get(SIZE);
36 >        } catch(IndexOutOfBoundsException success){
37 >        }
38 >        try {
39 >            ai.get(-1);
40 >        } catch(IndexOutOfBoundsException success){
41 >        }
42 >        try {
43 >            ai.set(SIZE, 0);
44 >        } catch(IndexOutOfBoundsException success){
45 >        }
46 >        try {
47 >            ai.set(-1, 0);
48 >        } catch(IndexOutOfBoundsException success){
49 >        }
50 >    }
51 >
52 >    /**
53 >     * get returns the last value set at index
54       */
55      public void testGetSet(){
56          AtomicLongArray ai = new AtomicLongArray(SIZE);
# Line 42 | Line 65 | public class AtomicLongArrayTest extends
65      }
66  
67      /**
68 <     *
68 >     * compareAndSet succeeds in changing value if equal to expected else fails
69       */
70      public void testCompareAndSet(){
71          AtomicLongArray ai = new AtomicLongArray(SIZE);
# Line 59 | Line 82 | public class AtomicLongArrayTest extends
82      }
83  
84      /**
85 <     *
85 >     * compareAndSet in one thread enables another waiting for value
86 >     * to succeed
87 >     */
88 >    public void testCompareAndSetInMultipleThreads() {
89 >        final AtomicLongArray a = new AtomicLongArray(1);
90 >        a.set(0, 1);
91 >        Thread t = new Thread(new Runnable() {
92 >                public void run() {
93 >                    while(!a.compareAndSet(0, 2, 3)) Thread.yield();
94 >                }});
95 >        try {
96 >            t.start();
97 >            assertTrue(a.compareAndSet(0, 1, 2));
98 >            t.join(LONG_DELAY_MS);
99 >            assertFalse(t.isAlive());
100 >            assertEquals(a.get(0), 3);
101 >        }
102 >        catch(Exception e) {
103 >            unexpectedException();
104 >        }
105 >    }
106 >
107 >    /**
108 >     * repeated weakCompareAndSet succeeds in changing value when equal
109 >     * to expected
110       */
111      public void testWeakCompareAndSet(){
112          AtomicLongArray ai = new AtomicLongArray(SIZE);
# Line 74 | Line 121 | public class AtomicLongArrayTest extends
121      }
122  
123      /**
124 <     *
124 >     *  getAndSet returns previous value and sets to given value at given index
125       */
126      public void testGetAndSet(){
127          AtomicLongArray ai = new AtomicLongArray(SIZE);
# Line 87 | Line 134 | public class AtomicLongArrayTest extends
134      }
135  
136      /**
137 <     *
137 >     *  getAndAdd returns previous value and adds given value
138       */
139      public void testGetAndAdd(){
140          AtomicLongArray ai = new AtomicLongArray(SIZE);
# Line 101 | Line 148 | public class AtomicLongArrayTest extends
148      }
149  
150      /**
151 <     *
151 >     * getAndDecrement returns previous value and decrements
152       */
153      public void testGetAndDecrement(){
154          AtomicLongArray ai = new AtomicLongArray(SIZE);
# Line 114 | Line 161 | public class AtomicLongArrayTest extends
161      }
162  
163      /**
164 <     *
164 >     * getAndIncrement returns previous value and increments
165       */
166      public void testGetAndIncrement(){
167          AtomicLongArray ai = new AtomicLongArray(SIZE);
# Line 131 | Line 178 | public class AtomicLongArrayTest extends
178      }
179  
180      /**
181 <     *
181 >     *  addAndGet adds given value to current, and returns current value
182       */
183      public void testAddAndGet() {
184          AtomicLongArray ai = new AtomicLongArray(SIZE);
# Line 145 | Line 192 | public class AtomicLongArrayTest extends
192      }
193  
194      /**
195 <     *
195 >     * decrementAndGet decrements and returns current value
196       */
197      public void testDecrementAndGet(){
198          AtomicLongArray ai = new AtomicLongArray(SIZE);
# Line 159 | Line 206 | public class AtomicLongArrayTest extends
206      }
207  
208      /**
209 <     *
209 >     * incrementAndGet increments and returns current value
210       */
211      public void testIncrementAndGet() {
212          AtomicLongArray ai = new AtomicLongArray(SIZE);
# Line 200 | Line 247 | public class AtomicLongArrayTest extends
247      }
248  
249      /**
250 <     *
250 >     * Multiple threads using same array of counters successfully
251 >     * update a number of times equal to total count
252       */
253      public void testCountingInMultipleThreads() {
254          try {
# Line 223 | Line 271 | public class AtomicLongArrayTest extends
271      }
272  
273      /**
274 <     *
274 >     * a deserialized serialized array holds same values
275       */
276      public void testSerialization() {
277          AtomicLongArray l = new AtomicLongArray(SIZE);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines