Search in sources :

Example 31 with ArrayBlockingQueue

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

the class ArrayBlockingQueueTest method testContains.

/**
     * contains(x) reports true when elements added but not yet removed
     */
public void testContains() {
    ArrayBlockingQueue q = populatedQueue(SIZE);
    for (int i = 0; i < SIZE; ++i) {
        assertTrue(q.contains(new Integer(i)));
        assertEquals(i, q.poll());
        assertFalse(q.contains(new Integer(i)));
    }
}
Also used : ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue)

Example 32 with ArrayBlockingQueue

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

the class ArrayBlockingQueueTest method testClear.

/**
     * clear removes all elements
     */
public void testClear() {
    ArrayBlockingQueue q = populatedQueue(SIZE);
    q.clear();
    assertTrue(q.isEmpty());
    assertEquals(0, q.size());
    assertEquals(SIZE, q.remainingCapacity());
    q.add(one);
    assertFalse(q.isEmpty());
    assertTrue(q.contains(one));
    q.clear();
    assertTrue(q.isEmpty());
}
Also used : ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue)

Example 33 with ArrayBlockingQueue

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

the class ArrayBlockingQueueTest method testPut.

/**
     * all elements successfully put are contained
     */
public void testPut() throws InterruptedException {
    ArrayBlockingQueue q = new ArrayBlockingQueue(SIZE);
    for (int i = 0; i < SIZE; ++i) {
        Integer x = new Integer(i);
        q.put(x);
        assertTrue(q.contains(x));
    }
    assertEquals(0, q.remainingCapacity());
}
Also used : ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue)

Example 34 with ArrayBlockingQueue

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

the class ArrayBlockingQueueTest method testIteratorRemove.

/**
     * iterator.remove removes current element
     */
public void testIteratorRemove() {
    final ArrayBlockingQueue q = new ArrayBlockingQueue(3);
    q.add(two);
    q.add(one);
    q.add(three);
    Iterator it = q.iterator();
    it.next();
    it.remove();
    it = q.iterator();
    assertSame(it.next(), one);
    assertSame(it.next(), three);
    assertFalse(it.hasNext());
}
Also used : ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) Iterator(java.util.Iterator)

Example 35 with ArrayBlockingQueue

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

the class ArrayBlockingQueueTest method testPoll.

/**
     * poll succeeds unless empty
     */
public void testPoll() {
    ArrayBlockingQueue q = populatedQueue(SIZE);
    for (int i = 0; i < SIZE; ++i) {
        assertEquals(i, q.poll());
    }
    assertNull(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