예제 #1
0
        public void IntuitRetryPolicyConstructorTestWithNegativeRetryCount()
        {
            int      retryCount      = -1;
            TimeSpan initialInterval = TimeSpan.FromSeconds(1);
            TimeSpan increment       = TimeSpan.FromSeconds(1);

            try
            {
                IntuitRetryPolicy target = new IntuitRetryPolicy(retryCount, initialInterval, increment);
                Assert.Fail();
            }
            catch (ArgumentException)
            {
            }
        }
예제 #2
0
        public void ExecuteActionTestWithNonRetryException()
        {
            retryCount = 1;
            IntuitRetryPolicy target = new IntuitRetryPolicy(2, TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(2));
            Action            action = this.ThrowUnauthorizedAccessException;

            try
            {
                target.ExecuteAction(action);
                Assert.Fail();
            }
            catch (UnauthorizedAccessException ex)
            {
                Console.WriteLine(@"Message: {0}", ex.Message);
            }
        }
예제 #3
0
        public void IntuitRetryPolicyConstructorTestWitMaxBackoffNegative()
        {
            int      retryCount   = 1;
            TimeSpan minBackoff   = TimeSpan.FromSeconds(1);
            TimeSpan maxBackoff   = TimeSpan.FromSeconds(-1);
            TimeSpan deltaBackoff = TimeSpan.FromSeconds(1);

            try
            {
                IntuitRetryPolicy target = new IntuitRetryPolicy(retryCount, minBackoff, maxBackoff, deltaBackoff);
                Assert.Fail();
            }
            catch (ArgumentException)
            {
            }
        }
예제 #4
0
        public void ExecuteActionTestWithExtendedRetryException()
        {
            IntuitRetryPolicy target = new IntuitRetryPolicy(2, TimeSpan.FromSeconds(1));

            target.ExtendedRetryException = new ExtendedRetryUnauthorizedAccessException();
            Action action = this.ThrowUnauthorizedAccessException;

            try
            {
                target.ExecuteAction(action);
                Assert.Fail();
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(@"Message: {0}", ex.Message);
            }
        }
예제 #5
0
        public void ExecuteActionAsyncTestWithFixedRetryArgumentException()
        {
            retryCount = 1;

            IntuitRetryPolicy target    = new IntuitRetryPolicy(2, TimeSpan.FromSeconds(1));
            Exception         exception = null;

            try
            {
                target.ExecuteAction(
                    ac =>
                {
                    // Invoke the begin method of the asynchronous call.
                    this.BeginRequestForArgumentException(ac);
                },
                    ar =>
                {
                    // Invoke the end method of the asynchronous call.
                },
                    () =>
                {
                    // Action to perform if the asynchronous operation
                    // succeeded.
                },
                    e =>
                {
                    // Action to perform if the asynchronous operation
                    // failed after all the retries.
                    exception = e;
                });

                throw exception;
            }
            catch (RetryExceededException)
            {
                Assert.Fail();
            }
            catch (System.Exception ex)
            {
                if (!(ex is ArgumentException))
                {
                    Assert.Fail();
                }
            }
        }
예제 #6
0
        public void ExecuteActionTestWithTimeoutException()
        {
            try
            {
                IntuitRetryPolicy target = new IntuitRetryPolicy(0, TimeSpan.FromSeconds(1));
                target.ExecuteAction(
                    () =>
                {
                    // Invoke the begin method of the asynchronous call.
                    throw new TimeoutException();
                });

                Assert.Fail();
            }
            catch (RetryExceededException)
            {
            }
        }
예제 #7
0
        public void ExecuteActionAsyncTestWithFixedRetryExceededException()
        {
            retryCount = 1;
            Exception         exception = null;
            IntuitRetryPolicy target    = new IntuitRetryPolicy(2, TimeSpan.FromSeconds(1));

            try
            {
                target.ExecuteAction(
                    ac =>
                {
                    // Invoke the begin method of the asynchronous call.
                    this.BeginRequestForProtocolException(ac);
                },
                    ar =>
                {
                    // Invoke the end method of the asynchronous call.
                },
                    () =>
                {
                    // Action to perform if the asynchronous operation
                    // succeeded.
                },
                    e =>
                {
                    // Action to perform if the asynchronous operation
                    // failed after all the retries.
                    exception = e;
                });

                throw exception;
            }
            catch (RetryExceededException intuitRetryExceededException)
            {
                WebException webException = intuitRetryExceededException.InnerException as WebException;
                if (!((webException != null) && webException.Status == WebExceptionStatus.ProtocolError))
                {
                    Assert.Fail();
                }
            }
        }
