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 |
|
} |
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)); |