Search in sources :

Example 21 with ArrayBlockingQueue

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

the class ArrayBlockingQueueTest method testRemove.

/**
     * remove removes next element, or throws NSEE if empty
     */
public void testRemove() {
    ArrayBlockingQueue q = populatedQueue(SIZE);
    for (int i = 0; i < SIZE; ++i) {
        assertEquals(i, q.remove());
    }
    try {
        q.remove();
        shouldThrow();
    } catch (NoSuchElementException success) {
    }
}
Also used : ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) NoSuchElementException(java.util.NoSuchElementException)

Example 22 with ArrayBlockingQueue

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

the class ArrayBlockingQueueTest method testTimedPoll.

/**
     * timed poll with nonzero timeout succeeds when non-empty, else times out
     */
public void testTimedPoll() throws InterruptedException {
    ArrayBlockingQueue q = populatedQueue(SIZE);
    for (int i = 0; i < SIZE; ++i) {
        long startTime = System.nanoTime();
        assertEquals(i, q.poll(LONG_DELAY_MS, MILLISECONDS));
        assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
    }
    long startTime = System.nanoTime();
    assertNull(q.poll(timeoutMillis(), MILLISECONDS));
    assertTrue(millisElapsedSince(startTime) >= timeoutMillis());
    checkEmpty(q);
}
Also used : ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue)

Example 23 with ArrayBlockingQueue

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

the class ArrayBlockingQueueTest 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) {
        ArrayBlockingQueue q = populatedQueue(SIZE);
        ArrayBlockingQueue 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 : ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue)

Example 24 with ArrayBlockingQueue

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

the class ArrayBlockingQueueTest method testAddAll3.

/**
     * addAll of a collection with any null elements throws NPE after
     * possibly adding some elements
     */
public void testAddAll3() {
    ArrayBlockingQueue q = new ArrayBlockingQueue(SIZE);
    Integer[] ints = new Integer[SIZE];
    for (int i = 0; i < SIZE - 1; ++i) ints[i] = new Integer(i);
    try {
        q.addAll(Arrays.asList(ints));
        shouldThrow();
    } catch (NullPointerException success) {
    }
}
Also used : ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue)

Example 25 with ArrayBlockingQueue

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

the class ArrayBlockingQueueTest 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);
    ArrayBlockingQueue q = new ArrayBlockingQueue(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 : ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue)

Aggregations

ArrayBlockingQueue (java.util.concurrent.ArrayBlockingQueue)172 Test (org.junit.Test)40 ArrayList (java.util.ArrayList)26 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)26 ExecutorService (java.util.concurrent.ExecutorService)25 IOException (java.io.IOException)23 CountDownLatch (java.util.concurrent.CountDownLatch)20 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)17 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)15 File (java.io.File)11 LinkedList (java.util.LinkedList)11 ExecutionException (java.util.concurrent.ExecutionException)11 HashMap (java.util.HashMap)10 BlockingQueue (java.util.concurrent.BlockingQueue)9 AtomicLong (java.util.concurrent.atomic.AtomicLong)9 Map (java.util.Map)8 Test (org.testng.annotations.Test)8 InputStream (java.io.InputStream)7 List (java.util.List)7 RejectedExecutionHandler (java.util.concurrent.RejectedExecutionHandler)7