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); }
private void RunToSuccessNormallyFromConcreteClass() { SampleIsolationCommand command = new SampleIsolationCommand(TestCommandKey, execute: () => Expected); ScenarioTestHelper.SleepHealthSnapshotInverval(); string actual = command.Run(); Assert.AreEqual(Expected, actual); }
private void RunToTimeoutNormallyFromConcreteClass() { SampleIsolationCommand command = new SampleIsolationCommand(TestCommandKey, expectedResult: Expected, sleepTimeInMilliseconds: TimeoutInMilliseconds + 2); ScenarioTestHelper.SleepHealthSnapshotInverval(); string actual = command.Run(); Assert.AreEqual(Expected, actual); }
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) { } }
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); } }
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]); } }
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]); } }