Пример #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 ShouldCallExceptionHandlerOnTimeoutException()
    {
        var waitStrategy    = new AsyncWaitStrategy(TimeSpan.FromMilliseconds(1));
        var ringBuffer      = new RingBuffer <StubEvent>(() => new StubEvent(-1), new SingleProducerSequencer(16, waitStrategy));
        var sequenceBarrier = ringBuffer.NewAsyncBarrier();

        var exception        = new TaskCompletionSource <Exception>();
        var exceptionHandler = new TestExceptionHandler <StubEvent>(x => exception.TrySetResult(x.ex));
        var eventHandler     = new TestAsyncBatchEventHandler <StubEvent> {
            OnTimeoutAction = TestException.ThrowOnce()
        };
        var eventProcessor = CreateEventProcessor(ringBuffer, sequenceBarrier, eventHandler);

        ringBuffer.AddGatingSequences(eventProcessor.Sequence);

        eventProcessor.SetExceptionHandler(exceptionHandler);

        var task = eventProcessor.Start();

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

        eventProcessor.Halt();

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