This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch fix/CAMEL-24066 in repository https://gitbox.apache.org/repos/asf/camel.git
commit d9ad5b026f83924a7b647ea9066002ddb042da9a Author: Claus Ibsen <[email protected]> AuthorDate: Wed Jul 15 12:18:10 2026 +0200 CAMEL-24066: Fix SpringScheduledPollConsumerScheduler ignoring startScheduler=false Co-Authored-By: Claude Opus 4.6 <[email protected]> Signed-off-by: Claus Ibsen <[email protected]> --- ...ledPollConsumerSchedulerStartSchedulerTest.java | 47 ++++++++++++++++++++++ ...uledPollConsumerSchedulerStartSchedulerTest.xml | 35 ++++++++++++++++ .../SpringScheduledPollConsumerScheduler.java | 9 +++-- 3 files changed, 87 insertions(+), 4 deletions(-) diff --git a/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/spring/pollingconsumer/SpringScheduledPollConsumerSchedulerStartSchedulerTest.java b/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/spring/pollingconsumer/SpringScheduledPollConsumerSchedulerStartSchedulerTest.java new file mode 100644 index 000000000000..f058767e609e --- /dev/null +++ b/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/spring/pollingconsumer/SpringScheduledPollConsumerSchedulerStartSchedulerTest.java @@ -0,0 +1,47 @@ +/* + * 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.spring.pollingconsumer; + +import java.util.concurrent.TimeUnit; + +import org.apache.camel.CamelContext; +import org.apache.camel.ContextTestSupport; +import org.apache.camel.Exchange; +import org.junit.jupiter.api.Test; + +import static org.apache.camel.spring.processor.SpringTestHelper.createSpringCamelContext; +import static org.awaitility.Awaitility.await; + +public class SpringScheduledPollConsumerSchedulerStartSchedulerTest extends ContextTestSupport { + + @Override + protected CamelContext createCamelContext() throws Exception { + return createSpringCamelContext(this, + "org/apache/camel/spring/pollingconsumer/SpringScheduledPollConsumerSchedulerStartSchedulerTest.xml"); + } + + @Test + public void testStartSchedulerFalseMustNotPoll() throws Exception { + template.sendBodyAndHeader(fileUri(), "Hello World", Exchange.FILE_NAME, "hello.txt"); + + getMockEndpoint("mock:result").expectedMessageCount(0); + + // startScheduler=false should prevent polling even with scheduler=spring + await().during(3, TimeUnit.SECONDS).atMost(4, TimeUnit.SECONDS) + .untilAsserted(() -> getMockEndpoint("mock:result").assertIsSatisfied()); + } +} diff --git a/components/camel-spring-parent/camel-spring-xml/src/test/resources/org/apache/camel/spring/pollingconsumer/SpringScheduledPollConsumerSchedulerStartSchedulerTest.xml b/components/camel-spring-parent/camel-spring-xml/src/test/resources/org/apache/camel/spring/pollingconsumer/SpringScheduledPollConsumerSchedulerStartSchedulerTest.xml new file mode 100644 index 000000000000..6bdf6473bb31 --- /dev/null +++ b/components/camel-spring-parent/camel-spring-xml/src/test/resources/org/apache/camel/spring/pollingconsumer/SpringScheduledPollConsumerSchedulerStartSchedulerTest.xml @@ -0,0 +1,35 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + 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. + +--> +<beans xmlns="http://www.springframework.org/schema/beans" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation=" + http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd + http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd + "> + + <camelContext xmlns="http://camel.apache.org/schema/spring"> + <jmxAgent id="jmx" disabled="true"/> + <route id="foo"> + <from uri="file:{{testDirectory}}?noop=true&startScheduler=false&scheduler=spring&scheduler.cron=0/1+*+*+*+*+?"/> + <to uri="mock:result"/> + </route> + </camelContext> + +</beans> diff --git a/components/camel-spring-parent/camel-spring/src/main/java/org/apache/camel/spring/pollingconsumer/SpringScheduledPollConsumerScheduler.java b/components/camel-spring-parent/camel-spring/src/main/java/org/apache/camel/spring/pollingconsumer/SpringScheduledPollConsumerScheduler.java index a20239f25c72..720769858a0e 100644 --- a/components/camel-spring-parent/camel-spring/src/main/java/org/apache/camel/spring/pollingconsumer/SpringScheduledPollConsumerScheduler.java +++ b/components/camel-spring-parent/camel-spring/src/main/java/org/apache/camel/spring/pollingconsumer/SpringScheduledPollConsumerScheduler.java @@ -69,12 +69,15 @@ public class SpringScheduledPollConsumerScheduler extends ServiceSupport @Override public void startScheduler() { - // we start the scheduler in doStart + if (future == null) { + LOG.debug("Scheduling cron trigger {}", getCron()); + future = taskScheduler.schedule(runnable, trigger); + } } @Override public boolean isSchedulerStarted() { - return taskScheduler != null && !taskScheduler.getScheduledExecutor().isShutdown(); + return future != null && !future.isCancelled(); } @Override @@ -126,8 +129,6 @@ public class SpringScheduledPollConsumerScheduler extends ServiceSupport destroyTaskScheduler = true; } - LOG.debug("Scheduling cron trigger {}", getCron()); - future = taskScheduler.schedule(runnable, trigger); } @Override
