Search in sources :

Example 11 with BlockingQueue

use of java.util.concurrent.BlockingQueue in project mapdb by jankotek.

the class BlockingQueueTest method testTimedPollFromEmptyAfterInterrupt.

/**
     * timed poll() throws InterruptedException immediately if
     * interrupted before waiting
     */
public void testTimedPollFromEmptyAfterInterrupt() {
    final BlockingQueue q = emptyCollection();
    Thread t = newStartedThread(new CheckedRunnable() {

        public void realRun() {
            Thread.currentThread().interrupt();
            try {
                q.poll(2 * LONG_DELAY_MS, MILLISECONDS);
                shouldThrow();
            } catch (InterruptedException success) {
            }
            assertFalse(Thread.interrupted());
        }
    });
    awaitTermination(t);
}
Also used : BlockingQueue(java.util.concurrent.BlockingQueue)

Example 12 with BlockingQueue

use of java.util.concurrent.BlockingQueue in project mapdb by jankotek.

the class BlockingQueueTest method testPutNull.

/**
     * put(null) throws NullPointerException
     */
public void testPutNull() throws InterruptedException {
    final BlockingQueue q = emptyCollection();
    try {
        q.put(null);
        shouldThrow();
    } catch (NullPointerException success) {
    }
}
Also used : BlockingQueue(java.util.concurrent.BlockingQueue)

Example 13 with BlockingQueue

use of java.util.concurrent.BlockingQueue in project mapdb by jankotek.

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)

Example 14 with BlockingQueue

use of java.util.concurrent.BlockingQueue in project mapdb by jankotek.

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 15 with BlockingQueue

use of java.util.concurrent.BlockingQueue in project mapdb by jankotek.

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)

Aggregations

BlockingQueue (java.util.concurrent.BlockingQueue)124 Test (org.junit.Test)58 CountDownLatch (java.util.concurrent.CountDownLatch)21 LocalConcurrentBlockingObjectQueue (net.openhft.chronicle.sandbox.queue.LocalConcurrentBlockingObjectQueue)21 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)16 Ignore (org.junit.Ignore)12 IOException (java.io.IOException)10 BlockingQueueTest (net.openhft.chronicle.sandbox.queue.common.BlockingQueueTest)10 ArrayList (java.util.ArrayList)8 ArrayBlockingQueue (java.util.concurrent.ArrayBlockingQueue)8 TimeUnit (java.util.concurrent.TimeUnit)8 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)7 ByteBuffer (java.nio.ByteBuffer)4 SynchronousQueue (java.util.concurrent.SynchronousQueue)4 TimeoutException (java.util.concurrent.TimeoutException)3 AsyncContext (javax.servlet.AsyncContext)3 ReadListener (javax.servlet.ReadListener)3 ServletException (javax.servlet.ServletException)3 ServletInputStream (javax.servlet.ServletInputStream)3 ServletOutputStream (javax.servlet.ServletOutputStream)3