Esempio n. 1
0
        public void ShouldPublishAndHandleEvents()
        {
            var eventCounter = new CountdownEvent(4);
            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.PublishEvents(2))
            {
                scope.Event(0).Value = 101;
                scope.Event(1).Value = 102;
            }
            using (var scope = _disruptor.PublishEvents(2))
            {
                scope.Event(0).Value = 103;
                scope.Event(1).Value = 104;
            }

            Assert.IsTrue(eventCounter.Wait(TimeSpan.FromSeconds(5)));
            Assert.AreEqual(new List <int> {
                101, 102, 103, 104
            }, values);
        }
        public void ShouldPublishAndHandleEvents()
        {
            var eventCounter = new CountdownEvent(4);

            _disruptor.HandleEventsWith(new TestValueEventHandler <TestValueEvent>(e => eventCounter.Signal()));

            _disruptor.Start();

            _disruptor.PublishEvents(2).Dispose();
            _disruptor.PublishEvents(2).Dispose();

            Assert.IsTrue(eventCounter.Wait(TimeSpan.FromSeconds(5)));
        }