10 |
|
import junit.framework.*; |
11 |
|
import java.util.*; |
12 |
|
import java.util.concurrent.*; |
13 |
+ |
import static java.util.concurrent.TimeUnit.MILLISECONDS; |
14 |
|
import java.io.*; |
15 |
|
|
16 |
|
public class ArrayBlockingQueueTest extends JSR166TestCase { |
390 |
|
try { |
391 |
|
q.put(new Object()); |
392 |
|
q.put(new Object()); |
393 |
< |
threadAssertFalse(q.offer(new Object(), SHORT_DELAY_MS/2, TimeUnit.MILLISECONDS)); |
394 |
< |
q.offer(new Object(), LONG_DELAY_MS, TimeUnit.MILLISECONDS); |
393 |
> |
threadAssertFalse(q.offer(new Object(), SHORT_DELAY_MS/2, MILLISECONDS)); |
394 |
> |
q.offer(new Object(), LONG_DELAY_MS, MILLISECONDS); |
395 |
|
threadShouldThrow(); |
396 |
|
} catch (InterruptedException success) {} |
397 |
|
} |
490 |
|
try { |
491 |
|
ArrayBlockingQueue q = populatedQueue(SIZE); |
492 |
|
for (int i = 0; i < SIZE; ++i) { |
493 |
< |
assertEquals(i, ((Integer)q.poll(0, TimeUnit.MILLISECONDS)).intValue()); |
493 |
> |
assertEquals(i, ((Integer)q.poll(0, MILLISECONDS)).intValue()); |
494 |
|
} |
495 |
< |
assertNull(q.poll(0, TimeUnit.MILLISECONDS)); |
495 |
> |
assertNull(q.poll(0, MILLISECONDS)); |
496 |
|
} catch (InterruptedException e) { |
497 |
|
unexpectedException(); |
498 |
|
} |
505 |
|
try { |
506 |
|
ArrayBlockingQueue q = populatedQueue(SIZE); |
507 |
|
for (int i = 0; i < SIZE; ++i) { |
508 |
< |
assertEquals(i, ((Integer)q.poll(SHORT_DELAY_MS, TimeUnit.MILLISECONDS)).intValue()); |
508 |
> |
assertEquals(i, ((Integer)q.poll(SHORT_DELAY_MS, MILLISECONDS)).intValue()); |
509 |
|
} |
510 |
< |
assertNull(q.poll(SHORT_DELAY_MS, TimeUnit.MILLISECONDS)); |
510 |
> |
assertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS)); |
511 |
|
} catch (InterruptedException e) { |
512 |
|
unexpectedException(); |
513 |
|
} |
523 |
|
try { |
524 |
|
ArrayBlockingQueue q = populatedQueue(SIZE); |
525 |
|
for (int i = 0; i < SIZE; ++i) { |
526 |
< |
threadAssertEquals(i, ((Integer)q.poll(SHORT_DELAY_MS, TimeUnit.MILLISECONDS)).intValue()); |
526 |
> |
threadAssertEquals(i, ((Integer)q.poll(SHORT_DELAY_MS, MILLISECONDS)).intValue()); |
527 |
|
} |
528 |
< |
threadAssertNull(q.poll(SHORT_DELAY_MS, TimeUnit.MILLISECONDS)); |
528 |
> |
threadAssertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS)); |
529 |
|
} catch (InterruptedException success) { |
530 |
|
} |
531 |
|
}}); |
549 |
|
Thread t = new Thread(new Runnable() { |
550 |
|
public void run() { |
551 |
|
try { |
552 |
< |
threadAssertNull(q.poll(SHORT_DELAY_MS, TimeUnit.MILLISECONDS)); |
553 |
< |
q.poll(LONG_DELAY_MS, TimeUnit.MILLISECONDS); |
554 |
< |
q.poll(LONG_DELAY_MS, TimeUnit.MILLISECONDS); |
552 |
> |
threadAssertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS)); |
553 |
> |
q.poll(LONG_DELAY_MS, MILLISECONDS); |
554 |
> |
q.poll(LONG_DELAY_MS, MILLISECONDS); |
555 |
|
threadShouldThrow(); |
556 |
|
} catch (InterruptedException success) { } |
557 |
|
} |
559 |
|
try { |
560 |
|
t.start(); |
561 |
|
Thread.sleep(SMALL_DELAY_MS); |
562 |
< |
assertTrue(q.offer(zero, SHORT_DELAY_MS, TimeUnit.MILLISECONDS)); |
562 |
> |
assertTrue(q.offer(zero, SHORT_DELAY_MS, MILLISECONDS)); |
563 |
|
t.interrupt(); |
564 |
|
t.join(); |
565 |
|
} catch (Exception e) { |
855 |
|
public void run() { |
856 |
|
threadAssertFalse(q.offer(three)); |
857 |
|
try { |
858 |
< |
threadAssertTrue(q.offer(three, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS)); |
858 |
> |
threadAssertTrue(q.offer(three, MEDIUM_DELAY_MS, MILLISECONDS)); |
859 |
|
threadAssertEquals(0, q.remainingCapacity()); |
860 |
|
} |
861 |
|
catch (InterruptedException e) { |
890 |
|
public void run() { |
891 |
|
threadAssertNull(q.poll()); |
892 |
|
try { |
893 |
< |
threadAssertTrue(null != q.poll(MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS)); |
893 |
> |
threadAssertTrue(null != q.poll(MEDIUM_DELAY_MS, MILLISECONDS)); |
894 |
|
threadAssertTrue(q.isEmpty()); |
895 |
|
} |
896 |
|
catch (InterruptedException e) { |