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