Exemplo n.º 1
0
        public void InvokeTestWith_429_And_No_MaxRetryTime()
        {
            var retryConfig = new ApiClient.RetryConfiguration
            {
                MaxRetryTimeSec     = 0,
                RetryAfterDefaultMs = 100,
                RetryMax            = 50
            };

            var          mockRestClient = new Mock <IRestClient>();
            RestResponse response       = GetTestResponse(429, "3");

            mockRestClient.Setup(x => x.Execute(It.IsAny <RestRequest>())).Returns(response);

            var apiClient = new ApiClient(new PureCloudPlatform.Client.V2.Client.Configuration());

            apiClient.RetryConfig = retryConfig;
            apiClient.RestClient  = mockRestClient.Object;

            stopwatch = Stopwatch.StartNew();
            RestResponse user = (RestResponse)apiClient.CallApi(path, method, queryParams, postBody, headerParams, formParams, fileParams, pathParams, contentType);

            Assert.IsTrue(stopwatch.ElapsedMilliseconds >= 0 && stopwatch.ElapsedMilliseconds < 100, "Since maxRetryTime is not provided it will not retry even if the status code is 429");
            Assert.AreEqual(429, (int)user.StatusCode);
            stopwatch.Stop();
        }
Exemplo n.º 2
0
        public void InvokeTestWith_429()
        {
            var retryConfig = new ApiClient.RetryConfiguration
            {
                MaxRetryTimeSec     = 6,
                RetryAfterDefaultMs = 100,
                RetryMax            = 50
            };

            var          mockRestClient = new Mock <IRestClient>();
            RestResponse response       = GetTestResponse(429, "3");

            mockRestClient.Setup(x => x.Execute(It.IsAny <RestRequest>())).Returns(response);

            var apiClient = new ApiClient(new PureCloudPlatform.Client.V2.Client.Configuration());

            apiClient.RetryConfig = retryConfig;
            apiClient.RestClient  = mockRestClient.Object;

            stopwatch = Stopwatch.StartNew();
            RestResponse user = (RestResponse)apiClient.CallApi(path, method, queryParams, postBody, headerParams, formParams, fileParams, pathParams, contentType);

            Assert.IsTrue(stopwatch.ElapsedMilliseconds >= 6000 && stopwatch.ElapsedMilliseconds < 6100, "It will wait for every 100 Mills and retry until 6 Seconds");
            Assert.AreEqual(429, (int)user.StatusCode);
            stopwatch.Stop();
        }
Exemplo n.º 3
0
        public async Task InvokeAsyncTestWith_504_And_No_MaxRetryTime()
        {
            var retryConfig = new ApiClient.RetryConfiguration
            {
                MaxRetryTimeSec = 0,
                RetryMax        = 50
            };

            var          mockRestClient = new Mock <IRestClient>();
            RestResponse response       = new RestResponse();

            response.StatusCode = (HttpStatusCode)504;

            mockRestClient.Setup(x => x.ExecuteTaskAsync(It.IsAny <RestRequest>())).Returns(Task.FromResult <IRestResponse>(response));

            var apiClient = new ApiClient(new PureCloudPlatform.Client.V2.Client.Configuration());

            apiClient.RetryConfig = retryConfig;
            apiClient.RestClient  = mockRestClient.Object;

            stopwatch = Stopwatch.StartNew();
            RestResponse user = (RestResponse)await apiClient.CallApiAsync(path, method, queryParams, postBody, headerParams, formParams, fileParams, pathParams, contentType);

            Assert.IsTrue(stopwatch.ElapsedMilliseconds >= 0 && stopwatch.ElapsedMilliseconds < 100, "Since maxRetryTime is not provided it will not retry even if the status code is 504");
            Assert.AreEqual(504, (int)user.StatusCode);
            stopwatch.Stop();
        }
