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() { |
214 |
|
shouldThrow(); |
215 |
|
} catch (NullPointerException success) {} |
216 |
|
} |
217 |
+ |
|
218 |
|
/** |
219 |
|
* addAll of a collection with any null elements throws NPE after |
220 |
|
* possibly adding some elements |
229 |
|
shouldThrow(); |
230 |
|
} catch (NullPointerException success) {} |
231 |
|
} |
232 |
+ |
|
233 |
|
/** |
234 |
|
* addAll throws ISE if not enough room |
235 |
|
*/ |
243 |
|
shouldThrow(); |
244 |
|
} catch (IllegalStateException success) {} |
245 |
|
} |
246 |
+ |
|
247 |
|
/** |
248 |
|
* Queue contains all elements, in traversal order, of successful addAll |
249 |
|
*/ |
468 |
|
final LinkedBlockingQueue q = new LinkedBlockingQueue(2); |
469 |
|
Thread t = new Thread(new CheckedRunnable() { |
470 |
|
public void realRun() throws InterruptedException { |
468 |
– |
assertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS)); |
469 |
– |
assertSame(zero, q.poll(LONG_DELAY_MS, MILLISECONDS)); |
471 |
|
try { |
472 |
+ |
assertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS)); |
473 |
+ |
assertSame(zero, q.poll(LONG_DELAY_MS, MILLISECONDS)); |
474 |
|
q.poll(LONG_DELAY_MS, MILLISECONDS); |
475 |
|
shouldThrow(); |
476 |
|
} catch (InterruptedException success) {} |
689 |
|
/** |
690 |
|
* iterator.remove removes current element |
691 |
|
*/ |
692 |
< |
public void testIteratorRemove () { |
692 |
> |
public void testIteratorRemove() { |
693 |
|
final LinkedBlockingQueue q = new LinkedBlockingQueue(3); |
694 |
|
q.add(two); |
695 |
|
q.add(one); |
700 |
|
it.remove(); |
701 |
|
|
702 |
|
it = q.iterator(); |
703 |
< |
assertEquals(it.next(), one); |
704 |
< |
assertEquals(it.next(), three); |
703 |
> |
assertSame(it.next(), one); |
704 |
> |
assertSame(it.next(), three); |
705 |
|
assertFalse(it.hasNext()); |
706 |
|
} |
707 |
|
|
725 |
|
/** |
726 |
|
* Modifications do not cause iterators to fail |
727 |
|
*/ |
728 |
< |
public void testWeaklyConsistentIteration () { |
728 |
> |
public void testWeaklyConsistentIteration() { |
729 |
|
final LinkedBlockingQueue q = new LinkedBlockingQueue(3); |
730 |
|
q.add(one); |
731 |
|
q.add(two); |
760 |
|
ExecutorService executor = Executors.newFixedThreadPool(2); |
761 |
|
executor.execute(new CheckedRunnable() { |
762 |
|
public void realRun() throws InterruptedException { |
763 |
< |
threadAssertFalse(q.offer(three)); |
764 |
< |
threadAssertTrue(q.offer(three, MEDIUM_DELAY_MS, MILLISECONDS)); |
765 |
< |
threadAssertEquals(0, q.remainingCapacity()); |
763 |
> |
assertFalse(q.offer(three)); |
764 |
> |
assertTrue(q.offer(three, MEDIUM_DELAY_MS, MILLISECONDS)); |
765 |
> |
assertEquals(0, q.remainingCapacity()); |
766 |
|
}}); |
767 |
|
|
768 |
|
executor.execute(new CheckedRunnable() { |
769 |
|
public void realRun() throws InterruptedException { |
770 |
|
Thread.sleep(SMALL_DELAY_MS); |
771 |
< |
threadAssertEquals(one, q.take()); |
771 |
> |
assertSame(one, q.take()); |
772 |
|
}}); |
773 |
|
|
774 |
|
joinPool(executor); |
782 |
|
ExecutorService executor = Executors.newFixedThreadPool(2); |
783 |
|
executor.execute(new CheckedRunnable() { |
784 |
|
public void realRun() throws InterruptedException { |
785 |
< |
threadAssertNull(q.poll()); |
786 |
< |
threadAssertTrue(null != q.poll(MEDIUM_DELAY_MS, MILLISECONDS)); |
787 |
< |
threadAssertTrue(q.isEmpty()); |
785 |
> |
assertNull(q.poll()); |
786 |
> |
assertSame(one, q.poll(MEDIUM_DELAY_MS, MILLISECONDS)); |
787 |
> |
assertTrue(q.isEmpty()); |
788 |
|
}}); |
789 |
|
|
790 |
|
executor.execute(new CheckedRunnable() { |