Croway commented on code in PR #26553: URL: https://github.com/apache/camel/pull/26553#discussion_r4038698294
########## core/camel-core/src/test/java/org/apache/camel/processor/PooledExchangeSplitLeakTest.java: ########## @@ -0,0 +1,74 @@ +/* + * 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.processor; + +import java.util.List; + +import org.apache.camel.CamelContext; +import org.apache.camel.ContextTestSupport; +import org.apache.camel.ExtendedCamelContext; +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.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertNull; + +public class PooledExchangeSplitLeakTest extends ContextTestSupport { + + @Override + protected CamelContext createCamelContext() throws Exception { + CamelContext camelContext = super.createCamelContext(); + ExtendedCamelContext ecc = camelContext.getCamelContextExtension(); + ecc.setExchangeFactory(new PooledExchangeFactory()); + ecc.setProcessorExchangeFactory(new PooledProcessorExchangeFactory()); + return camelContext; + } + + @Test + public void testSplitChildrenDoNotLeakStateBetweenMessages() throws Exception { + MockEndpoint mock = getMockEndpoint("mock:split"); + mock.expectedMessageCount(2); + + template.sendBody("direct:start", List.of("first")); + template.sendBody("direct:start", List.of("second")); + + mock.assertIsSatisfied(); + + // the child of the second message is a reused pooled exchange; it must not carry the first child's state + assertNull(mock.getExchanges().get(1).getProperty("leakProp")); + assertNull(mock.getExchanges().get(1).getVariable("leak")); + } + + @Override Review Comment: Done in 1f9f43b261bb: the test now asserts the first child carries both the property and the variable before asserting the second child has neither. Kept JUnit assertions since camel-core tests use them throughout (1652 files vs 56 with AssertJ), per the project's no-mixing rule. _Claude Code on behalf of Croway_ -- 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]
