public void WaitTimes()
        {
            TimeSpan[] waitTimes = new TimeSpan[] {
                TimeSpan.FromSeconds(1),
                TimeSpan.FromSeconds(2),
                TimeSpan.FromSeconds(3),
                TimeSpan.FromSeconds(4),
                TimeSpan.FromSeconds(5),
                TimeSpan.FromSeconds(6),
                TimeSpan.FromSeconds(7),
                TimeSpan.FromSeconds(8),
                TimeSpan.FromSeconds(9),
            };
            LinearBackoffRetryStrategy strategy = new LinearBackoffRetryStrategy(9, TimeSpan.FromSeconds(1));

            Assert.That(strategy.RetryCount, Is.EqualTo(9));

            for (int i = 0; i < strategy.RetryCount; i++)
            {
                Assert.That(strategy.ShouldRetry(i + 1), Is.True, "Attempt " + (i + 1));
                Assert.That(strategy.GetWaitTime(i + 1), Is.EqualTo(waitTimes[i]), "Attempt " + (i + 1));
            }

            Assert.That(strategy.ShouldRetry(11), Is.False, "Attempt 11");
            Assert.Throws(Is.TypeOf<ArgumentOutOfRangeException>().And.Property("ParamName").EqualTo("attempt"),
              () => strategy.GetWaitTime(11));

            Assert.That(strategy.ShouldRetry(0), Is.False, "Attempt 0");
            Assert.Throws(Is.TypeOf<ArgumentOutOfRangeException>().And.Property("ParamName").EqualTo("attempt"),
              () => strategy.GetWaitTime(0));

            Assert.That(strategy.ShouldRetry(-1), Is.False, "Attempt -2");
            Assert.Throws(Is.TypeOf<ArgumentOutOfRangeException>().And.Property("ParamName").EqualTo("attempt"),
              () => strategy.GetWaitTime(-1));
        }
        public void WaitTimes()
        {
            TimeSpan inifiteWaitTime = TimeSpan.FromSeconds(3);

            TimeSpan[] waitTimes = new TimeSpan[] {
                TimeSpan.FromSeconds(1),
                TimeSpan.FromSeconds(2),
                TimeSpan.FromSeconds(3),
            };
            LinearBackoffRetryStrategy    baseStrategy = new LinearBackoffRetryStrategy(3, TimeSpan.FromSeconds(1));
            InfiniteRepeaterRetryStrategy strategy     = new InfiniteRepeaterRetryStrategy(baseStrategy);

            for (int i = 0; i < waitTimes.Length; i++)
            {
                Assert.That(strategy.ShouldRetry(i + 1), Is.True, "Attempt " + (i + 1));
                Assert.That(strategy.GetWaitTime(i + 1), Is.EqualTo(waitTimes[i]), "Attempt " + (i + 1));
            }

            Assert.That(strategy.GetWaitTime(4), Is.EqualTo(inifiteWaitTime), "Attempt 4");
            Assert.That(strategy.GetWaitTime(50), Is.EqualTo(inifiteWaitTime), "Attempt 50");
            Assert.That(strategy.GetWaitTime(600), Is.EqualTo(inifiteWaitTime), "Attempt 600");
            Assert.That(strategy.GetWaitTime(7000), Is.EqualTo(inifiteWaitTime), "Attempt 7000");
            Assert.That(strategy.GetWaitTime(9999999), Is.EqualTo(inifiteWaitTime), "Attempt 9999999");
            Assert.That(strategy.GetWaitTime(int.MaxValue), Is.EqualTo(inifiteWaitTime), "Attempt MaxValue");
        }
