davsclaus commented on code in PR #26603:
URL: https://github.com/apache/camel/pull/26603#discussion_r4049438050


##########
components/camel-microprofile/camel-microprofile-fault-tolerance/src/test/java/org/apache/camel/component/microprofile/faulttolerance/FaultToleranceCallCountersTest.java:
##########
@@ -0,0 +1,126 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.microprofile.faulttolerance;
+
+import org.apache.camel.RoutesBuilder;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.test.junit6.CamelTestSupport;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+/**
+ * The fallback, timed out and bulkhead rejected counters, which the circuit 
breaker listeners do not tell apart.
+ */
+public class FaultToleranceCallCountersTest extends CamelTestSupport {
+
+    @Test
+    public void testFallbackAndRejectedCounters() throws Exception {
+        getMockEndpoint("mock:down").expectedMessageCount(3);
+
+        // two failures open the breaker, the third call is rejected without 
being attempted
+        template.sendBody("direct:down", "Hello World");
+        template.sendBody("direct:down", "Hello World");
+        template.sendBody("direct:down", "Hello World");
+
+        MockEndpoint.assertIsSatisfied(context);
+
+        FaultToleranceProcessor cb = context.getProcessor("cbDown", 
FaultToleranceProcessor.class);
+        assertEquals(3, cb.getNumberOfFallbackCalls());
+        assertEquals(1, cb.getNumberOfNotPermittedCalls());
+        assertEquals(0, cb.getNumberOfTimedOutCalls());
+        assertEquals(0, cb.getNumberOfBulkheadRejectedCalls());
+
+        cb.transitionToCloseState();
+        assertEquals(0, cb.getNumberOfFallbackCalls());
+    }
+
+    @Test
+    public void testTimedOutCounter() throws Exception {
+        getMockEndpoint("mock:slow").expectedBodiesReceived("Fallback 
response");
+
+        template.sendBody("direct:slow", "Hello World");
+
+        MockEndpoint.assertIsSatisfied(context);
+
+        FaultToleranceProcessor cb = context.getProcessor("cbSlow", 
FaultToleranceProcessor.class);
+        assertEquals(1, cb.getNumberOfFallbackCalls());
+        assertEquals(1, cb.getNumberOfTimedOutCalls());
+        assertEquals(0, cb.getNumberOfNotPermittedCalls());
+    }
+
+    @Test
+    public void testBulkheadRejectedWithFallbackCounter() throws Exception {
+        getMockEndpoint("mock:bulkhead").expectedMessageCount(2);
+
+        // the first call holds the only bulkhead permit while it is slow,
+        // so the second call is rejected by the bulkhead and answered by the 
fallback
+        template.asyncSendBody("direct:bulkhead", "Hello World");
+        Thread.sleep(500);
+        template.sendBody("direct:bulkhead", "Hello World");
+
+        MockEndpoint.assertIsSatisfied(context);
+
+        FaultToleranceProcessor cb = context.getProcessor("cbBulkhead", 
FaultToleranceProcessor.class);
+        assertEquals(1, cb.getNumberOfBulkheadRejectedCalls(),
+                "the rejected call is counted from inside the fallback path");
+        assertEquals(1, cb.getNumberOfFallbackCalls());
+        assertEquals(0, cb.getNumberOfNotPermittedCalls());
+        assertEquals(0, cb.getNumberOfTimedOutCalls());
+    }
+
+    @Override
+    protected RoutesBuilder createRouteBuilder() {
+        return new RouteBuilder() {

Review Comment:
   Agreed, replaced the sleep with a `CountDownLatch` counted down by a 
`process` step inside the breaker, right before the slow call, and the test 
awaits it (5 s) before sending the second call. Same in 
`ResilienceCallCountersTest`. Both pass.



##########
dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/process/ListCircuitBreakerTest.java:
##########
@@ -78,6 +78,9 @@ void testShowsClosedCircuitBreaker() throws Exception {
             String output = printer.getOutput();
             assertTrue(output.contains("myCB"), "Should show circuit breaker 
ID");
             assertTrue(output.contains("CLOSED"), "Should show CLOSED state");
+            assertTrue(output.contains("FALLBACK"), "Should show FALLBACK 
column");
+            assertTrue(output.contains("TIMEOUT"), "Should show TIMEOUT 
column");

Review Comment:
   Done, `assertFalse` it is (the import was not there yet, added).



##########
components/camel-resilience4j/src/main/java/org/apache/camel/component/resilience4j/ResilienceProcessor.java:
##########
@@ -409,11 +429,14 @@ public String getCircuitBreakerState() {
         }
     }
 
-    @ManagedOperation(description = "Transitions the circuit breaker to CLOSED 
state.")
+    @ManagedOperation(description = "Transitions the circuit breaker to CLOSED 
state and resets the fallback, timed out and bulkhead rejected call counters.")

Review Comment:
   I left this as it is, on purpose. The three counters are totals since start, 
like the fault tolerance processor's success, failed and not-permitted 
counters, which are cleared by `transitionToCloseState` alone; 
`transitionToCloseState` is the one operation documented as a reset in both 
processors, so they stay in step. Clearing them on `transitionToOpenState` or 
`transitionToForcedOpenState` would hide exactly the history an operator 
forcing a breaker open wants to see, and a half-open trial is part of the same 
cycle. If a separate reset is wanted, a `resetCallCounters` operation is the 
cleaner way to add it, rather than tying it to state transitions.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to