コード例 #1
0
        public void TestThrottlingWithRetryAfterHeader()
        {
            try
            {
                HttpResponseMessage responseMessage = new HttpResponseMessage(HttpStatusCode.ServiceUnavailable);
                responseMessage.Headers.RetryAfter = new RetryConditionHeaderValue(TimeSpan.FromSeconds(4));

                this.TestThrottlingBehaviorWithCustomStatusCode(
                    HttpStatusCode.ServiceUnavailable,
                    responseMessage);
            }
            catch (AggregateException e)
            {
                CallThrottledException throttledException = (CallThrottledException)e.InnerException;
                Assert.IsNotNull(throttledException);
                Assert.AreEqual(
                    3,
                    throttledException.RetryCount);

                // 3 * 4 seconds retrieved from Retry-After
                Assert.AreEqual(
                    12,
                    throttledException.TotalDelayApplied);

                throw;
            }
        }
コード例 #2
0
        public void TestThrottling503Behavior()
        {
            try
            {
                this.TestThrottlingBehaviorWithCustomStatusCode(HttpStatusCode.ServiceUnavailable);
                Assert.Fail("We shouldn't be here...");
            }
            catch (AggregateException e)
            {
                CallThrottledException throttledException = (CallThrottledException)e.InnerException;
                Assert.IsNotNull(throttledException);
                Assert.AreEqual(
                    3,
                    throttledException.RetryCount);

                Assert.AreEqual(
                    6,
                    throttledException.TotalDelayApplied);

                throw;
            }
        }