14 |
|
|
15 |
|
public class LinkedBlockingQueueTest extends JSR166TestCase { |
16 |
|
|
17 |
+ |
public static class Unbounded extends BlockingQueueTest { |
18 |
+ |
protected BlockingQueue emptyCollection() { |
19 |
+ |
return new LinkedBlockingQueue(); |
20 |
+ |
} |
21 |
+ |
} |
22 |
+ |
|
23 |
+ |
public static class Bounded extends BlockingQueueTest { |
24 |
+ |
protected BlockingQueue emptyCollection() { |
25 |
+ |
return new LinkedBlockingQueue(20); |
26 |
+ |
} |
27 |
+ |
} |
28 |
+ |
|
29 |
|
public static void main(String[] args) { |
30 |
< |
junit.textui.TestRunner.run (suite()); |
30 |
> |
junit.textui.TestRunner.run(suite()); |
31 |
|
} |
32 |
|
|
33 |
|
public static Test suite() { |
34 |
< |
return new TestSuite(LinkedBlockingQueueTest.class); |
34 |
> |
return newTestSuite(LinkedBlockingQueueTest.class, |
35 |
> |
new Unbounded().testSuite(), |
36 |
> |
new Bounded().testSuite()); |
37 |
|
} |
38 |
|
|
39 |
|
|
228 |
|
shouldThrow(); |
229 |
|
} catch (NullPointerException success) {} |
230 |
|
} |
231 |
+ |
|
232 |
|
/** |
233 |
|
* addAll of a collection with any null elements throws NPE after |
234 |
|
* possibly adding some elements |
243 |
|
shouldThrow(); |
244 |
|
} catch (NullPointerException success) {} |
245 |
|
} |
246 |
+ |
|
247 |
|
/** |
248 |
|
* addAll throws ISE if not enough room |
249 |
|
*/ |
257 |
|
shouldThrow(); |
258 |
|
} catch (IllegalStateException success) {} |
259 |
|
} |
260 |
+ |
|
261 |
|
/** |
262 |
|
* Queue contains all elements, in traversal order, of successful addAll |
263 |
|
*/ |
475 |
|
} |
476 |
|
|
477 |
|
/** |
461 |
– |
* timed poll before a delayed offer fails; after offer succeeds; |
462 |
– |
* on interruption throws |
463 |
– |
*/ |
464 |
– |
public void testTimedPollWithOffer() throws InterruptedException { |
465 |
– |
final LinkedBlockingQueue q = new LinkedBlockingQueue(2); |
466 |
– |
Thread t = new Thread(new CheckedRunnable() { |
467 |
– |
public void realRun() throws InterruptedException { |
468 |
– |
assertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS)); |
469 |
– |
assertSame(zero, q.poll(LONG_DELAY_MS, MILLISECONDS)); |
470 |
– |
try { |
471 |
– |
q.poll(LONG_DELAY_MS, MILLISECONDS); |
472 |
– |
shouldThrow(); |
473 |
– |
} catch (InterruptedException success) {} |
474 |
– |
}}); |
475 |
– |
|
476 |
– |
t.start(); |
477 |
– |
Thread.sleep(SMALL_DELAY_MS); |
478 |
– |
assertTrue(q.offer(zero, SHORT_DELAY_MS, MILLISECONDS)); |
479 |
– |
t.interrupt(); |
480 |
– |
t.join(); |
481 |
– |
} |
482 |
– |
|
483 |
– |
/** |
478 |
|
* peek returns next element, or null if empty |
479 |
|
*/ |
480 |
|
public void testPeek() { |
680 |
|
/** |
681 |
|
* iterator.remove removes current element |
682 |
|
*/ |
683 |
< |
public void testIteratorRemove () { |
683 |
> |
public void testIteratorRemove() { |
684 |
|
final LinkedBlockingQueue q = new LinkedBlockingQueue(3); |
685 |
|
q.add(two); |
686 |
|
q.add(one); |
691 |
|
it.remove(); |
692 |
|
|
693 |
|
it = q.iterator(); |
694 |
< |
assertEquals(it.next(), one); |
695 |
< |
assertEquals(it.next(), three); |
694 |
> |
assertSame(it.next(), one); |
695 |
> |
assertSame(it.next(), three); |
696 |
|
assertFalse(it.hasNext()); |
697 |
|
} |
698 |
|
|
716 |
|
/** |
717 |
|
* Modifications do not cause iterators to fail |
718 |
|
*/ |
719 |
< |
public void testWeaklyConsistentIteration () { |
719 |
> |
public void testWeaklyConsistentIteration() { |
720 |
|
final LinkedBlockingQueue q = new LinkedBlockingQueue(3); |
721 |
|
q.add(one); |
722 |
|
q.add(two); |