void setup() { ringBuffer = new RingBuffer<StubEvent>(StubEvent.EVENT_FACTORY, 32); ringBuffer.setGatingSequences(new NoOpEventProcessor(ringBuffer).getSequence()); sequenceBarrier = ringBuffer.newBarrier(); EXECUTOR = Executors.newSingleThreadExecutor(new DaemonThreadFactory()); }
public void shouldPreventPublishersOvertakingEventProcessorWrapPoint() { int ringBufferSize = 4; CountDownLatch latch = new CountDownLatch(ringBufferSize); AtomicBoolean publisherComplete = new AtomicBoolean(false); RingBuffer<StubEvent> ringBuffer = new RingBuffer<StubEvent>(StubEvent.EVENT_FACTORY, ringBufferSize); TestEventProcessor processor = new TestEventProcessor(ringBuffer.newBarrier()); ringBuffer.setGatingSequences(processor.getSequence()); Thread thread = new Thread(() => { { for (int i = 0; i <= ringBufferSize; i++) { long sequence = ringBuffer.next(); StubEvent @event = ringBuffer.get(sequence); @event.setValue(i); ringBuffer.publish(sequence); latch.countDown(); } publisherComplete.set(true); } }); thread.Start(); latch.await(); assertEquals(ringBuffer.getCursor(), ringBufferSize - 1); Assert.IsFalse(publisherComplete.get()); processor.run(); thread.Join(); Assert.IsTrue(publisherComplete.get()); }