Search in sources :

Example 6 with SharedConcurrentBlockingObjectQueue

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

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

the class SharedJSR166TestCase method testPollInExecutor.

/**
     * timed poll retrieves elements across Executor threads
     */
@Test
public void testPollInExecutor() throws IOException {
    final BlockingQueue<Integer> q = new SharedConcurrentBlockingObjectQueue<Integer>(2, Integer.class);
    final CheckedBarrier threadsStarted = new CheckedBarrier(2);
    ExecutorService executor = Executors.newFixedThreadPool(2);
    executor.execute(new CheckedRunnable() {

        public void realRun() throws Exception {
            assertNull(q.poll());
            threadsStarted.await();
            final Integer value = q.poll(LONG_DELAY_MS, MILLISECONDS);
            assertEquals(one, value);
            checkEmpty(q);
        }
    });
    executor.execute(new CheckedRunnable() {

        public void realRun() throws Exception {
            threadsStarted.await();
            q.put(one);
        }
    });
    joinPool(executor);
}
Also used : ExecutorService(java.util.concurrent.ExecutorService) SharedConcurrentBlockingObjectQueue(net.openhft.chronicle.sandbox.queue.SharedConcurrentBlockingObjectQueue) IOException(java.io.IOException) Test(org.junit.Test) BlockingQueueTest(net.openhft.chronicle.sandbox.queue.common.BlockingQueueTest)

Aggregations

SharedConcurrentBlockingObjectQueue (net.openhft.chronicle.sandbox.queue.SharedConcurrentBlockingObjectQueue)7 BlockingQueueTest (net.openhft.chronicle.sandbox.queue.common.BlockingQueueTest)7 Test (org.junit.Test)7 IOException (java.io.IOException)5 BlockingQueue (java.util.concurrent.BlockingQueue)4 CountDownLatch (java.util.concurrent.CountDownLatch)3 ExecutorService (java.util.concurrent.ExecutorService)2 Ignore (org.junit.Ignore)2