Fix ThresholdCircuitBreaker (#1100)

* Fix ThresholdCircuitBreaker checkState bug

According to the document, checkState() should return `true` if the circuit breaker is currently closed。

* Update ThresholdCircuitBreakerTest.java

Fix threshold circuitbreaker unit test
This commit is contained in:
yichinzhu 2023-10-07 22:38:10 +08:00 committed by GitHub
parent e53d4c52d3
commit b55d278cce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 5 deletions

View File

@ -89,7 +89,7 @@ public class ThresholdCircuitBreaker extends AbstractCircuitBreaker<Long> {
*/
@Override
public boolean checkState() {
return isOpen();
return !isOpen();
}
/**

View File

@ -42,7 +42,7 @@ public class ThresholdCircuitBreakerTest extends AbstractLangTest {
public void testThreshold() {
final ThresholdCircuitBreaker circuit = new ThresholdCircuitBreaker(threshold);
circuit.incrementAndCheckState(9L);
assertFalse(circuit.incrementAndCheckState(1L), "Circuit opened before reaching the threshold");
assertTrue(circuit.incrementAndCheckState(1L), "Circuit opened before reaching the threshold");
}
/**
@ -52,7 +52,7 @@ public class ThresholdCircuitBreakerTest extends AbstractLangTest {
public void testThresholdCircuitBreakingException() {
final ThresholdCircuitBreaker circuit = new ThresholdCircuitBreaker(threshold);
circuit.incrementAndCheckState(9L);
assertTrue(circuit.incrementAndCheckState(2L), "The circuit was supposed to be open after increment above the threshold");
assertFalse(circuit.incrementAndCheckState(2L), "The circuit was supposed to be open after increment above the threshold");
}
/**
@ -61,7 +61,7 @@ public class ThresholdCircuitBreakerTest extends AbstractLangTest {
@Test
public void testThresholdEqualsZero() {
final ThresholdCircuitBreaker circuit = new ThresholdCircuitBreaker(zeroThreshold);
assertTrue(circuit.incrementAndCheckState(0L), "When the threshold is zero, the circuit is supposed to be always open");
assertFalse(circuit.incrementAndCheckState(0L), "When the threshold is zero, the circuit is supposed to be always open");
}
/**
@ -73,7 +73,7 @@ public class ThresholdCircuitBreakerTest extends AbstractLangTest {
circuit.incrementAndCheckState(9L);
circuit.close();
// now the internal counter is back at zero, not 9 anymore. So it is safe to increment 9 again
assertFalse(circuit.incrementAndCheckState(9L), "Internal counter was not reset back to zero");
assertTrue(circuit.incrementAndCheckState(9L), "Internal counter was not reset back to zero");
}
/**