14 |
|
import java.io.*; |
15 |
|
|
16 |
|
public class ArrayBlockingQueueTest extends JSR166TestCase { |
17 |
+ |
|
18 |
+ |
public static class Fair extends BlockingQueueTest { |
19 |
+ |
protected BlockingQueue emptyCollection() { |
20 |
+ |
return new ArrayBlockingQueue(20, true); |
21 |
+ |
} |
22 |
+ |
} |
23 |
+ |
|
24 |
+ |
public static class NonFair extends BlockingQueueTest { |
25 |
+ |
protected BlockingQueue emptyCollection() { |
26 |
+ |
return new ArrayBlockingQueue(20, false); |
27 |
+ |
} |
28 |
+ |
} |
29 |
+ |
|
30 |
|
public static void main(String[] args) { |
31 |
|
junit.textui.TestRunner.run(suite()); |
32 |
|
} |
33 |
+ |
|
34 |
|
public static Test suite() { |
35 |
< |
return new TestSuite(ArrayBlockingQueueTest.class); |
35 |
> |
return newTestSuite(ArrayBlockingQueueTest.class, |
36 |
> |
new Fair().testSuite(), |
37 |
> |
new NonFair().testSuite()); |
38 |
|
} |
39 |
|
|
40 |
|
/** |
240 |
|
shouldThrow(); |
241 |
|
} catch (NullPointerException success) {} |
242 |
|
} |
243 |
+ |
|
244 |
|
/** |
245 |
|
* addAll of a collection with any null elements throws NPE after |
246 |
|
* possibly adding some elements |
255 |
|
shouldThrow(); |
256 |
|
} catch (NullPointerException success) {} |
257 |
|
} |
258 |
+ |
|
259 |
|
/** |
260 |
|
* addAll throws ISE if not enough room |
261 |
|
*/ |
269 |
|
shouldThrow(); |
270 |
|
} catch (IllegalStateException success) {} |
271 |
|
} |
272 |
+ |
|
273 |
|
/** |
274 |
|
* Queue contains all elements, in traversal order, of successful addAll |
275 |
|
*/ |
488 |
|
} |
489 |
|
|
490 |
|
/** |
472 |
– |
* timed poll before a delayed offer fails; after offer succeeds; |
473 |
– |
* on interruption throws |
474 |
– |
*/ |
475 |
– |
public void testTimedPollWithOffer() throws InterruptedException { |
476 |
– |
final ArrayBlockingQueue q = new ArrayBlockingQueue(2); |
477 |
– |
Thread t = new Thread(new CheckedRunnable() { |
478 |
– |
public void realRun() throws InterruptedException { |
479 |
– |
assertNull(q.poll(SHORT_DELAY_MS, MILLISECONDS)); |
480 |
– |
assertSame(zero, q.poll(LONG_DELAY_MS, MILLISECONDS)); |
481 |
– |
try { |
482 |
– |
q.poll(LONG_DELAY_MS, MILLISECONDS); |
483 |
– |
shouldThrow(); |
484 |
– |
} catch (InterruptedException success) {} |
485 |
– |
}}); |
486 |
– |
|
487 |
– |
t.start(); |
488 |
– |
Thread.sleep(SMALL_DELAY_MS); |
489 |
– |
assertTrue(q.offer(zero, SHORT_DELAY_MS, MILLISECONDS)); |
490 |
– |
t.interrupt(); |
491 |
– |
t.join(); |
492 |
– |
} |
493 |
– |
|
494 |
– |
|
495 |
– |
/** |
491 |
|
* peek returns next element, or null if empty |
492 |
|
*/ |
493 |
|
public void testPeek() { |