private static ITestRemoteService GetRemoteService(int numFailures, bool usingExceptionName, bool isDelay, TestSleepHandler testSleepHandler)
        {
            TestRemoteService remoteService = new TestRemoteService();

            remoteService.NumFailures = numFailures;
            ProxyFactory factory = new ProxyFactory(remoteService);

            RetryAdvice retryAdvice = new RetryAdvice(new RetryAdvice.SleepHandler(testSleepHandler.Sleep));

            if (usingExceptionName)
            {
                if (isDelay)
                {
                    retryAdvice.RetryExpression = "on exception name ArithmeticException retry 3x delay 1s";
                }
                else
                {
                    retryAdvice.RetryExpression = "on exception name ArithmeticException retry 3x rate (1*#n + 0.5)";
                }
            }
            else
            {
                if (isDelay)
                {
                    retryAdvice.RetryExpression = "on exception (#e is T(System.ArithmeticException)) retry 3x delay 1s";
                }
                else
                {
                    retryAdvice.RetryExpression = "on exception (#e is T(System.ArithmeticException)) retry 3x rate (1*#n + 0.5)";
                }
            }
            retryAdvice.AfterPropertiesSet();
            factory.AddAdvice(retryAdvice);
            ITestRemoteService rs = factory.GetProxy() as ITestRemoteService;

            Assert.IsNotNull(rs);
            return(rs);
        }
Exemplo n.º 2
0
        private static ITestRemoteService GetRemoteService(int numFailures, bool usingExceptionName, bool isDelay, TestSleepHandler testSleepHandler)
        {
            TestRemoteService remoteService = new TestRemoteService();
            remoteService.NumFailures = numFailures;
            ProxyFactory factory = new ProxyFactory(remoteService);

            RetryAdvice retryAdvice = new RetryAdvice(new RetryAdvice.SleepHandler(testSleepHandler.Sleep));
            if (usingExceptionName)
            {
                if (isDelay)
                {
                    retryAdvice.RetryExpression = "on exception name ArithmeticException retry 3x delay 1s";
                }
                else
                {
                    retryAdvice.RetryExpression = "on exception name ArithmeticException retry 3x rate (1*#n + 0.5)";
                }
            }
            else
            {
                if (isDelay)
                {
                    retryAdvice.RetryExpression = "on exception (#e is T(System.ArithmeticException)) retry 3x delay 1s";
                }
                else
                {
                    retryAdvice.RetryExpression = "on exception (#e is T(System.ArithmeticException)) retry 3x rate (1*#n + 0.5)";
                }
            }
            retryAdvice.AfterPropertiesSet();
            factory.AddAdvice(retryAdvice);
            ITestRemoteService rs = factory.GetProxy() as ITestRemoteService;
            Assert.IsNotNull(rs);
            return rs;
        }