예제 #8
0
        public void ExecuteActionTestWithFixedRetryExceededException()
        {
            retryCount = 1;

            IntuitRetryPolicy target = new IntuitRetryPolicy(2, TimeSpan.FromSeconds(1));
            Action            action = this.ThrowProtocolException;

            try
            {
                target.ExecuteAction(action);
                Assert.Fail();
            }
            catch (RetryExceededException intuitRetryExceededException)
            {
                WebException webException = intuitRetryExceededException.InnerException as WebException;
                if (!((webException != null) && webException.Status == WebExceptionStatus.ProtocolError))
                {
                    Assert.Fail();
                }
            }
        }
예제 #9
0
        public void ExecuteActionAsyncTestWithExtendedRetryException()
        {
            IntuitRetryPolicy target = new IntuitRetryPolicy(2, TimeSpan.FromSeconds(1));

            target.ExtendedRetryException = new ExtendedRetryUnauthorizedAccessException();
            Exception exception = null;

            try
            {
                target.ExecuteAction(
                    ac =>
                {
                    // Invoke the begin method of the asynchronous call.
                    this.BeginRequestForUnauthorizedException(ac);
                },
                    ar =>
                {
                    // Invoke the end method of the asynchronous call.
                },
                    () =>
                {
                    // Action to perform if the asynchronous operation
                    // succeeded.
                },
                    e =>
                {
                    // Action to perform if the asynchronous operation
                    // failed after all the retries.
                    exception = e;
                });

                throw exception;
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(@"Message: {0}", ex.Message);
                Assert.Fail();
            }
        }
예제 #10
0
        public void ExecuteActionAsyncTestWithExponentialBackoffRetryExceededException()
        {
            retryCount = 1;
            IntuitRetryPolicy target    = new IntuitRetryPolicy(2, TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(2), TimeSpan.FromSeconds(1));
            Exception         exception = null;

            try
            {
                target.ExecuteAction(
                    ac =>
                {
                    // Invoke the begin method of the asynchronous call.
                    this.BeginRequestForProtocolException(ac);
                },
                    ar =>
                {
                    // Invoke the end method of the asynchronous call.
                },
                    () =>
                {
                    // Action to perform if the asynchronous operation
                    // succeeded.
                },
                    e =>
                {
                    // Action to perform if the asynchronous operation
                    // failed after all the retries.
                    exception = e;
                });

                throw exception;
            }
            catch (RetryExceededException ex)
            {
                Console.WriteLine(@"Message: {0}", ex.Message);
                Assert.Fail();
            }
        }
예제 #11
0
        public void ExecuteActionAsyncTestWithIncrementalRetry()
        {
            retryCount = 1;
            IntuitRetryPolicy target    = new IntuitRetryPolicy(3, TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(2));
            Exception         exception = null;

            try
            {
                target.ExecuteAction(
                    ac =>
                {
                    // Invoke the begin method of the asynchronous call.
                    this.BeginRequestForProtocolException(ac);
                },
                    ar =>
                {
                    // Invoke the end method of the asynchronous call.
                },
                    () =>
                {
                    // Action to perform if the asynchronous operation
                    // succeeded.
                },
                    e =>
                {
                    // Action to perform if the asynchronous operation
                    // failed after all the retries.
                    exception = e;
                });

                throw exception;
            }
            catch (RetryExceededException)
            {
            }
        }
예제 #12
0
        public void ExecuteActionTestWithFixedRetryArgumentException()
        {
            retryCount = 1;

            IntuitRetryPolicy target = new IntuitRetryPolicy(2, TimeSpan.FromSeconds(1));
            Action            action = this.ThrowArgumentException;

            try
            {
                target.ExecuteAction(action);
                Assert.Fail();
            }
            catch (RetryExceededException)
            {
                Assert.Fail();
            }
            catch (System.Exception ex)
            {
                if (!(ex is ArgumentException))
                {
                    Assert.Fail();
                }
            }
        }
예제 #13
0
 public void IntuitRetryPolicyConstructorTestForFixed()
 {
     int               retryCount    = 0;
     TimeSpan          retryInterval = TimeSpan.FromSeconds(1);
     IntuitRetryPolicy target        = new IntuitRetryPolicy(retryCount, retryInterval);
 }