106 |
|
} |
107 |
|
|
108 |
|
/** |
109 |
< |
* put(null) throws NullPointerException |
109 |
> |
* addAll(null) throws NullPointerException |
110 |
|
*/ |
111 |
|
public void testAddAllNull() throws InterruptedException { |
112 |
|
final Collection q = emptyCollection(); |
134 |
|
public void testToArray_NullArray() { |
135 |
|
final Collection q = emptyCollection(); |
136 |
|
try { |
137 |
< |
q.toArray(null); |
137 |
> |
q.toArray((Object[])null); |
138 |
|
shouldThrow(); |
139 |
|
} catch (NullPointerException success) {} |
140 |
|
} |
189 |
|
public void testDrainToNonPositiveMaxElements() { |
190 |
|
final BlockingQueue q = emptyCollection(); |
191 |
|
final int[] ns = { 0, -1, -42, Integer.MIN_VALUE }; |
192 |
< |
for (int n : ns) |
193 |
< |
assertEquals(0, q.drainTo(new ArrayList(), n)); |
192 |
> |
final ArrayList sink = new ArrayList(); |
193 |
> |
for (int n : ns) { |
194 |
> |
assertEquals(0, q.drainTo(sink, n)); |
195 |
> |
assertTrue(sink.isEmpty()); |
196 |
> |
} |
197 |
|
if (q.remainingCapacity() > 0) { |
198 |
|
// Not SynchronousQueue, that is |
199 |
|
Object one = makeElement(1); |
200 |
|
q.add(one); |
198 |
– |
ArrayList c = new ArrayList(); |
201 |
|
for (int n : ns) |
202 |
< |
assertEquals(0, q.drainTo(new ArrayList(), n)); |
202 |
> |
assertEquals(0, q.drainTo(sink, n)); |
203 |
|
assertEquals(1, q.size()); |
204 |
|
assertSame(one, q.poll()); |
205 |
< |
assertTrue(c.isEmpty()); |
205 |
> |
assertTrue(sink.isEmpty()); |
206 |
|
} |
207 |
|
} |
208 |
|
|
226 |
|
|
227 |
|
Thread.currentThread().interrupt(); |
228 |
|
try { |
229 |
< |
q.poll(LONG_DELAY_MS, MILLISECONDS); |
229 |
> |
q.poll(randomTimeout(), randomTimeUnit()); |
230 |
|
shouldThrow(); |
231 |
|
} catch (InterruptedException success) {} |
232 |
|
assertFalse(Thread.interrupted()); |
247 |
|
assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS); |
248 |
|
|
249 |
|
barrier.await(); |
250 |
< |
assertThreadStaysAlive(t); |
250 |
> |
if (randomBoolean()) assertThreadBlocks(t, Thread.State.TIMED_WAITING); |
251 |
|
t.interrupt(); |
252 |
|
awaitTermination(t); |
253 |
|
} |
269 |
|
}}); |
270 |
|
|
271 |
|
await(threadStarted); |
272 |
< |
assertThreadStaysAlive(t); |
272 |
> |
if (randomBoolean()) assertThreadBlocks(t, Thread.State.WAITING); |
273 |
|
t.interrupt(); |
274 |
|
awaitTermination(t); |
275 |
|
} |
302 |
|
Thread t = newStartedThread(new CheckedRunnable() { |
303 |
|
public void realRun() { |
304 |
|
threadStarted.countDown(); |
305 |
+ |
long startTime = System.nanoTime(); |
306 |
+ |
|
307 |
|
try { |
308 |
< |
q.poll(2 * LONG_DELAY_MS, MILLISECONDS); |
308 |
> |
q.poll(LONG_DELAY_MS, MILLISECONDS); |
309 |
|
shouldThrow(); |
310 |
|
} catch (InterruptedException success) {} |
311 |
|
assertFalse(Thread.interrupted()); |
312 |
+ |
|
313 |
+ |
assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS); |
314 |
|
}}); |
315 |
|
|
316 |
|
await(threadStarted); |
317 |
< |
assertThreadStaysAlive(t); |
317 |
> |
if (randomBoolean()) assertThreadBlocks(t, Thread.State.TIMED_WAITING); |
318 |
|
t.interrupt(); |
319 |
|
awaitTermination(t); |
320 |
|
} |
327 |
|
final BlockingQueue q = emptyCollection(); |
328 |
|
Thread t = newStartedThread(new CheckedRunnable() { |
329 |
|
public void realRun() { |
330 |
+ |
long startTime = System.nanoTime(); |
331 |
+ |
|
332 |
|
Thread.currentThread().interrupt(); |
333 |
|
try { |
334 |
< |
q.poll(2 * LONG_DELAY_MS, MILLISECONDS); |
334 |
> |
q.poll(LONG_DELAY_MS, MILLISECONDS); |
335 |
|
shouldThrow(); |
336 |
|
} catch (InterruptedException success) {} |
337 |
|
assertFalse(Thread.interrupted()); |
338 |
+ |
|
339 |
+ |
assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS); |
340 |
|
}}); |
341 |
|
|
342 |
|
awaitTermination(t); |