Search in sources :

Example 91 with BlockingQueue

use of java.util.concurrent.BlockingQueue in project HugeCollections-OLD by peter-lawrey.

the class SharedJSR166TestCase method testRemoveAll.

/**
     * removeAll(c) removes only those elements of c and reports true if changed
     */
@Test
public void testRemoveAll() throws IOException {
    for (int i = 1; i < SIZE; ++i) {
        BlockingQueue<Integer> q = populatedQueue(SIZE);
        BlockingQueue p = populatedQueue(i);
        assertTrue(q.removeAll(p));
        assertEquals(SIZE - i, q.size());
        for (int j = 0; j < i; ++j) {
            Integer I = (Integer) (p.remove());
            assertFalse(q.contains(I));
        }
    }
}
Also used : BlockingQueue(java.util.concurrent.BlockingQueue) Test(org.junit.Test) BlockingQueueTest(net.openhft.chronicle.sandbox.queue.common.BlockingQueueTest)

Example 92 with BlockingQueue

use of java.util.concurrent.BlockingQueue in project HugeCollections-OLD by peter-lawrey.

the class SharedJSR166TestCase method testRetainAll.

/**
     * retainAll(c) retains only those elements of c and reports true if changed
     */
@Test
public void testRetainAll() throws IOException {
    BlockingQueue q = populatedQueue(SIZE);
    BlockingQueue 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 : BlockingQueue(java.util.concurrent.BlockingQueue) Test(org.junit.Test) BlockingQueueTest(net.openhft.chronicle.sandbox.queue.common.BlockingQueueTest)

Example 93 with BlockingQueue

use of java.util.concurrent.BlockingQueue in project HugeCollections-OLD by peter-lawrey.

the class LocalJSR166TestCase method testIteratorRemove.

/**
     * iterator.remove removes current element
     */
@Ignore
@Test
public void testIteratorRemove() {
    final BlockingQueue q = new LocalConcurrentBlockingObjectQueue(3);
    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 : BlockingQueue(java.util.concurrent.BlockingQueue) LocalConcurrentBlockingObjectQueue(net.openhft.chronicle.sandbox.queue.LocalConcurrentBlockingObjectQueue) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 94 with BlockingQueue

use of java.util.concurrent.BlockingQueue in project HugeCollections-OLD by peter-lawrey.

the class LocalJSR166TestCase method testTimedPoll0.

/**
     * timed poll with zero timeout succeeds when non-empty, else times out
     */
@Test
public void testTimedPoll0() throws InterruptedException {
    BlockingQueue q = populatedQueue(SIZE);
    for (int i = 0; i < SIZE; ++i) {
        assertEquals(i, q.poll(0, MILLISECONDS));
    }
    assertNull(q.poll(0, MILLISECONDS));
    checkEmpty(q);
}
Also used : BlockingQueue(java.util.concurrent.BlockingQueue) Test(org.junit.Test)

Example 95 with BlockingQueue

use of java.util.concurrent.BlockingQueue in project HugeCollections-OLD by peter-lawrey.

the class LocalJSR166TestCase method testAddAll4.

/**
     * addAll throws ISE if not enough room
     */
@Test
public void testAddAll4() {
    try {
        BlockingQueue q = new LocalConcurrentBlockingObjectQueue(1);
        Integer[] ints = new Integer[SIZE];
        for (int i = 0; i < SIZE; ++i) ints[i] = new Integer(i);
        q.addAll(Arrays.asList(ints));
        shouldThrow();
    } catch (IllegalStateException success) {
    }
}
Also used : BlockingQueue(java.util.concurrent.BlockingQueue) LocalConcurrentBlockingObjectQueue(net.openhft.chronicle.sandbox.queue.LocalConcurrentBlockingObjectQueue) Test(org.junit.Test)

Aggregations

BlockingQueue (java.util.concurrent.BlockingQueue)129 Test (org.junit.Test)59 CountDownLatch (java.util.concurrent.CountDownLatch)21 LocalConcurrentBlockingObjectQueue (net.openhft.chronicle.sandbox.queue.LocalConcurrentBlockingObjectQueue)21 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)18 ArrayList (java.util.ArrayList)12 Ignore (org.junit.Ignore)12 IOException (java.io.IOException)10 BlockingQueueTest (net.openhft.chronicle.sandbox.queue.common.BlockingQueueTest)10 ArrayBlockingQueue (java.util.concurrent.ArrayBlockingQueue)9 TimeUnit (java.util.concurrent.TimeUnit)9 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)8 ByteBuffer (java.nio.ByteBuffer)4 List (java.util.List)4 Assert (org.junit.Assert)4 SynchronousQueue (java.util.concurrent.SynchronousQueue)3 TimeoutException (java.util.concurrent.TimeoutException)3 AsyncContext (javax.servlet.AsyncContext)3 ReadListener (javax.servlet.ReadListener)3 ServletException (javax.servlet.ServletException)3