Ejemplo n.º 1
0
        public void ExponentialRetryWithParameterTest()
        {
            var    invocationCounter = 0;
            string data = string.Empty;
            var    sw   = new Stopwatch();

            var error = new Func <string, string>(s =>
            {
                invocationCounter++;
                data = s;
                throw new NotImplementedException();
            });

            var retry = new FaultTolerantFunc <string, string>(error, 5, new ExponentialRetryStrategy(1000));

            sw.Start();
            var success = retry.Invoke("myvalue");

            sw.Stop();

            Assert.AreEqual(5, invocationCounter);
            Assert.AreEqual(5, retry.Tries);
            Assert.IsNotNull(retry.Exception);
            Assert.IsTrue(sw.ElapsedMilliseconds >= 15000);
            Assert.IsTrue(sw.ElapsedMilliseconds < 15500);
            Assert.IsNull(success);
            Assert.AreEqual("myvalue", data);
        }
Ejemplo n.º 2
0
        public void LinearRetryTest()
        {
            int invocationCounter = 0;
            var sw = new Stopwatch();

            var error = new Func <int>(() =>
            {
                invocationCounter++;
                throw new NotImplementedException();
            });

            var retry = new FaultTolerantFunc <int>(error, 5);

            sw.Start();
            var result = retry.Invoke();

            sw.Stop();

            Assert.AreEqual(5, invocationCounter);
            Assert.AreEqual(5, retry.Tries);
            Assert.IsNotNull(retry.Exception);
            Assert.IsTrue(sw.ElapsedMilliseconds >= 4000);
            Assert.IsTrue(sw.ElapsedMilliseconds < 4500);
            Assert.AreEqual(0, result);
        }
Ejemplo n.º 3
0
        public void ExponentialRetryTest()
        {
            int invocationCounter = 0;
            var sw = new Stopwatch();

            var error = new Func <bool>(() =>
            {
                invocationCounter++;
                throw new NotImplementedException();
            });

            var retry = new FaultTolerantFunc <bool>(error, 5, new ExponentialRetryStrategy(1000));

            sw.Start();
            retry.Invoke();
            sw.Stop();

            Assert.AreEqual(5, invocationCounter);
            Assert.AreEqual(5, retry.Tries);
            Assert.IsNotNull(retry.Exception);
            Assert.IsTrue(sw.ElapsedMilliseconds >= 15000);
            Assert.IsTrue(sw.ElapsedMilliseconds < 15500);
        }