393 |
|
} |
394 |
|
|
395 |
|
/** |
396 |
– |
* take blocks interruptibly when empty |
397 |
– |
*/ |
398 |
– |
public void testTakeFromEmpty() throws InterruptedException { |
399 |
– |
final ArrayBlockingQueue q = new ArrayBlockingQueue(2); |
400 |
– |
Thread t = new ThreadShouldThrow(InterruptedException.class) { |
401 |
– |
public void realRun() throws InterruptedException { |
402 |
– |
q.take(); |
403 |
– |
}}; |
404 |
– |
|
405 |
– |
t.start(); |
406 |
– |
Thread.sleep(SHORT_DELAY_MS); |
407 |
– |
t.interrupt(); |
408 |
– |
t.join(); |
409 |
– |
} |
410 |
– |
|
411 |
– |
/** |
396 |
|
* Take removes existing elements until empty, then blocks interruptibly |
397 |
|
*/ |
398 |
|
public void testBlockingTake() throws InterruptedException { |
880 |
|
} |
881 |
|
|
882 |
|
/** |
883 |
< |
* drainTo(c, n) empties first max {n, size} elements of queue into c |
883 |
> |
* drainTo(c, n) empties first min(n, size) elements of queue into c |
884 |
|
*/ |
885 |
|
public void testDrainToN() { |
886 |
|
ArrayBlockingQueue q = new ArrayBlockingQueue(SIZE*2); |
889 |
|
assertTrue(q.offer(new Integer(j))); |
890 |
|
ArrayList l = new ArrayList(); |
891 |
|
q.drainTo(l, i); |
892 |
< |
int k = (i < SIZE)? i : SIZE; |
892 |
> |
int k = (i < SIZE) ? i : SIZE; |
893 |
|
assertEquals(l.size(), k); |
894 |
|
assertEquals(q.size(), SIZE-k); |
895 |
|
for (int j = 0; j < k; ++j) |