Search in sources :

Example 71 with LinkedBlockingDeque

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

the class LinkedBlockingDequeTest method testRetainAll.

/**
     * retainAll(c) retains only those elements of c and reports true if changed
     */
public void testRetainAll() {
    LinkedBlockingDeque q = populatedDeque(SIZE);
    LinkedBlockingDeque p = populatedDeque(SIZE);
    for (int i = 0; i < SIZE; ++i) {
        boolean changed = q.retainAll(p);
        if (i == 0)
            assertFalse(changed);
        else
            assertTrue(changed);
        assertTrue(q.containsAll(p));
        assertEquals(SIZE - i, q.size());
        p.remove();
    }
}
Also used : LinkedBlockingDeque(java.util.concurrent.LinkedBlockingDeque)

Example 72 with LinkedBlockingDeque

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

the class LinkedBlockingDequeTest method testContainsAll.

/**
     * containsAll(c) is true when c contains a subset of elements
     */
public void testContainsAll() {
    LinkedBlockingDeque q = populatedDeque(SIZE);
    LinkedBlockingDeque p = new LinkedBlockingDeque(SIZE);
    for (int i = 0; i < SIZE; ++i) {
        assertTrue(q.containsAll(p));
        assertFalse(p.containsAll(q));
        p.add(new Integer(i));
    }
    assertTrue(p.containsAll(q));
}
Also used : LinkedBlockingDeque(java.util.concurrent.LinkedBlockingDeque)

Example 73 with LinkedBlockingDeque

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

the class LinkedBlockingDequeTest method testBlockingTakeFirst.

/**
     * takeFirst removes existing elements until empty, then blocks interruptibly
     */
public void testBlockingTakeFirst() throws InterruptedException {
    final LinkedBlockingDeque q = populatedDeque(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.takeFirst());
            }
            Thread.currentThread().interrupt();
            try {
                q.takeFirst();
                shouldThrow();
            } catch (InterruptedException success) {
            }
            assertFalse(Thread.interrupted());
            pleaseInterrupt.countDown();
            try {
                q.takeFirst();
                shouldThrow();
            } catch (InterruptedException success) {
            }
            assertFalse(Thread.interrupted());
        }
    });
    await(pleaseInterrupt);
    assertThreadStaysAlive(t);
    t.interrupt();
    awaitTermination(t);
}
Also used : LinkedBlockingDeque(java.util.concurrent.LinkedBlockingDeque) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 74 with LinkedBlockingDeque

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

the class LinkedBlockingDequeTest method testPollLast.

/**
     * pollLast succeeds unless empty
     */
public void testPollLast() {
    LinkedBlockingDeque q = populatedDeque(SIZE);
    for (int i = SIZE - 1; i >= 0; --i) {
        assertEquals(i, q.pollLast());
    }
    assertNull(q.pollLast());
}
Also used : LinkedBlockingDeque(java.util.concurrent.LinkedBlockingDeque)

Example 75 with LinkedBlockingDeque

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

the class LinkedBlockingDequeTest method testTimedPollFirst0.

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

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