gnodet-bot commented on code in PR #26850: URL: https://github.com/apache/camel/pull/26850#discussion_r4093166670
########## core/camel-core/src/test/java/org/apache/camel/processor/enricher/EnricherResourceCompletionTest.java: ########## @@ -0,0 +1,122 @@ +/* + * 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.enricher; + +import java.util.Map; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicInteger; + +import org.apache.camel.AggregationStrategy; +import org.apache.camel.Consumer; +import org.apache.camel.ContextTestSupport; +import org.apache.camel.Endpoint; +import org.apache.camel.Exchange; +import org.apache.camel.Processor; +import org.apache.camel.Producer; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.support.DefaultComponent; +import org.apache.camel.support.DefaultEndpoint; +import org.apache.camel.support.DefaultProducer; +import org.apache.camel.support.SynchronizationAdapter; +import org.junit.jupiter.api.Test; + +import static org.awaitility.Awaitility.await; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; + +/** + * The on completions registered on the resource exchange (for example to close a response stream) run when the enrich + * fails, both when the resource fails and when the aggregation fails. + */ +public class EnricherResourceCompletionTest extends ContextTestSupport { + + private final AtomicInteger completions = new AtomicInteger(); + + @Test + public void testResourceFailed() { + assertThrows(Exception.class, () -> template.requestBody("direct:resourceFails", "Hello")); + await().atMost(5, TimeUnit.SECONDS).untilAsserted(() -> assertEquals(1, completions.get())); + } + + @Test + public void testAggregationFailed() { Review Comment: ⚠️ **Missing test case: `aggregate()` returns `null`.** The new code in `Enricher.done()` unconditionally calls `handoverCompletions` after the `if/else` block — which means it now fires even when `aggregationStrategy.aggregate()` returns `null`. In the old code, the call was inside `if (aggregatedExchange != null)`, so a null return would silently skip it. This is the correct behavior (the resource should always be released), but none of the three test cases here covers it. A test with a strategy that returns `null` would close the gap: ```java @Test public void testAggregationReturnsNull() { from("direct:aggregationReturnsNull") .enrich("resource:ok", (oldExchange, newExchange) -> null); assertThrows(Exception.class, () -> template.requestBody("direct:aggregationReturnsNull", "Hello")); await().atMost(5, TimeUnit.SECONDS) .untilAsserted(() -> assertEquals(1, completions.get())); } ``` (The route configuration goes in `createRouteBuilder`, and the assertion verifies that the on-completion runs even when the strategy discards both exchanges.) -- 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]
