Search in sources :

Example 51 with BlockingQueue

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

the class LocalJSR166TestCase method testContainsAll.

/**
     * containsAll(c) is true when c contains a subset of elements
     */
@Test
public void testContainsAll() {
    BlockingQueue q = populatedQueue(SIZE);
    LocalConcurrentBlockingObjectQueue p = new LocalConcurrentBlockingObjectQueue(SIZE);
    for (int i = 0; i < SIZE; ++i) {
        assertTrue(q.containsAll(p));
        assertFalse(p.containsAll(q));
        p.add(new Integer(i));
    }
    assertTrue(p.containsAll(q));
}
Also used : BlockingQueue(java.util.concurrent.BlockingQueue) LocalConcurrentBlockingObjectQueue(net.openhft.chronicle.sandbox.queue.LocalConcurrentBlockingObjectQueue) Test(org.junit.Test)

Example 52 with BlockingQueue

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

the class LocalJSR166TestCase method testDrainTo.

/**
     * drainTo(c) empties queue into another collection c
     */
@Test
@Ignore
public void testDrainTo() {
    BlockingQueue q = populatedQueue(SIZE);
    ArrayList l = new ArrayList();
    q.drainTo(l);
    assertEquals(0, q.size());
    assertEquals(SIZE, l.size());
    for (int i = 0; i < SIZE; ++i) assertEquals(l.get(i), new Integer(i));
    q.add(zero);
    q.add(one);
    assertFalse(q.isEmpty());
    assertTrue(q.contains(zero));
    assertTrue(q.contains(one));
    l.clear();
    q.drainTo(l);
    assertEquals(0, q.size());
    assertEquals(2, l.size());
    for (int i = 0; i < 2; ++i) assertEquals(l.get(i), new Integer(i));
}
Also used : BlockingQueue(java.util.concurrent.BlockingQueue) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 53 with BlockingQueue

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

the class LocalJSR166TestCase method testToArray1_BadArg.

/**
     * toArray(incompatible array type) throws ArrayStoreException
     */
@Test
public void testToArray1_BadArg() {
    BlockingQueue q = populatedQueue(SIZE);
    try {
        q.toArray(new String[10]);
        shouldThrow();
    } catch (ArrayStoreException success) {
    }
}
Also used : BlockingQueue(java.util.concurrent.BlockingQueue) Test(org.junit.Test)

Example 54 with BlockingQueue

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

the class LocalJSR166TestCase method testDrainToN.

/**
     * drainTo(c, n) empties first min(n, size) elements of queue into c
     */
@Ignore
@Test
public void testDrainToN() {
    BlockingQueue q = new LocalConcurrentBlockingObjectQueue(SIZE * 2);
    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) LocalConcurrentBlockingObjectQueue(net.openhft.chronicle.sandbox.queue.LocalConcurrentBlockingObjectQueue) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 55 with BlockingQueue

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

the class LocalJSR166TestCase method testToArray.

/**
     * toArray() contains all elements in FIFO order
     */
@Test
public void testToArray() {
    BlockingQueue q = new LocalConcurrentBlockingObjectQueue(SIZE);
    for (int i = 0; i < SIZE; i++) {
        checkToArray(q);
        q.add(i);
    }
    // Provoke wraparound
    for (int i = 0; i < SIZE; i++) {
        checkToArray(q);
        assertEquals(i, q.poll());
        checkToArray(q);
        q.add(SIZE + i);
    }
    for (int i = 0; i < SIZE; i++) {
        checkToArray(q);
        assertEquals(SIZE + i, q.poll());
    }
}
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