Exemplo n.º 3
0
        public void WaitTimes()
        {
            TimeSpan[] waitTimes = new TimeSpan[] {
                TimeSpan.FromSeconds(1),
                TimeSpan.FromSeconds(2),
                TimeSpan.FromSeconds(3),
                TimeSpan.FromSeconds(4),
                TimeSpan.FromSeconds(5),
                TimeSpan.FromSeconds(6),
                TimeSpan.FromSeconds(7),
                TimeSpan.FromSeconds(8),
                TimeSpan.FromSeconds(9),
            };
            LinearBackoffRetryStrategy strategy = new LinearBackoffRetryStrategy(9, TimeSpan.FromSeconds(1));

            Assert.That(strategy.RetryCount, Is.EqualTo(9));

            for (int i = 0; i < strategy.RetryCount; i++)
            {
                Assert.That(strategy.ShouldRetry(i + 1), Is.True, "Attempt " + (i + 1));
                Assert.That(strategy.GetWaitTime(i + 1), Is.EqualTo(waitTimes[i]), "Attempt " + (i + 1));
            }

            Assert.That(strategy.ShouldRetry(11), Is.False, "Attempt 11");
            Assert.Throws(Is.TypeOf <ArgumentOutOfRangeException>().And.Property("ParamName").EqualTo("attempt"),
                          () => strategy.GetWaitTime(11));

            Assert.That(strategy.ShouldRetry(0), Is.False, "Attempt 0");
            Assert.Throws(Is.TypeOf <ArgumentOutOfRangeException>().And.Property("ParamName").EqualTo("attempt"),
                          () => strategy.GetWaitTime(0));

            Assert.That(strategy.ShouldRetry(-1), Is.False, "Attempt -2");
            Assert.Throws(Is.TypeOf <ArgumentOutOfRangeException>().And.Property("ParamName").EqualTo("attempt"),
                          () => strategy.GetWaitTime(-1));
        }
        private void WaitTimes_SkippingFirstFew(int skip)
        {
            TimeSpan inifiteWaitTime = TimeSpan.FromSeconds(3);
            LinearBackoffRetryStrategy    baseStrategy = new LinearBackoffRetryStrategy(3, TimeSpan.FromSeconds(1));
            InfiniteRepeaterRetryStrategy strategy     = new InfiniteRepeaterRetryStrategy(baseStrategy);

            Assert.That(strategy.GetWaitTime(1), Is.EqualTo(TimeSpan.FromSeconds(1)), "Attempt 1");
            Assert.That(strategy.GetWaitTime(skip), Is.EqualTo(inifiteWaitTime), "Attempt " + skip);
            Assert.That(strategy.GetWaitTime(8), Is.EqualTo(inifiteWaitTime), "Attempt 8");
        }
        public void ShouldAttempt()
        {
            LinearBackoffRetryStrategy strategy = new LinearBackoffRetryStrategy(4, TimeSpan.FromSeconds(1));

            Assert.That(strategy.RetryCount, Is.EqualTo(4));

            Assert.That(strategy.ShouldRetry(-1), Is.False, "Attempt -1");
            Assert.That(strategy.ShouldRetry(0), Is.False, "Attempt 0");
            Assert.That(strategy.ShouldRetry(1), Is.True, "Attempt 1");
            Assert.That(strategy.ShouldRetry(2), Is.True, "Attempt 2");
            Assert.That(strategy.ShouldRetry(3), Is.True, "Attempt 3");
            Assert.That(strategy.ShouldRetry(4), Is.True, "Attempt 4");
            Assert.That(strategy.ShouldRetry(5), Is.False, "Attempt 5");
            Assert.That(strategy.ShouldRetry(6), Is.False, "Attempt 6");
        }
