예제 #1
0
        public void ShouldMakeEntriesAvailableToFirstCustomProcessorsImmediately()
        {
            var countDownLatch = new CountdownEvent(2);
            var eventHandler   = new CountDownEventHandler <TestEvent>(countDownLatch);

            _disruptor.HandleEventsWith(new EventProcessorFactory(_disruptor, eventHandler, 0));

            EnsureTwoEventsProcessedAccordingToDependencies(countDownLatch);
        }
예제 #2
0
        public void ShouldAllowEventHandlerWithSuperType()
        {
            var latch         = new CountdownEvent(2);
            var objectHandler = new CountDownEventHandler <object>(latch);

            _disruptor.HandleEventsWith(objectHandler);

            EnsureTwoEventsProcessedAccordingToDependencies(latch);
        }
예제 #3
0
        public void ShouldMakeEntriesAvailableToFirstHandlersImmediately()
        {
            var countDownLatch = new CountdownEvent(2);
            var eventHandler   = new CountDownEventHandler <TestEvent>(countDownLatch);

            _disruptor.HandleEventsWith(CreateDelayedEventHandler(), eventHandler);

            EnsureTwoEventsProcessedAccordingToDependencies(countDownLatch);
        }
예제 #4
0
        public void ShouldAllowChainingEventHandlersWithSuperType()
        {
            var latch = new CountdownEvent(2);
            var delayedEventHandler = CreateDelayedEventHandler();
            var objectHandler       = new CountDownEventHandler <object>(latch);

            _disruptor.HandleEventsWith(delayedEventHandler).Then(objectHandler);

            EnsureTwoEventsProcessedAccordingToDependencies(latch, delayedEventHandler);
        }
예제 #5
0
        public void ShouldHonourDependenciesForCustomProcessors()
        {
            var countDownLatch      = new CountdownEvent(2);
            var eventHandler        = new CountDownEventHandler <TestEvent>(countDownLatch);
            var delayedEventHandler = CreateDelayedEventHandler();

            _disruptor.HandleEventsWith(delayedEventHandler).Then(new EventProcessorFactory(_disruptor, eventHandler, 1));

            EnsureTwoEventsProcessedAccordingToDependencies(countDownLatch, delayedEventHandler);
        }
예제 #6
0
        public void ShouldWaitUntilAllFirstEventProcessorsProcessEventBeforeMakingItAvailableToDependentEventProcessors()
        {
            var eventHandler1 = CreateDelayedEventHandler();

            var countDownLatch = new CountdownEvent(2);
            var eventHandler2  = new CountDownEventHandler <TestEvent>(countDownLatch);

            _disruptor.HandleEventsWith(eventHandler1).Then(eventHandler2);

            EnsureTwoEventsProcessedAccordingToDependencies(countDownLatch, eventHandler1);
        }
예제 #7
0
        public void ShouldMakeEntriesAvailableToFirstCustomProcessorsImmediately()
        {
            var countDownLatch = new CountdownEvent(2);
            var eventHandler   = new CountDownEventHandler <TestEvent>(countDownLatch);

            _disruptor.HandleEventsWith(new TestEventProcessorFactory <TestEvent>((ringBuffer, barrierSequences) =>
            {
                Assert.AreEqual(0, barrierSequences.Length, "Should not have had any barrier sequences");
                return(BatchEventProcessorFactory.Create(_disruptor.RingBuffer, ringBuffer.NewBarrier(barrierSequences), eventHandler));
            }));

            EnsureTwoEventsProcessedAccordingToDependencies(countDownLatch);
        }
예제 #8
0
        public void ShouldAllowSpecifyingSpecificEventProcessorsToWaitFor()
        {
            var handler1 = CreateDelayedEventHandler();
            var handler2 = CreateDelayedEventHandler();

            var countDownLatch     = new CountdownEvent(2);
            var handlerWithBarrier = new CountDownEventHandler <TestEvent>(countDownLatch);

            _disruptor.HandleEventsWith(handler1, handler2);
            _disruptor.After(handler1, handler2).HandleEventsWith(handlerWithBarrier);

            EnsureTwoEventsProcessedAccordingToDependencies(countDownLatch, handler1, handler2);
        }
예제 #9
0
        public void ShouldHonourDependenciesForCustomProcessors()
        {
            var countDownLatch      = new CountdownEvent(2);
            var eventHandler        = new CountDownEventHandler <TestEvent>(countDownLatch);
            var delayedEventHandler = CreateDelayedEventHandler();

            _disruptor.HandleEventsWith(delayedEventHandler).Then(new TestEventProcessorFactory <TestEvent>((ringBuffer, barrierSequences) =>
            {
                Assert.AreEqual(1, barrierSequences.Length, "Should have had a barrier sequence");
                return(BatchEventProcessorFactory.Create(_disruptor.RingBuffer, ringBuffer.NewBarrier(barrierSequences), eventHandler));
            }));

            EnsureTwoEventsProcessedAccordingToDependencies(countDownLatch, delayedEventHandler);
        }
