public void TestGetRetryableList()
        {
            var loadFromJson = new LoadFromJsonFile("retry_config.json");

            var list = loadFromJson.GetRetryableApiList(product, version, sectionName);

            Assert.True(79 == list.Count);

            sectionName = "RetryableNormalErrors";
            list        = loadFromJson.GetRetryableApiList(product, version, sectionName);

            Assert.True(3 == list.Count);
        }
        public RetryCondition ShouldRetry(RetryPolicyContext retryPolicyContext)
        {
            var exception = retryPolicyContext.Exception;

            if (exception == null)
            {
                return(RetryCondition.NoRetry);
            }

            if (exception.ErrorCode != null &&
                exception.ErrorCode.Equals(SdkHttpError))
            {
                return(RetryCondition.ShouldRetry);
            }

            if (exception is ServerException)
            {
                var serverException = (ServerException)exception;
                var errorCode       = serverException.ErrorCode;

                var product          = retryPolicyContext.Product;
                var version          = retryPolicyContext.Version;
                var loadFromJsonFile = new LoadFromJsonFile(configFile);

                var normalErrorList = loadFromJsonFile.GetRetryableApiList(product, version, NormalErrorSectionName);
                if (normalErrorList != null && normalErrorList.Contains(errorCode))
                {
                    return(RetryCondition.ShouldRetry);
                }

                var throttlingErrorList =
                    loadFromJsonFile.GetRetryableApiList(product, version, ThrottlingErrorSectionName);

                if (throttlingErrorList == null)
                {
                    return(RetryCondition.NoRetry);
                }

                var shouldThrottlingFromConfig = throttlingErrorList.Contains(errorCode);

                var localShouldRetry = shouldThrottlingFromConfig ? RetryCondition.ShouldRetry : RetryCondition.NoRetry;
                return(localShouldRetry | RetryCondition.ShouldRetryWithThrottlingBackoff);
            }

            return(RetryCondition.NoRetry);
        }
        public RetryCondition ShouldRetry(RetryPolicyContext retryPolicyContext)
        {
            var loadFromJsonFile = new LoadFromJsonFile(configFile);
            var product          = retryPolicyContext.Product;
            var version          = retryPolicyContext.Version;
            var currentApiName   = retryPolicyContext.ApiName;

            var apiList = loadFromJsonFile.GetRetryableApiList(product, version, ApiSectionName);

            if (apiList == null)
            {
                return(RetryCondition.NoRetry);
            }

            return(apiList.Contains(currentApiName)
                ? RetryCondition.ShouldRetry
                : RetryCondition.NoRetry);
        }
        public void TestInvalidJsonSection()
        {
            product = "ecs1";

            var loadFromJson = new LoadFromJsonFile("retry_config.json");
            var list         = loadFromJson.GetRetryableApiList(product, version, sectionName);

            Assert.Null(list);

            product = "ecs";
            version = "2014-05-27";

            list = loadFromJson.GetRetryableApiList(product, version, sectionName);
            Assert.Null(list);

            sectionName = "RetryableAPIsTest";
            list        = loadFromJson.GetRetryableApiList(product, version, sectionName);
            Assert.Null(list);
        }
        public void TestLoadFromJsonWithException()
        {
            var loadFromJson = new LoadFromJsonFile("TESTLocation.json");

            Assert.Throws <ClientException>(() => { loadFromJson.GetRetryableApiList(product, version, sectionName); });
        }