Exemplo n.º 1
0
        public void LoadValidInternalTypes(string method1, string method2)
        {
            RetryLogicConfigs cnnCfg = RetryLogicConfigHelper.CreateRandomConfig(method1);
            RetryLogicConfigs cmdCfg = RetryLogicConfigHelper.CreateRandomConfig(method2,
                                                                                 // Doesn't accept DML statements
                                                                                 @"^\b(?!UPDATE|DELETE|TRUNCATE|INSERT( +INTO){0,1})\b");

            // for sake of reducing the retry time in total
            cnnCfg.NumberOfTries = 1;
            cmdCfg.NumberOfTries = 1;

            object loaderObj = RetryLogicConfigHelper.ReturnLoaderAndProviders(cnnCfg, cmdCfg, out SqlRetryLogicBaseProvider cnnProvider, out SqlRetryLogicBaseProvider cmdProvider);

            Assert.NotNull(loaderObj);
            RetryLogicConfigHelper.AssessProvider(cnnProvider, cnnCfg);
            RetryLogicConfigHelper.AssessProvider(cmdProvider, cmdCfg);

            // check the retry in action
            s_connectionCRLTest.ConnectionRetryOpenInvalidCatalogFailed(TcpCnnString, cnnProvider);
            s_commandCRLTest.RetryExecuteFail(TcpCnnString, cmdProvider);
            if (DataTestUtility.IsNotAzureSynapse())
            {
                s_commandCRLTest.RetryExecuteUnauthorizedSqlStatementDML(TcpCnnString, cmdProvider);
            }
        }
Exemplo n.º 2
0
        public void OutOfRangeTime(TimeSpan deltaTime, TimeSpan minTime, TimeSpan maxTime)
        {
            RetryLogicConfigs cnnCfg = RetryLogicConfigHelper.CreateRandomConfig(RetryLogicConfigHelper.RetryMethodName_Fix);

            cnnCfg.DeltaTime = deltaTime;
            RetryLogicConfigs cmdCfg = RetryLogicConfigHelper.CreateRandomConfig(RetryLogicConfigHelper.RetryMethodName_Fix, @"Don't care!");

            bool switchValue = true;
            var  ex          = Assert.Throws <System.Reflection.TargetInvocationException>(() => RetryLogicConfigHelper.ReturnLoaderAndProviders(cnnCfg, cmdCfg, switchValue, out SqlRetryLogicBaseProvider cnnProvider, out SqlRetryLogicBaseProvider cmdProvider));

            Assert.Equal(typeof(System.Configuration.ConfigurationErrorsException), ex.InnerException?.GetType());
            Assert.Equal(typeof(ArgumentException), ex.InnerException?.InnerException?.GetType());

            cnnCfg = RetryLogicConfigHelper.CreateRandomConfig(RetryLogicConfigHelper.RetryMethodName_Fix);
            cnnCfg.MinTimeInterval = minTime;
            ex = Assert.Throws <System.Reflection.TargetInvocationException>(() => RetryLogicConfigHelper.ReturnLoaderAndProviders(cnnCfg, cmdCfg, switchValue, out SqlRetryLogicBaseProvider cnnProvider, out SqlRetryLogicBaseProvider cmdProvider));
            Assert.Equal(typeof(System.Configuration.ConfigurationErrorsException), ex.InnerException?.GetType());
            Assert.Equal(typeof(ArgumentException), ex.InnerException?.InnerException?.GetType());

            cnnCfg = RetryLogicConfigHelper.CreateRandomConfig(RetryLogicConfigHelper.RetryMethodName_Fix);
            cnnCfg.MaxTimeInterval = maxTime;
            ex = Assert.Throws <System.Reflection.TargetInvocationException>(() => RetryLogicConfigHelper.ReturnLoaderAndProviders(cnnCfg, cmdCfg, switchValue, out SqlRetryLogicBaseProvider cnnProvider, out SqlRetryLogicBaseProvider cmdProvider));
            Assert.Equal(typeof(System.Configuration.ConfigurationErrorsException), ex.InnerException?.GetType());
            Assert.Equal(typeof(ArgumentException), ex.InnerException?.InnerException?.GetType());
        }
