37 |
|
Integer[] a = null; |
38 |
|
AtomicReferenceArray<Integer> ai = new AtomicReferenceArray<Integer>(a); |
39 |
|
shouldThrow(); |
40 |
< |
} catch (NullPointerException success) { |
40 |
> |
} catch (NullPointerException success) {} |
41 |
|
} |
42 |
|
|
43 |
|
/** |
130 |
|
* compareAndSet in one thread enables another waiting for value |
131 |
|
* to succeed |
132 |
|
*/ |
133 |
< |
public void testCompareAndSetInMultipleThreads() { |
133 |
> |
public void testCompareAndSetInMultipleThreads() throws InterruptedException { |
134 |
|
final AtomicReferenceArray a = new AtomicReferenceArray(1); |
135 |
|
a.set(0, one); |
136 |
|
Thread t = new Thread(new Runnable() { |
137 |
|
public void run() { |
138 |
|
while (!a.compareAndSet(0, two, three)) Thread.yield(); |
139 |
|
}}); |
140 |
< |
try { |
141 |
< |
t.start(); |
142 |
< |
assertTrue(a.compareAndSet(0, one, two)); |
143 |
< |
t.join(LONG_DELAY_MS); |
144 |
< |
assertFalse(t.isAlive()); |
145 |
< |
assertEquals(a.get(0), three); |
146 |
< |
} |
147 |
< |
catch (Exception e) { |
148 |
< |
unexpectedException(); |
149 |
< |
} |
140 |
> |
|
141 |
> |
t.start(); |
142 |
> |
assertTrue(a.compareAndSet(0, one, two)); |
143 |
> |
t.join(LONG_DELAY_MS); |
144 |
> |
assertFalse(t.isAlive()); |
145 |
> |
assertEquals(a.get(0), three); |
146 |
|
} |
147 |
|
|
148 |
|
/** |
177 |
|
/** |
178 |
|
* a deserialized serialized array holds same values |
179 |
|
*/ |
180 |
< |
public void testSerialization() { |
180 |
> |
public void testSerialization() throws Exception { |
181 |
|
AtomicReferenceArray l = new AtomicReferenceArray(SIZE); |
182 |
|
for (int i = 0; i < SIZE; ++i) { |
183 |
|
l.set(i, new Integer(-i)); |
184 |
|
} |
185 |
|
|
186 |
< |
try { |
187 |
< |
ByteArrayOutputStream bout = new ByteArrayOutputStream(10000); |
188 |
< |
ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout)); |
189 |
< |
out.writeObject(l); |
190 |
< |
out.close(); |
191 |
< |
|
192 |
< |
ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray()); |
193 |
< |
ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin)); |
194 |
< |
AtomicReferenceArray r = (AtomicReferenceArray) in.readObject(); |
195 |
< |
assertEquals(l.length(), r.length()); |
196 |
< |
for (int i = 0; i < SIZE; ++i) { |
201 |
< |
assertEquals(r.get(i), l.get(i)); |
202 |
< |
} |
203 |
< |
} catch (Exception e) { |
204 |
< |
unexpectedException(); |
186 |
> |
ByteArrayOutputStream bout = new ByteArrayOutputStream(10000); |
187 |
> |
ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout)); |
188 |
> |
out.writeObject(l); |
189 |
> |
out.close(); |
190 |
> |
|
191 |
> |
ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray()); |
192 |
> |
ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin)); |
193 |
> |
AtomicReferenceArray r = (AtomicReferenceArray) in.readObject(); |
194 |
> |
assertEquals(l.length(), r.length()); |
195 |
> |
for (int i = 0; i < SIZE; ++i) { |
196 |
> |
assertEquals(r.get(i), l.get(i)); |
197 |
|
} |
198 |
|
} |
199 |
|
|