Search in sources :

Example 16 with LocalConcurrentBlockingObjectQueue

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

the class LocalJSR166TestCase method testPut.

/**
     * all elements successfully put are contained
     */
@Test
public void testPut() throws InterruptedException {
    BlockingQueue q = new LocalConcurrentBlockingObjectQueue(SIZE);
    for (int i = 0; i < SIZE; ++i) {
        Integer I = new Integer(i);
        q.put(I);
        assertTrue(q.contains(I));
    }
    assertEquals(0, q.remainingCapacity());
}
Also used : BlockingQueue(java.util.concurrent.BlockingQueue) LocalConcurrentBlockingObjectQueue(net.openhft.chronicle.sandbox.queue.LocalConcurrentBlockingObjectQueue) Test(org.junit.Test)

Example 17 with LocalConcurrentBlockingObjectQueue

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

the class LocalJSR166TestCase method testOfferInExecutor.

/**
     * offer transfers elements across Executor tasks
     */
@Test
public void testOfferInExecutor() {
    final BlockingQueue q = new LocalConcurrentBlockingObjectQueue(2);
    q.add(one);
    q.add(two);
    ExecutorService executor = Executors.newFixedThreadPool(2);
    final CheckedBarrier threadsStarted = new CheckedBarrier(2);
    executor.execute(new CheckedRunnable() {

        public void realRun() throws InterruptedException {
            assertFalse(q.offer(three));
            threadsStarted.await();
            assertTrue(q.offer(three, LONG_DELAY_MS, MILLISECONDS));
            assertEquals(0, q.remainingCapacity());
        }
    });
    executor.execute(new CheckedRunnable() {

        public void realRun() throws InterruptedException {
            threadsStarted.await();
            assertEquals(0, q.remainingCapacity());
            assertSame(one, q.take());
        }
    });
    joinPool(executor);
}
Also used : BlockingQueue(java.util.concurrent.BlockingQueue) ExecutorService(java.util.concurrent.ExecutorService) LocalConcurrentBlockingObjectQueue(net.openhft.chronicle.sandbox.queue.LocalConcurrentBlockingObjectQueue) Test(org.junit.Test)

Example 18 with LocalConcurrentBlockingObjectQueue

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

the class LocalJSR166TestCase method testPollInExecutor.

/**
     * timed poll retrieves elements across Executor threads
     */
@Test
public void testPollInExecutor() {
    final BlockingQueue q = new LocalConcurrentBlockingObjectQueue(2);
    final CheckedBarrier threadsStarted = new CheckedBarrier(2);
    ExecutorService executor = Executors.newFixedThreadPool(2);
    executor.execute(new CheckedRunnable() {

        public void realRun() throws InterruptedException {
            assertNull(q.poll());
            threadsStarted.await();
            assertSame(one, q.poll(LONG_DELAY_MS, MILLISECONDS));
            checkEmpty(q);
        }
    });
    executor.execute(new CheckedRunnable() {

        public void realRun() throws InterruptedException {
            threadsStarted.await();
            q.put(one);
        }
    });
    joinPool(executor);
}
Also used : BlockingQueue(java.util.concurrent.BlockingQueue) ExecutorService(java.util.concurrent.ExecutorService) LocalConcurrentBlockingObjectQueue(net.openhft.chronicle.sandbox.queue.LocalConcurrentBlockingObjectQueue) Test(org.junit.Test)

Example 19 with LocalConcurrentBlockingObjectQueue

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

the class LocalJSR166TestCase method testAddAll3.

/**
     * addAll of a collection with any null elements throws NPE after
     * possibly adding some elements
     */
@Test
public void testAddAll3() {
    try {
        BlockingQueue q = new LocalConcurrentBlockingObjectQueue(SIZE);
        Integer[] ints = new Integer[SIZE];
        for (int i = 0; i < SIZE - 1; ++i) ints[i] = new Integer(i);
        q.addAll(Arrays.asList(ints));
        shouldThrow();
    } catch (NullPointerException success) {
    }
}
Also used : BlockingQueue(java.util.concurrent.BlockingQueue) LocalConcurrentBlockingObjectQueue(net.openhft.chronicle.sandbox.queue.LocalConcurrentBlockingObjectQueue) Test(org.junit.Test)

Example 20 with LocalConcurrentBlockingObjectQueue

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

the class LocalJSR166TestCase method testWeaklyConsistentIteration.

/**
     * Modifications do not cause iterators to fail
     */
@Test
public void testWeaklyConsistentIteration() {
    final BlockingQueue q = new LocalConcurrentBlockingObjectQueue(3);
    q.add(one);
    q.add(two);
    q.add(three);
    for (Iterator it = q.iterator(); it.hasNext(); ) {
        q.remove();
        it.next();
    }
    assertEquals(0, q.size());
}
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