allthingssecurity commented on code in PR #30825: URL: https://github.com/apache/camel/pull/30825#discussion_r4703673818
########## components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsAsyncStartListenerSuspendResumeTest.java: ########## @@ -0,0 +1,505 @@ +/* + * 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.jms; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Proxy; +import java.util.Map; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.stream.Collectors; + +import jakarta.jms.ConnectionFactory; +import jakarta.jms.JMSException; + +import org.apache.camel.CamelContext; +import org.apache.camel.ProducerTemplate; +import org.apache.camel.RuntimeCamelException; +import org.apache.camel.ServiceStatus; +import org.apache.camel.ShutdownRoute; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.mock.MockEndpoint; +import org.apache.camel.impl.DefaultCamelContext; +import org.apache.camel.test.infra.artemis.common.ConnectionFactoryHelper; +import org.apache.camel.test.infra.core.CamelContextExtension; +import org.apache.camel.test.infra.core.DefaultCamelContextExtension; +import org.apache.camel.util.function.ThrowingRunnable; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Order; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.Timeout; +import org.junit.jupiter.api.extension.RegisterExtension; +import org.springframework.jms.listener.DefaultMessageListenerContainer; + +import static org.awaitility.Awaitility.await; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +/** + * Suspending and resuming a JMS consumer with asyncStartListener=true (as route policies, JMX and the route controller + * do) while the asynchronous start of its listener container is pending, or after it failed, must leave a suspended + * consumer idle and a resumed consumer with one listener container, initialized once and counted once. + * <p/> + * The tasks the consumer submits to the component's async start/stop thread pool are held, and the test runs them + * itself, so the interleaving is deterministic. + * <p/> + * The start must also start the listener container once while the container is not allowed to run (the CamelContext is + * stopping, or the endpoint is not started), with and without asyncStartListener. + */ +@TestInstance(TestInstance.Lifecycle.PER_METHOD) +@Timeout(60) +class JmsAsyncStartListenerSuspendResumeTest extends AbstractJMSTest { + + @Order(2) + @RegisterExtension + public static CamelContextExtension camelContextExtension = new DefaultCamelContextExtension(); + + private static final String QUEUE = "JmsAsyncStartListenerSuspendResumeTest"; + + // static: the CamelContext (and so the component) is created once for the class + private static final JmsAsyncStopListenerRestartTest.HeldExecutorService HELD + = new JmsAsyncStopListenerRestartTest.HeldExecutorService(); Review Comment: No change here. HeldExecutorService lives in JmsAsyncStopListenerRestartTest, which is already on main and in the same package, so reusing it keeps a single copy of the helper. Moving it to a shared class would touch a test this PR does not change, and a local copy would be about 50 duplicated lines. If a third test needs it I will extract it in a separate cleanup. ########## components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsAsyncStartListenerSuspendResumeTest.java: ########## @@ -0,0 +1,505 @@ +/* + * 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.jms; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Proxy; +import java.util.Map; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.stream.Collectors; + +import jakarta.jms.ConnectionFactory; +import jakarta.jms.JMSException; + +import org.apache.camel.CamelContext; +import org.apache.camel.ProducerTemplate; +import org.apache.camel.RuntimeCamelException; +import org.apache.camel.ServiceStatus; +import org.apache.camel.ShutdownRoute; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.mock.MockEndpoint; +import org.apache.camel.impl.DefaultCamelContext; +import org.apache.camel.test.infra.artemis.common.ConnectionFactoryHelper; +import org.apache.camel.test.infra.core.CamelContextExtension; +import org.apache.camel.test.infra.core.DefaultCamelContextExtension; +import org.apache.camel.util.function.ThrowingRunnable; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Order; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.Timeout; +import org.junit.jupiter.api.extension.RegisterExtension; +import org.springframework.jms.listener.DefaultMessageListenerContainer; + +import static org.awaitility.Awaitility.await; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +/** + * Suspending and resuming a JMS consumer with asyncStartListener=true (as route policies, JMX and the route controller + * do) while the asynchronous start of its listener container is pending, or after it failed, must leave a suspended + * consumer idle and a resumed consumer with one listener container, initialized once and counted once. + * <p/> + * The tasks the consumer submits to the component's async start/stop thread pool are held, and the test runs them + * itself, so the interleaving is deterministic. + * <p/> + * The start must also start the listener container once while the container is not allowed to run (the CamelContext is + * stopping, or the endpoint is not started), with and without asyncStartListener. + */ +@TestInstance(TestInstance.Lifecycle.PER_METHOD) +@Timeout(60) +class JmsAsyncStartListenerSuspendResumeTest extends AbstractJMSTest { + + @Order(2) + @RegisterExtension + public static CamelContextExtension camelContextExtension = new DefaultCamelContextExtension(); + + private static final String QUEUE = "JmsAsyncStartListenerSuspendResumeTest"; + + // static: the CamelContext (and so the component) is created once for the class + private static final JmsAsyncStopListenerRestartTest.HeldExecutorService HELD + = new JmsAsyncStopListenerRestartTest.HeldExecutorService(); Review Comment: No change here. HeldExecutorService lives in JmsAsyncStopListenerRestartTest, which is already on main and in the same package, so reusing it keeps a single copy of the helper. Moving it to a shared class would touch a test this PR does not change, and a local copy would be about 60 duplicated lines. If a third test needs it I will extract it in a separate cleanup. -- 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]
