Search in sources :

Example 41 with LinkedBlockingQueue

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

the class LinkedBlockingQueueTest method testPollInExecutor.

/**
     * timed poll retrieves elements across Executor threads
     */
public void testPollInExecutor() {
    final LinkedBlockingQueue q = new LinkedBlockingQueue(2);
    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 {
                assertNull(q.poll());
                threadsStarted.await();
                assertSame(one, q.poll(LONG_DELAY_MS, MILLISECONDS));
                checkEmpty(q);
            }
        });
        executor.execute(new CheckedRunnable() {

            public void realRun() throws InterruptedException {
                threadsStarted.await();
                q.put(one);
            }
        });
    }
}
Also used : ExecutorService(java.util.concurrent.ExecutorService) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue)

Example 42 with LinkedBlockingQueue

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

the class LinkedBlockingQueueTest method testToArray.

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

Example 43 with LinkedBlockingQueue

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

the class LinkedBlockingQueueTest method testAddAllSelf.

/**
     * addAll(this) throws IllegalArgumentException
     */
public void testAddAllSelf() {
    LinkedBlockingQueue q = populatedQueue(SIZE);
    try {
        q.addAll(q);
        shouldThrow();
    } catch (IllegalArgumentException success) {
    }
}
Also used : LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue)

Example 44 with LinkedBlockingQueue

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

the class LinkedBlockingQueueTest method testRemoveAll.

/**
     * removeAll(c) removes only those elements of c and reports true if changed
     */
public void testRemoveAll() {
    for (int i = 1; i < SIZE; ++i) {
        LinkedBlockingQueue q = populatedQueue(SIZE);
        LinkedBlockingQueue p = populatedQueue(i);
        assertTrue(q.removeAll(p));
        assertEquals(SIZE - i, q.size());
        for (int j = 0; j < i; ++j) {
            Integer x = (Integer) (p.remove());
            assertFalse(q.contains(x));
        }
    }
}
Also used : LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue)

Example 45 with LinkedBlockingQueue

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

the class LinkedBlockingQueueTest method testAddAll5.

/**
     * Queue contains all elements, in traversal order, of successful addAll
     */
public void testAddAll5() {
    Integer[] empty = new Integer[0];
    Integer[] ints = new Integer[SIZE];
    for (int i = 0; i < SIZE; ++i) ints[i] = new Integer(i);
    LinkedBlockingQueue q = new LinkedBlockingQueue(SIZE);
    assertFalse(q.addAll(Arrays.asList(empty)));
    assertTrue(q.addAll(Arrays.asList(ints)));
    for (int i = 0; i < SIZE; ++i) assertEquals(ints[i], q.poll());
}
Also used : LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue)

Aggregations

LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)259 Test (org.junit.Test)91 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)64 IOException (java.io.IOException)26 ArrayList (java.util.ArrayList)23 Emitter (io.socket.emitter.Emitter)19 JSONObject (org.json.JSONObject)19 CountDownLatch (java.util.concurrent.CountDownLatch)18 ThreadFactory (java.util.concurrent.ThreadFactory)16 ExecutorService (java.util.concurrent.ExecutorService)14 BlockingQueue (java.util.concurrent.BlockingQueue)13 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)13 List (java.util.List)12 URI (java.net.URI)11 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)11 Intent (android.content.Intent)9 HashMap (java.util.HashMap)9 ThreadFactoryBuilder (com.google.common.util.concurrent.ThreadFactoryBuilder)8 Map (java.util.Map)8 UUID (java.util.UUID)8