/**
* 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);
}