Exemplo n.º 6
0
        public void ShouldAttempt()
        {
            LinearBackoffRetryStrategy strategy = new LinearBackoffRetryStrategy(4, TimeSpan.FromSeconds(1));

            Assert.That(strategy.RetryCount, Is.EqualTo(4));

            Assert.That(strategy.ShouldRetry(-1), Is.False, "Attempt -1");
            Assert.That(strategy.ShouldRetry(0), Is.False, "Attempt 0");
            Assert.That(strategy.ShouldRetry(1), Is.True, "Attempt 1");
            Assert.That(strategy.ShouldRetry(2), Is.True, "Attempt 2");
            Assert.That(strategy.ShouldRetry(3), Is.True, "Attempt 3");
            Assert.That(strategy.ShouldRetry(4), Is.True, "Attempt 4");
            Assert.That(strategy.ShouldRetry(5), Is.False, "Attempt 5");
            Assert.That(strategy.ShouldRetry(6), Is.False, "Attempt 6");
        }
        public void ShouldAttempt()
        {
            LinearBackoffRetryStrategy baseStrategy = new LinearBackoffRetryStrategy(3, TimeSpan.FromSeconds(1));
            InfiniteRepeaterRetryStrategy strategy = new InfiniteRepeaterRetryStrategy(baseStrategy);

            Assert.That(strategy.ShouldRetry(-1), Is.False, "Attempt -1");
            Assert.That(strategy.ShouldRetry(0), Is.False, "Attempt 0");
            Assert.That(strategy.ShouldRetry(1), Is.True, "Attempt 1");
            Assert.That(strategy.ShouldRetry(2), Is.True, "Attempt 2");
            Assert.That(strategy.ShouldRetry(3), Is.True, "Attempt 3");
            Assert.That(strategy.ShouldRetry(4), Is.True, "Attempt 4");
            Assert.That(strategy.ShouldRetry(50), Is.True, "Attempt 50");
            Assert.That(strategy.ShouldRetry(600), Is.True, "Attempt 600");
            Assert.That(strategy.ShouldRetry(7000), Is.True, "Attempt 7000");
            Assert.That(strategy.ShouldRetry(9999999), Is.True, "Attempt 9999999");
            Assert.That(strategy.ShouldRetry(int.MaxValue), Is.True, "Attempt MaxValue");
        }
        public void ShouldAttempt()
        {
            LinearBackoffRetryStrategy    baseStrategy = new LinearBackoffRetryStrategy(3, TimeSpan.FromSeconds(1));
            InfiniteRepeaterRetryStrategy strategy     = new InfiniteRepeaterRetryStrategy(baseStrategy);

            Assert.That(strategy.ShouldRetry(-1), Is.False, "Attempt -1");
            Assert.That(strategy.ShouldRetry(0), Is.False, "Attempt 0");
            Assert.That(strategy.ShouldRetry(1), Is.True, "Attempt 1");
            Assert.That(strategy.ShouldRetry(2), Is.True, "Attempt 2");
            Assert.That(strategy.ShouldRetry(3), Is.True, "Attempt 3");
            Assert.That(strategy.ShouldRetry(4), Is.True, "Attempt 4");
            Assert.That(strategy.ShouldRetry(50), Is.True, "Attempt 50");
            Assert.That(strategy.ShouldRetry(600), Is.True, "Attempt 600");
            Assert.That(strategy.ShouldRetry(7000), Is.True, "Attempt 7000");
            Assert.That(strategy.ShouldRetry(9999999), Is.True, "Attempt 9999999");
            Assert.That(strategy.ShouldRetry(int.MaxValue), Is.True, "Attempt MaxValue");
        }
        public void WaitTimes()
        {
            TimeSpan inifiteWaitTime = TimeSpan.FromSeconds(3);
            TimeSpan[] waitTimes = new TimeSpan[] {
                TimeSpan.FromSeconds(1),
                TimeSpan.FromSeconds(2),
                TimeSpan.FromSeconds(3),
            };
            LinearBackoffRetryStrategy baseStrategy = new LinearBackoffRetryStrategy(3, TimeSpan.FromSeconds(1));
            InfiniteRepeaterRetryStrategy strategy = new InfiniteRepeaterRetryStrategy(baseStrategy);

            for (int i = 0; i < waitTimes.Length; i++)
            {
                Assert.That(strategy.ShouldRetry(i + 1), Is.True, "Attempt " + (i + 1));
                Assert.That(strategy.GetWaitTime(i + 1), Is.EqualTo(waitTimes[i]), "Attempt " + (i + 1));
            }

            Assert.That(strategy.GetWaitTime(4), Is.EqualTo(inifiteWaitTime), "Attempt 4");
            Assert.That(strategy.GetWaitTime(50), Is.EqualTo(inifiteWaitTime), "Attempt 50");
            Assert.That(strategy.GetWaitTime(600), Is.EqualTo(inifiteWaitTime), "Attempt 600");
            Assert.That(strategy.GetWaitTime(7000), Is.EqualTo(inifiteWaitTime), "Attempt 7000");
            Assert.That(strategy.GetWaitTime(9999999), Is.EqualTo(inifiteWaitTime), "Attempt 9999999");
            Assert.That(strategy.GetWaitTime(int.MaxValue), Is.EqualTo(inifiteWaitTime), "Attempt MaxValue");
        }
 public void SetUp()
 {
     strategy = new LinearBackoffRetryStrategy(5, 1.Seconds(), 4.Seconds(), 1.Seconds(), 0.0);
 }