9 |
|
import junit.framework.*; |
10 |
|
import java.util.*; |
11 |
|
import java.util.concurrent.*; |
12 |
+ |
import static java.util.concurrent.TimeUnit.MILLISECONDS; |
13 |
|
import java.io.*; |
14 |
|
|
15 |
|
public class LinkedBlockingQueueTest extends JSR166TestCase { |
379 |
|
try { |
380 |
|
q.put(new Object()); |
381 |
|
q.put(new Object()); |
382 |
< |
threadAssertFalse(q.offer(new Object(), SHORT_DELAY_MS, TimeUnit.MILLISECONDS)); |
383 |
< |
q.offer(new Object(), LONG_DELAY_MS, TimeUnit.MILLISECONDS); |
382 |
> |
threadAssertFalse(q.offer(new Object(), SHORT_DELAY_MS, MILLISECONDS)); |
383 |
> |
q.offer(new Object(), LONG_DELAY_MS, MILLISECONDS); |
384 |
|
threadShouldThrow(); |
385 |
|
} catch (InterruptedException success) {} |
386 |
|
} |
479 |
|
try { |
480 |
|
LinkedBlockingQueue q = populatedQueue(SIZE); |
481 |
|
for (int i = 0; i < SIZE; ++i) { |
482 |
< |
assertEquals(i, ((Integer)q.poll(0, TimeUnit.MILLISECONDS)).intValue()); |
482 |
> |
assertEquals(i, ((Integer)q.poll(0, MILLISECONDS)).intValue()); |
483 |
|
} |
484 |
< |
assertNull(q.poll(0, TimeUnit.MILLISECONDS)); |
484 |
> |
assertNull(q.poll(0, MILLISECONDS)); |
485 |
|
} catch (InterruptedException e) { |
486 |
|
unexpectedException(); |
487 |
|
} |
494 |
|
try { |
495 |
|
LinkedBlockingQueue q = populatedQueue(SIZE); |
496 |
|
for (int i = 0; i < SIZE; ++i) { |
497 |
< |
assertEquals(i, ((Integer)q.poll(SHORT_DELAY_MS, TimeUnit.MILLISECONDS)).intValue()); |
497 |
> |
assertEquals(i, ((Integer)q.poll(SHORT_DELAY_MS, MILLISECONDS)).intValue()); |
498 |
|
} |
499 |
< |
assertNull(q.poll(SHORT_DELAY_MS, TimeUnit.MILLISECONDS)); |
499 |
> |
assertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS)); |
500 |
|
} catch (InterruptedException e) { |
501 |
|
unexpectedException(); |
502 |
|
} |
512 |
|
try { |
513 |
|
LinkedBlockingQueue q = populatedQueue(SIZE); |
514 |
|
for (int i = 0; i < SIZE; ++i) { |
515 |
< |
threadAssertEquals(i, ((Integer)q.poll(SHORT_DELAY_MS, TimeUnit.MILLISECONDS)).intValue()); |
515 |
> |
threadAssertEquals(i, ((Integer)q.poll(SHORT_DELAY_MS, MILLISECONDS)).intValue()); |
516 |
|
} |
517 |
< |
threadAssertNull(q.poll(SHORT_DELAY_MS, TimeUnit.MILLISECONDS)); |
517 |
> |
threadAssertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS)); |
518 |
|
} catch (InterruptedException success) { |
519 |
|
} |
520 |
|
}}); |
538 |
|
Thread t = new Thread(new Runnable() { |
539 |
|
public void run() { |
540 |
|
try { |
541 |
< |
threadAssertNull(q.poll(SHORT_DELAY_MS, TimeUnit.MILLISECONDS)); |
542 |
< |
q.poll(LONG_DELAY_MS, TimeUnit.MILLISECONDS); |
543 |
< |
q.poll(LONG_DELAY_MS, TimeUnit.MILLISECONDS); |
541 |
> |
threadAssertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS)); |
542 |
> |
q.poll(LONG_DELAY_MS, MILLISECONDS); |
543 |
> |
q.poll(LONG_DELAY_MS, MILLISECONDS); |
544 |
|
threadShouldThrow(); |
545 |
|
} catch (InterruptedException success) { } |
546 |
|
} |
548 |
|
try { |
549 |
|
t.start(); |
550 |
|
Thread.sleep(SMALL_DELAY_MS); |
551 |
< |
assertTrue(q.offer(zero, SHORT_DELAY_MS, TimeUnit.MILLISECONDS)); |
551 |
> |
assertTrue(q.offer(zero, SHORT_DELAY_MS, MILLISECONDS)); |
552 |
|
t.interrupt(); |
553 |
|
t.join(); |
554 |
|
} catch (Exception e) { |
859 |
|
public void run() { |
860 |
|
threadAssertFalse(q.offer(three)); |
861 |
|
try { |
862 |
< |
threadAssertTrue(q.offer(three, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS)); |
862 |
> |
threadAssertTrue(q.offer(three, MEDIUM_DELAY_MS, MILLISECONDS)); |
863 |
|
threadAssertEquals(0, q.remainingCapacity()); |
864 |
|
} |
865 |
|
catch (InterruptedException e) { |
893 |
|
public void run() { |
894 |
|
threadAssertNull(q.poll()); |
895 |
|
try { |
896 |
< |
threadAssertTrue(null != q.poll(MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS)); |
896 |
> |
threadAssertTrue(null != q.poll(MEDIUM_DELAY_MS, MILLISECONDS)); |
897 |
|
threadAssertTrue(q.isEmpty()); |
898 |
|
} |
899 |
|
catch (InterruptedException e) { |