{
final int ringBufferSize = 4;
final CountDownLatch latch = new CountDownLatch(ringBufferSize);
final AtomicBoolean producerComplete = new AtomicBoolean(false);
final RingBuffer<StubEntry> ringBuffer = new RingBuffer<StubEntry>(StubEntry.ENTRY_FACTORY, ringBufferSize, null, null);
final TestConsumer consumer = new TestConsumer(ringBuffer.createConsumerBarrier(new Consumer[0]));
final TestConsumer[] consumers = new TestConsumer[] { consumer };
ringBuffer.consumersToTrack_(consumers);
Thread thread = new Thread(new Runnable()
{
@Override
public void run()
{
for (int i = 0; i <= ringBufferSize; i++)
{
StubEntry entry = ringBuffer.nextEntry();
entry.setValue(i);
ringBuffer.commit(entry);
latch.countDown();
}
producerComplete.set(true);
}
});
thread.start();
latch.await();
assertThat(Long.valueOf(ringBuffer.cursor()), is(Long.valueOf(ringBufferSize - 1)));
assertFalse(producerComplete.get());
consumer.run();
thread.join();
assertTrue(producerComplete.get());
}