public void Keeps_The_Circuit_Closed_When_Closed() { var dateTimeProvider = new Mock <IDateTimeProvider>(); var commandIdentifier = new HystrixCommandIdentifier("group", "key"); var configurationServiceMock = new Mock <IHystrixConfigurationService>(); var commandMetricsMock = new Mock <IHystrixCommandMetrics>(); var circuitBreaker = new HystrixCircuitBreaker(dateTimeProvider.Object, commandIdentifier, configurationServiceMock.Object, commandMetricsMock.Object); circuitBreaker.OpenCircuit(); Assert.True(circuitBreaker.CircuitIsOpen); circuitBreaker.CloseCircuit(); Assert.False(circuitBreaker.CircuitIsOpen); // Act circuitBreaker.CloseCircuit(); Assert.False(circuitBreaker.CircuitIsOpen); }
public void Returns_True_When_Circuit_Has_Been_Closed_After_Being_Open() { var commandIdentifier = new HystrixCommandIdentifier("group", "key"); var configurationServiceMock = new Mock <IHystrixConfigurationService>(); var commandMetricsMock = new Mock <IHystrixCommandMetrics>(); var circuitBreaker = new HystrixCircuitBreaker(commandIdentifier, configurationServiceMock.Object, commandMetricsMock.Object); commandMetricsMock.Setup(collector => collector.GetHealthCounts()).Returns(new HystrixHealthCounts(100, 16, 16)); configurationServiceMock.Setup(service => service.GetCircuitBreakerErrorThresholdPercentage()).Returns(17); circuitBreaker.OpenCircuit(); circuitBreaker.CloseCircuit(); // Act bool allowRequest = circuitBreaker.AllowRequest(); Assert.True(allowRequest); }
public void Returns_True_When_Circuit_Is_Open_But_Request_Is_First_After_GetCircuitBreakerSleepWindowInMilliseconds() { var dateTimeProviderMock = new Mock <IDateTimeProvider>(); var commandIdentifier = new HystrixCommandIdentifier("group", "key"); var configurationServiceMock = new Mock <IHystrixConfigurationService>(); var commandMetricsMock = new Mock <IHystrixCommandMetrics>(); var circuitBreaker = new HystrixCircuitBreaker(dateTimeProviderMock.Object, commandIdentifier, configurationServiceMock.Object, commandMetricsMock.Object); dateTimeProviderMock.Setup(time => time.CurrentTimeInMilliseconds).Returns(0); circuitBreaker.OpenCircuit(); configurationServiceMock.Setup(service => service.GetCircuitBreakerSleepWindowInMilliseconds()).Returns(5000); dateTimeProviderMock.Setup(time => time.CurrentTimeInMilliseconds).Returns(6000); // Act bool allowRequest = circuitBreaker.AllowRequest(); Assert.True(allowRequest); }