Search in sources :

Example 56 with LinkedTransferQueue

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

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)

Example 57 with LinkedTransferQueue

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

the class LinkedTransferQueueTest method testPollInExecutor.

/**
 * timed poll retrieves elements across Executor threads
 */
public void testPollInExecutor() {
    final LinkedTransferQueue q = new LinkedTransferQueue();
    final CheckedBarrier threadsStarted = new CheckedBarrier(2);
    final ExecutorService executor = Executors.newFixedThreadPool(2);
    try (PoolCleaner cleaner = cleaner(executor)) {
        executor.execute(new CheckedRunnable() {

            public void realRun() throws InterruptedException {
                assertNull(q.poll());
                threadsStarted.await();
                long startTime = System.nanoTime();
                assertSame(one, q.poll(LONG_DELAY_MS, MILLISECONDS));
                assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
                checkEmpty(q);
            }
        });
        executor.execute(new CheckedRunnable() {

            public void realRun() throws InterruptedException {
                threadsStarted.await();
                q.put(one);
            }
        });
    }
}
Also used : ExecutorService(java.util.concurrent.ExecutorService) LinkedTransferQueue(java.util.concurrent.LinkedTransferQueue)

Example 58 with LinkedTransferQueue

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

the class LinkedTransferQueueTest method testOfferInExecutor.

/**
 * offer transfers elements across Executor tasks
 */
public void testOfferInExecutor() {
    final LinkedTransferQueue q = new LinkedTransferQueue();
    final CheckedBarrier threadsStarted = new CheckedBarrier(2);
    final ExecutorService executor = Executors.newFixedThreadPool(2);
    try (PoolCleaner cleaner = cleaner(executor)) {
        executor.execute(new CheckedRunnable() {

            public void realRun() throws InterruptedException {
                threadsStarted.await();
                long startTime = System.nanoTime();
                assertTrue(q.offer(one, LONG_DELAY_MS, MILLISECONDS));
                assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
            }
        });
        executor.execute(new CheckedRunnable() {

            public void realRun() throws InterruptedException {
                threadsStarted.await();
                assertSame(one, q.take());
                checkEmpty(q);
            }
        });
    }
}
Also used : ExecutorService(java.util.concurrent.ExecutorService) LinkedTransferQueue(java.util.concurrent.LinkedTransferQueue)

Example 59 with LinkedTransferQueue

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

the class LinkedTransferQueueTest method testIteratorRemove.

/**
 * iterator.remove() removes current element
 */
public void testIteratorRemove() {
    final LinkedTransferQueue q = new LinkedTransferQueue();
    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 : Iterator(java.util.Iterator) LinkedTransferQueue(java.util.concurrent.LinkedTransferQueue)

Example 60 with LinkedTransferQueue

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

the class LinkedTransferQueueTest method testAddAllSelf.

/**
 * addAll(this) throws IllegalArgumentException
 */
public void testAddAllSelf() {
    LinkedTransferQueue q = populatedQueue(SIZE);
    try {
        q.addAll(q);
        shouldThrow();
    } catch (IllegalArgumentException success) {
    }
}
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