public long Run(ThroughputSessionContext sessionContext) { long expectedCount = _batchEventProcessor.Sequence.Value + _iterations; _eventHandler.Reset(expectedCount); var processorTask = _batchEventProcessor.Start(); _batchEventProcessor.WaitUntilStarted(TimeSpan.FromSeconds(5)); sessionContext.Start(); var ringBuffer = _ringBuffer; for (long i = 0; i < _iterations; i++) { var sequence = ringBuffer.Next(); ringBuffer[sequence].Value = i; ringBuffer.Publish(sequence); } _eventHandler.WaitForSequence(); sessionContext.Stop(); PerfTestUtil.WaitForEventProcessorSequence(expectedCount, _batchEventProcessor); _batchEventProcessor.Halt(); processorTask.Wait(2000); sessionContext.SetBatchData(_eventHandler.BatchesProcessed, _iterations); PerfTestUtil.FailIfNot(_expectedResult, _eventHandler.Value, $"Handler should have processed {_expectedResult} events, but was: {_eventHandler.Value}"); return(_iterations); }
public long Run(ThroughputSessionContext sessionContext) { var signal = new ManualResetEvent(false); var expectedCount = _batchEventProcessor.Sequence.Value + _iterations * _batchSize; _handler.Reset(signal, expectedCount); var processorTask = _executor.Execute(_batchEventProcessor.Run); _batchEventProcessor.WaitUntilStarted(TimeSpan.FromSeconds(5)); sessionContext.Start(); var rb = _ringBuffer; for (var i = 0; i < _iterations; i++) { var hi = rb.Next(_batchSize); var lo = hi - (_batchSize - 1); for (var l = lo; l <= hi; l++) { rb[l].Value = (i); } rb.Publish(lo, hi); } signal.WaitOne(); sessionContext.Stop(); PerfTestUtil.WaitForEventProcessorSequence(expectedCount, _batchEventProcessor); _batchEventProcessor.Halt(); processorTask.Wait(2000); sessionContext.SetBatchData(_handler.BatchesProcessedCount.Value, _iterations * _batchSize); PerfTestUtil.FailIfNot(_expectedResult, _handler.Value, $"Handler should have processed {_expectedResult} events, but was: {_handler.Value}"); return(_batchSize * _iterations); }