Search in sources :

Example 96 with LinkedBlockingDeque

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

the class LinkedBlockingDequeTest method testPeek.

/**
     * peek returns next element, or null if empty
     */
public void testPeek() {
    LinkedBlockingDeque q = populatedDeque(SIZE);
    for (int i = 0; i < SIZE; ++i) {
        assertEquals(i, q.peek());
        assertEquals(i, q.pollFirst());
        assertTrue(q.peek() == null || !q.peek().equals(i));
    }
    assertNull(q.peek());
}
Also used : LinkedBlockingDeque(java.util.concurrent.LinkedBlockingDeque)

Example 97 with LinkedBlockingDeque

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

the class LinkedBlockingDequeTest method testRemoveLastOccurrence.

/**
     * removeLastOccurrence(x) removes x and returns true if present
     */
public void testRemoveLastOccurrence() {
    LinkedBlockingDeque q = populatedDeque(SIZE);
    for (int i = 1; i < SIZE; i += 2) {
        assertTrue(q.removeLastOccurrence(new Integer(i)));
    }
    for (int i = 0; i < SIZE; i += 2) {
        assertTrue(q.removeLastOccurrence(new Integer(i)));
        assertFalse(q.removeLastOccurrence(new Integer(i + 1)));
    }
    assertTrue(q.isEmpty());
}
Also used : LinkedBlockingDeque(java.util.concurrent.LinkedBlockingDeque)

Example 98 with LinkedBlockingDeque

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

the class LinkedBlockingDequeTest method testRemoveFirstOccurrence.

/**
     * removeFirstOccurrence(x) removes x and returns true if present
     */
public void testRemoveFirstOccurrence() {
    LinkedBlockingDeque q = populatedDeque(SIZE);
    for (int i = 1; i < SIZE; i += 2) {
        assertTrue(q.removeFirstOccurrence(new Integer(i)));
    }
    for (int i = 0; i < SIZE; i += 2) {
        assertTrue(q.removeFirstOccurrence(new Integer(i)));
        assertFalse(q.removeFirstOccurrence(new Integer(i + 1)));
    }
    assertTrue(q.isEmpty());
}
Also used : LinkedBlockingDeque(java.util.concurrent.LinkedBlockingDeque)

Example 99 with LinkedBlockingDeque

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

the class LinkedBlockingDequeTest method testOfferInExecutor.

/**
     * offer transfers elements across Executor tasks
     */
public void testOfferInExecutor() {
    final LinkedBlockingDeque q = new LinkedBlockingDeque(2);
    q.add(one);
    q.add(two);
    final CheckedBarrier threadsStarted = new CheckedBarrier(2);
    final ExecutorService executor = Executors.newFixedThreadPool(2);
    try (PoolCleaner cleaner = cleaner(executor)) {
        executor.execute(new CheckedRunnable() {

            public void realRun() throws InterruptedException {
                assertFalse(q.offer(three));
                threadsStarted.await();
                assertTrue(q.offer(three, LONG_DELAY_MS, MILLISECONDS));
                assertEquals(0, q.remainingCapacity());
            }
        });
        executor.execute(new CheckedRunnable() {

            public void realRun() throws InterruptedException {
                threadsStarted.await();
                assertSame(one, q.take());
            }
        });
    }
}
Also used : LinkedBlockingDeque(java.util.concurrent.LinkedBlockingDeque) ExecutorService(java.util.concurrent.ExecutorService)

Example 100 with LinkedBlockingDeque

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

the class LinkedBlockingDequeTest method testToString.

/**
     * toString contains toStrings of elements
     */
public void testToString() {
    LinkedBlockingDeque q = populatedDeque(SIZE);
    String s = q.toString();
    for (int i = 0; i < SIZE; ++i) {
        assertTrue(s.contains(String.valueOf(i)));
    }
}
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