Ejemplo n.º 1
0
        public void CustomBadRequestNotCauseCircuitBreakerOpen_CheckerThrowException()
        {
            HystrixCommandBase.RegisterCustomBadRequestExceptionChecker(WithExceptionCheckerName, IsBadRequestExceptionWithException);

            CommandComponents.ConfigSet.CircuitBreakerRequestCountThreshold = 2;
            int circuitBreakerCount = 0;

            for (int i = 0; i < 100; i++)
            {
                SampleIsolationCommand command = new SampleIsolationCommand(
                    TestCommandKey,
                    execute: () => { throw new ArgumentOutOfRangeException(); });
                try
                {
                    command.Run();
                }
                catch (ArgumentOutOfRangeException)
                {
                }
                catch (HystrixException)
                {
                }

                ScenarioTestHelper.SleepHealthSnapshotInverval();
                Dictionary <CommandExecutionEventEnum, int> counts = CommandComponents.Metrics.ToConcrete().GetExecutionEventDistribution();
                circuitBreakerCount += counts[CommandExecutionEventEnum.ShortCircuited];
            }

            Assert.AreNotEqual(0, circuitBreakerCount);
        }
Ejemplo n.º 2
0
        public void CircuitBreakerForceClosedIsFalseWithoutFallback()
        {
            CommandComponents.ConfigSet.ToConcrete().CircuitBreakerForceClosed = false;

            string expected = string.Empty;

            for (int i = 0; i < CommandComponents.ConfigSet.CircuitBreakerRequestCountThreshold; i++)
            {
                try
                {
                    ScenarioTestHelper.SleepHealthSnapshotInverval();
                    HystrixCommandBase.RunCommand <string>(TestCommandKey, () => { throw new ScenarioTestException(); });
                    Assert.Fail("Execution should throw exception.");
                }
                catch (ScenarioTestException)
                {
                }
            }

            try
            {
                ScenarioTestHelper.SleepHealthSnapshotInverval();
                HystrixCommandBase.RunCommand <string>(TestCommandKey, () => { throw new ScenarioTestException(); });
                Assert.Fail("Execution should throw exception.");
            }
            catch (HystrixException ex)
            {
                Assert.AreEqual(FailureTypeEnum.ShortCircuited, ex.FailureType);
            }
        }
Ejemplo n.º 3
0
        private void RunToSuccessNormally()
        {
            ScenarioTestHelper.SleepHealthSnapshotInverval();
            string actual = HystrixCommandBase.RunCommand <string>(TestCommandKey, () => Expected);

            Assert.AreEqual(Expected, actual);
        }
        public void Execution_Success()
        {
            SL.Config(TestCommandKey, TestGroupKey, TestDomain);
            for (int i = 0; i < DefaultConfigSet.CircuitBreakerRequestCountThreshold * 2; i++)
            {
                Assert.AreEqual(DefaultConfigSet.CommandMaxConcurrentCount, TestSemaphore.CurrentCount);
                using (SL instance = new SL(TestCommandKey, TestGroupKey, TestDomain))
                {
                    instance.StartExecution();
                    Assert.AreEqual(DefaultConfigSet.CommandMaxConcurrentCount - 1, TestSemaphore.CurrentCount);
                    instance.MarkSuccess();
                }
                Assert.AreEqual(DefaultConfigSet.CommandMaxConcurrentCount, TestSemaphore.CurrentCount);
            }

            CommandComponents.ConfigSet.InitTestHealthSnapshotInterval();
            for (int i = 0; i < DefaultConfigSet.CircuitBreakerRequestCountThreshold * 2; i++)
            {
                Assert.AreEqual(DefaultConfigSet.CommandMaxConcurrentCount, TestSemaphore.CurrentCount);
                using (SL instance = new SL(TestCommandKey, TestGroupKey, TestDomain))
                {
                    ScenarioTestHelper.SleepHealthSnapshotInverval();
                    instance.StartExecution();
                    Assert.AreEqual(DefaultConfigSet.CommandMaxConcurrentCount - 1, TestSemaphore.CurrentCount);
                    instance.MarkSuccess();
                }
                Assert.AreEqual(DefaultConfigSet.CommandMaxConcurrentCount, TestSemaphore.CurrentCount);
            }
        }
