This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-lang.git


The following commit(s) were added to refs/heads/master by this push:
     new b55d278cc Fix ThresholdCircuitBreaker (#1100)
b55d278cc is described below

commit b55d278cce19df99fd50f2ae800c5de2fc0991f7
Author: yichinzhu <7543516+yichin...@users.noreply.github.com>
AuthorDate: Sat Oct 7 22:38:10 2023 +0800

    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
---
 .../apache/commons/lang3/concurrent/ThresholdCircuitBreaker.java  | 2 +-
 .../commons/lang3/concurrent/ThresholdCircuitBreakerTest.java     | 8 ++++----
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git 
a/src/main/java/org/apache/commons/lang3/concurrent/ThresholdCircuitBreaker.java
 
b/src/main/java/org/apache/commons/lang3/concurrent/ThresholdCircuitBreaker.java
index 8cfd58e9a..7c6148c05 100644
--- 
a/src/main/java/org/apache/commons/lang3/concurrent/ThresholdCircuitBreaker.java
+++ 
b/src/main/java/org/apache/commons/lang3/concurrent/ThresholdCircuitBreaker.java
@@ -89,7 +89,7 @@ public class ThresholdCircuitBreaker extends 
AbstractCircuitBreaker<Long> {
      */
     @Override
     public boolean checkState() {
-        return isOpen();
+        return !isOpen();
     }
 
     /**
diff --git 
a/src/test/java/org/apache/commons/lang3/concurrent/ThresholdCircuitBreakerTest.java
 
b/src/test/java/org/apache/commons/lang3/concurrent/ThresholdCircuitBreakerTest.java
index c6a97fe44..be8a85e31 100644
--- 
a/src/test/java/org/apache/commons/lang3/concurrent/ThresholdCircuitBreakerTest.java
+++ 
b/src/test/java/org/apache/commons/lang3/concurrent/ThresholdCircuitBreakerTest.java
@@ -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");
     }
 
     /**

Reply via email to