Search in sources :

Example 26 with ArrayBlockingQueue

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

the class ArrayBlockingQueueTest method testAdd.

/**
     * add succeeds if not full; throws ISE if full
     */
public void testAdd() {
    ArrayBlockingQueue q = new ArrayBlockingQueue(SIZE);
    for (int i = 0; i < SIZE; ++i) {
        assertTrue(q.add(new Integer(i)));
    }
    assertEquals(0, q.remainingCapacity());
    try {
        q.add(new Integer(SIZE));
        shouldThrow();
    } catch (IllegalStateException success) {
    }
}
Also used : ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue)

Example 27 with ArrayBlockingQueue

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

the class ArrayBlockingQueueTest method testEmptyFull.

/**
     * Queue transitions from empty to full when elements added
     */
public void testEmptyFull() {
    ArrayBlockingQueue q = new ArrayBlockingQueue(2);
    assertTrue(q.isEmpty());
    assertEquals(2, q.remainingCapacity());
    q.add(one);
    assertFalse(q.isEmpty());
    q.add(two);
    assertFalse(q.isEmpty());
    assertEquals(0, q.remainingCapacity());
    assertFalse(q.offer(three));
}
Also used : ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue)

Example 28 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 29 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 30 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)

Aggregations

ArrayBlockingQueue (java.util.concurrent.ArrayBlockingQueue)157 Test (org.junit.Test)33 ExecutorService (java.util.concurrent.ExecutorService)24 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)24 ArrayList (java.util.ArrayList)23 IOException (java.io.IOException)22 CountDownLatch (java.util.concurrent.CountDownLatch)19 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)14 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)12 File (java.io.File)11 LinkedList (java.util.LinkedList)11 ExecutionException (java.util.concurrent.ExecutionException)10 HashMap (java.util.HashMap)9 BlockingQueue (java.util.concurrent.BlockingQueue)8 Test (org.testng.annotations.Test)8 InputStream (java.io.InputStream)7 Map (java.util.Map)7 RejectedExecutionHandler (java.util.concurrent.RejectedExecutionHandler)7 TestCircuitBreaker (com.netflix.hystrix.HystrixCircuitBreakerTest.TestCircuitBreaker)6 ImageStack (ij.ImageStack)6