gnodet-bot commented on code in PR #26603: URL: https://github.com/apache/camel/pull/26603#discussion_r4049788300
########## 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: ⚠️ **Missing test: timeout and bulkhead-rejected WITHOUT a fallback.** `testTimedOutCounter` exercises the timeout-with-fallback path (the `call()` method inside the fallback handler). The no-fallback path — the `catch (TimeoutException e)` block in `process()` — is not tested. Same gap exists for `BulkheadException` without a fallback. These are structurally separate code paths (`// the circuit breaker triggered a timeout (no fallback)` comment confirms this). A test that verifies `timedOutCalls` increments when no `onFallback` is configured would lock in the counter for both paths. Without it, a refactor that removed the counter from one path would pass CI silently. Suggested test (add alongside the existing three): ```java @Test public void testTimedOutWithoutFallbackCounter() throws Exception { // no onFallback — the TimeoutException propagates to the caller from("direct:slowNoFallback") .circuitBreaker().id("cbSlowNoFallback") .faultToleranceConfiguration().timeoutEnabled(true).timeoutDuration(200).end() .to("direct:slowService") .end(); Exchange result = template.request("direct:slowNoFallback", e -> e.getMessage().setBody("Hello World")); assertTrue(result.isFailed()); FaultToleranceProcessor cb = context.getProcessor("cbSlowNoFallback", FaultToleranceProcessor.class); assertEquals(1, cb.getNumberOfTimedOutCalls()); assertEquals(0, cb.getNumberOfFallbackCalls()); } ``` ########## 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: ⚠️ **Same gap as `FaultToleranceCallCountersTest`**: the no-fallback timeout and bulkhead paths are not covered. The `apply()` method in `ResilienceProcessor` has two branches: one for when no fallback is configured (`// there is no fallback`) and one for the fallback case. Only the fallback path is exercised by `testTimedOutCounter`. Add a companion test without `onFallback` to close the gap. -- 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]
