コード例 #1
0
    public void ShouldCallExceptionHandlerOnTimeoutException()
    {
        var waitStrategy    = new TimeoutBlockingWaitStrategy(TimeSpan.FromMilliseconds(1));
        var ringBuffer      = new ValueRingBuffer <StubValueEvent>(() => new StubValueEvent(-1), new SingleProducerSequencer(16, waitStrategy));
        var sequenceBarrier = ringBuffer.NewBarrier();

        var exceptionSignal  = new CountdownEvent(1);
        var exceptionHandler = new TestValueExceptionHandler <StubValueEvent>(x => exceptionSignal.Signal());
        var eventHandler     = new TestValueEventHandler <StubValueEvent> {
            OnTimeoutAction = TestException.ThrowOnce()
        };
        var eventProcessor = CreateEventProcessor(ringBuffer, sequenceBarrier, eventHandler);

        ringBuffer.AddGatingSequences(eventProcessor.Sequence);

        eventProcessor.SetExceptionHandler(exceptionHandler);

        var task = eventProcessor.Start();

        Assert.IsTrue(exceptionSignal.Wait(TimeSpan.FromSeconds(2)));
        Assert.AreEqual(0, exceptionHandler.EventExceptionCount);
        Assert.AreEqual(1, exceptionHandler.TimeoutExceptionCount);

        eventProcessor.Halt();

        Assert.IsTrue(task.Wait(TimeSpan.FromSeconds(2)));
    }
コード例 #2
0
    public void ShouldCallExceptionHandlerOnMultipleUncaughtException()
    {
        var processingSignal = new CountdownEvent(5);
        var exceptionHandler = new TestValueExceptionHandler <StubValueEvent>(x => processingSignal.Signal());
        var eventHandler     = new TestValueEventHandler <StubValueEvent>(x =>
        {
            if (x.Value == 1)
            {
                throw new Exception();
            }

            processingSignal.Signal();
        });
        var eventProcessor = CreateEventProcessor(_ringBuffer, _sequenceBarrier, eventHandler);

        _ringBuffer.AddGatingSequences(eventProcessor.Sequence);

        eventProcessor.SetExceptionHandler(exceptionHandler);

        var task = eventProcessor.Start();

        _ringBuffer.PublishStubEvent(0);
        _ringBuffer.PublishStubEvent(1);
        _ringBuffer.PublishStubEvent(0);
        _ringBuffer.PublishStubEvent(1);
        _ringBuffer.PublishStubEvent(0);

        Assert.IsTrue(processingSignal.Wait(TimeSpan.FromSeconds(2)));
        Assert.AreEqual(2, exceptionHandler.EventExceptionCount);
        Assert.AreEqual(0, exceptionHandler.TimeoutExceptionCount);

        eventProcessor.Halt();

        Assert.IsTrue(task.Wait(TimeSpan.FromSeconds(2)));
    }
コード例 #3
0
        public void ShouldTrackRemainingCapacity()
        {
            long[] remainingCapacity = { -1 };
            //Given
            var eventHandler = new TestValueEventHandler <TestValueEvent>(e => remainingCapacity[0] = _disruptor.RingBuffer.GetRemainingCapacity());

            _disruptor.HandleEventsWith(eventHandler);

            //When
            PublishEvent();

            //Then
            while (remainingCapacity[0] == -1)
            {
                Thread.Sleep(100);
            }
            Assert.That(remainingCapacity[0], Is.EqualTo(_ringBuffer.BufferSize - 1L));
            Assert.That(_disruptor.RingBuffer.GetRemainingCapacity(), Is.EqualTo(_ringBuffer.BufferSize - 0L));
        }
コード例 #4
0
    public void ShouldCallMethodsInLifecycleOrderForBatch()
    {
        var eventSignal    = new CountdownEvent(3);
        var eventHandler   = new TestValueEventHandler <StubValueEvent>(x => eventSignal.Signal());
        var eventProcessor = CreateEventProcessor(_ringBuffer, _sequenceBarrier, eventHandler);

        _ringBuffer.AddGatingSequences(eventProcessor.Sequence);

        _ringBuffer.PublishStubEvent(0);
        _ringBuffer.PublishStubEvent(0);
        _ringBuffer.PublishStubEvent(0);

        var task = eventProcessor.Start();

        Assert.IsTrue(eventSignal.Wait(TimeSpan.FromSeconds(2)));

        eventProcessor.Halt();

        Assert.IsTrue(task.Wait(TimeSpan.FromSeconds(2)));
    }
コード例 #5
0
    public void ShouldCallOnTimeout()
    {
        var waitStrategy    = new TimeoutBlockingWaitStrategy(TimeSpan.FromMilliseconds(1));
        var ringBuffer      = new ValueRingBuffer <StubValueEvent>(() => new StubValueEvent(-1), new SingleProducerSequencer(16, waitStrategy));
        var sequenceBarrier = ringBuffer.NewBarrier();

        var onTimeoutSignal = new ManualResetEvent(false);
        var eventHandler    = new TestValueEventHandler <StubValueEvent> {
            OnTimeoutAction = () => onTimeoutSignal.Set()
        };
        var eventProcessor = CreateEventProcessor(ringBuffer, sequenceBarrier, eventHandler);

        ringBuffer.AddGatingSequences(eventProcessor.Sequence);

        var task = eventProcessor.Start();

        Assert.IsTrue(onTimeoutSignal.WaitOne(TimeSpan.FromSeconds(2)));

        eventProcessor.Halt();

        Assert.IsTrue(task.Wait(TimeSpan.FromSeconds(2)));
    }