Search in sources :

Example 1 with LinkedTransferQueue

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

the class LinkedTransferQueueTest method testDrainToN.

/**
     * drainTo(c, n) empties first min(n, size) elements of queue into c
     */
public void testDrainToN() {
    LinkedTransferQueue q = new LinkedTransferQueue();
    for (int i = 0; i < SIZE + 2; ++i) {
        for (int j = 0; j < SIZE; j++) {
            assertTrue(q.offer(j));
        }
        ArrayList l = new ArrayList();
        q.drainTo(l, i);
        int k = (i < SIZE) ? i : SIZE;
        assertEquals(k, l.size());
        assertEquals(SIZE - k, q.size());
        for (int j = 0; j < k; ++j) assertEquals(j, l.get(j));
        do {
        } while (q.poll() != null);
    }
}
Also used : ArrayList(java.util.ArrayList) LinkedTransferQueue(java.util.concurrent.LinkedTransferQueue)

Example 2 with LinkedTransferQueue

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

the class LinkedTransferQueueTest 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] = i;
    }
    LinkedTransferQueue q = new LinkedTransferQueue();
    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 : LinkedTransferQueue(java.util.concurrent.LinkedTransferQueue)

Example 3 with LinkedTransferQueue

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

the class LinkedTransferQueueTest method testWeaklyConsistentIteration.

/**
     * Modifications do not cause iterators to fail
     */
public void testWeaklyConsistentIteration() {
    final LinkedTransferQueue q = new LinkedTransferQueue();
    q.add(one);
    q.add(two);
    q.add(three);
    for (Iterator it = q.iterator(); it.hasNext(); ) {
        q.remove();
        it.next();
    }
    assertEquals(0, q.size());
}
Also used : Iterator(java.util.Iterator) LinkedTransferQueue(java.util.concurrent.LinkedTransferQueue)

Example 4 with LinkedTransferQueue

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

the class LinkedTransferQueueTest method testToString.

/**
     * toString contains toStrings of elements
     */
public void testToString() {
    LinkedTransferQueue q = populatedQueue(SIZE);
    String s = q.toString();
    for (int i = 0; i < SIZE; ++i) {
        assertTrue(s.contains(String.valueOf(i)));
    }
}
Also used : LinkedTransferQueue(java.util.concurrent.LinkedTransferQueue)

Example 5 with LinkedTransferQueue

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

the class LinkedTransferQueueTest method testClear.

/**
     * clear removes all elements
     */
public void testClear() throws InterruptedException {
    LinkedTransferQueue q = populatedQueue(SIZE);
    q.clear();
    checkEmpty(q);
    assertEquals(Integer.MAX_VALUE, q.remainingCapacity());
    q.add(one);
    assertFalse(q.isEmpty());
    assertEquals(1, q.size());
    assertTrue(q.contains(one));
    q.clear();
    checkEmpty(q);
}
Also used : LinkedTransferQueue(java.util.concurrent.LinkedTransferQueue)

Aggregations

LinkedTransferQueue (java.util.concurrent.LinkedTransferQueue)66 ArrayList (java.util.ArrayList)10 Iterator (java.util.Iterator)6 CountDownLatch (java.util.concurrent.CountDownLatch)6 List (java.util.List)4 ExecutorService (java.util.concurrent.ExecutorService)4 Callable (java.util.concurrent.Callable)2 IOException (java.io.IOException)1 RandomAccessFile (java.io.RandomAccessFile)1 MappedByteBuffer (java.nio.MappedByteBuffer)1 FileChannel (java.nio.channels.FileChannel)1 AbstractList (java.util.AbstractList)1 Arrays.asList (java.util.Arrays.asList)1 Collection (java.util.Collection)1 LinkedList (java.util.LinkedList)1 Queue (java.util.Queue)1 RejectedExecutionHandler (java.util.concurrent.RejectedExecutionHandler)1 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)1 TransferQueue (java.util.concurrent.TransferQueue)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1