Exemplo n.º 4
0
        public async Task InvokeAsyncTestWith_504()
        {
            var retryConfig = new ApiClient.RetryConfiguration
            {
                MaxRetryTimeSec     = 2,
                RetryAfterDefaultMs = 1000,
                RetryMax            = 50
            };

            var          mockRestClient = new Mock <IRestClient>();
            RestResponse response       = new RestResponse();

            response.StatusCode = (HttpStatusCode)504;

            mockRestClient.Setup(x => x.ExecuteTaskAsync(It.IsAny <RestRequest>())).Returns(Task.FromResult <IRestResponse>(response));

            var apiClient = new ApiClient(new PureCloudPlatform.Client.V2.Client.Configuration());

            apiClient.RetryConfig = retryConfig;
            apiClient.RestClient  = mockRestClient.Object;

            stopwatch = Stopwatch.StartNew();
            RestResponse user = (RestResponse)await apiClient.CallApiAsync(path, method, queryParams, postBody, headerParams, formParams, fileParams, pathParams, contentType);

            Assert.IsTrue(stopwatch.ElapsedMilliseconds >= 2000 && stopwatch.ElapsedMilliseconds < 2100, "It will wait for every 1 sec and retry for 2 times");
            Assert.AreEqual(504, (int)user.StatusCode);
            stopwatch.Stop();
        }
Exemplo n.º 5
0
        public async Task InvokeAsyncTestWith_429()
        {
            var retryConfig = new ApiClient.RetryConfiguration
            {
                MaxRetryTimeSec = 5,
                RetryMax        = 50
            };

            var          mockRestClient = new Mock <IRestClient>();
            RestResponse response       = GetTestResponse(429, "1");

            mockRestClient.Setup(x => x.ExecuteTaskAsync(It.IsAny <RestRequest>())).Returns(Task.FromResult <IRestResponse>(response));

            var apiClient = new ApiClient(new PureCloudPlatform.Client.V2.Client.Configuration());

            apiClient.RetryConfig = retryConfig;
            apiClient.RestClient  = mockRestClient.Object;

            stopwatch = Stopwatch.StartNew();
            RestResponse user = (RestResponse)await apiClient.CallApiAsync(path, method, queryParams, postBody, headerParams, formParams, fileParams, pathParams, contentType);

            Assert.IsTrue(stopwatch.ElapsedMilliseconds >= 5000 && stopwatch.ElapsedMilliseconds < 5100, "It will wait for every 1 Sec provided by Retry-After header Sec and retry for 5 Sec");
            Assert.AreEqual(429, (int)user.StatusCode);
            stopwatch.Stop();
        }
Exemplo n.º 6
0
        public void InvokeTestWith_503()
        {
            var retryConfig = new ApiClient.RetryConfiguration
            {
                MaxRetryTimeSec     = 40,
                RetryAfterDefaultMs = 200,
                BackOffIntervalMs   = 3000,
                RetryMax            = 50
            };

            var          mockRestClient = new Mock <IRestClient>();
            RestResponse response       = new RestResponse();

            response.StatusCode = (HttpStatusCode)503;

            mockRestClient.Setup(x => x.Execute(It.IsAny <RestRequest>())).Returns(response);

            var apiClient = new ApiClient(new PureCloudPlatform.Client.V2.Client.Configuration());

            apiClient.RetryConfig = retryConfig;
            apiClient.RestClient  = mockRestClient.Object;

            stopwatch = Stopwatch.StartNew();
            RestResponse user = (RestResponse)apiClient.CallApi(path, method, queryParams, postBody, headerParams, formParams, fileParams, pathParams, contentType);

            Assert.IsTrue(stopwatch.ElapsedMilliseconds >= 40000 && stopwatch.ElapsedMilliseconds < 40100, "It will wait for every 200 Mills and retry for 5 times then it will backoff for 3 Sec once, 9 Sec once and 27 Sec before retrying");
            Assert.AreEqual(503, (int)user.StatusCode);
            stopwatch.Stop();
        }