Search in sources :

Example 81 with BlockingQueue

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());
    }
}
Also used : BlockingQueue(java.util.concurrent.BlockingQueue) ArrayList(java.util.ArrayList)

Example 82 with BlockingQueue

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);
}
Also used : BlockingQueue(java.util.concurrent.BlockingQueue)

Example 83 with BlockingQueue

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) {
    }
}
Also used : BlockingQueue(java.util.concurrent.BlockingQueue)

Example 84 with BlockingQueue

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);
}
Also used : BlockingQueue(java.util.concurrent.BlockingQueue) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 85 with BlockingQueue

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) {
    }
}
Also used : BlockingQueue(java.util.concurrent.BlockingQueue)

Aggregations

BlockingQueue (java.util.concurrent.BlockingQueue)129 Test (org.junit.Test)59 CountDownLatch (java.util.concurrent.CountDownLatch)21 LocalConcurrentBlockingObjectQueue (net.openhft.chronicle.sandbox.queue.LocalConcurrentBlockingObjectQueue)21 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)18 ArrayList (java.util.ArrayList)12 Ignore (org.junit.Ignore)12 IOException (java.io.IOException)10 BlockingQueueTest (net.openhft.chronicle.sandbox.queue.common.BlockingQueueTest)10 ArrayBlockingQueue (java.util.concurrent.ArrayBlockingQueue)9 TimeUnit (java.util.concurrent.TimeUnit)9 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)8 ByteBuffer (java.nio.ByteBuffer)4 List (java.util.List)4 Assert (org.junit.Assert)4 SynchronousQueue (java.util.concurrent.SynchronousQueue)3 TimeoutException (java.util.concurrent.TimeoutException)3 AsyncContext (javax.servlet.AsyncContext)3 ReadListener (javax.servlet.ReadListener)3 ServletException (javax.servlet.ServletException)3