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


##########
components/camel-microprofile/camel-microprofile-fault-tolerance/src/test/java/org/apache/camel/component/microprofile/faulttolerance/FaultToleranceCallCountersTest.java:
##########
@@ -0,0 +1,133 @@
+/*
+ * 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 java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+
+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;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * The fallback, timed out and bulkhead rejected counters, which the circuit 
breaker listeners do not tell apart.
+ */
+public class FaultToleranceCallCountersTest extends CamelTestSupport {
+
+    private final CountDownLatch permitAcquired = new CountDownLatch(1);
+
+    @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);

Review Comment:
   Added `testTimedOutWithoutFallbackCounter` and 
`testBulkheadRejectedWithoutFallbackCounter` here, with routes that have no 
`onFallback`: the exchange fails, the timed out or bulkhead rejected counter is 
1 and `fallbackCalls` stays 0, so both branches are locked in. Five tests per 
class now, all passing.



##########
components/camel-resilience4j/src/test/java/org/apache/camel/component/resilience4j/ResilienceCallCountersTest.java:
##########
@@ -0,0 +1,134 @@
+/*
+ * 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.resilience4j;
+
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+
+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;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * The fallback, timed out and bulkhead rejected counters, which the circuit 
breaker metrics do not tell apart.
+ */
+public class ResilienceCallCountersTest extends CamelTestSupport {
+
+    private final CountDownLatch permitAcquired = new CountDownLatch(1);
+
+    @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);
+
+        ResilienceProcessor cb = context.getProcessor("cbDown", 
ResilienceProcessor.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);
+
+        ResilienceProcessor cb = context.getProcessor("cbSlow", 
ResilienceProcessor.class);
+        assertEquals(1, cb.getNumberOfFallbackCalls());
+        assertEquals(1, cb.getNumberOfTimedOutCalls());
+        assertEquals(0, cb.getNumberOfNotPermittedCalls());
+    }
+
+    @Test
+    public void testBulkheadRejectedWithFallbackCounter() throws Exception {
+        getMockEndpoint("mock:bulkhead").expectedMessageCount(2);

Review Comment:
   Added `testTimedOutWithoutFallbackCounter` and 
`testBulkheadRejectedWithoutFallbackCounter` here, with routes that have no 
`onFallback`: the exchange fails, the timed out or bulkhead rejected counter is 
1 and `fallbackCalls` stays 0, so both branches are locked in. Five tests per 
class now, all passing.



-- 
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