Search in sources :

Example 26 with LinkedBlockingDeque

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

the class LinkedBlockingDequeTest method testContains.

/**
     * contains(x) reports true when elements added but not yet removed
     */
public void testContains() {
    LinkedBlockingDeque q = populatedDeque(SIZE);
    for (int i = 0; i < SIZE; ++i) {
        assertTrue(q.contains(new Integer(i)));
        q.poll();
        assertFalse(q.contains(new Integer(i)));
    }
}
Also used : LinkedBlockingDeque(java.util.concurrent.LinkedBlockingDeque)

Example 27 with LinkedBlockingDeque

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

the class LinkedBlockingDequeTest method testPollFirst.

/**
     * pollFirst succeeds unless empty
     */
public void testPollFirst() {
    LinkedBlockingDeque q = populatedDeque(SIZE);
    for (int i = 0; i < SIZE; ++i) {
        assertEquals(i, q.pollFirst());
    }
    assertNull(q.pollFirst());
}
Also used : LinkedBlockingDeque(java.util.concurrent.LinkedBlockingDeque)

Example 28 with LinkedBlockingDeque

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

the class LinkedBlockingDequeTest method testTimedPoll0.

/**
     * timed poll with zero timeout succeeds when non-empty, else times out
     */
public void testTimedPoll0() throws InterruptedException {
    LinkedBlockingDeque q = populatedDeque(SIZE);
    for (int i = 0; i < SIZE; ++i) {
        assertEquals(i, q.poll(0, MILLISECONDS));
    }
    assertNull(q.poll(0, MILLISECONDS));
}
Also used : LinkedBlockingDeque(java.util.concurrent.LinkedBlockingDeque)

Example 29 with LinkedBlockingDeque

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

the class LinkedBlockingDequeTest method testTakeLastFromEmptyAfterInterrupt.

/**
     * takeLast() throws InterruptedException immediately if interrupted
     * before waiting
     */
public void testTakeLastFromEmptyAfterInterrupt() {
    final BlockingDeque q = new LinkedBlockingDeque();
    Thread t = newStartedThread(new CheckedRunnable() {

        public void realRun() {
            Thread.currentThread().interrupt();
            try {
                q.takeLast();
                shouldThrow();
            } catch (InterruptedException success) {
            }
            assertFalse(Thread.interrupted());
        }
    });
    awaitTermination(t);
}
Also used : LinkedBlockingDeque(java.util.concurrent.LinkedBlockingDeque) BlockingDeque(java.util.concurrent.BlockingDeque) LinkedBlockingDeque(java.util.concurrent.LinkedBlockingDeque)

Example 30 with LinkedBlockingDeque

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

the class LinkedBlockingDequeTest method testRemove.

/**
     * remove removes next element, or throws NSEE if empty
     */
public void testRemove() {
    LinkedBlockingDeque q = populatedDeque(SIZE);
    for (int i = 0; i < SIZE; ++i) {
        assertEquals(i, q.remove());
    }
    try {
        q.remove();
        shouldThrow();
    } catch (NoSuchElementException success) {
    }
}
Also used : LinkedBlockingDeque(java.util.concurrent.LinkedBlockingDeque) NoSuchElementException(java.util.NoSuchElementException)

Aggregations

LinkedBlockingDeque (java.util.concurrent.LinkedBlockingDeque)119 Test (org.junit.Test)21 CountDownLatch (java.util.concurrent.CountDownLatch)20 NoSuchElementException (java.util.NoSuchElementException)8 ArrayList (java.util.ArrayList)7 Iterator (java.util.Iterator)7 IOException (java.io.IOException)5 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)5 ExecutorService (java.util.concurrent.ExecutorService)5 BlockingDeque (java.util.concurrent.BlockingDeque)4 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)4 ByteBuffer (java.nio.ByteBuffer)3 HashMap (java.util.HashMap)3 IotHubOutboundPacket (com.microsoft.azure.sdk.iot.device.transport.IotHubOutboundPacket)2 AmqpsMessage (com.microsoft.azure.sdk.iot.device.transport.amqps.AmqpsMessage)2 AmqpsTransport (com.microsoft.azure.sdk.iot.device.transport.amqps.AmqpsTransport)2 ByteBuf (io.netty.buffer.ByteBuf)2 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)2 ChannelInboundHandlerAdapter (io.netty.channel.ChannelInboundHandlerAdapter)2 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)2