Exemplo n.º 3
0
        public void InvalidTransientError(string errors)
        {
            RetryLogicConfigs cnnCfg = RetryLogicConfigHelper.CreateRandomConfig(RetryLogicConfigHelper.RetryMethodName_Fix);

            cnnCfg.TransientErrors = errors;
            RetryLogicConfigs cmdCfg = RetryLogicConfigHelper.CreateRandomConfig(RetryLogicConfigHelper.RetryMethodName_Fix, @"Don't care!");

            var ex = Assert.Throws <System.Reflection.TargetInvocationException>(() => RetryLogicConfigHelper.ReturnLoaderAndProviders(cnnCfg, cmdCfg, out SqlRetryLogicBaseProvider cnnProvider, out SqlRetryLogicBaseProvider cmdProvider));

            Assert.Equal(typeof(System.Configuration.ConfigurationErrorsException), ex.InnerException?.GetType());
            Assert.Equal(typeof(ArgumentException), ex.InnerException?.InnerException?.GetType());
        }
Exemplo n.º 4
0
        public void InvalidNumberOfTries(int num)
        {
            RetryLogicConfigs cnnCfg = RetryLogicConfigHelper.CreateRandomConfig(RetryLogicConfigHelper.RetryMethodName_Fix);

            cnnCfg.NumberOfTries = num;
            RetryLogicConfigs cmdCfg = RetryLogicConfigHelper.CreateRandomConfig(RetryLogicConfigHelper.RetryMethodName_Fix, @"Don't care!");

            bool switchValue = true;
            var  ex          = Assert.Throws <System.Reflection.TargetInvocationException>(() => RetryLogicConfigHelper.ReturnLoaderAndProviders(cnnCfg, cmdCfg, switchValue, out SqlRetryLogicBaseProvider cnnProvider, out SqlRetryLogicBaseProvider cmdProvider));

            Assert.Equal(typeof(System.Configuration.ConfigurationErrorsException), ex.InnerException?.GetType());
            Assert.Equal(typeof(ArgumentException), ex.InnerException?.InnerException?.GetType());
        }
Exemplo n.º 5
0
        public void InvalidRetryMethodName(string methodName)
        {
            RetryLogicConfigs cnnCfg = RetryLogicConfigHelper.CreateRandomConfig(methodName);
            RetryLogicConfigs cmdCfg = RetryLogicConfigHelper.CreateRandomConfig(methodName, @"Don't care!");

            object loaderObj = RetryLogicConfigHelper.ReturnLoaderAndProviders(cnnCfg, cmdCfg, out SqlRetryLogicBaseProvider cnnProvider, out SqlRetryLogicBaseProvider cmdProvider);

            Assert.NotNull(loaderObj);

            // none retriable logic applies.
            s_connectionCRLTest.DefaultOpenWithoutRetry(TcpCnnString, cnnProvider);
            s_commandCRLTest.NoneRetriableExecuteFail(TcpCnnString, cmdProvider);
        }
Exemplo n.º 6
0
        public void LoadValidInternalTypesWithoutEnablingSwitch(string method1, string method2)
        {
            bool switchValue         = false;
            RetryLogicConfigs cnnCfg = RetryLogicConfigHelper.CreateRandomConfig(method1);
            RetryLogicConfigs cmdCfg = RetryLogicConfigHelper.CreateRandomConfig(method2, @"Don't care!");

            object loaderObj = RetryLogicConfigHelper.ReturnLoaderAndProviders(cnnCfg, cmdCfg, switchValue, out SqlRetryLogicBaseProvider cnnProvider, out SqlRetryLogicBaseProvider cmdProvider);

            Assert.NotNull(loaderObj);
            RetryLogicConfigHelper.AssessProvider(cnnProvider, cnnCfg, switchValue);
            RetryLogicConfigHelper.AssessProvider(cmdProvider, cmdCfg, switchValue);

            s_connectionCRLTest.DefaultOpenWithoutRetry(TcpCnnString, cnnProvider);
            s_commandCRLTest.NoneRetriableExecuteFail(TcpCnnString, cmdProvider);
        }
