69 |
|
// suppress [overrides] javac warning |
70 |
|
public int hashCode() { return pseudodelay; } |
71 |
|
public long getDelay(TimeUnit ignore) { |
72 |
< |
return Integer.MIN_VALUE + pseudodelay; |
72 |
> |
return (long) Integer.MIN_VALUE + pseudodelay; |
73 |
|
} |
74 |
|
public String toString() { |
75 |
|
return String.valueOf(pseudodelay); |
234 |
|
} |
235 |
|
|
236 |
|
/** |
237 |
< |
* addAll(this) throws IAE |
237 |
> |
* addAll(this) throws IllegalArgumentException |
238 |
|
*/ |
239 |
|
public void testAddAllSelf() { |
240 |
|
DelayQueue q = populatedQueue(SIZE); |
305 |
|
} |
306 |
|
|
307 |
|
/** |
308 |
< |
* timed offer does not time out |
308 |
> |
* Queue is unbounded, so timed offer never times out |
309 |
|
*/ |
310 |
|
public void testTimedOffer() throws InterruptedException { |
311 |
|
final DelayQueue q = new DelayQueue(); |
357 |
|
}}); |
358 |
|
|
359 |
|
await(pleaseInterrupt); |
360 |
< |
assertThreadBlocks(t, Thread.State.WAITING); |
360 |
> |
if (randomBoolean()) assertThreadBlocks(t, Thread.State.WAITING); |
361 |
|
t.interrupt(); |
362 |
|
awaitTermination(t); |
363 |
|
} |
409 |
|
final DelayQueue q = populatedQueue(SIZE); |
410 |
|
Thread t = newStartedThread(new CheckedRunnable() { |
411 |
|
public void realRun() throws InterruptedException { |
412 |
< |
long startTime = System.nanoTime(); |
413 |
< |
for (int i = 0; i < SIZE; ++i) { |
412 |
> |
for (int i = 0; i < SIZE; i++) |
413 |
|
assertEquals(new PDelay(i), |
414 |
|
((PDelay)q.poll(LONG_DELAY_MS, MILLISECONDS))); |
416 |
– |
} |
415 |
|
|
416 |
|
Thread.currentThread().interrupt(); |
417 |
|
try { |
418 |
< |
q.poll(LONG_DELAY_MS, MILLISECONDS); |
418 |
> |
q.poll(randomTimeout(), randomTimeUnit()); |
419 |
|
shouldThrow(); |
420 |
|
} catch (InterruptedException success) {} |
421 |
|
assertFalse(Thread.interrupted()); |
422 |
|
|
423 |
|
pleaseInterrupt.countDown(); |
424 |
|
try { |
425 |
< |
q.poll(LONG_DELAY_MS, MILLISECONDS); |
425 |
> |
q.poll(LONGER_DELAY_MS, MILLISECONDS); |
426 |
|
shouldThrow(); |
427 |
|
} catch (InterruptedException success) {} |
428 |
|
assertFalse(Thread.interrupted()); |
431 |
– |
assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS); |
429 |
|
}}); |
430 |
|
|
431 |
|
await(pleaseInterrupt); |
432 |
< |
assertThreadBlocks(t, Thread.State.TIMED_WAITING); |
432 |
> |
if (randomBoolean()) assertThreadBlocks(t, Thread.State.TIMED_WAITING); |
433 |
|
t.interrupt(); |
434 |
|
awaitTermination(t); |
435 |
|
checkEmpty(q); |
563 |
|
*/ |
564 |
|
public void testToArray() throws InterruptedException { |
565 |
|
DelayQueue q = populatedQueue(SIZE); |
566 |
< |
Object[] o = q.toArray(); |
567 |
< |
Arrays.sort(o); |
568 |
< |
for (int i = 0; i < o.length; i++) |
569 |
< |
assertSame(o[i], q.take()); |
566 |
> |
Object[] a = q.toArray(); |
567 |
> |
assertSame(Object[].class, a.getClass()); |
568 |
> |
Arrays.sort(a); |
569 |
> |
for (Object o : a) |
570 |
> |
assertSame(o, q.take()); |
571 |
> |
assertTrue(q.isEmpty()); |
572 |
|
} |
573 |
|
|
574 |
|
/** |
580 |
|
PDelay[] array = q.toArray(ints); |
581 |
|
assertSame(ints, array); |
582 |
|
Arrays.sort(ints); |
583 |
< |
for (int i = 0; i < ints.length; i++) |
584 |
< |
assertSame(ints[i], q.remove()); |
583 |
> |
for (PDelay o : ints) |
584 |
> |
assertSame(o, q.remove()); |
585 |
> |
assertTrue(q.isEmpty()); |
586 |
|
} |
587 |
|
|
588 |
|
/** |