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.9 by dl, Wed May 25 14:27:37 2005 UTC vs.
Revision 1.10 by jsr166, Mon Nov 2 20:28:31 2009 UTC

# Line 2 | Line 2
2   * Written by Doug Lea with assistance from members of JCP JSR-166
3   * Expert Group and released to the public domain, as explained at
4   * http://creativecommons.org/licenses/publicdomain
5 < * Other contributors include Andrew Wright, Jeffrey Hayes,
6 < * Pat Fisher, Mike Judd.
5 > * Other contributors include Andrew Wright, Jeffrey Hayes,
6 > * Pat Fisher, Mike Judd.
7   */
8  
9   import junit.framework.*;
# Line 24 | Line 24 | public class AtomicLongArrayTest extends
24       */
25      public void testConstructor(){
26          AtomicLongArray ai = new AtomicLongArray(SIZE);
27 <        for (int i = 0; i < SIZE; ++i)
27 >        for (int i = 0; i < SIZE; ++i)
28              assertEquals(0,ai.get(i));
29      }
30  
# Line 48 | Line 48 | public class AtomicLongArrayTest extends
48          long[] a = { 17L, 3L, -42L, 99L, -7L};
49          AtomicLongArray ai = new AtomicLongArray(a);
50          assertEquals(a.length, ai.length());
51 <        for (int i = 0; i < a.length; ++i)
51 >        for (int i = 0; i < a.length; ++i)
52              assertEquals(a[i], ai.get(i));
53      }
54  
# Line 79 | Line 79 | public class AtomicLongArrayTest extends
79       * get returns the last value set at index
80       */
81      public void testGetSet(){
82 <        AtomicLongArray ai = new AtomicLongArray(SIZE);
82 >        AtomicLongArray ai = new AtomicLongArray(SIZE);
83          for (int i = 0; i < SIZE; ++i) {
84              ai.set(i, 1);
85              assertEquals(1,ai.get(i));
# Line 94 | Line 94 | public class AtomicLongArrayTest extends
94       * get returns the last value lazySet at index by same thread
95       */
96      public void testGetLazySet(){
97 <        AtomicLongArray ai = new AtomicLongArray(SIZE);
97 >        AtomicLongArray ai = new AtomicLongArray(SIZE);
98          for (int i = 0; i < SIZE; ++i) {
99              ai.lazySet(i, 1);
100              assertEquals(1,ai.get(i));
# Line 109 | Line 109 | public class AtomicLongArrayTest extends
109       * compareAndSet succeeds in changing value if equal to expected else fails
110       */
111      public void testCompareAndSet(){
112 <        AtomicLongArray ai = new AtomicLongArray(SIZE);
112 >        AtomicLongArray ai = new AtomicLongArray(SIZE);
113          for (int i = 0; i < SIZE; ++i) {
114              ai.set(i, 1);
115              assertTrue(ai.compareAndSet(i, 1,2));
# Line 147 | Line 147 | public class AtomicLongArrayTest extends
147  
148      /**
149       * repeated weakCompareAndSet succeeds in changing value when equal
150 <     * to expected
150 >     * to expected
151       */
152      public void testWeakCompareAndSet(){
153 <        AtomicLongArray ai = new AtomicLongArray(SIZE);
153 >        AtomicLongArray ai = new AtomicLongArray(SIZE);
154          for (int i = 0; i < SIZE; ++i) {
155              ai.set(i, 1);
156              while(!ai.weakCompareAndSet(i, 1,2));
# Line 165 | Line 165 | public class AtomicLongArrayTest extends
165       *  getAndSet returns previous value and sets to given value at given index
166       */
167      public void testGetAndSet(){
168 <        AtomicLongArray ai = new AtomicLongArray(SIZE);
168 >        AtomicLongArray ai = new AtomicLongArray(SIZE);
169          for (int i = 0; i < SIZE; ++i) {
170              ai.set(i, 1);
171              assertEquals(1,ai.getAndSet(i,0));
# Line 178 | Line 178 | public class AtomicLongArrayTest extends
178       *  getAndAdd returns previous value and adds given value
179       */
180      public void testGetAndAdd(){
181 <        AtomicLongArray ai = new AtomicLongArray(SIZE);
181 >        AtomicLongArray ai = new AtomicLongArray(SIZE);
182          for (int i = 0; i < SIZE; ++i) {
183              ai.set(i, 1);
184              assertEquals(1,ai.getAndAdd(i,2));
# Line 192 | Line 192 | public class AtomicLongArrayTest extends
192       * getAndDecrement returns previous value and decrements
193       */
194      public void testGetAndDecrement(){
195 <        AtomicLongArray ai = new AtomicLongArray(SIZE);
195 >        AtomicLongArray ai = new AtomicLongArray(SIZE);
196          for (int i = 0; i < SIZE; ++i) {
197              ai.set(i, 1);
198              assertEquals(1,ai.getAndDecrement(i));
# Line 205 | Line 205 | public class AtomicLongArrayTest extends
205       * getAndIncrement returns previous value and increments
206       */
207      public void testGetAndIncrement(){
208 <        AtomicLongArray ai = new AtomicLongArray(SIZE);
208 >        AtomicLongArray ai = new AtomicLongArray(SIZE);
209          for (int i = 0; i < SIZE; ++i) {
210              ai.set(i, 1);
211              assertEquals(1,ai.getAndIncrement(i));
# Line 222 | Line 222 | public class AtomicLongArrayTest extends
222       *  addAndGet adds given value to current, and returns current value
223       */
224      public void testAddAndGet() {
225 <        AtomicLongArray ai = new AtomicLongArray(SIZE);
225 >        AtomicLongArray ai = new AtomicLongArray(SIZE);
226          for (int i = 0; i < SIZE; ++i) {
227              ai.set(i, 1);
228              assertEquals(3,ai.addAndGet(i,2));
# Line 236 | Line 236 | public class AtomicLongArrayTest extends
236       * decrementAndGet decrements and returns current value
237       */
238      public void testDecrementAndGet(){
239 <        AtomicLongArray ai = new AtomicLongArray(SIZE);
239 >        AtomicLongArray ai = new AtomicLongArray(SIZE);
240          for (int i = 0; i < SIZE; ++i) {
241              ai.set(i, 1);
242              assertEquals(0,ai.decrementAndGet(i));
# Line 250 | Line 250 | public class AtomicLongArrayTest extends
250       * incrementAndGet increments and returns current value
251       */
252      public void testIncrementAndGet() {
253 <        AtomicLongArray ai = new AtomicLongArray(SIZE);
253 >        AtomicLongArray ai = new AtomicLongArray(SIZE);
254          for (int i = 0; i < SIZE; ++i) {
255              ai.set(i, 1);
256              assertEquals(2,ai.incrementAndGet(i));
# Line 264 | Line 264 | public class AtomicLongArrayTest extends
264      }
265  
266      static final long COUNTDOWN = 100000;
267 <    
267 >
268      class Counter implements Runnable {
269          final AtomicLongArray ai;
270          volatile long counts;
# Line 293 | Line 293 | public class AtomicLongArrayTest extends
293       */
294      public void testCountingInMultipleThreads() {
295          try {
296 <            final AtomicLongArray ai = new AtomicLongArray(SIZE);
297 <            for (int i = 0; i < SIZE; ++i)
296 >            final AtomicLongArray ai = new AtomicLongArray(SIZE);
297 >            for (int i = 0; i < SIZE; ++i)
298                  ai.set(i, COUNTDOWN);
299              Counter c1 = new Counter(ai);
300              Counter c2 = new Counter(ai);
# Line 315 | Line 315 | public class AtomicLongArrayTest extends
315       * a deserialized serialized array holds same values
316       */
317      public void testSerialization() {
318 <        AtomicLongArray l = new AtomicLongArray(SIZE);
319 <        for (int i = 0; i < SIZE; ++i)
318 >        AtomicLongArray l = new AtomicLongArray(SIZE);
319 >        for (int i = 0; i < SIZE; ++i)
320              l.set(i, -i);
321  
322          try {
# Line 338 | Line 338 | public class AtomicLongArrayTest extends
338  
339      /**
340       * toString returns current value.
341 <     */
341 >     */
342      public void testToString() {
343          long[] a = { 17, 3, -42, 99, -7};
344          AtomicLongArray ai = new AtomicLongArray(a);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines