mirror of
https://github.com/apache/commons-lang.git
synced 2025-02-10 03:55:10 +00:00
LANG-1370 Fix EventCountCircuitBreaker increment batch
Fixes #incrementAndCheckState(Integer increment) by passing the increment downstream.
This commit is contained in:
parent
6049e77fdc
commit
7d061e33e5
@ -271,7 +271,7 @@ public boolean checkState() {
|
||||
@Override
|
||||
public boolean incrementAndCheckState(final Integer increment)
|
||||
throws CircuitBreakingException {
|
||||
return performStateCheck(1);
|
||||
return performStateCheck(increment);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -154,6 +154,21 @@ public void testOpeningWhenThresholdReached() {
|
||||
assertFalse("Closed", breaker.isClosed());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that the circuit breaker opens if all conditions are met when using
|
||||
* {@link EventCountCircuitBreaker#incrementAndCheckState(Integer increment)}.
|
||||
*/
|
||||
@Test
|
||||
public void testOpeningWhenThresholdReachedThroughBatch() {
|
||||
final long timeIncrement = NANO_FACTOR / OPENING_THRESHOLD - 1;
|
||||
final EventCountCircuitBreakerTestImpl breaker = new EventCountCircuitBreakerTestImpl(OPENING_THRESHOLD, 1,
|
||||
TimeUnit.SECONDS, CLOSING_THRESHOLD, 1, TimeUnit.SECONDS);
|
||||
long startTime = timeIncrement * (OPENING_THRESHOLD + 1);
|
||||
boolean open = !breaker.at(startTime).incrementAndCheckState(OPENING_THRESHOLD + 1);
|
||||
assertTrue("Not open", open);
|
||||
assertFalse("Closed", breaker.isClosed());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that an open circuit breaker does not close itself when the number of events
|
||||
* received is over the threshold.
|
||||
|
Loading…
x
Reference in New Issue
Block a user