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) ;
}
}
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);
}
Aggregations