コード例 #1
0
            public void Keeps_The_Circuit_Closed_When_Closed()
            {
                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);

                circuitBreaker.OpenCircuit();
                Assert.True(circuitBreaker.CircuitIsOpen);
                circuitBreaker.CloseCircuit();
                Assert.False(circuitBreaker.CircuitIsOpen);

                // Act
                circuitBreaker.CloseCircuit();

                Assert.False(circuitBreaker.CircuitIsOpen);
            }
コード例 #2
0
            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);
            }