1 |
|
/* |
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 |
4 |
> |
* http://creativecommons.org/publicdomain/zero/1.0/ |
5 |
|
* Other contributors include Andrew Wright, Jeffrey Hayes, |
6 |
|
* Pat Fisher, Mike Judd. |
7 |
|
*/ |
12 |
|
import java.util.*; |
13 |
|
|
14 |
|
public class AtomicReferenceArrayTest extends JSR166TestCase { |
15 |
< |
public static void main (String[] args) { |
16 |
< |
junit.textui.TestRunner.run (suite()); |
15 |
> |
public static void main(String[] args) { |
16 |
> |
junit.textui.TestRunner.run(suite()); |
17 |
|
} |
18 |
|
public static Test suite() { |
19 |
|
return new TestSuite(AtomicReferenceArrayTest.class); |
51 |
|
assertEquals(a[i], ai.get(i)); |
52 |
|
} |
53 |
|
|
54 |
– |
|
54 |
|
/** |
55 |
|
* get and set for out of bound indices throw IndexOutOfBoundsException |
56 |
|
*/ |
85 |
|
AtomicReferenceArray ai = new AtomicReferenceArray(SIZE); |
86 |
|
for (int i = 0; i < SIZE; ++i) { |
87 |
|
ai.set(i, one); |
88 |
< |
assertEquals(one,ai.get(i)); |
88 |
> |
assertSame(one,ai.get(i)); |
89 |
|
ai.set(i, two); |
90 |
< |
assertEquals(two,ai.get(i)); |
90 |
> |
assertSame(two,ai.get(i)); |
91 |
|
ai.set(i, m3); |
92 |
< |
assertEquals(m3,ai.get(i)); |
92 |
> |
assertSame(m3,ai.get(i)); |
93 |
|
} |
94 |
|
} |
95 |
|
|
100 |
|
AtomicReferenceArray ai = new AtomicReferenceArray(SIZE); |
101 |
|
for (int i = 0; i < SIZE; ++i) { |
102 |
|
ai.lazySet(i, one); |
103 |
< |
assertEquals(one,ai.get(i)); |
103 |
> |
assertSame(one,ai.get(i)); |
104 |
|
ai.lazySet(i, two); |
105 |
< |
assertEquals(two,ai.get(i)); |
105 |
> |
assertSame(two,ai.get(i)); |
106 |
|
ai.lazySet(i, m3); |
107 |
< |
assertEquals(m3,ai.get(i)); |
107 |
> |
assertSame(m3,ai.get(i)); |
108 |
|
} |
109 |
|
} |
110 |
|
|
117 |
|
ai.set(i, one); |
118 |
|
assertTrue(ai.compareAndSet(i, one,two)); |
119 |
|
assertTrue(ai.compareAndSet(i, two,m4)); |
120 |
< |
assertEquals(m4,ai.get(i)); |
120 |
> |
assertSame(m4,ai.get(i)); |
121 |
|
assertFalse(ai.compareAndSet(i, m5,seven)); |
122 |
< |
assertFalse((seven.equals(ai.get(i)))); |
122 |
> |
assertSame(m4,ai.get(i)); |
123 |
|
assertTrue(ai.compareAndSet(i, m4,seven)); |
124 |
< |
assertEquals(seven,ai.get(i)); |
124 |
> |
assertSame(seven,ai.get(i)); |
125 |
|
} |
126 |
|
} |
127 |
|
|
142 |
|
assertTrue(a.compareAndSet(0, one, two)); |
143 |
|
t.join(LONG_DELAY_MS); |
144 |
|
assertFalse(t.isAlive()); |
145 |
< |
assertEquals(a.get(0), three); |
145 |
> |
assertSame(a.get(0), three); |
146 |
|
} |
147 |
|
|
148 |
|
/** |
155 |
|
ai.set(i, one); |
156 |
|
while (!ai.weakCompareAndSet(i, one,two)); |
157 |
|
while (!ai.weakCompareAndSet(i, two,m4)); |
158 |
< |
assertEquals(m4,ai.get(i)); |
158 |
> |
assertSame(m4,ai.get(i)); |
159 |
|
while (!ai.weakCompareAndSet(i, m4,seven)); |
160 |
< |
assertEquals(seven,ai.get(i)); |
160 |
> |
assertSame(seven,ai.get(i)); |
161 |
|
} |
162 |
|
} |
163 |
|
|
168 |
|
AtomicReferenceArray ai = new AtomicReferenceArray(SIZE); |
169 |
|
for (int i = 0; i < SIZE; ++i) { |
170 |
|
ai.set(i, one); |
171 |
< |
assertEquals(one,ai.getAndSet(i,zero)); |
172 |
< |
assertEquals(0,ai.getAndSet(i,m10)); |
173 |
< |
assertEquals(m10,ai.getAndSet(i,one)); |
171 |
> |
assertSame(one,ai.getAndSet(i,zero)); |
172 |
> |
assertSame(zero,ai.getAndSet(i,m10)); |
173 |
> |
assertSame(m10,ai.getAndSet(i,one)); |
174 |
|
} |
175 |
|
} |
176 |
|
|
197 |
|
} |
198 |
|
} |
199 |
|
|
201 |
– |
|
200 |
|
/** |
201 |
|
* toString returns current value. |
202 |
|
*/ |