LANG-1370 Fix EventCountCircuitBreaker increment batch

Fixes #incrementAndCheckState(Integer increment) by passing the increment downstream.
This commit is contained in:
Andre Dieb Martins 2017-11-22 13:44:23 -05:00 committed by Bruno P. Kinoshita
parent 6049e77fdc
commit 7d061e33e5
2 changed files with 16 additions and 1 deletions

View File

@ -271,7 +271,7 @@ public class EventCountCircuitBreaker extends AbstractCircuitBreaker<Integer> {
@Override
public boolean incrementAndCheckState(final Integer increment)
throws CircuitBreakingException {
return performStateCheck(1);
return performStateCheck(increment);
}
/**

View File

@ -154,6 +154,21 @@ public class EventCountCircuitBreakerTest {
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.