public void Test_retry_interceptor()
        {
            var counter = new Counter();
            var a       = new SimpleInterceptor(counter);
            var b       = new RetryInterceptor(10);
            var c       = new SimpleInterceptor(counter);

            var inv = new TestInvocation();

            Assert.AreEqual(0, inv.ProceedCount);
            Assert.AreEqual(0, inv.InvokeCount);

            var chain = new AopInterceptorChain(new IInterceptor[] { a, b, c });

            chain.Intercept(inv);

            // check invocation ultimately invoked 10 times, but NOT via the Proceed() method
            Assert.AreEqual(0, inv.ProceedCount);
            Assert.AreEqual(10, inv.InvokeCount);

            // check each interceptor called correct number of times
            Assert.AreEqual(1, a.InterceptCount);
            Assert.AreEqual(1, b.InterceptCount);
            Assert.AreEqual(10, c.InterceptCount);
        }
Пример #2
0
        public async Task Invoke_WithFailingRetryCall_ShouldHaveCorrectNumberOfCalls(int maxAttempts)
        {
            var callCount   = 0;
            var interceptor = new RetryInterceptor <object>(
                this.context,
                new RetryOptions(TimeSpan.FromMilliseconds(1), maxAttempts),
                () =>
            {
                callCount++;
                throw new Exception();
            });

            try
            {
                await interceptor.Invoke();
            }
            catch
            {
                // ignored
            }

            Assert.AreEqual(maxAttempts, callCount, 0, $"There should be {maxAttempts} function calls for {maxAttempts} max attempts.");
        }
Пример #3
0
		public void Test_retry_interceptor()
		{
			var counter = new Counter();
			var a = new SimpleInterceptor(counter);
			var b = new RetryInterceptor(10);
			var c = new SimpleInterceptor(counter);

			var inv = new TestInvocation();

			Assert.AreEqual(0, inv.ProceedCount);
			Assert.AreEqual(0, inv.InvokeCount);

			var chain = new AopInterceptorChain(new IInterceptor[] { a, b, c });
			chain.Intercept(inv);

			// check invocation ultimately invoked 10 times, but NOT via the Proceed() method
			Assert.AreEqual(0, inv.ProceedCount);
			Assert.AreEqual(10, inv.InvokeCount);

			// check each interceptor called correct number of times
			Assert.AreEqual(1, a.InterceptCount);
			Assert.AreEqual(1, b.InterceptCount);
			Assert.AreEqual(10, c.InterceptCount);
		}