8 |
|
|
9 |
|
import junit.framework.*; |
10 |
|
import java.util.*; |
11 |
+ |
import static java.util.concurrent.TimeUnit.MILLISECONDS; |
12 |
|
import java.util.concurrent.*; |
13 |
|
|
14 |
|
public class DelayQueueTest extends JSR166TestCase { |
408 |
|
try { |
409 |
|
q.put(new PDelay(0)); |
410 |
|
q.put(new PDelay(0)); |
411 |
< |
threadAssertTrue(q.offer(new PDelay(0), SHORT_DELAY_MS, TimeUnit.MILLISECONDS)); |
412 |
< |
threadAssertTrue(q.offer(new PDelay(0), LONG_DELAY_MS, TimeUnit.MILLISECONDS)); |
411 |
> |
threadAssertTrue(q.offer(new PDelay(0), SHORT_DELAY_MS, MILLISECONDS)); |
412 |
> |
threadAssertTrue(q.offer(new PDelay(0), LONG_DELAY_MS, MILLISECONDS)); |
413 |
|
} finally { } |
414 |
|
} |
415 |
|
}); |
507 |
|
try { |
508 |
|
DelayQueue q = populatedQueue(SIZE); |
509 |
|
for (int i = 0; i < SIZE; ++i) { |
510 |
< |
assertEquals(new PDelay(i), ((PDelay)q.poll(0, TimeUnit.MILLISECONDS))); |
510 |
> |
assertEquals(new PDelay(i), ((PDelay)q.poll(0, MILLISECONDS))); |
511 |
|
} |
512 |
< |
assertNull(q.poll(0, TimeUnit.MILLISECONDS)); |
512 |
> |
assertNull(q.poll(0, MILLISECONDS)); |
513 |
|
} catch (InterruptedException e) { |
514 |
|
unexpectedException(); |
515 |
|
} |
522 |
|
try { |
523 |
|
DelayQueue q = populatedQueue(SIZE); |
524 |
|
for (int i = 0; i < SIZE; ++i) { |
525 |
< |
assertEquals(new PDelay(i), ((PDelay)q.poll(SHORT_DELAY_MS, TimeUnit.MILLISECONDS))); |
525 |
> |
assertEquals(new PDelay(i), ((PDelay)q.poll(SHORT_DELAY_MS, MILLISECONDS))); |
526 |
|
} |
527 |
< |
assertNull(q.poll(SHORT_DELAY_MS, TimeUnit.MILLISECONDS)); |
527 |
> |
assertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS)); |
528 |
|
} catch (InterruptedException e) { |
529 |
|
unexpectedException(); |
530 |
|
} |
540 |
|
try { |
541 |
|
DelayQueue q = populatedQueue(SIZE); |
542 |
|
for (int i = 0; i < SIZE; ++i) { |
543 |
< |
threadAssertEquals(new PDelay(i), ((PDelay)q.poll(SHORT_DELAY_MS, TimeUnit.MILLISECONDS))); |
543 |
> |
threadAssertEquals(new PDelay(i), ((PDelay)q.poll(SHORT_DELAY_MS, MILLISECONDS))); |
544 |
|
} |
545 |
< |
threadAssertNull(q.poll(SHORT_DELAY_MS, TimeUnit.MILLISECONDS)); |
545 |
> |
threadAssertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS)); |
546 |
|
} catch (InterruptedException success) { |
547 |
|
} |
548 |
|
}}); |
566 |
|
Thread t = new Thread(new Runnable() { |
567 |
|
public void run() { |
568 |
|
try { |
569 |
< |
threadAssertNull(q.poll(SHORT_DELAY_MS, TimeUnit.MILLISECONDS)); |
570 |
< |
q.poll(LONG_DELAY_MS, TimeUnit.MILLISECONDS); |
571 |
< |
q.poll(LONG_DELAY_MS, TimeUnit.MILLISECONDS); |
569 |
> |
threadAssertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS)); |
570 |
> |
q.poll(LONG_DELAY_MS, MILLISECONDS); |
571 |
> |
q.poll(LONG_DELAY_MS, MILLISECONDS); |
572 |
|
threadFail("Should block"); |
573 |
|
} catch (InterruptedException success) { } |
574 |
|
} |
576 |
|
try { |
577 |
|
t.start(); |
578 |
|
Thread.sleep(SMALL_DELAY_MS); |
579 |
< |
assertTrue(q.offer(new PDelay(0), SHORT_DELAY_MS, TimeUnit.MILLISECONDS)); |
579 |
> |
assertTrue(q.offer(new PDelay(0), SHORT_DELAY_MS, MILLISECONDS)); |
580 |
|
t.interrupt(); |
581 |
|
t.join(); |
582 |
|
} catch (Exception e) { |
832 |
|
public void run() { |
833 |
|
threadAssertNull(q.poll()); |
834 |
|
try { |
835 |
< |
threadAssertTrue(null != q.poll(MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS)); |
835 |
> |
threadAssertTrue(null != q.poll(MEDIUM_DELAY_MS, MILLISECONDS)); |
836 |
|
threadAssertTrue(q.isEmpty()); |
837 |
|
} |
838 |
|
catch (InterruptedException e) { |
912 |
|
DelayQueue q = new DelayQueue(); |
913 |
|
q.add(new NanoDelay(LONG_DELAY_MS * 1000000L)); |
914 |
|
try { |
915 |
< |
assertNull(q.poll(SHORT_DELAY_MS, TimeUnit.MILLISECONDS)); |
915 |
> |
assertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS)); |
916 |
|
} catch (Exception ex) { |
917 |
|
unexpectedException(); |
918 |
|
} |