Ejemplo n.º 5
0
        private void TestErrorPercentageThresholdSetting100()
        {
            CommandComponents.ConfigSet.CircuitBreakerErrorThresholdPercentage = 100;

            for (int i = 0; i < 100; i++)
            {
                ScenarioTestHelper.SleepHealthSnapshotInverval();
                try
                {
                    HystrixCommandBase.RunCommand <string>(TestCommandKey, () => { throw new ScenarioTestException(); });
                    Assert.Fail("Execution should throw exception.");
                }
                catch (ScenarioTestException)
                {
                    if (i >= CommandComponents.ConfigSet.CircuitBreakerRequestCountThreshold)
                    {
                        Assert.Fail("Execution should throw HystrixException.");
                    }
                }
                catch (HystrixException ex)
                {
                    if (i < CommandComponents.ConfigSet.CircuitBreakerRequestCountThreshold)
                    {
                        Assert.Fail("Execution should throw ScenarioTestException.");
                    }
                    Assert.AreEqual(FailureTypeEnum.ShortCircuited, ex.FailureType);
                }
            }
        }
Ejemplo n.º 6
0
        public void CircuitBreakerForceClosedIsTrueWithoutFallback()
        {
            CommandComponents.ConfigSet.ToConcrete().CircuitBreakerForceClosed = true;

            for (int i = 0; i < CommandComponents.ConfigSet.CircuitBreakerRequestCountThreshold; i++)
            {
                try
                {
                    ScenarioTestHelper.SleepHealthSnapshotInverval();
                    HystrixCommandBase.RunCommand <string>(TestCommandKey, () => { throw new ScenarioTestException(); });
                    Assert.Fail("Execution should throw exception.");
                }
                catch (ScenarioTestException)
                {
                }
            }

            try
            {
                ScenarioTestHelper.SleepHealthSnapshotInverval();
                HystrixCommandBase.RunCommand <string>(TestCommandKey, () => { throw new ScenarioTestException(); });
                Assert.Fail("Execution should throw exception.");
            }
            catch (ScenarioTestException)
            {
            }
        }
Ejemplo n.º 7
0
        private void TestRequestCountThresholdSetting(int?setting = null)
        {
            if (setting.HasValue)
            {
                CommandComponents.ConfigSet.CircuitBreakerRequestCountThreshold = setting.Value;
            }
            else
            {
                setting = CommandComponents.ConfigSet.CircuitBreakerRequestCountThreshold;
            }

            for (int i = 0; i < setting.Value; i++)
            {
                ScenarioTestHelper.SleepHealthSnapshotInverval();
                try
                {
                    HystrixCommandBase.RunCommand <string>(TestCommandKey, () => { throw new ScenarioTestException(); });
                    Assert.Fail("Execution should throw exception.");
                }
                catch (ScenarioTestException)
                {
                }
            }

            ScenarioTestHelper.SleepHealthSnapshotInverval();
            try
            {
                HystrixCommandBase.RunCommand <string>(TestCommandKey, () => { throw new ScenarioTestException(); });
                Assert.Fail("Execution should throw exception.");
            }
            catch (HystrixException)
            {
            }
        }
Ejemplo n.º 8
0
        private void RunToTimeoutNormally()
        {
            ScenarioTestHelper.SleepHealthSnapshotInverval();
            string actual = HystrixCommandBase.RunCommand <string>(TestCommandKey, ExecuteTimeout);

            Assert.AreEqual(Expected, actual);
        }
Ejemplo n.º 9
0
        private void RunToSuccessNormallyFromConcreteClass()
        {
            SampleIsolationCommand command = new SampleIsolationCommand(TestCommandKey, execute: () => Expected);

            ScenarioTestHelper.SleepHealthSnapshotInverval();
            string actual = command.Run();

            Assert.AreEqual(Expected, actual);
        }
Ejemplo n.º 10
0
        private void RunToTimeoutNormallyFromConcreteClass()
        {
            SampleIsolationCommand command = new SampleIsolationCommand(TestCommandKey, expectedResult: Expected,
                                                                        sleepTimeInMilliseconds: TimeoutInMilliseconds + 2);

            ScenarioTestHelper.SleepHealthSnapshotInverval();
            string actual = command.Run();

            Assert.AreEqual(Expected, actual);
        }
