Exemple #1
0
        public void GetPolicyTPolicy_with_predicate_should_throw_if_multiple_TPolicy_if_multiple_match_predicate()
        {
            Policy     policyA = Policy.NoOp();
            Policy     policyB = Policy.Handle <Exception>().Retry();
            Policy     policyC = Policy.NoOp();
            PolicyWrap wrap    = policyA.Wrap(policyB.Wrap(policyC));

            wrap.Invoking(p => p.GetPolicy <NoOpPolicy>(_ => true)).ShouldThrow <InvalidOperationException>();
        }
Exemple #2
0
        public void GetPolicyTPolicy_should_throw_if_multiple_TPolicy()
        {
            Policy     policyA = Policy.NoOp();
            Policy     policyB = Policy.Handle <Exception>().Retry();
            Policy     policyC = Policy.NoOp();
            PolicyWrap wrap    = policyA.Wrap(policyB.Wrap(policyC));

            wrap.Invoking(p => p.GetPolicy <NoOpPolicy>()).Should().Throw <InvalidOperationException>();
        }
Exemple #3
0
        public void Wrapping_two_policies_by_static_syntax_and_executing_should_wrap_outer_then_inner_around_delegate()
        {
            RetryPolicy          retry   = Policy.Handle <Exception>().Retry(1); // Two tries in total: first try, plus one retry.
            CircuitBreakerPolicy breaker = Policy.Handle <Exception>().CircuitBreaker(2, TimeSpan.MaxValue);

            PolicyWrap retryWrappingBreaker = Policy.Wrap(retry, breaker);
            PolicyWrap breakerWrappingRetry = Policy.Wrap(breaker, retry);

            // When the retry wraps the breaker, the retry (being outer) should cause the call to be put through the breaker twice - causing the breaker to break.
            breaker.Reset();
            retryWrappingBreaker.Invoking(x => x.RaiseException <DivideByZeroException>(2))
            .ShouldThrow <DivideByZeroException>();
            breaker.CircuitState.Should().Be(CircuitState.Open);

            // When the breaker wraps the retry, the retry (being inner) should retry twice before throwing the exception back on the breaker - the exception only hits the breaker once - so the breaker should not break.
            breaker.Reset();
            breakerWrappingRetry.Invoking(x => x.RaiseException <DivideByZeroException>(2))
            .ShouldThrow <DivideByZeroException>();
            breaker.CircuitState.Should().Be(CircuitState.Closed);
        }