public WhenMessageHandlerThrowsExceptionsDefinedByRetryPolicy()
        {
            var fixture = new Fixture()
                          .CustomizeConnectedProjectionIdentifiers();

            var exceptionSequence = fixture
                                    .CreateMany <RetryException>(2, 10)
                                    .ToArray <Exception>();

            _loggerMock           = new FakeLoggerFactory().ResolveLoggerMock <MessageHandlerWithExecutionTracking>();
            _projection           = fixture.Create <ConnectedProjectionIdentifier>();
            _handlerWithoutPolicy = new MessageHandlerWithExecutionTracking(
                _projection,
                _loggerMock.AsLogger(),
                exceptionSequence);

            _numberOfRetries          = exceptionSequence.Length;
            _numberOfExpectedAttempts = Times.Exactly(1 + _numberOfRetries);
            _initialWait = TimeSpan.FromMilliseconds(fixture.CreatePositive <int>());
            _messages    = fixture.CreateMany <StreamMessage>().ToList();

            new LinearBackOff <RetryException>(_numberOfRetries, _initialWait)
            .ApplyOn(_handlerWithoutPolicy)
            .HandleAsync(_messages, Mock.Of <IStreamGapStrategy>(), CancellationToken.None)
            .GetAwaiter()
            .GetResult();
        }
        public WhenMessageHandlerThrowsAnExceptionThatWasNotDefinedToRetryAfterRetrying()
        {
            var fixture = new Fixture()
                          .CustomizeConnectedProjectionIdentifiers();

            _exceptionSequence = new Exception[] { new RetryException(), new DoNotRetryException() };

            _loggerMock           = new FakeLoggerFactory().ResolveLoggerMock <MessageHandlerWithExecutionTracking>();
            _projection           = fixture.Create <ConnectedProjectionIdentifier>();
            _handlerWithoutPolicy = new MessageHandlerWithExecutionTracking(
                _projection,
                _loggerMock.AsLogger(),
                _exceptionSequence);

            var numberOfRetries = _exceptionSequence.Count(exception => exception is RetryException);

            _numberOfExpectedAttempts = Times.Exactly(1 + numberOfRetries);
            _initialWait = TimeSpan.FromMilliseconds(fixture.CreatePositive <int>());
            _messages    = fixture.CreateMany <StreamMessage>().ToList();

            _sut = new LinearBackOff <RetryException>(numberOfRetries, _initialWait)
                   .ApplyOn(_handlerWithoutPolicy);
        }
        public WhenMessageHandlerThrowsTheExceptionDefinedInThePolicyMoreThanTheNumberOfRetries()
        {
            var fixture = new Fixture()
                          .CustomizeConnectedProjectionIdentifiers();

            var exceptionSequence = fixture
                                    .CreateMany <RetryException>(2, 10)
                                    .ToArray <Exception>();

            _loggerMock           = new FakeLoggerFactory().ResolveLoggerMock <MessageHandlerWithExecutionTracking>();
            _projection           = fixture.Create <ConnectedProjectionIdentifier>();
            _handlerWithoutPolicy = new MessageHandlerWithExecutionTracking(
                _projection,
                _loggerMock.AsLogger(),
                exceptionSequence);

            _numberOfRetries          = exceptionSequence.Length - 1;
            _numberOfExpectedAttempts = Times.Exactly(1 + _numberOfRetries);
            _initialWait = TimeSpan.FromMilliseconds(fixture.CreatePositive <int>());
            _messages    = fixture.CreateMany <StreamMessage>().ToList();

            _sut = new LinearBackOff <RetryException>(_numberOfRetries, _initialWait)
                   .ApplyOn(_handlerWithoutPolicy);
        }
Beispiel #4
0
        public When_a_projection_catch_up_processes_a_stream_and_throws_a_detected_stream_gap_exception()
        {
            var fixture = new Fixture()
                          .CustomizeConnectedProjectionIdentifiers();

            var contextMock = new Mock <IConnectedProjectionContext <FakeProjectionContext> >();

            contextMock
            .Setup(context => context.GetProjectionPosition(It.IsAny <ConnectedProjectionIdentifier>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync((long?)null);

            var streamMock = new Mock <IReadonlyStreamStore>();

            streamMock
            .Setup(store =>
                   store.ReadAllForwards(
                       It.IsAny <long>(),
                       It.IsAny <int>(),
                       It.IsAny <bool>(),
                       It.IsAny <CancellationToken>()))
            .ReturnsAsync(() =>
            {
                var position = fixture.CreatePositive <long>().WithMaximumValueOf(long.MaxValue - 1000);
                return(new ReadAllPage(
                           position,
                           position.CreateRandomHigherValue(),
                           true,
                           ReadDirection.Forward,
                           (p, token) => throw new NotImplementedException(),
                           fixture.CreateMany <StreamMessage>(2, 10).ToArray()));
            });

            _commandBusMock = new Mock <IConnectedProjectionsCommandBus>();

            _gapStrategySettings = fixture.Create <StreamGapStrategyConfigurationSettings>();
            var gapStrategyMock = new Mock <IStreamGapStrategy>();

            gapStrategyMock
            .SetupGet(strategy => strategy.Settings)
            .Returns(_gapStrategySettings);

            _loggerMock = new FakeLogger();
            _projection = new FakeProjection(
                "catch-up-dummy",
                (messages, strategy, name, ct)
                => throw new ConnectedProjectionMessageHandlingException(
                    new StreamGapDetectedException(fixture.CreateMany <long>(1, 10), name),
                    name,
                    new ActiveProcessedStreamState(0)),
                contextMock.Object);

            var sut = new ConnectedProjectionCatchUp <FakeProjectionContext>(
                _projection,
                ConnectedProjectionSettings.Default,
                streamMock.Object,
                _commandBusMock.Object,
                gapStrategyMock.Object,
                _loggerMock.AsLogger());

            sut.CatchUpAsync(CancellationToken.None).GetAwaiter();
        }