Search in sources :

Example 36 with LinkedTransferQueue

use of java.util.concurrent.LinkedTransferQueue in project j2objc by google.

the class LinkedTransferQueueTest method testRemoveElementAndAdd.

/**
 * An add following remove(x) succeeds
 */
public void testRemoveElementAndAdd() throws InterruptedException {
    LinkedTransferQueue q = new LinkedTransferQueue();
    assertTrue(q.add(one));
    assertTrue(q.add(two));
    assertTrue(q.remove(one));
    assertTrue(q.remove(two));
    assertTrue(q.add(three));
    assertSame(q.take(), three);
}
Also used : LinkedTransferQueue(java.util.concurrent.LinkedTransferQueue)

Example 37 with LinkedTransferQueue

use of java.util.concurrent.LinkedTransferQueue in project j2objc by google.

the class LinkedTransferQueueTest method testTryTransfer8.

/**
 * tryTransfer attempts to enqueue into the queue and fails
 * returning false not enqueueing and the successive poll is null
 */
public void testTryTransfer8() throws InterruptedException {
    final LinkedTransferQueue q = new LinkedTransferQueue();
    assertTrue(q.offer(four));
    assertEquals(1, q.size());
    long startTime = System.nanoTime();
    assertFalse(q.tryTransfer(five, timeoutMillis(), MILLISECONDS));
    assertTrue(millisElapsedSince(startTime) >= timeoutMillis());
    assertEquals(1, q.size());
    assertSame(four, q.poll());
    assertNull(q.poll());
    checkEmpty(q);
}
Also used : LinkedTransferQueue(java.util.concurrent.LinkedTransferQueue)

Example 38 with LinkedTransferQueue

use of java.util.concurrent.LinkedTransferQueue in project dubbo by alibaba.

the class StringToTransferQueueConverterTest method testConvert.

@Test
public void testConvert() {
    TransferQueue values = new LinkedTransferQueue(asList(1, 2, 3));
    TransferQueue result = (TransferQueue) converter.convert("1,2,3", List.class, Integer.class);
    assertTrue(CollectionUtils.equals(values, result));
    values.clear();
    values.addAll(asList("123"));
    result = (TransferQueue) converter.convert("123", NavigableSet.class, String.class);
    assertTrue(CollectionUtils.equals(values, result));
    assertNull(converter.convert(null, Collection.class, Integer.class));
    assertNull(converter.convert("", Collection.class, null));
}
Also used : LinkedTransferQueue(java.util.concurrent.LinkedTransferQueue) TransferQueue(java.util.concurrent.TransferQueue) Collection(java.util.Collection) AbstractList(java.util.AbstractList) ArrayList(java.util.ArrayList) Arrays.asList(java.util.Arrays.asList) LinkedList(java.util.LinkedList) List(java.util.List) LinkedTransferQueue(java.util.concurrent.LinkedTransferQueue) Test(org.junit.jupiter.api.Test)

Example 39 with LinkedTransferQueue

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

the class LinkedTransferQueueTest 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) {
        LinkedTransferQueue q = populatedQueue(SIZE);
        LinkedTransferQueue p = populatedQueue(i);
        assertTrue(q.removeAll(p));
        assertEquals(SIZE - i, q.size());
        for (int j = 0; j < i; ++j) {
            assertFalse(q.contains(p.remove()));
        }
    }
}
Also used : LinkedTransferQueue(java.util.concurrent.LinkedTransferQueue)

Example 40 with LinkedTransferQueue

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

the class LinkedTransferQueueTest method testToArray.

/**
     * toArray() contains all elements in FIFO order
     */
public void testToArray() {
    LinkedTransferQueue q = populatedQueue(SIZE);
    Object[] o = q.toArray();
    for (int i = 0; i < o.length; i++) {
        assertSame(o[i], q.poll());
    }
}
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