Search in sources :

Example 16 with BlockingQueue

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

the class LinkedTransferQueueTest method testBlockingTake.

/**
     * take removes existing elements until empty, then blocks interruptibly
     */
public void testBlockingTake() throws InterruptedException {
    final BlockingQueue q = populatedQueue(SIZE);
    final CountDownLatch pleaseInterrupt = new CountDownLatch(1);
    Thread t = newStartedThread(new CheckedRunnable() {

        public void realRun() throws InterruptedException {
            for (int i = 0; i < SIZE; ++i) {
                assertEquals(i, q.take());
            }
            Thread.currentThread().interrupt();
            try {
                q.take();
                shouldThrow();
            } catch (InterruptedException success) {
            }
            assertFalse(Thread.interrupted());
            pleaseInterrupt.countDown();
            try {
                q.take();
                shouldThrow();
            } catch (InterruptedException success) {
            }
            assertFalse(Thread.interrupted());
        }
    });
    await(pleaseInterrupt);
    assertThreadStaysAlive(t);
    t.interrupt();
    awaitTermination(t);
}
Also used : BlockingQueue(java.util.concurrent.BlockingQueue) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 17 with BlockingQueue

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

the class LinkedTransferQueueTest method testRemainingCapacity.

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

Example 18 with BlockingQueue

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

the class LinkedBlockingQueueTest method testBlockingTake.

/**
     * Take removes existing elements until empty, then blocks interruptibly
     */
public void testBlockingTake() throws InterruptedException {
    final BlockingQueue q = populatedQueue(SIZE);
    final CountDownLatch pleaseInterrupt = new CountDownLatch(1);
    Thread t = newStartedThread(new CheckedRunnable() {

        public void realRun() throws InterruptedException {
            for (int i = 0; i < SIZE; ++i) {
                assertEquals(i, q.take());
            }
            Thread.currentThread().interrupt();
            try {
                q.take();
                shouldThrow();
            } catch (InterruptedException success) {
            }
            assertFalse(Thread.interrupted());
            pleaseInterrupt.countDown();
            try {
                q.take();
                shouldThrow();
            } catch (InterruptedException success) {
            }
            assertFalse(Thread.interrupted());
        }
    });
    await(pleaseInterrupt);
    assertThreadStaysAlive(t);
    t.interrupt();
    awaitTermination(t);
}
Also used : BlockingQueue(java.util.concurrent.BlockingQueue) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 19 with BlockingQueue

use of java.util.concurrent.BlockingQueue in project HugeCollections-OLD by peter-lawrey.

the class LocalJSR166TestCase method testConstructor7.

/**
     * Queue contains all elements of collection used to initialize
     */
@Ignore
@Test
public void testConstructor7() {
    Integer[] ints = new Integer[SIZE];
    for (int i = 0; i < SIZE; ++i) ints[i] = i;
    Collection<Integer> elements = Arrays.asList(ints);
    BlockingQueue q = new LocalConcurrentBlockingObjectQueue(SIZE, true, elements);
    for (int i = 0; i < SIZE; ++i) assertEquals(ints[i], q.poll());
}
Also used : BlockingQueue(java.util.concurrent.BlockingQueue) LocalConcurrentBlockingObjectQueue(net.openhft.chronicle.sandbox.queue.LocalConcurrentBlockingObjectQueue) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 20 with BlockingQueue

use of java.util.concurrent.BlockingQueue in project HugeCollections-OLD by peter-lawrey.

the class LocalJSR166TestCase method testBlockingTake.

/**
     * Take removes existing elements until empty, then blocks interruptibly
     */
@Ignore
@Test
public void testBlockingTake() throws InterruptedException {
    final BlockingQueue q = populatedQueue(SIZE);
    final CountDownLatch pleaseInterrupt = new CountDownLatch(1);
    Thread t = newStartedThread(new CheckedRunnable() {

        public void realRun() throws InterruptedException {
            for (int i = 0; i < SIZE; ++i) {
                assertEquals(i, q.take());
            }
            Thread.currentThread().interrupt();
            try {
                q.take();
                shouldThrow();
            } catch (InterruptedException success) {
            }
            assertFalse(Thread.interrupted());
            pleaseInterrupt.countDown();
            try {
                q.take();
                shouldThrow();
            } catch (InterruptedException success) {
            }
            assertFalse(Thread.interrupted());
        }
    });
    await(pleaseInterrupt);
    assertThreadStaysAlive(t);
    t.interrupt();
    awaitTermination(t);
}
Also used : BlockingQueue(java.util.concurrent.BlockingQueue) CountDownLatch(java.util.concurrent.CountDownLatch) Ignore(org.junit.Ignore) Test(org.junit.Test)

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