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.38 by jsr166, Sun Jan 7 22:59:17 2018 UTC vs.
Revision 1.39 by dl, Tue Jan 26 13:33:05 2021 UTC

# Line 45 | Line 45 | public class AtomicReferenceArrayTest ex
45       * constructor with array is of same size and has all elements
46       */
47      public void testConstructor2() {
48 <        Integer[] a = { two, one, three, four, seven };
49 <        AtomicReferenceArray<Integer> aa = new AtomicReferenceArray<>(a);
48 >        Item[] a = { two, one, three, four, seven };
49 >        AtomicReferenceArray<Item> aa = new AtomicReferenceArray<>(a);
50          assertEquals(a.length, aa.length());
51          for (int i = 0; i < a.length; i++)
52              assertEquals(a[i], aa.get(i));
# Line 56 | Line 56 | public class AtomicReferenceArrayTest ex
56       * Initialize AtomicReferenceArray<Class> with SubClass[]
57       */
58      public void testConstructorSubClassArray() {
59 <        Integer[] a = { two, one, three, four, seven };
59 >        Item[] a = { two, one, three, four, seven };
60          AtomicReferenceArray<Number> aa = new AtomicReferenceArray<>(a);
61          assertEquals(a.length, aa.length());
62          for (int i = 0; i < a.length; i++) {
# Line 70 | Line 70 | public class AtomicReferenceArrayTest ex
70      /**
71       * get and set for out of bound indices throw IndexOutOfBoundsException
72       */
73 +    @SuppressWarnings("deprecation")
74      public void testIndexing() {
75          AtomicReferenceArray<Integer> aa = new AtomicReferenceArray<>(SIZE);
76          for (int index : new int[] { -1, SIZE }) {
# Line 100 | Line 101 | public class AtomicReferenceArrayTest ex
101       * get returns the last value set at index
102       */
103      public void testGetSet() {
104 <        AtomicReferenceArray aa = new AtomicReferenceArray(SIZE);
104 >        AtomicReferenceArray<Item> aa = new AtomicReferenceArray<Item>(SIZE);
105          for (int i = 0; i < SIZE; i++) {
106              aa.set(i, one);
107              assertSame(one, aa.get(i));
108              aa.set(i, two);
109              assertSame(two, aa.get(i));
110 <            aa.set(i, m3);
111 <            assertSame(m3, aa.get(i));
110 >            aa.set(i, minusThree);
111 >            assertSame(minusThree, aa.get(i));
112          }
113      }
114  
# Line 115 | Line 116 | public class AtomicReferenceArrayTest ex
116       * get returns the last value lazySet at index by same thread
117       */
118      public void testGetLazySet() {
119 <        AtomicReferenceArray aa = new AtomicReferenceArray(SIZE);
119 >        AtomicReferenceArray<Item> aa = new AtomicReferenceArray<Item>(SIZE);
120          for (int i = 0; i < SIZE; i++) {
121              aa.lazySet(i, one);
122              assertSame(one, aa.get(i));
123              aa.lazySet(i, two);
124              assertSame(two, aa.get(i));
125 <            aa.lazySet(i, m3);
126 <            assertSame(m3, aa.get(i));
125 >            aa.lazySet(i, minusThree);
126 >            assertSame(minusThree, aa.get(i));
127          }
128      }
129  
# Line 130 | Line 131 | public class AtomicReferenceArrayTest ex
131       * compareAndSet succeeds in changing value if equal to expected else fails
132       */
133      public void testCompareAndSet() {
134 <        AtomicReferenceArray aa = new AtomicReferenceArray(SIZE);
134 >        AtomicReferenceArray<Item> aa = new AtomicReferenceArray<Item>(SIZE);
135          for (int i = 0; i < SIZE; i++) {
136              aa.set(i, one);
137              assertTrue(aa.compareAndSet(i, one, two));
138 <            assertTrue(aa.compareAndSet(i, two, m4));
139 <            assertSame(m4, aa.get(i));
140 <            assertFalse(aa.compareAndSet(i, m5, seven));
141 <            assertSame(m4, aa.get(i));
142 <            assertTrue(aa.compareAndSet(i, m4, seven));
138 >            assertTrue(aa.compareAndSet(i, two, minusFour));
139 >            assertSame(minusFour, aa.get(i));
140 >            assertFalse(aa.compareAndSet(i, minusFive, seven));
141 >            assertSame(minusFour, aa.get(i));
142 >            assertTrue(aa.compareAndSet(i, minusFour, seven));
143              assertSame(seven, aa.get(i));
144          }
145      }
# Line 148 | Line 149 | public class AtomicReferenceArrayTest ex
149       * to succeed
150       */
151      public void testCompareAndSetInMultipleThreads() throws InterruptedException {
152 <        final AtomicReferenceArray a = new AtomicReferenceArray(1);
152 >        final AtomicReferenceArray<Item> a = new AtomicReferenceArray<Item>(1);
153          a.set(0, one);
154          Thread t = new Thread(new CheckedRunnable() {
155              public void realRun() {
# Line 167 | Line 168 | public class AtomicReferenceArrayTest ex
168       * repeated weakCompareAndSet succeeds in changing value when equal
169       * to expected
170       */
171 +    @SuppressWarnings("deprecation")
172      public void testWeakCompareAndSet() {
173 <        AtomicReferenceArray aa = new AtomicReferenceArray(SIZE);
173 >        AtomicReferenceArray<Item> aa = new AtomicReferenceArray<Item>(SIZE);
174          for (int i = 0; i < SIZE; i++) {
175              aa.set(i, one);
176              do {} while (!aa.weakCompareAndSet(i, one, two));
177 <            do {} while (!aa.weakCompareAndSet(i, two, m4));
178 <            assertSame(m4, aa.get(i));
179 <            do {} while (!aa.weakCompareAndSet(i, m4, seven));
177 >            do {} while (!aa.weakCompareAndSet(i, two, minusFour));
178 >            assertSame(minusFour, aa.get(i));
179 >            do {} while (!aa.weakCompareAndSet(i, minusFour, seven));
180              assertSame(seven, aa.get(i));
181          }
182      }
# Line 183 | Line 185 | public class AtomicReferenceArrayTest ex
185       * getAndSet returns previous value and sets to given value at given index
186       */
187      public void testGetAndSet() {
188 <        AtomicReferenceArray aa = new AtomicReferenceArray(SIZE);
188 >        AtomicReferenceArray<Item> aa = new AtomicReferenceArray<Item>(SIZE);
189          for (int i = 0; i < SIZE; i++) {
190              aa.set(i, one);
191              assertSame(one, aa.getAndSet(i, zero));
192 <            assertSame(zero, aa.getAndSet(i, m10));
193 <            assertSame(m10, aa.getAndSet(i, one));
192 >            assertSame(zero, aa.getAndSet(i, minusTen));
193 >            assertSame(minusTen, aa.getAndSet(i, one));
194          }
195      }
196  
# Line 196 | Line 198 | public class AtomicReferenceArrayTest ex
198       * a deserialized/reserialized array holds same values in same order
199       */
200      public void testSerialization() throws Exception {
201 <        AtomicReferenceArray x = new AtomicReferenceArray(SIZE);
201 >        AtomicReferenceArray<Item> x = new AtomicReferenceArray<Item>(SIZE);
202          for (int i = 0; i < SIZE; i++) {
203 <            x.set(i, new Integer(-i));
203 >            x.set(i, minusOne);
204          }
205 <        AtomicReferenceArray y = serialClone(x);
205 >        AtomicReferenceArray<Item> y = serialClone(x);
206          assertNotSame(x, y);
207          assertEquals(x.length(), y.length());
208          for (int i = 0; i < SIZE; i++) {
# Line 212 | Line 214 | public class AtomicReferenceArrayTest ex
214       * toString returns current value.
215       */
216      public void testToString() {
217 <        Integer[] a = { two, one, three, four, seven };
218 <        AtomicReferenceArray<Integer> aa = new AtomicReferenceArray<>(a);
217 >        Item[] a = { two, one, three, four, seven };
218 >        AtomicReferenceArray<Item> aa = new AtomicReferenceArray<>(a);
219          assertEquals(Arrays.toString(a), aa.toString());
220      }
221  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines