public void IsBadRequestException_NonCustomBadRequestException() { HystrixCommandBase.RegisterCustomBadRequestExceptionChecker("custom", ex => ex is IndexOutOfRangeException); Exception ex2 = new Exception(); Assert.IsFalse(ex2.IsBadRequestException()); }
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); }
public void RegisterCustomBadRequestExceptionChecker_MultiAddWithSameNameOnlyUseTheFirstAddAndIngoreTheLatters() { HystrixCommandBase.RegisterCustomBadRequestExceptionChecker(NormalCheckerName, IsBadRequestException); HystrixCommandBase.RegisterCustomBadRequestExceptionChecker(NormalCheckerName, IsBadRequestExceptionWithException); Assert.AreNotEqual(IsBadRequestException, IsBadRequestExceptionWithException); Assert.AreEqual(IsBadRequestException, CustomBadRequestExceptionChecker.BadRequestExceptionCheckers[NormalCheckerName]); Assert.AreNotEqual(IsBadRequestExceptionWithException, CustomBadRequestExceptionChecker.BadRequestExceptionCheckers[NormalCheckerName]); }
public void RegisterCustomBadRequestExceptionChecker_IgnoreNameCase() { HystrixCommandBase.RegisterCustomBadRequestExceptionChecker(NormalCheckerName, IsBadRequestException); Assert.AreEqual(1, CustomBadRequestExceptionChecker.BadRequestExceptionCheckers.Count); Assert.AreEqual(IsBadRequestException, CustomBadRequestExceptionChecker.BadRequestExceptionCheckers[NormalCheckerName]); Assert.AreEqual(CustomBadRequestExceptionChecker.BadRequestExceptionCheckers[NormalCheckerName], CustomBadRequestExceptionChecker.BadRequestExceptionCheckers[NormalCheckerName.ToUpper()]); Assert.AreEqual(CustomBadRequestExceptionChecker.BadRequestExceptionCheckers[NormalCheckerName], CustomBadRequestExceptionChecker.BadRequestExceptionCheckers[NormalCheckerName.ToLower()]); }
public void CustomBadRequestExecuteFallback() { HystrixCommandBase.RegisterCustomBadRequestExceptionChecker(NormalCheckerName, IsBadRequestException); SampleHasFallbackIsolationCommand command = new SampleHasFallbackIsolationCommand( TestCommandKey, execute: () => { throw new ArgumentOutOfRangeException(); }, fallback: () => string.Empty); command.Run(); }
public void RegisterCustomBadRequestExceptionChecker_AddCustomCheckerSuccess() { Assert.AreEqual(0, CustomBadRequestExceptionChecker.BadRequestExceptionCheckers.Count); HystrixCommandBase.RegisterCustomBadRequestExceptionChecker(NormalCheckerName, IsBadRequestException); Assert.AreEqual(1, CustomBadRequestExceptionChecker.BadRequestExceptionCheckers.Count); Assert.AreEqual(IsBadRequestException, CustomBadRequestExceptionChecker.BadRequestExceptionCheckers[NormalCheckerName]); HystrixCommandBase.RegisterCustomBadRequestExceptionChecker(WithExceptionCheckerName, IsBadRequestExceptionWithException); Assert.AreEqual(2, CustomBadRequestExceptionChecker.BadRequestExceptionCheckers.Count); Assert.AreEqual(IsBadRequestException, CustomBadRequestExceptionChecker.BadRequestExceptionCheckers[NormalCheckerName]); Assert.AreEqual(IsBadRequestExceptionWithException, CustomBadRequestExceptionChecker.BadRequestExceptionCheckers[WithExceptionCheckerName]); }
public void CustomBadRequestNotExecuteFallback_CheckerThrowException() { HystrixCommandBase.RegisterCustomBadRequestExceptionChecker(WithExceptionCheckerName, IsBadRequestExceptionWithException); SampleHasFallbackIsolationCommand command = new SampleHasFallbackIsolationCommand( TestCommandKey, execute: () => { throw new ArgumentOutOfRangeException(); }, fallback: () => string.Empty); string result = command.Run(); Assert.AreEqual(string.Empty, result); }
public void RegisterCustomBadRequestExceptionChecker_NullNameParameterCausesArgumentNullException() { List <string> nullNames = new List <string>() { null, string.Empty, " ", "\t", "\n" }; foreach (string name in nullNames) { try { HystrixCommandBase.RegisterCustomBadRequestExceptionChecker(name, IsBadRequestException); Assert.Fail("ArgumentNullException should be thrown before this."); } catch (Exception ex) { Assert.IsInstanceOfType(ex, typeof(ArgumentNullException), "Exception should be ArgumentNullException"); } } }
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 CustomBadRequestNotCauseCircuitBreakerOpen() { HystrixCommandBase.RegisterCustomBadRequestExceptionChecker(NormalCheckerName, IsBadRequestException); CommandComponents.ConfigSet.CircuitBreakerRequestCountThreshold = 2; for (int i = 0; i < 100; 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(0, counts[CommandExecutionEventEnum.ShortCircuited]); } }
public void RegisterCustomBadRequestExceptionChecker_NullCheckerParameterCausesArgumentNullException() { HystrixCommandBase.RegisterCustomBadRequestExceptionChecker(NormalCheckerName, null); }