Exemplo n.º 7
0
        public void LoadInvalidCustomRetryLogicType(string typeName, string methodName)
        {
            RetryLogicConfigs cnnCfg = RetryLogicConfigHelper.CreateRandomConfig(methodName);
            RetryLogicConfigs cmdCfg = RetryLogicConfigHelper.CreateRandomConfig(methodName);

            // for sake of reducing the retry time in total
            cnnCfg.RetryLogicType = typeName;
            cmdCfg.RetryLogicType = typeName;
            // for sake of reducing the retry time in total
            cnnCfg.NumberOfTries = 1;
            cmdCfg.NumberOfTries = 3;

            object loaderObj = RetryLogicConfigHelper.ReturnLoaderAndProviders(cnnCfg, cmdCfg, out SqlRetryLogicBaseProvider cnnProvider, out SqlRetryLogicBaseProvider cmdProvider);

            Assert.NotNull(loaderObj);

            s_connectionCRLTest.DefaultOpenWithoutRetry(TcpCnnString, cnnProvider);
            s_commandCRLTest.NoneRetriableExecuteFail(TcpCnnString, cmdProvider);
        }
Exemplo n.º 8
0
        public void LoadCustomMethod(string typeName, string methodName)
        {
            RetryLogicConfigs cnnCfg = RetryLogicConfigHelper.CreateRandomConfig(methodName);
            RetryLogicConfigs cmdCfg = RetryLogicConfigHelper.CreateRandomConfig(methodName);

            // for sake of reducing the retry time in total
            cnnCfg.RetryLogicType = typeName;
            cmdCfg.RetryLogicType = typeName;
            // for sake of reducing the retry time in total
            cnnCfg.NumberOfTries = 1;
            cmdCfg.NumberOfTries = 3;

            object loaderObj = RetryLogicConfigHelper.ReturnLoaderAndProviders(cnnCfg, cmdCfg, out SqlRetryLogicBaseProvider cnnProvider, out SqlRetryLogicBaseProvider cmdProvider);

            Assert.NotNull(loaderObj);

            TestConnection(cnnProvider, cnnCfg);
            TestCommandExecute(cmdProvider, cmdCfg);
            TestCommandExecuteAsync(cmdProvider, cmdCfg).Wait();
        }
Exemplo n.º 9
0
        public void InvalidRetryLogicTypeWithValidInternalMethodName(string typeName)
        {
            RetryLogicConfigs cnnCfg = RetryLogicConfigHelper.CreateRandomConfig(RetryLogicConfigHelper.RetryMethodName_Fix);

            cnnCfg.RetryLogicType = typeName;
            RetryLogicConfigs cmdCfg = RetryLogicConfigHelper.CreateRandomConfig(RetryLogicConfigHelper.RetryMethodName_Fix);

            // for sake of reducing the retry time in total
            cnnCfg.NumberOfTries = 1;
            cmdCfg.NumberOfTries = 1;

            object loaderObj = RetryLogicConfigHelper.ReturnLoaderAndProviders(cnnCfg, cmdCfg, out SqlRetryLogicBaseProvider cnnProvider, out SqlRetryLogicBaseProvider cmdProvider);

            Assert.NotNull(loaderObj);
            RetryLogicConfigHelper.AssessProvider(cnnProvider, cnnCfg);
            RetryLogicConfigHelper.AssessProvider(cmdProvider, cmdCfg);

            // internal type used to resolve the specified method
            s_connectionCRLTest.ConnectionRetryOpenInvalidCatalogFailed(TcpCnnString, cnnProvider);
            s_commandCRLTest.RetryExecuteFail(TcpCnnString, cmdProvider);
        }
Exemplo n.º 10
0
 public void ContextSwitchMangerTest(string name, bool value)
 {
     RetryLogicConfigHelper.ApplyContextSwitchByManager(name, value);
     AppContext.TryGetSwitch(name, out bool result);
     Assert.Equal(value, result);
 }