366 |
|
} |
367 |
|
|
368 |
|
/** |
369 |
– |
* take blocks interruptibly when empty |
370 |
– |
*/ |
371 |
– |
public void testTakeFromEmpty() throws InterruptedException { |
372 |
– |
final PriorityBlockingQueue q = new PriorityBlockingQueue(2); |
373 |
– |
Thread t = new Thread(new CheckedInterruptedRunnable() { |
374 |
– |
public void realRun() throws InterruptedException { |
375 |
– |
q.take(); |
376 |
– |
}}); |
377 |
– |
|
378 |
– |
t.start(); |
379 |
– |
Thread.sleep(SHORT_DELAY_MS); |
380 |
– |
t.interrupt(); |
381 |
– |
t.join(); |
382 |
– |
} |
383 |
– |
|
384 |
– |
/** |
369 |
|
* Take removes existing elements until empty, then blocks interruptibly |
370 |
|
*/ |
371 |
|
public void testBlockingTake() throws InterruptedException { |
806 |
|
assertTrue(q.offer(new Integer(j))); |
807 |
|
ArrayList l = new ArrayList(); |
808 |
|
q.drainTo(l, i); |
809 |
< |
int k = (i < SIZE)? i : SIZE; |
809 |
> |
int k = (i < SIZE) ? i : SIZE; |
810 |
|
assertEquals(l.size(), k); |
811 |
|
assertEquals(q.size(), SIZE-k); |
812 |
|
for (int j = 0; j < k; ++j) |