use of java.util.concurrent.BlockingQueue in project j2objc by google.
the class BlockingQueueTest method testDrainToNonPositiveMaxElements.
/**
* drainTo(c, n) returns 0 and does nothing when n <= 0
*/
public void testDrainToNonPositiveMaxElements() {
final BlockingQueue q = emptyCollection();
final int[] ns = { 0, -1, -42, Integer.MIN_VALUE };
for (int n : ns) assertEquals(0, q.drainTo(new ArrayList(), n));
if (q.remainingCapacity() > 0) {
// Not SynchronousQueue, that is
Object one = makeElement(1);
q.add(one);
ArrayList c = new ArrayList();
for (int n : ns) assertEquals(0, q.drainTo(new ArrayList(), n));
assertEquals(1, q.size());
assertSame(one, q.poll());
assertTrue(c.isEmpty());
}
}
use of java.util.concurrent.BlockingQueue in project j2objc by google.
the class BlockingQueueTest method testTakeFromEmptyAfterInterrupt.
/**
* take() throws InterruptedException immediately if interrupted
* before waiting
*/
public void testTakeFromEmptyAfterInterrupt() {
final BlockingQueue q = emptyCollection();
Thread t = newStartedThread(new CheckedRunnable() {
public void realRun() {
Thread.currentThread().interrupt();
try {
q.take();
shouldThrow();
} catch (InterruptedException success) {
}
assertFalse(Thread.interrupted());
}
});
awaitTermination(t);
}
use of java.util.concurrent.BlockingQueue in project j2objc by google.
the class BlockingQueueTest method testDrainToNull.
/**
* drainTo(null) throws NullPointerException
*/
public void testDrainToNull() {
final BlockingQueue q = emptyCollection();
try {
q.drainTo(null);
shouldThrow();
} catch (NullPointerException success) {
}
}
use of java.util.concurrent.BlockingQueue in project j2objc by google.
the class BlockingQueueTest method testTakeFromEmptyBlocksInterruptibly.
/**
* take() blocks interruptibly when empty
*/
public void testTakeFromEmptyBlocksInterruptibly() {
final BlockingQueue q = emptyCollection();
final CountDownLatch threadStarted = new CountDownLatch(1);
Thread t = newStartedThread(new CheckedRunnable() {
public void realRun() {
threadStarted.countDown();
try {
q.take();
shouldThrow();
} catch (InterruptedException success) {
}
assertFalse(Thread.interrupted());
}
});
await(threadStarted);
assertThreadStaysAlive(t);
t.interrupt();
awaitTermination(t);
}
use of java.util.concurrent.BlockingQueue in project j2objc by google.
the class BlockingQueueTest method testDrainToSelf.
/**
* drainTo(this) throws IllegalArgumentException
*/
public void testDrainToSelf() {
final BlockingQueue q = emptyCollection();
try {
q.drainTo(q);
shouldThrow();
} catch (IllegalArgumentException success) {
}
}
Aggregations