コード例 #1
0
        public void Failing_operations_are_retried()
        {
            var operation = new FakeOperation { ThrowOnExecute = new Exception(), ErrorCount = 1 };
            var sut = new RetryBehavior(1, TimeSpan.Zero);
            sut.AttachTo(operation);

            sut.Execute();
        }
コード例 #2
0
        public void Failing_operations_are_retried_aspoecific_number_of_times()
        {
            var operation = new FakeOperation { ThrowOnExecute = new Exception(), ErrorCount = 2 };
            var sut = new RetryBehavior(1, TimeSpan.Zero);
            sut.AttachTo(operation);

            Assert.Throws<Exception>(() => sut.Execute());
        }
コード例 #3
0
        public void Retry_properties_are_populated_from_constructor_arguments()
        {
            var retryErrorTypes = new[] { typeof (Exception) };
            var sut = new RetryBehavior(3, TimeSpan.FromSeconds(5), retryErrorTypes);

            Assert.Equal(3, sut.TimesToRetry);
            Assert.Equal(TimeSpan.FromSeconds(5), sut.RetryDelay);
            Assert.Equal(retryErrorTypes, sut.RetryExceptionTypes);
        }
コード例 #4
0
        public void Retries_are_delayed_the_specified_duration()
        {
            var operation = new FakeOperation { ThrowOnExecute = new Exception(), ErrorCount = 1 };
            var sut = new RetryBehavior(1, TimeSpan.FromSeconds(5));
            sut.AttachTo(operation);
            var before = Time.OffsetUtcNow;

            sut.Execute();

            var duration = Time.OffsetUtcNow - before;
            Assert.Equal(TimeSpan.FromSeconds(5), duration); 
        }
コード例 #5
0
        public void You_can_retry_an_operation_where_an_indempotent_child_operation_has_executed()
        {
            var operation = new FakeOperation(new IndempotentOperation { ThrowOnExecute = new Exception(), ErrorCount = 1 });
            var sut = new RetryBehavior(1, TimeSpan.Zero);
            sut.AttachTo(operation);

            sut.Execute();
        }
コード例 #6
0
        public void The_behavior_has_work_recovery_level_precedence()
        {
            var sut = new RetryBehavior(1, TimeSpan.Zero);

            Assert.Equal(BehaviorPrecedence.WorkRecovery, sut.Precedence);
        }
コード例 #7
0
        public void Retried_operations_are_logged(Exception error, FakeWorkflowLogger log)
        {
            var sut = new RetryBehavior(2, TimeSpan.Zero).AttachTo(new FakeOperation { ThrowOnExecute = error, ErrorCount = 2 });
            sut.Initialize(new FakeWorkflowConfiguration { Logger = log });

            sut.Execute();

            Assert.Equal(2, log.AppliedBehaviors.Count);
            Assert.Equal("Operation retried", log.AppliedBehaviors[0].Description);
        }
コード例 #8
0
        public void When_retry_exception_types_are_specified_errors_of_different_types_will_not_be_retried()
        {
            var operation = new FakeOperation { ThrowOnExecute = new NullReferenceException(), ErrorCount = 1 };
            var sut = new RetryBehavior(1, TimeSpan.Zero, typeof(InsufficientMemoryException));
            sut.AttachTo(operation);

            Assert.Throws<NullReferenceException>(() => sut.Execute());
        }
コード例 #9
0
        public void When_retry_exception_types_are_specified_errors_of_sub_types_will_be_retried()
        {
            var operation = new FakeOperation { ThrowOnExecute = new ArgumentNullException(), ErrorCount = 1 };
            var sut = new RetryBehavior(1, TimeSpan.Zero, typeof(ArgumentException));
            sut.AttachTo(operation);

            sut.Execute();
        }