private ValueDisruptor <ValueEvent> CreateValueDisruptor(ProducerType producerType, int ringBufferSize, TaskScheduler scheduler) { var valueDisruptor = new ValueDisruptor <ValueEvent>(() => new ValueEvent(), ringBufferSize, scheduler, producerType, new BusySpinWaitStrategy()); valueDisruptor.HandleEventsWith(_eventProcessor); valueDisruptor.Start(); return(valueDisruptor); }
public void ShouldProcessMessagesPublishedBeforeStartIsCalled() { var eventCounter = new CountdownEvent(2); _disruptor.HandleEventsWith(new TestValueEventHandler <TestValueEvent>(e => eventCounter.Signal())); _disruptor.PublishEvent().Dispose(); _disruptor.Start(); _disruptor.PublishEvent().Dispose(); if (!eventCounter.Wait(TimeSpan.FromSeconds(5))) { Assert.Fail("Did not process event published before start was called. Missed events: " + eventCounter.CurrentCount); } }
public void ShouldPublishAndHandleEvent() { var eventCounter = new CountdownEvent(2); var values = new List <int>(); _disruptor.HandleEventsWith(new TestValueEventHandler <TestValueEvent>(e => values.Add(e.Value))) .Then(new TestValueEventHandler <TestValueEvent>(e => eventCounter.Signal())); _disruptor.Start(); using (var scope = _disruptor.PublishEvent()) { scope.Event().Value = 101; } using (var scope = _disruptor.PublishEvent()) { scope.Event().Value = 102; } Assert.IsTrue(eventCounter.Wait(TimeSpan.FromSeconds(5))); Assert.AreEqual(new List <int> { 101, 102 }, values); }
public static void SetupDisruptor() { _disruptor = new ValueDisruptor <ValueEvent>(() => new ValueEvent(), ringBufferSize: 1024); _disruptor.HandleEventsWith(new ValueEventHandler()); _disruptor.Start(); }
public void ShouldPublishAndHandleEvent() { var eventCounter = new CountdownEvent(2); _disruptor.HandleEventsWith(new TestValueEventHandler <TestValueEvent>(e => eventCounter.Signal())); _disruptor.Start(); _disruptor.PublishEvent().Dispose(); _disruptor.PublishEvent().Dispose(); Assert.IsTrue(eventCounter.Wait(TimeSpan.FromSeconds(5))); }