예제 #10
0
        public void ShouldSupportCustomProcessorsAsDependencies()
        {
            var ringBuffer = _disruptor.RingBuffer;

            var delayedEventHandler = CreateDelayedEventHandler();

            var countDownLatch     = new CountdownEvent(2);
            var handlerWithBarrier = new CountDownEventHandler <TestEvent>(countDownLatch);

            var processor = BatchEventProcessorFactory.Create(ringBuffer, ringBuffer.NewBarrier(), delayedEventHandler);

            _disruptor.HandleEventsWith(processor).Then(handlerWithBarrier);

            EnsureTwoEventsProcessedAccordingToDependencies(countDownLatch, delayedEventHandler);
        }
예제 #11
0
        public void ShouldWaitOnAllProducersJoinedByAnd()

        {
            var handler1 = CreateDelayedEventHandler();
            var handler2 = CreateDelayedEventHandler();

            var countDownLatch     = new CountdownEvent(2);
            var handlerWithBarrier = new CountDownEventHandler <TestEvent>(countDownLatch);

            _disruptor.HandleEventsWith(handler1);
            var handler2Group = _disruptor.HandleEventsWith(handler2);

            _disruptor.After(handler1).And(handler2Group).HandleEventsWith(handlerWithBarrier);

            EnsureTwoEventsProcessedAccordingToDependencies(countDownLatch, handler1, handler2);
        }
예제 #12
0
        public void ShouldSupportCustomProcessorsAndHandlersAsDependencies()
        {
            var delayedEventHandler1 = CreateDelayedEventHandler();
            var delayedEventHandler2 = CreateDelayedEventHandler();

            _disruptor.HandleEventsWith(delayedEventHandler1);

            var ringBuffer         = _disruptor.RingBuffer;
            var countDownLatch     = new CountdownEvent(2);
            var handlerWithBarrier = new CountDownEventHandler <TestEvent>(countDownLatch);

            var sequenceBarrier = _disruptor.After(delayedEventHandler1).AsSequenceBarrier();
            var processor       = BatchEventProcessorFactory.Create(ringBuffer, sequenceBarrier, delayedEventHandler2);

            _disruptor.After(delayedEventHandler1).And(processor).HandleEventsWith(handlerWithBarrier);

            EnsureTwoEventsProcessedAccordingToDependencies(countDownLatch, delayedEventHandler1, delayedEventHandler2);
        }
예제 #13
0
        public void ShouldSupportMultipleCustomProcessorsAndHandlersAsDependencies()
        {
            var ringBuffer         = _disruptor.RingBuffer;
            var countDownLatch     = new CountdownEvent(2);
            var handlerWithBarrier = new CountDownEventHandler <TestEvent>(countDownLatch);

            var delayedEventHandler1 = CreateDelayedEventHandler();
            var processor1           = BatchEventProcessorFactory.Create(ringBuffer, ringBuffer.NewBarrier(), delayedEventHandler1);

            var delayedEventHandler2 = CreateDelayedEventHandler();
            var processor2           = BatchEventProcessorFactory.Create(ringBuffer, ringBuffer.NewBarrier(), delayedEventHandler2);

            _disruptor.HandleEventsWith(processor1, processor2);
            _disruptor.After(processor1, processor2).HandleEventsWith(handlerWithBarrier);

            EnsureTwoEventsProcessedAccordingToDependencies(countDownLatch, delayedEventHandler1, delayedEventHandler2);

            Assert.That(_executor.GetExecutionCount(), Is.EqualTo(3));
        }
예제 #14
0
        public void ShouldSupportHandlersAsDependenciesToCustomProcessors()
        {
            var delayedEventHandler = CreateDelayedEventHandler();

            _disruptor.HandleEventsWith(delayedEventHandler);

            var ringBuffer         = _disruptor.RingBuffer;
            var countDownLatch     = new CountdownEvent(2);
            var handlerWithBarrier = new CountDownEventHandler <TestEvent>(countDownLatch);

            var sequenceBarrier = _disruptor.After(delayedEventHandler).AsSequenceBarrier();
            var processor       = BatchEventProcessorFactory.Create(ringBuffer, sequenceBarrier, handlerWithBarrier);

            _disruptor.HandleEventsWith(processor);

            EnsureTwoEventsProcessedAccordingToDependencies(countDownLatch, delayedEventHandler);

            Assert.That(_executor.GetExecutionCount(), Is.EqualTo(2));
        }