예제 #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);
        }
예제 #2
0
        private void RunToSuccessNormallyFromConcreteClass()
        {
            SampleIsolationCommand command = new SampleIsolationCommand(TestCommandKey, execute: () => Expected);

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

            Assert.AreEqual(Expected, actual);
        }
예제 #3
0
        private void RunToTimeoutNormallyFromConcreteClass()
        {
            SampleIsolationCommand command = new SampleIsolationCommand(TestCommandKey, expectedResult: Expected,
                                                                        sleepTimeInMilliseconds: TimeoutInMilliseconds + 2);

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

            Assert.AreEqual(Expected, actual);
        }
예제 #4
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)
     {
     }
 }
예제 #5
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);
     }
 }
예제 #6
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 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]);
            }
        }
예제 #8
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 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]);
            }
        }