359 |
|
public void testTake() throws InterruptedException { |
360 |
|
LinkedBlockingQueue q = populatedQueue(SIZE); |
361 |
|
for (int i = 0; i < SIZE; ++i) { |
362 |
< |
assertEquals(i, ((Integer)q.take()).intValue()); |
362 |
> |
assertEquals(i, q.take()); |
363 |
|
} |
364 |
|
} |
365 |
|
|
387 |
|
Thread t = new Thread(new CheckedRunnable() { |
388 |
|
public void realRun() throws InterruptedException { |
389 |
|
for (int i = 0; i < SIZE; ++i) { |
390 |
< |
assertEquals(i, ((Integer)q.take()).intValue()); |
390 |
> |
assertEquals(i, q.take()); |
391 |
|
} |
392 |
|
try { |
393 |
|
q.take(); |
407 |
|
public void testPoll() { |
408 |
|
LinkedBlockingQueue q = populatedQueue(SIZE); |
409 |
|
for (int i = 0; i < SIZE; ++i) { |
410 |
< |
assertEquals(i, ((Integer)q.poll()).intValue()); |
410 |
> |
assertEquals(i, q.poll()); |
411 |
|
} |
412 |
|
assertNull(q.poll()); |
413 |
|
} |
418 |
|
public void testTimedPoll0() throws InterruptedException { |
419 |
|
LinkedBlockingQueue q = populatedQueue(SIZE); |
420 |
|
for (int i = 0; i < SIZE; ++i) { |
421 |
< |
assertEquals(i, ((Integer)q.poll(0, MILLISECONDS)).intValue()); |
421 |
> |
assertEquals(i, q.poll(0, MILLISECONDS)); |
422 |
|
} |
423 |
|
assertNull(q.poll(0, MILLISECONDS)); |
424 |
|
} |
429 |
|
public void testTimedPoll() throws InterruptedException { |
430 |
|
LinkedBlockingQueue q = populatedQueue(SIZE); |
431 |
|
for (int i = 0; i < SIZE; ++i) { |
432 |
< |
assertEquals(i, ((Integer)q.poll(SHORT_DELAY_MS, MILLISECONDS)).intValue()); |
432 |
> |
assertEquals(i, q.poll(SHORT_DELAY_MS, MILLISECONDS)); |
433 |
|
} |
434 |
|
assertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS)); |
435 |
|
} |
443 |
|
public void realRun() throws InterruptedException { |
444 |
|
LinkedBlockingQueue q = populatedQueue(SIZE); |
445 |
|
for (int i = 0; i < SIZE; ++i) { |
446 |
< |
assertEquals(i, ((Integer)q.poll(SHORT_DELAY_MS, MILLISECONDS)).intValue()); |
446 |
> |
assertEquals(i, q.poll(SHORT_DELAY_MS, MILLISECONDS)); |
447 |
|
} |
448 |
|
try { |
449 |
|
q.poll(SMALL_DELAY_MS, MILLISECONDS); |
486 |
|
public void testPeek() { |
487 |
|
LinkedBlockingQueue q = populatedQueue(SIZE); |
488 |
|
for (int i = 0; i < SIZE; ++i) { |
489 |
< |
assertEquals(i, ((Integer)q.peek()).intValue()); |
490 |
< |
q.poll(); |
489 |
> |
assertEquals(i, q.peek()); |
490 |
> |
assertEquals(i, q.poll()); |
491 |
|
assertTrue(q.peek() == null || |
492 |
< |
i != ((Integer)q.peek()).intValue()); |
492 |
> |
!q.peek().equals(i)); |
493 |
|
} |
494 |
|
assertNull(q.peek()); |
495 |
|
} |
500 |
|
public void testElement() { |
501 |
|
LinkedBlockingQueue q = populatedQueue(SIZE); |
502 |
|
for (int i = 0; i < SIZE; ++i) { |
503 |
< |
assertEquals(i, ((Integer)q.element()).intValue()); |
504 |
< |
q.poll(); |
503 |
> |
assertEquals(i, q.element()); |
504 |
> |
assertEquals(i, q.poll()); |
505 |
|
} |
506 |
|
try { |
507 |
|
q.element(); |
515 |
|
public void testRemove() { |
516 |
|
LinkedBlockingQueue q = populatedQueue(SIZE); |
517 |
|
for (int i = 0; i < SIZE; ++i) { |
518 |
< |
assertEquals(i, ((Integer)q.remove()).intValue()); |
518 |
> |
assertEquals(i, q.remove()); |
519 |
|
} |
520 |
|
try { |
521 |
|
q.remove(); |
653 |
|
* toArray(null) throws NPE |
654 |
|
*/ |
655 |
|
public void testToArray_BadArg() { |
656 |
+ |
LinkedBlockingQueue q = populatedQueue(SIZE); |
657 |
|
try { |
657 |
– |
LinkedBlockingQueue q = populatedQueue(SIZE); |
658 |
|
Object o[] = q.toArray(null); |
659 |
|
shouldThrow(); |
660 |
|
} catch (NullPointerException success) {} |
664 |
|
* toArray with incompatible array type throws CCE |
665 |
|
*/ |
666 |
|
public void testToArray1_BadArg() { |
667 |
+ |
LinkedBlockingQueue q = populatedQueue(SIZE); |
668 |
|
try { |
669 |
< |
LinkedBlockingQueue q = populatedQueue(SIZE); |
669 |
< |
Object o[] = q.toArray(new String[10] ); |
669 |
> |
Object o[] = q.toArray(new String[10]); |
670 |
|
shouldThrow(); |
671 |
|
} catch (ArrayStoreException success) {} |
672 |
|
} |
714 |
|
assertEquals(0, q.remainingCapacity()); |
715 |
|
int k = 0; |
716 |
|
for (Iterator it = q.iterator(); it.hasNext();) { |
717 |
< |
int i = ((Integer)(it.next())).intValue(); |
718 |
< |
assertEquals(++k, i); |
717 |
> |
assertEquals(++k, it.next()); |
718 |
|
} |
719 |
|
assertEquals(3, k); |
720 |
|
} |
757 |
|
ExecutorService executor = Executors.newFixedThreadPool(2); |
758 |
|
executor.execute(new CheckedRunnable() { |
759 |
|
public void realRun() throws InterruptedException { |
760 |
< |
threadAssertFalse(q.offer(three)); |
761 |
< |
threadAssertTrue(q.offer(three, MEDIUM_DELAY_MS, MILLISECONDS)); |
762 |
< |
threadAssertEquals(0, q.remainingCapacity()); |
760 |
> |
assertFalse(q.offer(three)); |
761 |
> |
assertTrue(q.offer(three, MEDIUM_DELAY_MS, MILLISECONDS)); |
762 |
> |
assertEquals(0, q.remainingCapacity()); |
763 |
|
}}); |
764 |
|
|
765 |
|
executor.execute(new CheckedRunnable() { |
766 |
|
public void realRun() throws InterruptedException { |
767 |
|
Thread.sleep(SMALL_DELAY_MS); |
768 |
< |
threadAssertEquals(one, q.take()); |
768 |
> |
assertSame(one, q.take()); |
769 |
|
}}); |
770 |
|
|
771 |
|
joinPool(executor); |
779 |
|
ExecutorService executor = Executors.newFixedThreadPool(2); |
780 |
|
executor.execute(new CheckedRunnable() { |
781 |
|
public void realRun() throws InterruptedException { |
782 |
< |
threadAssertNull(q.poll()); |
783 |
< |
threadAssertTrue(null != q.poll(MEDIUM_DELAY_MS, MILLISECONDS)); |
784 |
< |
threadAssertTrue(q.isEmpty()); |
782 |
> |
assertNull(q.poll()); |
783 |
> |
assertSame(one, q.poll(MEDIUM_DELAY_MS, MILLISECONDS)); |
784 |
> |
assertTrue(q.isEmpty()); |
785 |
|
}}); |
786 |
|
|
787 |
|
executor.execute(new CheckedRunnable() { |