Search in sources :

Example 6 with LinkedBlockingDeque

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

the class LinkedBlockingDequeTest method testAdd.

/**
     * add succeeds if not full; throws ISE if full
     */
public void testAdd() {
    LinkedBlockingDeque q = new LinkedBlockingDeque(SIZE);
    for (int i = 0; i < SIZE; ++i) assertTrue(q.add(new Integer(i)));
    assertEquals(0, q.remainingCapacity());
    try {
        q.add(new Integer(SIZE));
        shouldThrow();
    } catch (IllegalStateException success) {
    }
}
Also used : LinkedBlockingDeque(java.util.concurrent.LinkedBlockingDeque)

Example 7 with LinkedBlockingDeque

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

the class LinkedBlockingDequeTest method testFirstElement.

/**
     * getFirst() returns first element, or throws NSEE if empty
     */
public void testFirstElement() {
    LinkedBlockingDeque q = populatedDeque(SIZE);
    for (int i = 0; i < SIZE; ++i) {
        assertEquals(i, q.getFirst());
        assertEquals(i, q.pollFirst());
    }
    try {
        q.getFirst();
        shouldThrow();
    } catch (NoSuchElementException success) {
    }
    assertNull(q.peekFirst());
}
Also used : LinkedBlockingDeque(java.util.concurrent.LinkedBlockingDeque) NoSuchElementException(java.util.NoSuchElementException)

Example 8 with LinkedBlockingDeque

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

the class LinkedBlockingDequeTest method testPushWithPeek.

/**
     * peekFirst returns element inserted with push
     */
public void testPushWithPeek() {
    LinkedBlockingDeque q = populatedDeque(3);
    q.pollLast();
    q.push(four);
    assertSame(four, q.peekFirst());
}
Also used : LinkedBlockingDeque(java.util.concurrent.LinkedBlockingDeque)

Example 9 with LinkedBlockingDeque

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

the class LinkedBlockingDequeTest method testLastElement.

/**
     * getLast() returns last element, or throws NSEE if empty
     */
public void testLastElement() {
    LinkedBlockingDeque q = populatedDeque(SIZE);
    for (int i = SIZE - 1; i >= 0; --i) {
        assertEquals(i, q.getLast());
        assertEquals(i, q.pollLast());
    }
    try {
        q.getLast();
        shouldThrow();
    } catch (NoSuchElementException success) {
    }
    assertNull(q.peekLast());
}
Also used : LinkedBlockingDeque(java.util.concurrent.LinkedBlockingDeque) NoSuchElementException(java.util.NoSuchElementException)

Example 10 with LinkedBlockingDeque

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

the class LinkedBlockingDequeTest method testToArray.

/**
     * toArray contains all elements in FIFO order
     */
public void testToArray() throws InterruptedException {
    LinkedBlockingDeque q = populatedDeque(SIZE);
    Object[] o = q.toArray();
    for (int i = 0; i < o.length; i++) assertSame(o[i], q.poll());
}
Also used : LinkedBlockingDeque(java.util.concurrent.LinkedBlockingDeque)

Aggregations

LinkedBlockingDeque (java.util.concurrent.LinkedBlockingDeque)116 CountDownLatch (java.util.concurrent.CountDownLatch)20 Test (org.junit.Test)19 NoSuchElementException (java.util.NoSuchElementException)8 ArrayList (java.util.ArrayList)7 Iterator (java.util.Iterator)7 IOException (java.io.IOException)5 ExecutorService (java.util.concurrent.ExecutorService)5 BlockingDeque (java.util.concurrent.BlockingDeque)4 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)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