200 |
|
PriorityBlockingQueue q = new PriorityBlockingQueue(1); |
201 |
|
try { |
202 |
|
q.offer(new Object()); |
203 |
– |
q.offer(new Object()); |
203 |
|
shouldThrow(); |
204 |
< |
} catch (ClassCastException success) {} |
204 |
> |
} catch (ClassCastException success) { |
205 |
> |
assertTrue(q.isEmpty()); |
206 |
> |
assertEquals(0, q.size()); |
207 |
> |
assertNull(q.poll()); |
208 |
> |
} |
209 |
|
} |
210 |
|
|
211 |
|
/** |
396 |
|
final CountDownLatch aboutToWait = new CountDownLatch(1); |
397 |
|
Thread t = newStartedThread(new CheckedRunnable() { |
398 |
|
public void realRun() throws InterruptedException { |
399 |
+ |
long startTime = System.nanoTime(); |
400 |
|
for (int i = 0; i < SIZE; ++i) { |
397 |
– |
long t0 = System.nanoTime(); |
401 |
|
assertEquals(i, (int) q.poll(LONG_DELAY_MS, MILLISECONDS)); |
399 |
– |
assertTrue(millisElapsedSince(t0) < SMALL_DELAY_MS); |
402 |
|
} |
401 |
– |
long t0 = System.nanoTime(); |
403 |
|
aboutToWait.countDown(); |
404 |
|
try { |
405 |
|
q.poll(LONG_DELAY_MS, MILLISECONDS); |
406 |
|
shouldThrow(); |
407 |
|
} catch (InterruptedException success) { |
408 |
< |
assertTrue(millisElapsedSince(t0) < MEDIUM_DELAY_MS); |
408 |
> |
assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS); |
409 |
|
} |
410 |
|
}}); |
411 |
|
|
412 |
|
aboutToWait.await(); |
413 |
< |
waitForThreadToEnterWaitState(t, SMALL_DELAY_MS); |
413 |
> |
waitForThreadToEnterWaitState(t, LONG_DELAY_MS); |
414 |
|
t.interrupt(); |
415 |
< |
awaitTermination(t, MEDIUM_DELAY_MS); |
415 |
> |
awaitTermination(t); |
416 |
|
} |
417 |
|
|
418 |
|
/** |