Search in sources :

Example 96 with BlockingQueue

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

the class LocalJSR166TestCase method testToArray2.

/**
     * toArray(a) contains all elements in FIFO order
     */
@Ignore
@Test
public void testToArray2() {
    BlockingQueue q = new LocalConcurrentBlockingObjectQueue(SIZE);
    for (int i = 0; i < SIZE; i++) {
        checkToArray2(q);
        q.add(i);
    }
    // Provoke wraparound
    for (int i = 0; i < SIZE; i++) {
        checkToArray2(q);
        assertEquals(i, q.poll());
        checkToArray2(q);
        q.add(SIZE + i);
    }
    for (int i = 0; i < SIZE; i++) {
        checkToArray2(q);
        assertEquals(SIZE + i, q.poll());
    }
}
Also used : BlockingQueue(java.util.concurrent.BlockingQueue) LocalConcurrentBlockingObjectQueue(net.openhft.chronicle.sandbox.queue.LocalConcurrentBlockingObjectQueue) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 97 with BlockingQueue

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

the class SharedJSR166TestCase method testTimedPoll0.

/**
     * timed poll with zero timeout succeeds when non-empty, else times out
     */
@Test
public void testTimedPoll0() throws Exception {
    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) BlockingQueueTest(net.openhft.chronicle.sandbox.queue.common.BlockingQueueTest)

Example 98 with BlockingQueue

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

the class SharedJSR166TestCase method testRemove.

/**
     * remove removes next element, or throws NSEE if empty
     */
@Test
public void testRemove() throws IOException {
    BlockingQueue q = populatedQueue(SIZE);
    for (int i = 0; i < SIZE; ++i) {
        assertEquals(i, q.remove());
    }
    try {
        q.remove();
        shouldThrow();
    } catch (NoSuchElementException success) {
    }
}
Also used : BlockingQueue(java.util.concurrent.BlockingQueue) Test(org.junit.Test) BlockingQueueTest(net.openhft.chronicle.sandbox.queue.common.BlockingQueueTest)

Example 99 with BlockingQueue

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

the class SharedJSR166TestCase method testDrainToN.

/**
     * drainTo(c, n) empties first min(n, size) elements of queue into c
     */
@Ignore
@Test
public void testDrainToN() throws IOException {
    BlockingQueue q = new SharedConcurrentBlockingObjectQueue<Integer>(SIZE * 2, Integer.class);
    for (int i = 0; i < SIZE + 2; ++i) {
        for (int j = 0; j < SIZE; j++) assertTrue(q.offer(new Integer(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(l.get(j), new Integer(j));
        while (q.poll() != null) ;
    }
}
Also used : BlockingQueue(java.util.concurrent.BlockingQueue) SharedConcurrentBlockingObjectQueue(net.openhft.chronicle.sandbox.queue.SharedConcurrentBlockingObjectQueue) Ignore(org.junit.Ignore) Test(org.junit.Test) BlockingQueueTest(net.openhft.chronicle.sandbox.queue.common.BlockingQueueTest)

Example 100 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)

Aggregations

BlockingQueue (java.util.concurrent.BlockingQueue)124 Test (org.junit.Test)58 CountDownLatch (java.util.concurrent.CountDownLatch)21 LocalConcurrentBlockingObjectQueue (net.openhft.chronicle.sandbox.queue.LocalConcurrentBlockingObjectQueue)21 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)16 Ignore (org.junit.Ignore)12 IOException (java.io.IOException)10 BlockingQueueTest (net.openhft.chronicle.sandbox.queue.common.BlockingQueueTest)10 ArrayList (java.util.ArrayList)8 ArrayBlockingQueue (java.util.concurrent.ArrayBlockingQueue)8 TimeUnit (java.util.concurrent.TimeUnit)8 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)7 ByteBuffer (java.nio.ByteBuffer)4 SynchronousQueue (java.util.concurrent.SynchronousQueue)4 TimeoutException (java.util.concurrent.TimeoutException)3 AsyncContext (javax.servlet.AsyncContext)3 ReadListener (javax.servlet.ReadListener)3 ServletException (javax.servlet.ServletException)3 ServletInputStream (javax.servlet.ServletInputStream)3 ServletOutputStream (javax.servlet.ServletOutputStream)3