Search in sources :

Example 6 with LocalConcurrentBlockingObjectQueue

use of net.openhft.chronicle.sandbox.queue.LocalConcurrentBlockingObjectQueue in project HugeCollections-OLD by peter-lawrey.

the class LocalJSR166TestCase method populatedQueue.

/**
     * Returns a new queue of given size containing consecutive
     * Integers 0 ... n.
     */
private BlockingQueue populatedQueue(int n) {
    BlockingQueue q = new LocalConcurrentBlockingObjectQueue(n);
    assertTrue(q.isEmpty());
    for (int i = 0; i < n; i++) assertTrue(q.offer(new Integer(i)));
    assertFalse(q.isEmpty());
    assertEquals(0, q.remainingCapacity());
    assertEquals(n, q.size());
    return q;
}
Also used : BlockingQueue(java.util.concurrent.BlockingQueue) LocalConcurrentBlockingObjectQueue(net.openhft.chronicle.sandbox.queue.LocalConcurrentBlockingObjectQueue)

Example 7 with LocalConcurrentBlockingObjectQueue

use of net.openhft.chronicle.sandbox.queue.LocalConcurrentBlockingObjectQueue 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 8 with LocalConcurrentBlockingObjectQueue

use of net.openhft.chronicle.sandbox.queue.LocalConcurrentBlockingObjectQueue 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 9 with LocalConcurrentBlockingObjectQueue

use of net.openhft.chronicle.sandbox.queue.LocalConcurrentBlockingObjectQueue 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)

Example 10 with LocalConcurrentBlockingObjectQueue

use of net.openhft.chronicle.sandbox.queue.LocalConcurrentBlockingObjectQueue in project HugeCollections-OLD by peter-lawrey.

the class LocalJSR166TestCase method testEmptyFull.

/**
     * Queue transitions from empty to full when elements added
     */
@Test
public void testEmptyFull() {
    BlockingQueue q = new LocalConcurrentBlockingObjectQueue(2);
    assertTrue(q.isEmpty());
    assertEquals(2, q.remainingCapacity());
    q.add(one);
    assertFalse(q.isEmpty());
    q.add(two);
    assertFalse(q.isEmpty());
    assertEquals(0, q.remainingCapacity());
    assertFalse(q.offer(three));
}
Also used : BlockingQueue(java.util.concurrent.BlockingQueue) LocalConcurrentBlockingObjectQueue(net.openhft.chronicle.sandbox.queue.LocalConcurrentBlockingObjectQueue) Test(org.junit.Test)

Aggregations

BlockingQueue (java.util.concurrent.BlockingQueue)21 LocalConcurrentBlockingObjectQueue (net.openhft.chronicle.sandbox.queue.LocalConcurrentBlockingObjectQueue)21 Test (org.junit.Test)20 Ignore (org.junit.Ignore)5 CountDownLatch (java.util.concurrent.CountDownLatch)3 ExecutorService (java.util.concurrent.ExecutorService)2