This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new c4ac91f2d0e6 CAMEL-24066: Fix SpringScheduledPollConsumerScheduler
ignoring startScheduler=false
c4ac91f2d0e6 is described below
commit c4ac91f2d0e625d24df73dbb98bb9d8cd3f48e9f
Author: Claus Ibsen <[email protected]>
AuthorDate: Wed Jul 15 15:19:03 2026 +0200
CAMEL-24066: Fix SpringScheduledPollConsumerScheduler ignoring
startScheduler=false
Move cron task scheduling from doStart() to startScheduler() so the
startScheduler=false flag is respected. Previously the cron trigger
fired unconditionally on route start, bypassing the SPI contract.
Also fix isSchedulerStarted() to check actual scheduling state.
Closes #24712
Co-Authored-By: Claude Opus 4.6 <[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