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

Comparing jsr166/src/test/tck/AtomicReferenceArrayTest.java (file contents):
Revision 1.25 by jsr166, Fri Jun 10 20:17:11 2011 UTC vs.
Revision 1.26 by jsr166, Wed Aug 10 07:14:48 2011 UTC

# Line 22 | Line 22 | public class AtomicReferenceArrayTest ex
22       * constructor creates array of given size with all elements null
23       */
24      public void testConstructor() {
25 <        AtomicReferenceArray<Integer> ai = new AtomicReferenceArray<Integer>(SIZE);
26 <        for (int i = 0; i < SIZE; ++i) {
27 <            assertNull(ai.get(i));
25 >        AtomicReferenceArray<Integer> aa = new AtomicReferenceArray<Integer>(SIZE);
26 >        for (int i = 0; i < SIZE; i++) {
27 >            assertNull(aa.get(i));
28          }
29      }
30  
# Line 34 | Line 34 | public class AtomicReferenceArrayTest ex
34      public void testConstructor2NPE() {
35          try {
36              Integer[] a = null;
37 <            AtomicReferenceArray<Integer> ai = new AtomicReferenceArray<Integer>(a);
37 >            AtomicReferenceArray<Integer> aa = new AtomicReferenceArray<Integer>(a);
38              shouldThrow();
39          } catch (NullPointerException success) {}
40      }
# Line 44 | Line 44 | public class AtomicReferenceArrayTest ex
44       */
45      public void testConstructor2() {
46          Integer[] a = { two, one, three, four, seven };
47 <        AtomicReferenceArray<Integer> ai = new AtomicReferenceArray<Integer>(a);
48 <        assertEquals(a.length, ai.length());
49 <        for (int i = 0; i < a.length; ++i)
50 <            assertEquals(a[i], ai.get(i));
47 >        AtomicReferenceArray<Integer> aa = new AtomicReferenceArray<Integer>(a);
48 >        assertEquals(a.length, aa.length());
49 >        for (int i = 0; i < a.length; i++)
50 >            assertEquals(a[i], aa.get(i));
51      }
52  
53      /**
# Line 57 | Line 57 | public class AtomicReferenceArrayTest ex
57          Integer[] a = { two, one, three, four, seven };
58          AtomicReferenceArray<Number> aa = new AtomicReferenceArray<Number>(a);
59          assertEquals(a.length, aa.length());
60 <        for (int i = 0; i < a.length; ++i) {
60 >        for (int i = 0; i < a.length; i++) {
61              assertSame(a[i], aa.get(i));
62              Long x = Long.valueOf(i);
63              aa.set(i, x);
# Line 69 | Line 69 | public class AtomicReferenceArrayTest ex
69       * get and set for out of bound indices throw IndexOutOfBoundsException
70       */
71      public void testIndexing() {
72 <        AtomicReferenceArray<Integer> ai = new AtomicReferenceArray<Integer>(SIZE);
73 <        try {
74 <            ai.get(SIZE);
75 <            shouldThrow();
76 <        } catch (IndexOutOfBoundsException success) {
77 <        }
78 <        try {
79 <            ai.get(-1);
80 <            shouldThrow();
81 <        } catch (IndexOutOfBoundsException success) {
82 <        }
83 <        try {
84 <            ai.set(SIZE, null);
85 <            shouldThrow();
86 <        } catch (IndexOutOfBoundsException success) {
87 <        }
88 <        try {
89 <            ai.set(-1, null);
90 <            shouldThrow();
91 <        } catch (IndexOutOfBoundsException success) {
72 >        AtomicReferenceArray<Integer> aa = new AtomicReferenceArray<Integer>(SIZE);
73 >        for (int index : new int[] { -1, SIZE }) {
74 >            try {
75 >                aa.get(index);
76 >                shouldThrow();
77 >            } catch (IndexOutOfBoundsException success) {}
78 >            try {
79 >                aa.set(index, null);
80 >                shouldThrow();
81 >            } catch (IndexOutOfBoundsException success) {}
82 >            try {
83 >                aa.lazySet(index, null);
84 >                shouldThrow();
85 >            } catch (IndexOutOfBoundsException success) {}
86 >            try {
87 >                aa.compareAndSet(index, null, null);
88 >                shouldThrow();
89 >            } catch (IndexOutOfBoundsException success) {}
90 >            try {
91 >                aa.weakCompareAndSet(index, null, null);
92 >                shouldThrow();
93 >            } catch (IndexOutOfBoundsException success) {}
94          }
95      }
96  
# Line 96 | Line 98 | public class AtomicReferenceArrayTest ex
98       * get returns the last value set at index
99       */
100      public void testGetSet() {
101 <        AtomicReferenceArray ai = new AtomicReferenceArray(SIZE);
102 <        for (int i = 0; i < SIZE; ++i) {
103 <            ai.set(i, one);
104 <            assertSame(one, ai.get(i));
105 <            ai.set(i, two);
106 <            assertSame(two, ai.get(i));
107 <            ai.set(i, m3);
108 <            assertSame(m3, ai.get(i));
101 >        AtomicReferenceArray aa = new AtomicReferenceArray(SIZE);
102 >        for (int i = 0; i < SIZE; i++) {
103 >            aa.set(i, one);
104 >            assertSame(one, aa.get(i));
105 >            aa.set(i, two);
106 >            assertSame(two, aa.get(i));
107 >            aa.set(i, m3);
108 >            assertSame(m3, aa.get(i));
109          }
110      }
111  
# Line 111 | Line 113 | public class AtomicReferenceArrayTest ex
113       * get returns the last value lazySet at index by same thread
114       */
115      public void testGetLazySet() {
116 <        AtomicReferenceArray ai = new AtomicReferenceArray(SIZE);
117 <        for (int i = 0; i < SIZE; ++i) {
118 <            ai.lazySet(i, one);
119 <            assertSame(one, ai.get(i));
120 <            ai.lazySet(i, two);
121 <            assertSame(two, ai.get(i));
122 <            ai.lazySet(i, m3);
123 <            assertSame(m3, ai.get(i));
116 >        AtomicReferenceArray aa = new AtomicReferenceArray(SIZE);
117 >        for (int i = 0; i < SIZE; i++) {
118 >            aa.lazySet(i, one);
119 >            assertSame(one, aa.get(i));
120 >            aa.lazySet(i, two);
121 >            assertSame(two, aa.get(i));
122 >            aa.lazySet(i, m3);
123 >            assertSame(m3, aa.get(i));
124          }
125      }
126  
# Line 126 | Line 128 | public class AtomicReferenceArrayTest ex
128       * compareAndSet succeeds in changing value if equal to expected else fails
129       */
130      public void testCompareAndSet() {
131 <        AtomicReferenceArray ai = new AtomicReferenceArray(SIZE);
132 <        for (int i = 0; i < SIZE; ++i) {
133 <            ai.set(i, one);
134 <            assertTrue(ai.compareAndSet(i, one, two));
135 <            assertTrue(ai.compareAndSet(i, two, m4));
136 <            assertSame(m4, ai.get(i));
137 <            assertFalse(ai.compareAndSet(i, m5, seven));
138 <            assertSame(m4, ai.get(i));
139 <            assertTrue(ai.compareAndSet(i, m4, seven));
140 <            assertSame(seven, ai.get(i));
131 >        AtomicReferenceArray aa = new AtomicReferenceArray(SIZE);
132 >        for (int i = 0; i < SIZE; i++) {
133 >            aa.set(i, one);
134 >            assertTrue(aa.compareAndSet(i, one, two));
135 >            assertTrue(aa.compareAndSet(i, two, m4));
136 >            assertSame(m4, aa.get(i));
137 >            assertFalse(aa.compareAndSet(i, m5, seven));
138 >            assertSame(m4, aa.get(i));
139 >            assertTrue(aa.compareAndSet(i, m4, seven));
140 >            assertSame(seven, aa.get(i));
141          }
142      }
143  
# Line 164 | Line 166 | public class AtomicReferenceArrayTest ex
166       * to expected
167       */
168      public void testWeakCompareAndSet() {
169 <        AtomicReferenceArray ai = new AtomicReferenceArray(SIZE);
170 <        for (int i = 0; i < SIZE; ++i) {
171 <            ai.set(i, one);
172 <            while (!ai.weakCompareAndSet(i, one, two));
173 <            while (!ai.weakCompareAndSet(i, two, m4));
174 <            assertSame(m4, ai.get(i));
175 <            while (!ai.weakCompareAndSet(i, m4, seven));
176 <            assertSame(seven, ai.get(i));
169 >        AtomicReferenceArray aa = new AtomicReferenceArray(SIZE);
170 >        for (int i = 0; i < SIZE; i++) {
171 >            aa.set(i, one);
172 >            while (!aa.weakCompareAndSet(i, one, two));
173 >            while (!aa.weakCompareAndSet(i, two, m4));
174 >            assertSame(m4, aa.get(i));
175 >            while (!aa.weakCompareAndSet(i, m4, seven));
176 >            assertSame(seven, aa.get(i));
177          }
178      }
179  
# Line 179 | Line 181 | public class AtomicReferenceArrayTest ex
181       * getAndSet returns previous value and sets to given value at given index
182       */
183      public void testGetAndSet() {
184 <        AtomicReferenceArray ai = new AtomicReferenceArray(SIZE);
185 <        for (int i = 0; i < SIZE; ++i) {
186 <            ai.set(i, one);
187 <            assertSame(one, ai.getAndSet(i, zero));
188 <            assertSame(zero, ai.getAndSet(i, m10));
189 <            assertSame(m10, ai.getAndSet(i, one));
184 >        AtomicReferenceArray aa = new AtomicReferenceArray(SIZE);
185 >        for (int i = 0; i < SIZE; i++) {
186 >            aa.set(i, one);
187 >            assertSame(one, aa.getAndSet(i, zero));
188 >            assertSame(zero, aa.getAndSet(i, m10));
189 >            assertSame(m10, aa.getAndSet(i, one));
190          }
191      }
192  
# Line 209 | Line 211 | public class AtomicReferenceArrayTest ex
211       */
212      public void testToString() {
213          Integer[] a = { two, one, three, four, seven };
214 <        AtomicReferenceArray<Integer> ai = new AtomicReferenceArray<Integer>(a);
215 <        assertEquals(Arrays.toString(a), ai.toString());
214 >        AtomicReferenceArray<Integer> aa = new AtomicReferenceArray<Integer>(a);
215 >        assertEquals(Arrays.toString(a), aa.toString());
216      }
217   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines