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");
        }
        /// <summary>
        /// Called once when the worker role is started in Azure.
        /// </summary>
        /// <returns><c>true</c> if the role should continue to run, <c>false</c> otherwise.</returns>
        /// <remarks>
        /// <para>
        /// If the OnStart method returns false, the role instance is immediately stopped. If the method returns true,
        /// Windows Azure starts the role by calling the Run method.
        /// </para>
        /// </remarks>
        public override bool OnStart()
        {
            // Set the maximum number of concurrent connections
            ServicePointManager.DefaultConnectionLimit = 12;

            // For information on handling configuration changes
            // see the MSDN topic at http://go.microsoft.com/fwlink/?LinkId=166357.

            using (var config = new SystemConfigurationSource())
            {
                var settings = RetryPolicyConfigurationSettings.GetRetryPolicySettings(config);

                // Initialize the RetryPolicyFactory with a RetryManager built from the
                // settings in the configuration file.
                RetryPolicyFactory.SetRetryManager(settings.BuildRetryManager());
            }

            // set up a logger
            _log = new Lazy <ILog>(() => LogManager.GetLogger("default"));

            // create a unique process id for this worker.  This is passed to the CopyTenant method on the
            // and table driver to allow for process specific functionality
            _uniqueProcessID = Guid.NewGuid();

            return(base.OnStart());
        }
Exemple #3
0
        private static RetryStrategyData GetRetryPolicyFromConfig(string policyName)
        {
            RetryPolicyConfigurationSettings retryPolicySettings = RetryPolicyConfigurationSettings.GetRetryPolicySettings(new SystemConfigurationSource());
            RetryStrategyData retryPolicyInfo = retryPolicySettings.RetryStrategies.Get(policyName);

            Assert.IsNotNull(retryPolicyInfo, String.Format("The retry policy {0} was expected in the configuration but has not been found.", policyName));

            return(retryPolicyInfo);
        }
Exemple #4
0
        public void ReadsFixedIntervalRetryStrategyValuesFromConfiguration()
        {
            var settings           = RetryPolicyConfigurationSettings.GetRetryPolicySettings(this.configurationSource);
            FixedIntervalData data = (FixedIntervalData)settings.RetryStrategies.Get("Fixed Interval Non Default");

            Assert.AreEqual("Fixed Interval Non Default", data.Name);
            Assert.AreEqual(new TimeSpan(0, 0, 2), data.RetryInterval);
            Assert.AreEqual(2, data.MaxRetryCount);
            Assert.AreEqual(false, data.FirstFastRetry);
        }
Exemple #5
0
 /// <summary>
 /// Creates a retry manager from the system configuration.
 /// </summary>
 /// <returns></returns>
 public static RetryManager CreateDefault()
 {
     using (var source = new SystemConfigurationSource())
     {
         var settings = RetryPolicyConfigurationSettings.GetRetryPolicySettings(source);
         var manager  = settings.BuildRetryManager();
         RetryManager.SetDefault(manager);
         return(manager);
     }
 }
Exemple #6
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            var settings = RetryPolicyConfigurationSettings.GetRetryPolicySettings(new SystemConfigurationSource());

            RetryPolicyFactory.SetRetryManager(settings.BuildRetryManager());

            Application.Run(new Main());
        }
Exemple #7
0
        private static void SetUpRetryPolicy()
        {
            using (var config = new SystemConfigurationSource())
            {
                var settings = RetryPolicyConfigurationSettings.GetRetryPolicySettings(config);

                // Initialize the RetryPolicyFactory with a RetryManager built from the
                // settings in the configuration file.
                var buildRetryManager = settings.BuildRetryManager();
                RetryPolicyFactory.SetRetryManager(buildRetryManager);
            }
        }
Exemple #8
0
        public void ReadsExponentialBackoffRetryStrategyValuesFromConfiguration()
        {
            var settings = RetryPolicyConfigurationSettings.GetRetryPolicySettings(this.configurationSource);
            ExponentialBackoffData data = (ExponentialBackoffData)settings.RetryStrategies.Get("Exponential Backoff Non Default");

            Assert.AreEqual("Exponential Backoff Non Default", data.Name);
            Assert.AreEqual(new TimeSpan(0, 0, 1), data.MinBackoff);
            Assert.AreEqual(new TimeSpan(0, 0, 2), data.MaxBackoff);
            Assert.AreEqual(TimeSpan.FromMilliseconds(300), data.DeltaBackoff);
            Assert.AreEqual(4, data.MaxRetryCount);
            Assert.AreEqual(false, data.FirstFastRetry);
        }
Exemple #9
0
        public static void Configure(IUnityContainer container)
        {
            // Get Entlib config source (Current is in Web.EnterpriseLibrary.config)
            IConfigurationSource source = ConfigurationSourceFactory.Create();

            // Config container from Policy injection config settings
            var policyInjectionSettings = (PolicyInjectionSettings)source.GetSection(PolicyInjectionSettings.SectionName);

            policyInjectionSettings.ConfigureContainer(container);

            // Config retry policy
            var retryPolicySettings = RetryPolicyConfigurationSettings.GetRetryPolicySettings(source);

            // turn off throwIfSet for unit testing
            RetryPolicyFactory.SetRetryManager(retryPolicySettings.BuildRetryManager(), throwIfSet: false);

            // get factories from config
            var policyFactory     = new ExceptionPolicyFactory(source);
            var dbFactory         = new DatabaseProviderFactory(source);
            var validationFactory = ConfigurationValidatorFactory.FromConfigurationSource(source);

            // Set default locator
            UnityServiceLocator locator = new UnityServiceLocator(container);

            ServiceLocator.SetLocatorProvider(() => locator);

            container
            .AddNewExtension <Interception>()

            // register Entlib types with appropiate factory
            .RegisterType <ExceptionManager>(new InjectionFactory(c => policyFactory.CreateManager()))
            .RegisterType <Database>(new InjectionFactory(c => dbFactory.CreateDefault()))
            .RegisterInstance <ValidatorFactory>(validationFactory)

            // use registration by convention extension for registering app types; IProfileStore, IUserRepository
            .RegisterTypes(AllClasses.FromAssemblies(Assembly.GetExecutingAssembly()),
                           WithMappings.FromAllInterfacesInSameAssembly,
                           WithName.Default,
                           WithLifetime.ContainerControlled)

            // register types with interception
            .RegisterType <AExpense.Model.User>(new Interceptor <VirtualMethodInterceptor>(),
                                                new InterceptionBehavior <TracingBehavior>())
            .RegisterType <IExpenseRepository, ExpenseRepository>(new Interceptor <VirtualMethodInterceptor>(),
                                                                  new InterceptionBehavior <PolicyInjectionBehavior>());
        }
 public void Initialize()
 {
     this.configurationSource = new SystemConfigurationSource();
     this.retryPolicySettings = RetryPolicyConfigurationSettings.GetRetryPolicySettings(this.configurationSource);
     this.retryManager        = retryPolicySettings.BuildRetryManager();
 }
 protected override void Arrange()
 {
     this.settings = RetryPolicyConfigurationSettings.GetRetryPolicySettings(new SystemConfigurationSource());
 }