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

davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/main by this push:
     new 9fa33b82b759 CAMEL-24133: Circuit Breaker EIP - Release correlated 
copy instead of original exchange in pooled mode (#24796)
9fa33b82b759 is described below

commit 9fa33b82b759c86132259a608cba4a3185079dce
Author: Claus Ibsen <[email protected]>
AuthorDate: Thu Jul 16 15:41:31 2026 +0200

    CAMEL-24133: Circuit Breaker EIP - Release correlated copy instead of 
original exchange in pooled mode (#24796)
    
    Co-Authored-By: Claude Opus 4.6 <[email protected]>
---
 .../faulttolerance/FaultToleranceProcessor.java    |  6 +-
 ...olerancePooledProcessorExchangeFactoryTest.java | 67 ++++++++++++++++++++++
 .../resilience4j/ResilienceProcessor.java          |  6 +-
 ...siliencePooledProcessorExchangeFactoryTest.java | 67 ++++++++++++++++++++++
 4 files changed, 142 insertions(+), 4 deletions(-)

diff --git 
a/components/camel-microprofile/camel-microprofile-fault-tolerance/src/main/java/org/apache/camel/component/microprofile/faulttolerance/FaultToleranceProcessor.java
 
b/components/camel-microprofile/camel-microprofile-fault-tolerance/src/main/java/org/apache/camel/component/microprofile/faulttolerance/FaultToleranceProcessor.java
index 072165aca2cb..018ebe5c9bb8 100644
--- 
a/components/camel-microprofile/camel-microprofile-fault-tolerance/src/main/java/org/apache/camel/component/microprofile/faulttolerance/FaultToleranceProcessor.java
+++ 
b/components/camel-microprofile/camel-microprofile-fault-tolerance/src/main/java/org/apache/camel/component/microprofile/faulttolerance/FaultToleranceProcessor.java
@@ -458,8 +458,10 @@ public class FaultToleranceProcessor extends 
BaseProcessorSupport
                 cause = exchange.getException();
             }
 
-            // and release exchange back in pool
-            processorExchangeFactory.release(exchange);
+            // and release correlated copy back in pool
+            if (copy != null) {
+                processorExchangeFactory.release(copy);
+            }
 
             if (cause != null) {
                 // throw exception so fault tolerance knows it was a failure
diff --git 
a/components/camel-microprofile/camel-microprofile-fault-tolerance/src/test/java/org/apache/camel/component/microprofile/faulttolerance/FaultTolerancePooledProcessorExchangeFactoryTest.java
 
b/components/camel-microprofile/camel-microprofile-fault-tolerance/src/test/java/org/apache/camel/component/microprofile/faulttolerance/FaultTolerancePooledProcessorExchangeFactoryTest.java
new file mode 100644
index 000000000000..27406fe2d298
--- /dev/null
+++ 
b/components/camel-microprofile/camel-microprofile-fault-tolerance/src/test/java/org/apache/camel/component/microprofile/faulttolerance/FaultTolerancePooledProcessorExchangeFactoryTest.java
@@ -0,0 +1,67 @@
+/*
+ * 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.TimeUnit;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.impl.engine.PooledExchangeFactory;
+import org.apache.camel.impl.engine.PooledProcessorExchangeFactory;
+import org.apache.camel.test.junit6.CamelTestSupport;
+import org.junit.jupiter.api.Test;
+
+public class FaultTolerancePooledProcessorExchangeFactoryTest extends 
CamelTestSupport {
+
+    @Override
+    protected CamelContext createCamelContext() throws Exception {
+        CamelContext context = super.createCamelContext();
+        context.getCamelContextExtension().setExchangeFactory(new 
PooledExchangeFactory());
+        context.getCamelContextExtension().setProcessorExchangeFactory(new 
PooledProcessorExchangeFactory());
+        return context;
+    }
+
+    @Test
+    public void testBodySurvivesCircuitBreaker() throws Exception {
+        getMockEndpoint("mock:result").expectedMinimumMessageCount(1);
+        getMockEndpoint("mock:result").allMessages().body().isEqualTo("Bye 
World");
+
+        context.getRouteController().startAllRoutes();
+
+        MockEndpoint.assertIsSatisfied(context, 30, TimeUnit.SECONDS);
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() {
+        return new RouteBuilder() {
+            @Override
+            public void configure() {
+                from("timer:foo?repeatCount=1").autoStartup(false)
+                        .setBody(constant("Hello World"))
+                        .circuitBreaker()
+                            .to("direct:foo")
+                        .end()
+                        .to("log:result")
+                        .to("mock:result");
+
+                from("direct:foo")
+                        .transform().constant("Bye World");
+            }
+        };
+    }
+}
diff --git 
a/components/camel-resilience4j/src/main/java/org/apache/camel/component/resilience4j/ResilienceProcessor.java
 
b/components/camel-resilience4j/src/main/java/org/apache/camel/component/resilience4j/ResilienceProcessor.java
index aa2e1c8dead5..6183d405c9d1 100644
--- 
a/components/camel-resilience4j/src/main/java/org/apache/camel/component/resilience4j/ResilienceProcessor.java
+++ 
b/components/camel-resilience4j/src/main/java/org/apache/camel/component/resilience4j/ResilienceProcessor.java
@@ -611,8 +611,10 @@ public class ResilienceProcessor extends 
BaseProcessorSupport
             cause = exchange.getException();
         }
 
-        // and release exchange back in pool
-        processorExchangeFactory.release(exchange);
+        // and release correlated copy back in pool
+        if (copy != null) {
+            processorExchangeFactory.release(copy);
+        }
 
         if (cause != null) {
             // throw exception so resilient4j know it was a failure
diff --git 
a/components/camel-resilience4j/src/test/java/org/apache/camel/component/resilience4j/ResiliencePooledProcessorExchangeFactoryTest.java
 
b/components/camel-resilience4j/src/test/java/org/apache/camel/component/resilience4j/ResiliencePooledProcessorExchangeFactoryTest.java
new file mode 100644
index 000000000000..2fc30e0502f2
--- /dev/null
+++ 
b/components/camel-resilience4j/src/test/java/org/apache/camel/component/resilience4j/ResiliencePooledProcessorExchangeFactoryTest.java
@@ -0,0 +1,67 @@
+/*
+ * 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.TimeUnit;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.impl.engine.PooledExchangeFactory;
+import org.apache.camel.impl.engine.PooledProcessorExchangeFactory;
+import org.apache.camel.test.junit6.CamelTestSupport;
+import org.junit.jupiter.api.Test;
+
+public class ResiliencePooledProcessorExchangeFactoryTest extends 
CamelTestSupport {
+
+    @Override
+    protected CamelContext createCamelContext() throws Exception {
+        CamelContext context = super.createCamelContext();
+        context.getCamelContextExtension().setExchangeFactory(new 
PooledExchangeFactory());
+        context.getCamelContextExtension().setProcessorExchangeFactory(new 
PooledProcessorExchangeFactory());
+        return context;
+    }
+
+    @Test
+    public void testBodySurvivesCircuitBreaker() throws Exception {
+        getMockEndpoint("mock:result").expectedMinimumMessageCount(1);
+        getMockEndpoint("mock:result").allMessages().body().isEqualTo("Bye 
World");
+
+        context.getRouteController().startAllRoutes();
+
+        MockEndpoint.assertIsSatisfied(context, 30, TimeUnit.SECONDS);
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() {
+        return new RouteBuilder() {
+            @Override
+            public void configure() {
+                from("timer:foo?repeatCount=1").autoStartup(false)
+                        .setBody(constant("Hello World"))
+                        .circuitBreaker()
+                            .to("direct:foo")
+                        .end()
+                        .to("log:result")
+                        .to("mock:result");
+
+                from("direct:foo")
+                        .transform().constant("Bye World");
+            }
+        };
+    }
+}

Reply via email to