public void CreatesDefaultSqlConnectionPolicyFromConfiguration()
        {
            RetryPolicy retryPolicy   = RetryPolicyFactory.GetDefaultSqlConnectionRetryPolicy();
            Incremental retryStrategy = retryPolicy.RetryStrategy as Incremental;

            Assert.AreEqual("Default SqlConnection Retry Strategy", retryStrategy.Name);
        }
Ejemplo n.º 2
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");
    }
Ejemplo n.º 3
0
        public void TestDefaultRetryPolicyWithRetryableError()
        {
            RetryPolicy defaultPolicy = RetryPolicyFactory.GetDefaultSqlConnectionRetryPolicy();

            RetryPolicyConfigurationSettings retryPolicySettings = RetryPolicyConfigurationSettings.GetRetryPolicySettings(new SystemConfigurationSource());
            var retryStrategyData = retryPolicySettings.RetryStrategies.Get(retryPolicySettings.DefaultSqlConnectionRetryStrategy) as FixedIntervalData;

            int execCount = 0;

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

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

            Assert.IsNotNull(retryStrategyData);
            Assert.AreEqual <int>(retryStrategyData.MaxRetryCount, execCount - 1, "The action was not retried using the expected amount of times");
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Initializes a new instance of the SQL Azure database-based persistence queue using the specified streaming mode, data type and buffer settings.
 /// </summary>
 /// <param name="streamingMode">The type of buffer that will be used for streaming operations.</param>
 /// <param name="streamingDataType">The type of data that will be used for streaming operations.</param>
 /// <param name="initialBufferSize">The initial size of the buffer where data is being collected before flushed into a SQL Azure database.</param>
 /// <param name="maxBufferSize">The maximum allowed size of the data buffer.</param>
 public SqlAzurePersistenceQueue(StreamingMode streamingMode, StreamingDataType streamingDataType, int initialBufferSize, int maxBufferSize)
 {
     this.streamingMode         = streamingMode;
     this.streamingDataType     = streamingDataType;
     this.initialBufferSize     = initialBufferSize;
     this.maxBufferSize         = maxBufferSize;
     this.connectionRetryPolicy = RetryPolicyFactory.GetDefaultSqlConnectionRetryPolicy();
     this.commandRetryPolicy    = RetryPolicyFactory.GetDefaultSqlCommandRetryPolicy();
 }
        public void PolicyInstancesAreNotSingletons()
        {
            RetryPolicy connPolicy         = RetryPolicyFactory.GetDefaultSqlConnectionRetryPolicy();
            Incremental nonDefaultIncRetry = connPolicy.RetryStrategy as Incremental;

            RetryPolicy connPolicy1         = RetryPolicyFactory.GetDefaultSqlConnectionRetryPolicy();
            Incremental nonDefaultIncRetry1 = connPolicy1.RetryStrategy as Incremental;

            Assert.AreNotSame(connPolicy, connPolicy1);
        }
Ejemplo n.º 6
0
    public void PolicyInstancesAreNotSingletons()
    {
        RetryPolicy connPolicy1         = RetryPolicyFactory.GetDefaultSqlConnectionRetryPolicy();
        Incremental?nonDefaultIncRetry1 = connPolicy1.RetryStrategy as Incremental;

        RetryPolicy connPolicy2         = RetryPolicyFactory.GetDefaultSqlConnectionRetryPolicy();
        Incremental?nonDefaultIncRetry2 = connPolicy2.RetryStrategy as Incremental;

        Assert.AreNotSame(connPolicy1, connPolicy2);
        Assert.AreEqual(nonDefaultIncRetry1?.Name, nonDefaultIncRetry2?.Name);
    }
Ejemplo n.º 7
0
        public void TestDefaultRetryPolicyWithNonRetryableError()
        {
            RetryPolicy defaultPolicy = RetryPolicyFactory.GetDefaultSqlConnectionRetryPolicy();
            int         execCount     = 0;

            try
            {
                defaultPolicy.ExecuteAction(() =>
                {
                    execCount++;
                    throw new ApplicationException("Forced Exception");
                });
            }
            catch (ApplicationException ex)
            {
                Assert.AreEqual("Forced Exception", ex.Message);
            }

            Assert.AreEqual <int>(1, execCount, "The action was not executed the expected amount of times");
        }
Ejemplo n.º 8
0
        public void TestDefaultRetryPolicyWithRetryableError()
        {
            RetryPolicy defaultPolicy = RetryPolicyFactory.GetDefaultSqlConnectionRetryPolicy();
            int         execCount     = 0;

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

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

            Assert.AreEqual <int>(RetryPolicy.DefaultClientRetryCount, execCount - 1, "The action was not retried using the expected amount of times");
        }
 protected override void Act()
 {
     this.retryPolicy = RetryPolicyFactory.GetDefaultSqlConnectionRetryPolicy();
 }
Ejemplo n.º 10
0
 public RetryPolicy GetDefaultSqlConnectionRetryPolicy()
 {
     return(RetryPolicyFactory.GetDefaultSqlConnectionRetryPolicy());
 }
Ejemplo n.º 11
0
 /// <summary>
 /// Opens a database connection with the connection settings specified in the ConnectionString property of the connection object.
 /// Uses the default retry policy when opening the connection.
 /// </summary>
 /// <param name="connection">The connection object which is required as per extension method declaration.</param>
 public static void OpenWithRetry(this SqlConnection connection)
 {
     OpenWithRetry(connection, RetryPolicyFactory.GetDefaultSqlConnectionRetryPolicy());
 }
Ejemplo n.º 12
0
 /// <summary>
 /// Initializes a new instance of the SqlAzureConnection class with a given connection string. Uses the default
 /// retry policy for connections and commands unless retry settings are provided in the connection string.
 /// </summary>
 /// <param name="connectionString">The connection string used to open the SQL Azure database.</param>
 public ReliableSqlConnection(string connectionString)
     : this(connectionString, RetryPolicyFactory.GetDefaultSqlConnectionRetryPolicy())
 {
 }