15 |
|
public class LinkedBlockingQueueTest extends JSR166TestCase { |
16 |
|
|
17 |
|
public static void main(String[] args) { |
18 |
< |
junit.textui.TestRunner.run (suite()); |
18 |
> |
junit.textui.TestRunner.run(suite()); |
19 |
|
} |
20 |
|
|
21 |
|
public static Test suite() { |
686 |
|
/** |
687 |
|
* iterator.remove removes current element |
688 |
|
*/ |
689 |
< |
public void testIteratorRemove () { |
689 |
> |
public void testIteratorRemove() { |
690 |
|
final LinkedBlockingQueue q = new LinkedBlockingQueue(3); |
691 |
|
q.add(two); |
692 |
|
q.add(one); |
697 |
|
it.remove(); |
698 |
|
|
699 |
|
it = q.iterator(); |
700 |
< |
assertEquals(it.next(), one); |
701 |
< |
assertEquals(it.next(), three); |
700 |
> |
assertSame(it.next(), one); |
701 |
> |
assertSame(it.next(), three); |
702 |
|
assertFalse(it.hasNext()); |
703 |
|
} |
704 |
|
|
722 |
|
/** |
723 |
|
* Modifications do not cause iterators to fail |
724 |
|
*/ |
725 |
< |
public void testWeaklyConsistentIteration () { |
725 |
> |
public void testWeaklyConsistentIteration() { |
726 |
|
final LinkedBlockingQueue q = new LinkedBlockingQueue(3); |
727 |
|
q.add(one); |
728 |
|
q.add(two); |
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() { |