96 |
|
} |
97 |
|
|
98 |
|
/** |
99 |
< |
* addAll throws ISE if no active taker |
99 |
> |
* addAll throws IllegalStateException if no active taker |
100 |
|
*/ |
101 |
|
public void testAddAll_ISE() { testAddAll_ISE(false); } |
102 |
|
public void testAddAll_ISE_fair() { testAddAll_ISE(true); } |
138 |
|
}}); |
139 |
|
|
140 |
|
await(pleaseInterrupt); |
141 |
< |
assertThreadBlocks(t, Thread.State.WAITING); |
141 |
> |
if (randomBoolean()) assertThreadBlocks(t, Thread.State.WAITING); |
142 |
|
t.interrupt(); |
143 |
|
awaitTermination(t); |
144 |
|
assertEquals(0, q.remainingCapacity()); |
158 |
|
pleaseTake.countDown(); |
159 |
|
q.put(one); |
160 |
|
|
161 |
+ |
Thread.currentThread().interrupt(); |
162 |
+ |
try { |
163 |
+ |
q.put(99); |
164 |
+ |
shouldThrow(); |
165 |
+ |
} catch (InterruptedException success) {} |
166 |
+ |
assertFalse(Thread.interrupted()); |
167 |
+ |
|
168 |
|
pleaseInterrupt.countDown(); |
169 |
|
try { |
170 |
|
q.put(99); |
179 |
|
catch (InterruptedException e) { threadUnexpectedException(e); } |
180 |
|
|
181 |
|
await(pleaseInterrupt); |
182 |
< |
assertThreadBlocks(t, Thread.State.WAITING); |
182 |
> |
if (randomBoolean()) assertThreadBlocks(t, Thread.State.WAITING); |
183 |
|
t.interrupt(); |
184 |
|
awaitTermination(t); |
185 |
|
assertEquals(0, q.remainingCapacity()); |
188 |
|
/** |
189 |
|
* timed offer times out if elements not taken |
190 |
|
*/ |
191 |
< |
public void testTimedOffer() { testTimedOffer(false); } |
192 |
< |
public void testTimedOffer_fair() { testTimedOffer(true); } |
186 |
< |
public void testTimedOffer(boolean fair) { |
191 |
> |
public void testTimedOffer() { |
192 |
> |
final boolean fair = randomBoolean(); |
193 |
|
final SynchronousQueue q = new SynchronousQueue(fair); |
194 |
|
final CountDownLatch pleaseInterrupt = new CountDownLatch(1); |
195 |
|
Thread t = newStartedThread(new CheckedRunnable() { |
196 |
|
public void realRun() throws InterruptedException { |
197 |
|
long startTime = System.nanoTime(); |
198 |
+ |
|
199 |
|
assertFalse(q.offer(new Object(), timeoutMillis(), MILLISECONDS)); |
200 |
|
assertTrue(millisElapsedSince(startTime) >= timeoutMillis()); |
201 |
+ |
|
202 |
+ |
Thread.currentThread().interrupt(); |
203 |
+ |
try { |
204 |
+ |
q.offer(new Object(), randomTimeout(), randomTimeUnit()); |
205 |
+ |
shouldThrow(); |
206 |
+ |
} catch (InterruptedException success) {} |
207 |
+ |
assertFalse(Thread.interrupted()); |
208 |
+ |
|
209 |
|
pleaseInterrupt.countDown(); |
210 |
|
try { |
211 |
< |
q.offer(new Object(), 2 * LONG_DELAY_MS, MILLISECONDS); |
211 |
> |
q.offer(new Object(), LONGER_DELAY_MS, MILLISECONDS); |
212 |
|
shouldThrow(); |
213 |
|
} catch (InterruptedException success) {} |
214 |
|
assertFalse(Thread.interrupted()); |
215 |
|
}}); |
216 |
|
|
217 |
|
await(pleaseInterrupt); |
218 |
< |
assertThreadBlocks(t, Thread.State.TIMED_WAITING); |
218 |
> |
if (randomBoolean()) assertThreadBlocks(t, Thread.State.TIMED_WAITING); |
219 |
|
t.interrupt(); |
220 |
|
awaitTermination(t); |
221 |
|
} |
244 |
|
/** |
245 |
|
* timed poll with nonzero timeout times out if no active putter |
246 |
|
*/ |
247 |
< |
public void testTimedPoll() { testTimedPoll(false); } |
248 |
< |
public void testTimedPoll_fair() { testTimedPoll(true); } |
234 |
< |
public void testTimedPoll(boolean fair) { |
247 |
> |
public void testTimedPoll() { |
248 |
> |
final boolean fair = randomBoolean(); |
249 |
|
final SynchronousQueue q = new SynchronousQueue(fair); |
250 |
< |
long startTime = System.nanoTime(); |
250 |
> |
final long startTime = System.nanoTime(); |
251 |
|
try { assertNull(q.poll(timeoutMillis(), MILLISECONDS)); } |
252 |
|
catch (InterruptedException e) { threadUnexpectedException(e); } |
253 |
|
assertTrue(millisElapsedSince(startTime) >= timeoutMillis()); |
257 |
|
* timed poll before a delayed offer times out, returning null; |
258 |
|
* after offer succeeds; on interruption throws |
259 |
|
*/ |
260 |
< |
public void testTimedPollWithOffer() { testTimedPollWithOffer(false); } |
261 |
< |
public void testTimedPollWithOffer_fair() { testTimedPollWithOffer(true); } |
248 |
< |
public void testTimedPollWithOffer(boolean fair) { |
260 |
> |
public void testTimedPollWithOffer() { |
261 |
> |
final boolean fair = randomBoolean(); |
262 |
|
final SynchronousQueue q = new SynchronousQueue(fair); |
263 |
|
final CountDownLatch pleaseOffer = new CountDownLatch(1); |
264 |
|
final CountDownLatch pleaseInterrupt = new CountDownLatch(1); |
274 |
|
|
275 |
|
Thread.currentThread().interrupt(); |
276 |
|
try { |
277 |
< |
q.poll(LONG_DELAY_MS, MILLISECONDS); |
277 |
> |
q.poll(randomTimeout(), randomTimeUnit()); |
278 |
|
shouldThrow(); |
279 |
|
} catch (InterruptedException success) {} |
280 |
|
assertFalse(Thread.interrupted()); |
296 |
|
assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS); |
297 |
|
|
298 |
|
await(pleaseInterrupt); |
299 |
< |
assertThreadBlocks(t, Thread.State.TIMED_WAITING); |
299 |
> |
if (randomBoolean()) assertThreadBlocks(t, Thread.State.TIMED_WAITING); |
300 |
|
t.interrupt(); |
301 |
|
awaitTermination(t); |
302 |
|
} |
437 |
|
public void testToArray_null(boolean fair) { |
438 |
|
final SynchronousQueue q = new SynchronousQueue(fair); |
439 |
|
try { |
440 |
< |
Object[] o = q.toArray(null); |
440 |
> |
Object[] o = q.toArray((Object[])null); |
441 |
|
shouldThrow(); |
442 |
|
} catch (NullPointerException success) {} |
443 |
|
} |
452 |
|
} |
453 |
|
|
454 |
|
/** |
455 |
< |
* iterator remove throws ISE |
455 |
> |
* iterator remove throws IllegalStateException |
456 |
|
*/ |
457 |
|
public void testIteratorRemove() { testIteratorRemove(false); } |
458 |
|
public void testIteratorRemove_fair() { testIteratorRemove(true); } |
530 |
|
} |
531 |
|
|
532 |
|
/** |
533 |
< |
* a deserialized serialized queue is usable |
533 |
> |
* a deserialized/reserialized queue is usable |
534 |
|
*/ |
535 |
|
public void testSerialization() { |
536 |
|
final SynchronousQueue x = new SynchronousQueue(); |