示例#1
0
    public void TestDefaultRetryPolicyWithRetryableError()
    {
        RetryPolicy defaultPolicy = RetryPolicyFactory.GetDefaultSqlConnectionRetryPolicy();

        RetryManagerOptions  retryManagerOptions  = RetryConfiguration.GetConfiguration().GetSection(nameof(RetryManager)).Get <RetryManagerOptions>(buildOptions => buildOptions.BindNonPublicProperties = true);
        FixedIntervalOptions retryStrategyOptions = retryManagerOptions.RetryStrategy !.GetSection(retryManagerOptions.DefaultSqlConnectionRetryStrategy).Get <FixedIntervalOptions>(buildOptions => buildOptions.BindNonPublicProperties = true);

        int execCount = 0;

        try
        {
            defaultPolicy.ExecuteAction(() =>
            {
                execCount++;

                throw new TimeoutException("Forced Exception");
            });
        }
        catch (TimeoutException ex)
        {
            Assert.AreEqual("Forced Exception", ex.Message);
        }

        Assert.IsNotNull(retryStrategyOptions);
        Assert.AreEqual(retryStrategyOptions.RetryCount, execCount - 1, "The action was not retried using the expected amount of times");
    }
    public void ReadsFixedIntervalRetryStrategyValuesFromConfiguration()
    {
        IConfigurationSection?section = this.retryManagerOptions?.RetryStrategy?.GetSection("Fixed Interval Non Default");
        FixedIntervalOptions  data    = section.Get <FixedIntervalOptions>();

        Assert.AreEqual("Fixed Interval Non Default", section?.Key);
        Assert.AreEqual(new TimeSpan(0, 0, 2), data.RetryInterval);
        Assert.AreEqual(2, data.RetryCount);
        Assert.AreEqual(false, data.FastFirstRetry);
    }
示例#3
0
        /// <summary>
        /// Converts <see cref="Microsoft.Practices.EnterpriseLibrary.TransientFaultHandling.FixedIntervalOptions"/> instance to <see cref="Microsoft.Practices.EnterpriseLibrary.TransientFaultHandling.FixedInterval"/> retry strategy.
        /// </summary>
        /// <param name="options">The <see cref="Microsoft.Practices.EnterpriseLibrary.TransientFaultHandling.FixedIntervalOptions"/> instance to convert.</param>
        /// <param name="name">The name of the retry strategy.</param>
        /// <returns>The converted <see cref="Microsoft.Practices.EnterpriseLibrary.TransientFaultHandling.FixedInterval"/> retry strategy.</returns>
        public static FixedInterval Strategy(this FixedIntervalOptions options, string name)
        {
            Guard.ArgumentNotNull(options, nameof(options));

            return(new FixedInterval(name, options.RetryCount, options.RetryInterval, options.FastFirstRetry));
        }
 /// <summary>
 /// Converts <see cref="Microsoft.Practices.EnterpriseLibrary.TransientFaultHandling.FixedIntervalOptions"/> instance to <see cref="Microsoft.Practices.EnterpriseLibrary.TransientFaultHandling.FixedInterval"/> retry strategy.
 /// </summary>
 /// <param name="options">The <see cref="Microsoft.Practices.EnterpriseLibrary.TransientFaultHandling.FixedIntervalOptions"/> instance to convert.</param>
 /// <param name="name">The name of the retry strategy.</param>
 /// <returns>The converted <see cref="Microsoft.Practices.EnterpriseLibrary.TransientFaultHandling.FixedInterval"/> retry strategy.</returns>
 public static FixedInterval ToFixedInterval(this FixedIntervalOptions options, string name) =>