Repository: commons-lang Updated Branches: refs/heads/master 6049e77fd -> dd2394323
LANG-1370 Fix EventCountCircuitBreaker increment batch Fixes #incrementAndCheckState(Integer increment) by passing the increment downstream. Project: http://git-wip-us.apache.org/repos/asf/commons-lang/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-lang/commit/7d061e33 Tree: http://git-wip-us.apache.org/repos/asf/commons-lang/tree/7d061e33 Diff: http://git-wip-us.apache.org/repos/asf/commons-lang/diff/7d061e33 Branch: refs/heads/master Commit: 7d061e33e59e23dc4b03378f35f50a7d70f033b3 Parents: 6049e77 Author: Andre Dieb Martins <[email protected]> Authored: Wed Nov 22 13:44:23 2017 -0500 Committer: Bruno P. Kinoshita <[email protected]> Committed: Sat Nov 25 21:32:52 2017 +1300 ---------------------------------------------------------------------- .../lang3/concurrent/EventCountCircuitBreaker.java | 2 +- .../concurrent/EventCountCircuitBreakerTest.java | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/commons-lang/blob/7d061e33/src/main/java/org/apache/commons/lang3/concurrent/EventCountCircuitBreaker.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/lang3/concurrent/EventCountCircuitBreaker.java b/src/main/java/org/apache/commons/lang3/concurrent/EventCountCircuitBreaker.java index b40213e..dd282dc 100644 --- a/src/main/java/org/apache/commons/lang3/concurrent/EventCountCircuitBreaker.java +++ b/src/main/java/org/apache/commons/lang3/concurrent/EventCountCircuitBreaker.java @@ -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); } /** http://git-wip-us.apache.org/repos/asf/commons-lang/blob/7d061e33/src/test/java/org/apache/commons/lang3/concurrent/EventCountCircuitBreakerTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/lang3/concurrent/EventCountCircuitBreakerTest.java b/src/test/java/org/apache/commons/lang3/concurrent/EventCountCircuitBreakerTest.java index 1c9e794..0053554 100644 --- a/src/test/java/org/apache/commons/lang3/concurrent/EventCountCircuitBreakerTest.java +++ b/src/test/java/org/apache/commons/lang3/concurrent/EventCountCircuitBreakerTest.java @@ -155,6 +155,21 @@ public class EventCountCircuitBreakerTest { } /** + * 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. */
