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:
parent
e53d4c52d3
commit
b55d278cce
|
@ -89,7 +89,7 @@ public class ThresholdCircuitBreaker extends AbstractCircuitBreaker<Long> {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean checkState() {
|
public boolean checkState() {
|
||||||
return isOpen();
|
return !isOpen();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -42,7 +42,7 @@ public class ThresholdCircuitBreakerTest extends AbstractLangTest {
|
||||||
public void testThreshold() {
|
public void testThreshold() {
|
||||||
final ThresholdCircuitBreaker circuit = new ThresholdCircuitBreaker(threshold);
|
final ThresholdCircuitBreaker circuit = new ThresholdCircuitBreaker(threshold);
|
||||||
circuit.incrementAndCheckState(9L);
|
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() {
|
public void testThresholdCircuitBreakingException() {
|
||||||
final ThresholdCircuitBreaker circuit = new ThresholdCircuitBreaker(threshold);
|
final ThresholdCircuitBreaker circuit = new ThresholdCircuitBreaker(threshold);
|
||||||
circuit.incrementAndCheckState(9L);
|
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
|
@Test
|
||||||
public void testThresholdEqualsZero() {
|
public void testThresholdEqualsZero() {
|
||||||
final ThresholdCircuitBreaker circuit = new ThresholdCircuitBreaker(zeroThreshold);
|
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.incrementAndCheckState(9L);
|
||||||
circuit.close();
|
circuit.close();
|
||||||
// now the internal counter is back at zero, not 9 anymore. So it is safe to increment 9 again
|
// 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");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue