Search in sources :

Example 31 with LinkedTransferQueue

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

the class LinkedTransferQueueTest method testTryTransfer4.

/**
 * If there is a consumer waiting in take, tryTransfer returns
 * true while successfully transfering object.
 */
public void testTryTransfer4() throws InterruptedException {
    final Object hotPotato = new Object();
    final LinkedTransferQueue q = new LinkedTransferQueue();
    Thread t = newStartedThread(new CheckedRunnable() {

        public void realRun() {
            while (!q.hasWaitingConsumer()) Thread.yield();
            assertTrue(q.hasWaitingConsumer());
            checkEmpty(q);
            assertTrue(q.tryTransfer(hotPotato));
        }
    });
    assertSame(q.take(), hotPotato);
    checkEmpty(q);
    awaitTermination(t);
}
Also used : LinkedTransferQueue(java.util.concurrent.LinkedTransferQueue)

Example 32 with LinkedTransferQueue

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

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 33 with LinkedTransferQueue

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

the class LinkedTransferQueueTest method testTryTransfer1.

/**
 * tryTransfer(null) throws NullPointerException
 */
public void testTryTransfer1() {
    final LinkedTransferQueue q = new LinkedTransferQueue();
    try {
        q.tryTransfer(null);
        shouldThrow();
    } catch (NullPointerException success) {
    }
}
Also used : LinkedTransferQueue(java.util.concurrent.LinkedTransferQueue)

Example 34 with LinkedTransferQueue

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

the class LinkedTransferQueueTest method testRetainAll.

/**
 * retainAll(c) retains only those elements of c and reports true
 * if changed
 */
public void testRetainAll() {
    LinkedTransferQueue q = populatedQueue(SIZE);
    LinkedTransferQueue p = populatedQueue(SIZE);
    for (int i = 0; i < SIZE; ++i) {
        boolean changed = q.retainAll(p);
        if (i == 0) {
            assertFalse(changed);
        } else {
            assertTrue(changed);
        }
        assertTrue(q.containsAll(p));
        assertEquals(SIZE - i, q.size());
        p.remove();
    }
}
Also used : LinkedTransferQueue(java.util.concurrent.LinkedTransferQueue)

Example 35 with LinkedTransferQueue

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

the class LinkedTransferQueueTest method testDrainToWithActivePut.

/**
 * drainTo(c) empties full queue, unblocking a waiting put.
 */
public void testDrainToWithActivePut() throws InterruptedException {
    final LinkedTransferQueue q = populatedQueue(SIZE);
    Thread t = newStartedThread(new CheckedRunnable() {

        public void realRun() {
            q.put(SIZE + 1);
        }
    });
    ArrayList l = new ArrayList();
    q.drainTo(l);
    assertTrue(l.size() >= SIZE);
    for (int i = 0; i < SIZE; ++i) assertEquals(i, l.get(i));
    awaitTermination(t);
    assertTrue(q.size() + l.size() >= SIZE);
}
Also used : ArrayList(java.util.ArrayList) 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