예제 #1
0
        public void TestLargeDeltaBackoff()
        {
            int      retryCount = 0;
            TimeSpan totalDelay;

            try
            {
                // Second, attempt to instantiate a retry policy from configuration with invalid settings.
                RetryPolicy retryPolicy = RetryPolicyFactory.GetRetryPolicy <SqlDatabaseTransientErrorDetectionStrategy>("LargeDeltaBackoff");

                GeneralRetryPolicyTests.TestRetryPolicy(retryPolicy, out retryCount, out totalDelay);
                Assert.AreEqual <int>(3, retryCount, "The action was not retried using the expected amount of times");
            }
            catch
            {
                Assert.Fail("When the DeltaBackoff is very large, the retry policy should work normally.");
            }

            try
            {
                // First, instantiate a policy directly bypassing the configuration data validation.
                RetryPolicy <SqlDatabaseTransientErrorDetectionStrategy> retryPolicy = new RetryPolicy <SqlDatabaseTransientErrorDetectionStrategy>(3, TimeSpan.FromMilliseconds(100), TimeSpan.FromMilliseconds(1000), TimeSpan.FromMilliseconds(100000000000000));

                GeneralRetryPolicyTests.TestRetryPolicy(retryPolicy, out retryCount, out totalDelay);
                Assert.AreEqual <int>(3, retryCount, "The action was not retried using the expected amount of times");
            }
            catch
            {
                Assert.Fail("When the DeltaBackoff is very large, the retry policy should work normally.");
            }
        }
예제 #2
0
        public void TestIncrementalInterval_MissingRetryInterval()
        {
            int      retryCount = 0;
            TimeSpan totalDelay;

            RetryPolicy retryPolicy = RetryPolicyFactory.GetRetryPolicy <SqlDatabaseTransientErrorDetectionStrategy>("IncrementalInterval_MissingRetryInterval");

            GeneralRetryPolicyTests.TestRetryPolicy(retryPolicy, out retryCount, out totalDelay);

            Assert.AreEqual <int>(3, retryCount, "The action was not retried using the expected amount of times");
        }
예제 #3
0
        public void TestProgressiveIncrementRetryPolicyWithRetryableError()
        {
            const int MaxRetryCount   = 4;
            TimeSpan  initialInterval = TimeSpan.FromMilliseconds(500);
            TimeSpan  increment       = TimeSpan.FromMilliseconds(500);

            RetryPolicy retryPolicy =
                new RetryPolicy <SqlDatabaseTransientErrorDetectionStrategy>(
                    new Incremental("", MaxRetryCount, initialInterval, increment, false));

            int       execCount = 0;
            TimeSpan  totalDelay;
            Stopwatch stopwatch = Stopwatch.StartNew();

            GeneralRetryPolicyTests.TestRetryPolicy(retryPolicy, out execCount, out totalDelay);

            stopwatch.Stop();

            Assert.AreEqual <int>(MaxRetryCount, execCount, "The action was not retried using the expected amount of times");
            Assert.IsTrue(stopwatch.ElapsedMilliseconds >= totalDelay.TotalMilliseconds, "Unexpected duration of retry block");
        }