gnodet-bot commented on code in PR #31172: URL: https://github.com/apache/camel/pull/31172#discussion_r4757601914
########## core/camel-core/src/test/java/org/apache/camel/component/seda/SedaSentinelTest.java: ########## @@ -0,0 +1,258 @@ +/* + * 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.seda; + +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicInteger; + +import org.apache.camel.ContextTestSupport; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.mock.MockEndpoint; +import org.junit.jupiter.api.AfterEach; +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.assertTrue; + +/** + * Regression tests for CAMEL-27896: + * <ul> + * <li>size=1000 (the SEDA default) or size=Integer.MAX_VALUE on an endpoint created after context start must not be + * treated as "not set" and must not be overridden by the component default.</li> + * <li>concurrentConsumers=1 with virtualThreadPerTask=true must be preserved and must not be reset to 0.</li> + * <li>A component-level concurrentConsumers (N≠1) with virtualThreadPerTask=true on the endpoint must be + * preserved.</li> + * </ul> + */ +class SedaSentinelTest extends ContextTestSupport { + + /** + * Per-message release latches: the processor in the concurrency-check route holds each message until the test + * releases it. Sized for 3 messages in {@link #testVirtualThreadsWithConcurrentConsumersOneEnforcesLimit()}. + */ + private final CountDownLatch[] releaseLatches = { + new CountDownLatch(1), new CountDownLatch(1), new CountDownLatch(1) }; + /** Signals when each message has entered the processor (i.e. is "in flight"). */ + private final CountDownLatch[] busyLatches = { + new CountDownLatch(1), new CountDownLatch(1), new CountDownLatch(1) }; + private final AtomicInteger msgIndex = new AtomicInteger(); + private final AtomicInteger active = new AtomicInteger(); + private final AtomicInteger maxActive = new AtomicInteger(); + + @AfterEach + void releaseAll() { + for (CountDownLatch l : releaseLatches) { + l.countDown(); + } + } + + // ── size sentinel ────────────────────────────────────────────────────── + + /** + * When a user explicitly sets size=1000 (which equals SedaConstants.QUEUE_SIZE) on an endpoint that is created + * after context start, the size must not be silently treated as "not set" and must not be replaced by the component + * default. + */ + @Test + void testExplicitSizeOfDefaultValueIsRespected() throws Exception { + // The component has a custom queueSize different from the endpoint's explicit size=1000. + SedaComponent comp = context.getComponent("seda", SedaComponent.class); + int originalComponentQueueSize = comp.getQueueSize(); + comp.setQueueSize(42); + try { + // Create endpoint after context start with size explicitly set to 1000. + SedaEndpoint ep = context.getEndpoint("seda:sentinelQueue1000?size=1000", SedaEndpoint.class); + ep.getQueue(); // force queue creation + assertEquals(1000, ep.getQueue().remainingCapacity(), + "Explicitly set size=1000 must be respected even though it matches SedaConstants.QUEUE_SIZE"); + } finally { + comp.setQueueSize(originalComponentQueueSize); + } + } + + /** + * When a user explicitly sets size=Integer.MAX_VALUE on an endpoint (unbounded queue), the size must not be + * silently treated as "not set" and replaced by the component default. + */ + @Test + void testExplicitSizeMaxValueIsRespected() throws Exception { + SedaComponent comp = context.getComponent("seda", SedaComponent.class); + int originalComponentQueueSize = comp.getQueueSize(); + comp.setQueueSize(42); + try { + SedaEndpoint ep = context.getEndpoint("seda:sentinelQueueMax?size=" + Integer.MAX_VALUE, SedaEndpoint.class); + ep.getQueue(); + assertEquals(Integer.MAX_VALUE, ep.getQueue().remainingCapacity(), Review Comment: ⚠️ **Assertion mismatch:** `comp.setQueueSize(42)` is set above. With the fix, `size=MAX_VALUE` → `null` → `getOrCreateQueue` falls through to `queueSize=42` → creates a queue with capacity 42. `remainingCapacity()` returns 42, not `MAX_VALUE`. Either fix the assertion to `assertEquals(42, ...)` / remove the capacity assertion (the fix's goal is preventing IAE, not guaranteeing MAX_VALUE capacity), or change `getOrCreateQueue` to call `create()` (no-arg, truly unbounded) when `size == Integer.MAX_VALUE`. ########## core/camel-core/src/test/java/org/apache/camel/component/seda/SedaSentinelTest.java: ########## @@ -0,0 +1,258 @@ +/* + * 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.seda; + +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicInteger; + +import org.apache.camel.ContextTestSupport; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.mock.MockEndpoint; +import org.junit.jupiter.api.AfterEach; +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.assertTrue; + +/** + * Regression tests for CAMEL-27896: + * <ul> + * <li>size=1000 (the SEDA default) or size=Integer.MAX_VALUE on an endpoint created after context start must not be + * treated as "not set" and must not be overridden by the component default.</li> + * <li>concurrentConsumers=1 with virtualThreadPerTask=true must be preserved and must not be reset to 0.</li> + * <li>A component-level concurrentConsumers (N≠1) with virtualThreadPerTask=true on the endpoint must be + * preserved.</li> + * </ul> + */ +class SedaSentinelTest extends ContextTestSupport { + + /** + * Per-message release latches: the processor in the concurrency-check route holds each message until the test + * releases it. Sized for 3 messages in {@link #testVirtualThreadsWithConcurrentConsumersOneEnforcesLimit()}. + */ + private final CountDownLatch[] releaseLatches = { + new CountDownLatch(1), new CountDownLatch(1), new CountDownLatch(1) }; + /** Signals when each message has entered the processor (i.e. is "in flight"). */ + private final CountDownLatch[] busyLatches = { + new CountDownLatch(1), new CountDownLatch(1), new CountDownLatch(1) }; + private final AtomicInteger msgIndex = new AtomicInteger(); + private final AtomicInteger active = new AtomicInteger(); + private final AtomicInteger maxActive = new AtomicInteger(); + + @AfterEach + void releaseAll() { + for (CountDownLatch l : releaseLatches) { + l.countDown(); + } + } + + // ── size sentinel ────────────────────────────────────────────────────── + + /** + * When a user explicitly sets size=1000 (which equals SedaConstants.QUEUE_SIZE) on an endpoint that is created + * after context start, the size must not be silently treated as "not set" and must not be replaced by the component + * default. + */ + @Test + void testExplicitSizeOfDefaultValueIsRespected() throws Exception { + // The component has a custom queueSize different from the endpoint's explicit size=1000. + SedaComponent comp = context.getComponent("seda", SedaComponent.class); + int originalComponentQueueSize = comp.getQueueSize(); + comp.setQueueSize(42); + try { + // Create endpoint after context start with size explicitly set to 1000. + SedaEndpoint ep = context.getEndpoint("seda:sentinelQueue1000?size=1000", SedaEndpoint.class); + ep.getQueue(); // force queue creation + assertEquals(1000, ep.getQueue().remainingCapacity(), + "Explicitly set size=1000 must be respected even though it matches SedaConstants.QUEUE_SIZE"); + } finally { + comp.setQueueSize(originalComponentQueueSize); + } + } + + /** + * When a user explicitly sets size=Integer.MAX_VALUE on an endpoint (unbounded queue), the size must not be + * silently treated as "not set" and replaced by the component default. + */ + @Test + void testExplicitSizeMaxValueIsRespected() throws Exception { + SedaComponent comp = context.getComponent("seda", SedaComponent.class); + int originalComponentQueueSize = comp.getQueueSize(); + comp.setQueueSize(42); + try { + SedaEndpoint ep = context.getEndpoint("seda:sentinelQueueMax?size=" + Integer.MAX_VALUE, SedaEndpoint.class); + ep.getQueue(); + assertEquals(Integer.MAX_VALUE, ep.getQueue().remainingCapacity(), + "Explicitly set size=Integer.MAX_VALUE must be respected and must not be replaced by the component default"); + } finally { + comp.setQueueSize(originalComponentQueueSize); + } + } + + /** + * Regression for CAMEL-27896: when an unbounded shared queue is registered (size=MAX_VALUE on the first endpoint, + * which maps to null/no-limit internally) a second endpoint with the same explicit size=MAX_VALUE must not throw + * {@link IllegalArgumentException} due to a size mismatch (null vs. MAX_VALUE). + */ + @Test + void testSharedUnboundedQueueWithExplicitMaxValueDoesNotThrow() throws Exception { + // First endpoint creates the shared queue as unbounded (MAX_VALUE → stored as null internally). + SedaEndpoint ep1 = context.getEndpoint( + "seda:sharedUnbounded?size=" + Integer.MAX_VALUE + "&multipleConsumers=true", SedaEndpoint.class); + ep1.getQueue(); // force queue registration + + // Second endpoint with the same explicit size=MAX_VALUE must reuse the existing queue without IAE. + SedaEndpoint ep2 = context.getEndpoint( + "seda:sharedUnbounded?size=" + Integer.MAX_VALUE + "&multipleConsumers=true", SedaEndpoint.class); + ep2.getQueue(); // must not throw IllegalArgumentException + + assertEquals(Integer.MAX_VALUE, ep1.getQueue().remainingCapacity(), Review Comment: ⚠️ **Same issue:** `context.getEndpoint()` with the same URI returns the cached endpoint, so `ep2 IS ep1` — no second endpoint instance is created. The test does not exercise the actual sharing scenario (two distinct endpoints, same queue name). To test that, use two different URI forms that map to the same queue (e.g. a producer and a consumer in route definitions). Also the `remainingCapacity()==MAX_VALUE` assertion fails: default `comp.queueSize=1000` → capacity 1000 → `remainingCapacity()=1000≠MAX_VALUE`. -- 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]
