Search in sources :

Example 76 with BlockingQueue

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

the class ArrayBlockingQueueTest method testRemainingCapacity.

/**
     * remainingCapacity decreases on add, increases on remove
     */
public void testRemainingCapacity() {
    BlockingQueue q = populatedQueue(SIZE);
    for (int i = 0; i < SIZE; ++i) {
        assertEquals(i, q.remainingCapacity());
        assertEquals(SIZE, q.size() + q.remainingCapacity());
        assertEquals(i, q.remove());
    }
    for (int i = 0; i < SIZE; ++i) {
        assertEquals(SIZE - i, q.remainingCapacity());
        assertEquals(SIZE, q.size() + q.remainingCapacity());
        assertTrue(q.add(i));
    }
}
Also used : BlockingQueue(java.util.concurrent.BlockingQueue) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue)

Example 77 with BlockingQueue

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

the class LinkedBlockingDequeTest method testRemainingCapacity.

/**
     * remainingCapacity decreases on add, increases on remove
     */
public void testRemainingCapacity() {
    BlockingQueue q = populatedDeque(SIZE);
    for (int i = 0; i < SIZE; ++i) {
        assertEquals(i, q.remainingCapacity());
        assertEquals(SIZE, q.size() + q.remainingCapacity());
        assertEquals(i, q.remove());
    }
    for (int i = 0; i < SIZE; ++i) {
        assertEquals(SIZE - i, q.remainingCapacity());
        assertEquals(SIZE, q.size() + q.remainingCapacity());
        assertTrue(q.add(i));
    }
}
Also used : BlockingQueue(java.util.concurrent.BlockingQueue)

Example 78 with BlockingQueue

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

the class LinkedBlockingQueueTest method testRemainingCapacity.

/**
     * remainingCapacity decreases on add, increases on remove
     */
public void testRemainingCapacity() {
    BlockingQueue q = populatedQueue(SIZE);
    for (int i = 0; i < SIZE; ++i) {
        assertEquals(i, q.remainingCapacity());
        assertEquals(SIZE, q.size() + q.remainingCapacity());
        assertEquals(i, q.remove());
    }
    for (int i = 0; i < SIZE; ++i) {
        assertEquals(SIZE - i, q.remainingCapacity());
        assertEquals(SIZE, q.size() + q.remainingCapacity());
        assertTrue(q.add(i));
    }
}
Also used : BlockingQueue(java.util.concurrent.BlockingQueue) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue)

Example 79 with BlockingQueue

use of java.util.concurrent.BlockingQueue in project j2objc by google.

the class BlockingQueueTest method testDrainToNullN.

/**
     * drainTo(null, n) throws NullPointerException
     */
public void testDrainToNullN() {
    final BlockingQueue q = emptyCollection();
    try {
        q.drainTo(null, 0);
        shouldThrow();
    } catch (NullPointerException success) {
    }
}
Also used : BlockingQueue(java.util.concurrent.BlockingQueue)

Example 80 with BlockingQueue

use of java.util.concurrent.BlockingQueue in project j2objc by google.

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)

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