Search in sources :

Example 16 with LinkedBlockingDeque

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

the class LinkedBlockingDequeTest method testSize.

/**
     * size changes when elements added and removed
     */
public void testSize() {
    LinkedBlockingDeque q = populatedDeque(SIZE);
    for (int i = 0; i < SIZE; ++i) {
        assertEquals(SIZE - i, q.size());
        q.removeFirst();
    }
    for (int i = 0; i < SIZE; ++i) {
        assertEquals(i, q.size());
        q.add(new Integer(i));
    }
}
Also used : LinkedBlockingDeque(java.util.concurrent.LinkedBlockingDeque)

Example 17 with LinkedBlockingDeque

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

the class LinkedBlockingDequeTest method testDescendingIterator.

/**
     * Descending iterator iterates through all elements
     */
public void testDescendingIterator() {
    LinkedBlockingDeque q = populatedDeque(SIZE);
    int i = 0;
    Iterator it = q.descendingIterator();
    while (it.hasNext()) {
        assertTrue(q.contains(it.next()));
        ++i;
    }
    assertEquals(i, SIZE);
    assertFalse(it.hasNext());
    try {
        it.next();
        shouldThrow();
    } catch (NoSuchElementException success) {
    }
}
Also used : LinkedBlockingDeque(java.util.concurrent.LinkedBlockingDeque) Iterator(java.util.Iterator) NoSuchElementException(java.util.NoSuchElementException)

Example 18 with LinkedBlockingDeque

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

the class LinkedBlockingDequeTest method testToArray1_BadArg.

/**
     * toArray(incompatible array type) throws ArrayStoreException
     */
public void testToArray1_BadArg() {
    LinkedBlockingDeque q = populatedDeque(SIZE);
    try {
        q.toArray(new String[10]);
        shouldThrow();
    } catch (ArrayStoreException success) {
    }
}
Also used : LinkedBlockingDeque(java.util.concurrent.LinkedBlockingDeque)

Example 19 with LinkedBlockingDeque

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

the class LinkedBlockingDequeTest method testOfferFirst.

/**
     * OfferFirst succeeds
     */
public void testOfferFirst() {
    LinkedBlockingDeque q = new LinkedBlockingDeque();
    assertTrue(q.offerFirst(new Integer(0)));
    assertTrue(q.offerFirst(new Integer(1)));
}
Also used : LinkedBlockingDeque(java.util.concurrent.LinkedBlockingDeque)

Example 20 with LinkedBlockingDeque

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

the class LinkedBlockingDequeTest method testPutLastWithTake.

/**
     * putLast blocks interruptibly waiting for take when full
     */
public void testPutLastWithTake() throws InterruptedException {
    final int capacity = 2;
    final LinkedBlockingDeque q = new LinkedBlockingDeque(capacity);
    final CountDownLatch pleaseTake = new CountDownLatch(1);
    final CountDownLatch pleaseInterrupt = new CountDownLatch(1);
    Thread t = newStartedThread(new CheckedRunnable() {

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

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