public void ShouldWaitForWorkCompleteWhereAllWorkersAreBlockedOnRingBuffer() { const long expectedNumberMessages = 10; FillRingBuffer(expectedNumberMessages); var workers = new StubEventProcessor[3]; for (var i = 0; i < workers.Length; i++) { workers[i] = new StubEventProcessor(expectedNumberMessages - 1); } var dependencyBarrier = _ringBuffer.NewBarrier(Util.GetSequencesFor(workers)); Task.Run(() => { var sequence = _ringBuffer.Next(); _ringBuffer[sequence].Value = (int)sequence; _ringBuffer.Publish(sequence); foreach (var stubWorker in workers) { stubWorker.Sequence.SetValue(sequence); } }); const long expectedWorkSequence = expectedNumberMessages; var completedWorkSequence = dependencyBarrier.WaitFor(expectedNumberMessages); Assert.IsTrue(completedWorkSequence >= expectedWorkSequence); }
public void ShouldWaitForWorkCompleteWhereCompleteWorkThresholdIsBehind() { const long expectedNumberMessages = 10; FillRingBuffer(expectedNumberMessages); var eventProcessors = new StubEventProcessor[3]; for (var i = 0; i < eventProcessors.Length; i++) { eventProcessors[i] = new StubEventProcessor(expectedNumberMessages - 2); } var eventProcessorBarrier = _ringBuffer.NewBarrier(Util.GetSequencesFor(eventProcessors)); Task.Factory.StartNew(() => { foreach (var stubWorker in eventProcessors) { stubWorker.Sequence.SetValue(stubWorker.Sequence.Value + 1); } }).Wait(); const long expectedWorkSequence = expectedNumberMessages - 1; var completedWorkSequence = eventProcessorBarrier.WaitFor(expectedWorkSequence); Assert.IsTrue(completedWorkSequence >= expectedWorkSequence); }
public void ShouldWaitForWorkCompleteWhereAllWorkersAreBlockedOnRingBuffer() { const long expectedNumberEvents = 10; FillRingBuffer(expectedNumberEvents); var workers = new StubEventProcessor[3]; for (var i = 0; i < workers.Length; i++) { workers[i] = new StubEventProcessor(expectedNumberEvents - 1); } var dependencyBarrier = _ringBuffer.NewBarrier(Util.GetSequencesFor(workers)); new Thread(() => { var sequence = _ringBuffer.Next(); _ringBuffer[sequence].Value = (int) sequence; _ringBuffer.Publish(sequence); foreach (var stubWorker in workers) { stubWorker.Sequence.Value = sequence; } }) .Start(); const long expectedWorkSequence = expectedNumberEvents; var completedWorkSequence = dependencyBarrier.WaitFor(expectedNumberEvents); Assert.IsTrue(completedWorkSequence >= expectedWorkSequence); }