269 |
|
* addAll throws ISE if not enough room |
270 |
|
*/ |
271 |
|
public void testAddAll_insufficientSpace() { |
272 |
< |
int size = ThreadLocalRandom.current().nextInt(SIZE); |
272 |
> |
int size = ThreadLocalRandom.current().nextInt(1, SIZE); |
273 |
|
ArrayBlockingQueue q = populatedQueue(0, size, size, false); |
274 |
|
// Just fits: |
275 |
|
q.addAll(populatedQueue(size, size, 2 * size, false)); |
425 |
|
final CountDownLatch pleaseInterrupt = new CountDownLatch(1); |
426 |
|
Thread t = newStartedThread(new CheckedRunnable() { |
427 |
|
public void realRun() throws InterruptedException { |
428 |
< |
for (int i = 0; i < SIZE; ++i) { |
429 |
< |
assertEquals(i, q.take()); |
430 |
< |
} |
428 |
> |
for (int i = 0; i < SIZE; i++) assertEquals(i, q.take()); |
429 |
|
|
430 |
|
Thread.currentThread().interrupt(); |
431 |
|
try { |
443 |
|
}}); |
444 |
|
|
445 |
|
await(pleaseInterrupt); |
446 |
< |
assertThreadStaysAlive(t); |
446 |
> |
assertThreadBlocks(t, Thread.State.WAITING); |
447 |
|
t.interrupt(); |
448 |
|
awaitTermination(t); |
449 |
|
} |
563 |
|
* contains(x) reports true when elements added but not yet removed |
564 |
|
*/ |
565 |
|
public void testContains() { |
566 |
< |
ArrayBlockingQueue q = populatedQueue(SIZE); |
567 |
< |
for (int i = 0; i < SIZE; ++i) { |
566 |
> |
int size = ThreadLocalRandom.current().nextInt(1, SIZE); |
567 |
> |
ArrayBlockingQueue q = populatedQueue(size, size, 2 * size, false); |
568 |
> |
assertFalse(q.contains(null)); |
569 |
> |
for (int i = 0; i < size; ++i) { |
570 |
|
assertTrue(q.contains(new Integer(i))); |
571 |
|
assertEquals(i, q.poll()); |
572 |
|
assertFalse(q.contains(new Integer(i))); |
577 |
|
* clear removes all elements |
578 |
|
*/ |
579 |
|
public void testClear() { |
580 |
< |
ArrayBlockingQueue q = populatedQueue(SIZE); |
580 |
> |
int size = ThreadLocalRandom.current().nextInt(1, 5); |
581 |
> |
ArrayBlockingQueue q = populatedQueue(size, size, 2 * size, false); |
582 |
> |
int capacity = size + q.remainingCapacity(); |
583 |
|
q.clear(); |
584 |
|
assertTrue(q.isEmpty()); |
585 |
|
assertEquals(0, q.size()); |
586 |
< |
assertEquals(SIZE, q.remainingCapacity()); |
586 |
> |
assertEquals(capacity, q.remainingCapacity()); |
587 |
|
q.add(one); |
588 |
|
assertFalse(q.isEmpty()); |
589 |
|
assertTrue(q.contains(one)); |
937 |
|
*/ |
938 |
|
public void testNeverContainsNull() { |
939 |
|
Collection<?>[] qs = { |
940 |
< |
new ArrayBlockingQueue<Object>(10), |
941 |
< |
populatedQueue(2), |
940 |
> |
populatedQueue(0, 1, 10, false), |
941 |
> |
populatedQueue(2, 2, 10, true), |
942 |
|
}; |
943 |
|
|
944 |
|
for (Collection<?> q : qs) { |