Exemplo n.º 1
0
        public void エラーコールバックを指定するとエラー時に呼ばれる()
        {
            // Arrange
            int retryCount = 3;
            int interval   = 100;

            // Act
            List <bool> tmpList = new List <bool>();

            int _count = 0;

            RetryHandler.Execute(retryCount, interval, () =>
            {
                tmpList.Add(true);
                throw new Exception();
            }, (info) =>
            {
                // Assert
                Assert.AreEqual <int>(info.RetryCount, ++_count);
                Assert.IsNotNull(info.Cause);
            });

            // Assert
            Assert.AreEqual <int>(4, tmpList.Count);
        }
Exemplo n.º 2
0
        public void エラーが発生していてもリトライ中に処理が成功したら例外は発生しない()
        {
            // Arrange
            int retryCount = 3;
            int interval   = 100;

            // Act
            List <bool> tmpList = new List <bool>();

            try
            {
                int count = 0;
                RetryHandler.Execute(retryCount, interval, () =>
                {
                    if (Interlocked.Increment(ref count) <= 3)
                    {
                        throw new Exception();
                    }

                    tmpList.Add(true);
                });
            }
            catch (RetryException ex)
            {
                // Assert
                Assert.Fail("例外が発生している");
            }

            // Assert
            Assert.AreEqual <int>(1, tmpList.Count);
        }
Exemplo n.º 3
0
        public void エラーコールバック内でリトライ停止設定するとリトライが中断される()
        {
            // Arrange
            int retryCount = 3;
            int interval   = 100;

            // Act
            List <bool> tmpList = new List <bool>();

            int _count = 0;

            RetryHandler.Execute(retryCount, interval, () =>
            {
                tmpList.Add(true);
                throw new Exception();
            }, (info) =>
            {
                // Assert
                Assert.AreEqual <int>(info.RetryCount, ++_count);
                Assert.IsNotNull(info.Cause);

                if (_count == 2)
                {
                    info.RetryStop = true;
                    return;
                }
            });

            // Assert
            Assert.AreEqual <int>(3, tmpList.Count);
        }
Exemplo n.º 4
0
        public void エラーが発生した場合指定された回数分リトライ処理を行う()
        {
            // Arrange
            int retryCount = 3;
            int interval   = 100;

            // Act
            List <bool> tmpList = new List <bool>();

            try
            {
                RetryHandler.Execute(retryCount, interval, () =>
                {
                    tmpList.Add(true);
                    throw new Exception();
                });
            }
            catch (RetryException ex)
            {
                // Assert
                Assert.AreEqual <int>(4, ex.ExceptionList.Count);
            }

            // Assert
            Assert.AreEqual <int>(4, tmpList.Count);
        }
Exemplo n.º 5
0
        public void エラーが無い状態だと一回だけ実行される()
        {
            // Arrange
            int retryCount = 3;
            int interval   = 500;

            // Act
            List <bool> tmpList = new List <bool>();

            RetryHandler.Execute(retryCount, interval, () =>
            {
                tmpList.Add(true);
            });

            // Assert
            Assert.AreEqual <int>(1, tmpList.Count);
        }