Ejemplo n.º 11
0
        public void CircuitBreakerOpenCausedByTimeout()
        {
            int timeoutInMilliseconds = 10;

            CommandComponents.ConfigSet.CommandTimeoutInMilliseconds = timeoutInMilliseconds;

            string        expected = string.Empty;
            string        actual;
            Func <string> execute = () =>
            {
                Thread.Sleep(timeoutInMilliseconds + 2);
                return(expected);
            };

            for (int i = 0; i < CommandComponents.ConfigSet.CircuitBreakerRequestCountThreshold; i++)
            {
                ScenarioTestHelper.SleepHealthSnapshotInverval();
                actual = HystrixCommandBase.RunCommand <string>(TestCommandKey, execute);
                Assert.AreEqual(expected, actual);
            }

            for (int i = 0; i < 10; i++)
            {
                try
                {
                    ScenarioTestHelper.SleepHealthSnapshotInverval();
                    HystrixCommandBase.RunCommand <string>(TestCommandKey, execute);
                    var snapshot = CommandComponents.Metrics.GetExecutionEventDistribution();
                    Assert.Fail("Execution should throw exception.");
                }
                catch (HystrixException ex)
                {
                    Assert.AreEqual(FailureTypeEnum.ShortCircuited, ex.FailureType);
                }
            }

            Thread.Sleep(CommandComponents.ConfigSet.CircuitBreakerSleepWindowInMilliseconds + 1);
            actual = HystrixCommandBase.RunCommand <string>(TestCommandKey, execute);
            Assert.AreEqual(expected, actual);
            try
            {
                ScenarioTestHelper.SleepHealthSnapshotInverval();
                HystrixCommandBase.RunCommand <string>(TestCommandKey, execute);
                Assert.Fail("Execution should throw exception.");
            }
            catch (HystrixException ex)
            {
                Assert.AreEqual(FailureTypeEnum.ShortCircuited, ex.FailureType);
            }

            Thread.Sleep(CommandComponents.ConfigSet.CircuitBreakerSleepWindowInMilliseconds + 1);
            actual = HystrixCommandBase.RunCommand <string>(TestCommandKey, () => expected);
            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 12
0
 private void RunToExceptionNormally()
 {
     ScenarioTestHelper.SleepHealthSnapshotInverval();
     try
     {
         HystrixCommandBase.RunCommand <string>(TestCommandKey, () => { throw new ScenarioTestException(); });
         Assert.Fail("Execution should throw exception.");
     }
     catch (ScenarioTestException)
     {
     }
 }
Ejemplo n.º 13
0
 private void RunToTimeoutShortCircuited()
 {
     ScenarioTestHelper.SleepHealthSnapshotInverval();
     try
     {
         HystrixCommandBase.RunCommand <string>(TestCommandKey, ExecuteTimeout);
     }
     catch (HystrixException ex)
     {
         Assert.AreEqual(FailureTypeEnum.ShortCircuited, ex.FailureType);
     }
 }
Ejemplo n.º 14
0
 private void RunToExceptionShortCircuited()
 {
     ScenarioTestHelper.SleepHealthSnapshotInverval();
     try
     {
         HystrixCommandBase.RunCommand <string>(TestCommandKey, () => { throw new ScenarioTestException(); });
         Assert.Fail("Execution should throw exception.");
     }
     catch (HystrixException ex)
     {
         Assert.AreEqual(FailureTypeEnum.ShortCircuited, ex.FailureType);
     }
 }
        public void Execution_ShortCircuited_ByFailureAndTimeout()
        {
            SL.Config(TestCommandKey, TestGroupKey, TestDomain);
            CommandComponents.ConfigSet.InitTestHealthSnapshotInterval();
            CommandComponents.ConfigSet.CommandTimeoutInMilliseconds = TimeoutInMilliseconds;
            for (int i = 0; i < DefaultConfigSet.CircuitBreakerRequestCountThreshold; i++)
            {
                Assert.AreEqual(DefaultConfigSet.CommandMaxConcurrentCount, TestSemaphore.CurrentCount);
                using (SL instance = new SL(TestCommandKey))
                {
                    ScenarioTestHelper.SleepHealthSnapshotInverval();
                    instance.StartExecution();
                    Assert.AreEqual(DefaultConfigSet.CommandMaxConcurrentCount - 1, TestSemaphore.CurrentCount);
                    if (i % 2 == 0)
                    {
                        if (i % 4 == 0)
                        {
                            instance.MarkFailure();
                            continue;
                        }

                        Thread.Sleep(TimeoutInMilliseconds + 2);
                    }

                    instance.MarkSuccess();
                }
                Assert.AreEqual(DefaultConfigSet.CommandMaxConcurrentCount, TestSemaphore.CurrentCount);
            }

            try
            {
                Assert.AreEqual(DefaultConfigSet.CommandMaxConcurrentCount, TestSemaphore.CurrentCount);
                using (SL instance = new SL(TestCommandKey))
                {
                    ScenarioTestHelper.SleepHealthSnapshotInverval();
                    try
                    {
                        instance.StartExecution();
                        Assert.Fail("Short circuited exception should be thrown before.");
                    }
                    finally
                    {
                        Assert.AreEqual(DefaultConfigSet.CommandMaxConcurrentCount, TestSemaphore.CurrentCount);
                    }
                }
            }
            catch (HystrixException ex)
            {
                Assert.AreEqual(FailureTypeEnum.ShortCircuited, ex.FailureType);
            }
        }
Ejemplo n.º 16
0
        private void TestErrorPercentageThresholdSetting(int?setting = null)
        {
            if (setting.HasValue)
            {
                CommandComponents.ConfigSet.CircuitBreakerErrorThresholdPercentage = setting.Value;
            }
            else
            {
                setting = CommandComponents.ConfigSet.CircuitBreakerErrorThresholdPercentage;
            }

            if (setting.Value == 100)
            {
                TestErrorPercentageThresholdSetting100();
                return;
            }

            int errorCount   = setting.Value;
            int successCount = 100 - errorCount;

            for (int i = 0; i < successCount; i++)
            {
                ScenarioTestHelper.SleepHealthSnapshotInverval();
                HystrixCommandBase.RunCommand <string>(TestCommandKey, () => null);
            }

            for (int i = 0; i < errorCount; i++)
            {
                ScenarioTestHelper.SleepHealthSnapshotInverval();
                try
                {
                    HystrixCommandBase.RunCommand <string>(TestCommandKey, () => { throw new ScenarioTestException(); });
                    Assert.Fail("Execution should throw exception.");
                }
                catch (ScenarioTestException)
                {
                }
            }

            ScenarioTestHelper.SleepHealthSnapshotInverval();
            try
            {
                HystrixCommandBase.RunCommand <string>(TestCommandKey, () => null);
                Assert.Fail("Execution should throw exception.");
            }
            catch (HystrixException ex)
            {
                Assert.AreEqual(FailureTypeEnum.ShortCircuited, ex.FailureType);
            }
        }
Ejemplo n.º 17
0
 private void RunToExceptionNormallyFromConcreteClass()
 {
     ScenarioTestHelper.SleepHealthSnapshotInverval();
     try
     {
         SampleIsolationCommand command = new SampleIsolationCommand(TestCommandKey, execute: () => { throw new ScenarioTestException(); });
         ScenarioTestHelper.SleepHealthSnapshotInverval();
         command.Run();
         Assert.Fail("Execution should throw exception.");
     }
     catch (ScenarioTestException)
     {
     }
 }
Ejemplo n.º 18
0
 private void RunToTimeoutShortCircuitedFromConcreteClass()
 {
     ScenarioTestHelper.SleepHealthSnapshotInverval();
     try
     {
         SampleIsolationCommand command = new SampleIsolationCommand(TestCommandKey, sleepTimeInMilliseconds: TimeoutInMilliseconds + 2);
         ScenarioTestHelper.SleepHealthSnapshotInverval();
         command.Run();
         Assert.Fail("Execution should throw exception.");
     }
     catch (HystrixException ex)
     {
         Assert.AreEqual(FailureTypeEnum.ShortCircuited, ex.FailureType);
     }
 }
Ejemplo n.º 19
0
 private void RunToBadRequestExceptionShortCircuitedFromConcreteClass()
 {
     ScenarioTestHelper.SleepHealthSnapshotInverval();
     try
     {
         SampleIsolationCommand command = new SampleIsolationCommand(TestCommandKey, execute: () => { throw new BadRequestException(); });
         ScenarioTestHelper.SleepHealthSnapshotInverval();
         command.Run();
         Assert.Fail("Execution should throw exception.");
     }
     catch (HystrixException ex)
     {
         Assert.AreEqual(FailureTypeEnum.ShortCircuited, ex.FailureType);
     }
 }
 public void MarkBadRequest_RunOnce()
 {
     SL.Config(TestCommandKey, TestGroupKey, TestDomain);
     CommandComponents.ConfigSet.InitTestHealthSnapshotInterval();
     for (int i = 1; i <= DefaultConfigSet.CircuitBreakerRequestCountThreshold; i++)
     {
         using (SL instance = new SL(TestCommandKey))
         {
             instance.StartExecution();
             instance.MarkBadRequest();
             ScenarioTestHelper.SleepHealthSnapshotInverval();
             Dictionary <CommandExecutionEventEnum, int> counts = CommandComponents.Metrics.ToConcrete().GetExecutionEventDistribution();
             Assert.AreEqual(i, counts[CommandExecutionEventEnum.BadRequest]);
         }
     }
 }
Ejemplo n.º 21
0
        public void CircuitBreakerForceClosedIsFalseWithFallback()
        {
            CommandComponents.ConfigSet.ToConcrete().CircuitBreakerForceClosed = false;

            string fallback = null;
            string actual;

            for (int i = 0; i < CommandComponents.ConfigSet.CircuitBreakerRequestCountThreshold; i++)
            {
                ScenarioTestHelper.SleepHealthSnapshotInverval();
                actual = HystrixCommandBase.RunCommand <string>(TestCommandKey, () => { throw new ScenarioTestException(); }, () => fallback);
                Assert.AreEqual(fallback, actual);
            }

            ScenarioTestHelper.SleepHealthSnapshotInverval();
            actual = HystrixCommandBase.RunCommand <string>(TestCommandKey, () => { throw new ScenarioTestException(); }, () => fallback);
            Assert.AreEqual(fallback, actual);
        }
Ejemplo n.º 22
0
        public void BadRequestRecordBadRequestMetrics()
        {
            for (int i = 1; i <= 3; i++)
            {
                SampleIsolationCommand command = new SampleIsolationCommand(TestCommandKey, execute: () => { throw new BadRequestException(); });
                try
                {
                    command.Run();
                }
                catch (Exception ex)
                {
                    Assert.IsInstanceOfType(ex, typeof(BadRequestException));
                }

                ScenarioTestHelper.SleepHealthSnapshotInverval();
                Dictionary <CommandExecutionEventEnum, int> counts = CommandComponents.Metrics.ToConcrete().GetExecutionEventDistribution();
                Assert.AreEqual(i, counts[CommandExecutionEventEnum.BadRequest]);
            }
        }
Ejemplo n.º 23
0
        public void CircuitBreakerEnabledSettingIsFalse()
        {
            CommandComponents.ConfigSet.ToConcrete().CircuitBreakerEnabled = false;

            for (int i = 0; i < CommandComponents.ConfigSet.CircuitBreakerRequestCountThreshold * 3; i++)
            {
                ScenarioTestHelper.SleepHealthSnapshotInverval();
                Assert.AreEqual(false, CommandComponents.CircuitBreaker.IsOpen());
                Assert.AreEqual(true, CommandComponents.CircuitBreaker.AllowRequest());

                try
                {
                    HystrixCommandBase.RunCommand <string>(TestCommandKey, () => { throw new ScenarioTestException(); });
                    Assert.Fail("Execution should throw exception.");
                }
                catch (ScenarioTestException)
                {
                }
            }
        }
Ejemplo n.º 24
0
        public void CustomBadRequestRecordBadRequestMetrics()
        {
            HystrixCommandBase.RegisterCustomBadRequestExceptionChecker(NormalCheckerName, IsBadRequestException);

            for (int i = 1; i <= 3; i++)
            {
                SampleIsolationCommand command = new SampleIsolationCommand(TestCommandKey, execute: () => { throw new ArgumentOutOfRangeException(); });
                try
                {
                    command.Run();
                }
                catch (Exception ex)
                {
                    Assert.IsInstanceOfType(ex, typeof(ArgumentOutOfRangeException));
                }

                ScenarioTestHelper.SleepHealthSnapshotInverval();
                Dictionary <CommandExecutionEventEnum, int> counts = CommandComponents.Metrics.ToConcrete().GetExecutionEventDistribution();
                Assert.AreEqual(i, counts[CommandExecutionEventEnum.BadRequest]);
            }
        }
        public void MarkBadRequest_WithInstance()
        {
            SL.Config(TestCommandKey, TestGroupKey, TestDomain);
            CommandComponents.ConfigSet.InitTestHealthSnapshotInterval();
            object instance = SL.CreateInstance(TestCommandKey);

            Assert.AreEqual(CommandComponents.ConfigSet.CommandMaxConcurrentCount, TestSemaphore.CurrentCount);
            SL.StartExecution(instance);
            Assert.AreEqual(CommandComponents.ConfigSet.CommandMaxConcurrentCount - 1, TestSemaphore.CurrentCount);

            SL.MarkBadRequest(instance);
            Assert.AreEqual(CommandComponents.ConfigSet.CommandMaxConcurrentCount - 1, TestSemaphore.CurrentCount);

            ScenarioTestHelper.SleepHealthSnapshotInverval();
            Dictionary <CommandExecutionEventEnum, int> counts = CommandComponents.Metrics.ToConcrete().GetExecutionEventDistribution();

            Assert.AreEqual(1, counts[CommandExecutionEventEnum.BadRequest]);

            SL.EndExecution(instance);
            Assert.AreEqual(CommandComponents.ConfigSet.CommandMaxConcurrentCount, TestSemaphore.CurrentCount);
        }
Ejemplo n.º 26
0
        public void BadRequestNotCauseCircuitBreakerOpen()
        {
            CommandComponents.ConfigSet.CircuitBreakerRequestCountThreshold = 2;
            for (int i = 0; i < 100; i++)
            {
                SampleIsolationCommand command = new SampleIsolationCommand(
                    TestCommandKey,
                    execute: () => { throw new BadRequestException(); });
                try
                {
                    command.Run();
                }
                catch (Exception ex)
                {
                    Assert.IsInstanceOfType(ex, typeof(BadRequestException));
                }

                ScenarioTestHelper.SleepHealthSnapshotInverval();
                Dictionary <CommandExecutionEventEnum, int> counts = CommandComponents.Metrics.ToConcrete().GetExecutionEventDistribution();
                Assert.AreEqual(0, counts[CommandExecutionEventEnum.ShortCircuited]);
            }
        }
Ejemplo n.º 27
0
        private void TestSleepWindowSetting(int?setting = null, bool autoTestSuccess = true)
        {
            if (setting.HasValue)
            {
                CommandComponents.ConfigSet.ToConcrete().CircuitBreakerSleepWindowInMilliseconds = setting.Value;
            }
            else
            {
                setting = CommandComponents.ConfigSet.CircuitBreakerSleepWindowInMilliseconds;
            }

            int errorCount   = CommandComponents.ConfigSet.CircuitBreakerErrorThresholdPercentage;
            int successCount = 100 - errorCount;

            for (int i = 0; i < successCount; i++)
            {
                ScenarioTestHelper.SleepHealthSnapshotInverval();
                HystrixCommandBase.RunCommand <string>(TestCommandKey, () => null);
            }

            for (int i = 0; i < errorCount; i++)
            {
                ScenarioTestHelper.SleepHealthSnapshotInverval();
                try
                {
                    HystrixCommandBase.RunCommand <string>(TestCommandKey, () => { throw new ScenarioTestException(); });
                    Assert.Fail("Execution should throw exception.");
                }
                catch (ScenarioTestException)
                {
                }
            }

            ScenarioTestHelper.SleepHealthSnapshotInverval();
            try
            {
                HystrixCommandBase.RunCommand <string>(TestCommandKey, () => null);
                Assert.Fail("Execution should throw exception.");
            }
            catch (HystrixException ex)
            {
                Assert.AreEqual(FailureTypeEnum.ShortCircuited, ex.FailureType);
            }

            Thread.Sleep(CommandComponents.ConfigSet.CircuitBreakerSleepWindowInMilliseconds + 1);

            if (autoTestSuccess)
            {
                string result = HystrixCommandBase.RunCommand <string>(TestCommandKey, () => null);
                Assert.AreEqual(null, result);
                return;
            }

            try
            {
                HystrixCommandBase.RunCommand <string>(TestCommandKey, () => { throw new ScenarioTestException(); });
                Assert.Fail("Execution should throw exception.");
            }
            catch (ScenarioTestException)
            {
            }

            try
            {
                HystrixCommandBase.RunCommand <string>(TestCommandKey, () => { throw new ScenarioTestException(); });
                Assert.Fail("Execution should throw exception.");
            }
            catch (HystrixException ex)
            {
                Assert.AreEqual(FailureTypeEnum.ShortCircuited, ex.FailureType);
            }
        }
        public void Execution_ShortCircuited_AutoRecover_WithInstance()
        {
            SL.Config(TestCommandKey, TestGroupKey, TestDomain);
            CommandComponents.ConfigSet.InitTestHealthSnapshotInterval();
            for (int i = 0; i < DefaultConfigSet.CircuitBreakerRequestCountThreshold; i++)
            {
                Assert.AreEqual(DefaultConfigSet.CommandMaxConcurrentCount, TestSemaphore.CurrentCount);
                object instance = SL.CreateInstance(TestCommandKey);
                ScenarioTestHelper.SleepHealthSnapshotInverval();
                SL.StartExecution(instance);
                Assert.AreEqual(DefaultConfigSet.CommandMaxConcurrentCount - 1, TestSemaphore.CurrentCount);
                SL.MarkFailure(instance);
                SL.EndExecution(instance);
                Assert.AreEqual(DefaultConfigSet.CommandMaxConcurrentCount, TestSemaphore.CurrentCount);
            }

            for (int i = 0; i < 10; i++)
            {
                try
                {
                    Assert.AreEqual(DefaultConfigSet.CommandMaxConcurrentCount, TestSemaphore.CurrentCount);
                    object instance = SL.CreateInstance(TestCommandKey);
                    ScenarioTestHelper.SleepHealthSnapshotInverval();
                    try
                    {
                        SL.StartExecution(instance);
                        Assert.Fail("Short circuited exception should be thrown before.");
                    }
                    catch (HystrixException)
                    {
                        Assert.AreEqual(DefaultConfigSet.CommandMaxConcurrentCount, TestSemaphore.CurrentCount);
                        throw;
                    }
                }
                catch (HystrixException ex)
                {
                    Assert.AreEqual(FailureTypeEnum.ShortCircuited, ex.FailureType);
                }
            }

            Thread.Sleep(DefaultConfigSet.CircuitBreakerSleepWindowInMilliseconds + 10);

            {
                Assert.AreEqual(DefaultConfigSet.CommandMaxConcurrentCount, TestSemaphore.CurrentCount);
                object instance = SL.CreateInstance(TestCommandKey);
                ScenarioTestHelper.SleepHealthSnapshotInverval();
                SL.StartExecution(instance);
                Assert.AreEqual(DefaultConfigSet.CommandMaxConcurrentCount - 1, TestSemaphore.CurrentCount);
                SL.MarkFailure(instance);
                SL.EndExecution(instance);
                Assert.AreEqual(DefaultConfigSet.CommandMaxConcurrentCount, TestSemaphore.CurrentCount);
            }

            for (int i = 0; i < 10; i++)
            {
                try
                {
                    Assert.AreEqual(DefaultConfigSet.CommandMaxConcurrentCount, TestSemaphore.CurrentCount);
                    object instance = SL.CreateInstance(TestCommandKey);
                    ScenarioTestHelper.SleepHealthSnapshotInverval();
                    try
                    {
                        SL.StartExecution(instance);
                        Assert.Fail("Short circuited exception should be thrown before.");
                    }
                    catch (HystrixException)
                    {
                        Assert.AreEqual(DefaultConfigSet.CommandMaxConcurrentCount, TestSemaphore.CurrentCount);
                        throw;
                    }
                }
                catch (HystrixException ex)
                {
                    Assert.AreEqual(FailureTypeEnum.ShortCircuited, ex.FailureType);
                }
            }

            Thread.Sleep(DefaultConfigSet.CircuitBreakerSleepWindowInMilliseconds + 10);

            for (int i = 0; i < 10; i++)
            {
                Assert.AreEqual(DefaultConfigSet.CommandMaxConcurrentCount, TestSemaphore.CurrentCount);
                object instance = SL.CreateInstance(TestCommandKey);
                SL.StartExecution(instance);
                Assert.AreEqual(DefaultConfigSet.CommandMaxConcurrentCount - 1, TestSemaphore.CurrentCount);
                SL.MarkSuccess(instance);
                SL.EndExecution(instance);
                Assert.AreEqual(DefaultConfigSet.CommandMaxConcurrentCount, TestSemaphore.CurrentCount);
            }
        }