You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by "prasanthrao (via GitHub)" <gi...@apache.org> on 2026/07/14 03:56:10 UTC

[PR] CAMEL-24055: QuartzEndpoint custom calendar name collision when multiple routes use customCalendar [camel]

prasanthrao opened a new pull request, #24670:
URL: https://github.com/apache/camel/pull/24670

   # Description
   
     `QuartzEndpoint` registered every custom calendar under the same hardcoded scheduler name
     `"CamelQuartzCustomCalendar"`. When two or more routes in the same `CamelContext` each configured
     a `customCalendar`, the second `addCalendar(..., replace=true)` call silently overwrote the first.
     All triggers were wired to that same name via `modifiedByCalendar(...)`, so every trigger ended up
     governed by whichever calendar registered last — not the one intended for it.
   
     **Fix:** replace the hardcoded constant with a per-endpoint name derived from the trigger key:
   
     CamelQuartzCustomCalendar_<group>_<name>
   
     The trigger key is always set by `QuartzComponent` before the endpoint starts, is stable across
     restarts (same URI → same trigger key), and is already guaranteed unique within the scheduler.
   
     A new regression test (`QuartzCustomCalendarCollisionTest`) verifies that two routes with different
     custom calendars each register and retain their own independent calendar entry.
   
     # Target
   
     - [x] I checked that the commit is targeting the correct branch (Camel 4 uses the `main` branch)
   
     # Tracking
   
     - [x] If this is a large change, bug fix, or code improvement, I checked there is a [JIRA issue](https://issues.apache.org/jira/browse/CAMEL-24055) filed for the change (usually before you start working on it).
   
     # Apache Camel coding standards and style
   
     - [x] I checked that each commit in the pull request has a meaningful subject line and body.
   
     - [x] I have run `mvn clean install -DskipTests` locally from root folder and I have committed all auto-generated changes.
   
     # AI-assisted contributions
   
     - [x] If this PR includes AI-generated code, commits have proper co-authorship attribution (e.g., `Co-authored-by` trailers) and the PR description identifies the AI tool used.
   
     _Claude Code on behalf of Prasanth Rao_


-- 
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: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-24055: QuartzEndpoint custom calendar name collision when multiple routes use customCalendar [camel]

Posted by "davsclaus (via GitHub)" <gi...@apache.org>.
davsclaus commented on code in PR #24670:
URL: https://github.com/apache/camel/pull/24670#discussion_r3577458387


##########
components/camel-quartz/src/main/java/org/apache/camel/component/quartz/QuartzEndpoint.java:
##########
@@ -352,6 +355,13 @@ private void removeJobInScheduler() throws Exception {
                 scheduler.unscheduleJob(triggerKey);
 
                 jobAdded.set(false);
+                if (ObjectHelper.isNotEmpty(customCalendar)) {
+                    try {
+                        scheduler.deleteCalendar(customCalendarName());
+                    } catch (SchedulerException e) {
+                        LOG.error("Could not delete calendar {}: {}", customCalendarName(), e.getMessage());

Review Comment:
   Minor: consider `LOG.warn` here instead of `LOG.error` — this is a cleanup failure during shutdown, not a runtime error. Also, passing the exception as the last arg captures the stack trace:
   
   ```suggestion
                       } catch (SchedulerException e) {
                           LOG.warn("Could not delete calendar {}: {}", customCalendarName(), e.getMessage(), e);
   ```



-- 
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: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-24055: QuartzEndpoint custom calendar name collision when multiple routes use customCalendar [camel]

Posted by "prasanthrao (via GitHub)" <gi...@apache.org>.
prasanthrao commented on code in PR #24670:
URL: https://github.com/apache/camel/pull/24670#discussion_r3576903349


##########
components/camel-quartz/src/main/java/org/apache/camel/component/quartz/QuartzEndpoint.java:
##########
@@ -328,14 +332,16 @@ protected void doStart() throws Exception {
             throw new IllegalArgumentException("Cannot have both options deleteJob and pauseJob enabled");
         }
         if (ObjectHelper.isNotEmpty(customCalendar)) {
-            getComponent().getScheduler().addCalendar(QuartzConstants.QUARTZ_CAMEL_CUSTOM_CALENDAR, customCalendar, true,
-                    false);
+            getComponent().getScheduler().addCalendar(customCalendarName(), customCalendar, true, false);
         }
         addJobInScheduler();
     }
 
     @Override
     protected void doStop() throws Exception {

Review Comment:
   Good catch — fixed. Moved `deleteCalendar` after `removeJobInScheduler` so the trigger is unscheduled first, added the `deleteJob` guard and the `scheduler != null && !isShutdown()` check, and wrapped in `try/catch` to tolerate clustered stores where the unschedule may be skipped. Thanks!



-- 
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: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-24055: QuartzEndpoint custom calendar name collision when multiple routes use customCalendar [camel]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #24670:
URL: https://github.com/apache/camel/pull/24670#issuecomment-4965770291

   :star2: Thank you for your contribution to the Apache Camel project! :star2:
     :robot: CI automation will test this PR automatically.
   
     :camel: Apache Camel Committers, please review the following items:
   
     * First-time contributors **require MANUAL approval** for the GitHub Actions to run
     * You can use the command `/component-test (camel-)component-name1 (camel-)component-name2..` to request a test from the test bot although they are normally detected and executed by CI.
     * You can label PRs using `skip-tests` and `test-dependents` to fine-tune the checks executed by this PR.
     * Build and test logs are available in the summary page. **Only** [Apache Camel committers](https://camel.apache.org/community/team/#committers) have access to the summary.
     
     :warning: Be careful when sharing logs. Review their contents before sharing them publicly.


-- 
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: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-24055: QuartzEndpoint custom calendar name collision when multiple routes use customCalendar [camel]

Posted by "prasanthrao (via GitHub)" <gi...@apache.org>.
prasanthrao commented on code in PR #24670:
URL: https://github.com/apache/camel/pull/24670#discussion_r3576026825


##########
components/camel-quartz/src/test/java/org/apache/camel/component/quartz/QuartzCustomCalendarCollisionTest.java:
##########
@@ -0,0 +1,78 @@
+/*
+ * 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.quartz;
+
+import java.util.Date;
+
+import org.apache.camel.BindToRegistry;
+import org.apache.camel.builder.RouteBuilder;
+import org.junit.jupiter.api.Test;
+import org.quartz.Calendar;
+import org.quartz.Scheduler;
+import org.quartz.impl.calendar.HolidayCalendar;
+
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNotSame;
+
+/**
+ * Regression test: two endpoints with different customCalendars must each register under a unique scheduler name so
+ * that the second addCalendar() does not overwrite the first.
+ */
+public class QuartzCustomCalendarCollisionTest extends BaseQuartzTest {
+
+    @BindToRegistry("calendarA")
+    public HolidayCalendar loadCalendarA() {
+        HolidayCalendar cal = new HolidayCalendar();
+        // Exclude today — this calendar should suppress triggers
+        cal.addExcludedDate(new Date());
+        return cal;
+    }
+
+    @BindToRegistry("calendarB")
+    public HolidayCalendar loadCalendarB() {
+        // No excluded dates — always-open calendar
+        return new HolidayCalendar();
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() {
+        return new RouteBuilder() {
+            public void configure() {
+                from("quartz://TimerA?customCalendar=#calendarA&cron=05+00+00+*+*+?").routeId("routeA").to("mock:a");
+                from("quartz://TimerB?customCalendar=#calendarB&cron=05+00+00+*+*+?").routeId("routeB").to("mock:b");
+            }
+        };
+    }
+
+    @Test
+    public void testEachEndpointRegistersItsOwnCalendar() throws Exception {
+        QuartzComponent component = context.getComponent("quartz", QuartzComponent.class);
+        Scheduler scheduler = component.getScheduler();
+
+        QuartzEndpoint endpointA = (QuartzEndpoint) context.getRoute("routeA").getConsumer().getEndpoint();
+        QuartzEndpoint endpointB = (QuartzEndpoint) context.getRoute("routeB").getConsumer().getEndpoint();
+
+        Calendar calA = scheduler.getCalendar(QuartzConstants.QUARTZ_CAMEL_CUSTOM_CALENDAR + "_" + endpointA.getGroupName()
+                                              + "_" + endpointA.getTriggerName());
+        Calendar calB = scheduler.getCalendar(QuartzConstants.QUARTZ_CAMEL_CUSTOM_CALENDAR + "_" + endpointB.getGroupName()
+                                              + "_" + endpointB.getTriggerName());
+
+        assertNotNull(calA, "Calendar for TimerA must be registered under its own unique name");
+        assertNotNull(calB, "Calendar for TimerB must be registered under its own unique name");
+        assertNotSame(calA, calB, "Each endpoint must register a distinct calendar object");

Review Comment:
   Thanks for the suggestion. Unfortunately this assertion cannot work in practice.`org.quartz.simpl.RAMJobStore.storeCalendar()` clones the calendar object before storing it, so `scheduler.getCalendar(name)` always returns a copy, never the original instance. assertSame would always fail regardless of the fix.
   
   `assertNotSame(calA, calB)` combined with assertNotNull on each is the best assertion we can do today. 



-- 
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: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-24055: QuartzEndpoint custom calendar name collision when multiple routes use customCalendar [camel]

Posted by "prasanthrao (via GitHub)" <gi...@apache.org>.
prasanthrao commented on code in PR #24670:
URL: https://github.com/apache/camel/pull/24670#discussion_r3575943052


##########
components/camel-quartz/src/main/java/org/apache/camel/component/quartz/QuartzEndpoint.java:
##########
@@ -310,6 +310,10 @@ public void setCustomCalendar(Calendar customCalendar) {
         this.customCalendar = customCalendar;
     }
 
+    private String customCalendarName() {

Review Comment:
   Thanks. I too felt this in my second review and have pushed the cleanup code



-- 
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: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-24055: QuartzEndpoint custom calendar name collision when multiple routes use customCalendar [camel]

Posted by "prasanthrao (via GitHub)" <gi...@apache.org>.
prasanthrao commented on code in PR #24670:
URL: https://github.com/apache/camel/pull/24670#discussion_r3577077005


##########
components/camel-quartz/src/main/java/org/apache/camel/component/quartz/QuartzEndpoint.java:
##########
@@ -328,14 +332,16 @@ protected void doStart() throws Exception {
             throw new IllegalArgumentException("Cannot have both options deleteJob and pauseJob enabled");
         }
         if (ObjectHelper.isNotEmpty(customCalendar)) {
-            getComponent().getScheduler().addCalendar(QuartzConstants.QUARTZ_CAMEL_CUSTOM_CALENDAR, customCalendar, true,
-                    false);
+            getComponent().getScheduler().addCalendar(customCalendarName(), customCalendar, true, false);
         }
         addJobInScheduler();
     }
 
     @Override
     protected void doStop() throws Exception {

Review Comment:
   This commit should ideally fix the concerns with calender deletion https://github.com/apache/camel/pull/24670/changes/9e26f1502c245b4567c02a4e7b2fe9b54ed7c49a 



-- 
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: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-24055: QuartzEndpoint custom calendar name collision when multiple routes use customCalendar [camel]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #24670:
URL: https://github.com/apache/camel/pull/24670#issuecomment-4966090725

   <!-- ci-tested-modules -->
   :test_tube: **CI tested the following changed modules:**
   
   - `components/camel-quartz`
   
   ---
   
   <details><summary>:microscope: Scalpel shadow comparison — Scalpel: 12 tested, 29 compile-only — current: 12 all tested</summary>
   
   [Maveniverse Scalpel](https://github.com/maveniverse/scalpel) detected **41 affected modules** (current approach: 12).
   
   <details><summary>:warning: Modules only in Scalpel (29)</summary>
   
   - `apache-camel`
   - `camel-allcomponents`
   - `camel-catalog`
   - `camel-catalog-console`
   - `camel-catalog-lucene`
   - `camel-catalog-maven`
   - `camel-catalog-suggest`
   - `camel-componentdsl`
   - `camel-csimple-maven-plugin`
   - `camel-endpointdsl`
   - `camel-endpointdsl-support`
   - `camel-itest`
   - `camel-jbang-core`
   - `camel-jbang-it`
   - `camel-jbang-main`
   - `camel-jbang-plugin-edit`
   - `camel-jbang-plugin-generate`
   - `camel-jbang-plugin-kubernetes`
   - `camel-jbang-plugin-test`
   - `camel-kamelet-main`
   - `camel-launcher`
   - `camel-report-maven-plugin`
   - `camel-route-parser`
   - `camel-yaml-dsl`
   - `camel-yaml-dsl-deserializers`
   - `camel-yaml-dsl-maven-plugin`
   - `coverage`
   - `docs`
   - `dummy-component`
   
   </details>
   
   **Skip-tests mode would test 12 modules** (1 direct + 11 downstream), **skip tests for 29** (generated code, meta-modules)
   
   <details><summary>Modules Scalpel would test (12)</summary>
   
   - `camel-jbang-mcp`
   - `camel-jbang-plugin-mcp`
   - `camel-jbang-plugin-route-parser`
   - `camel-jbang-plugin-tui`
   - `camel-jbang-plugin-validate`
   - `camel-launcher-container`
   - `camel-mail`
   - `camel-mail-microsoft-oauth`
   - `camel-quartz`
   - `camel-yaml-dsl-validator`
   - `camel-yaml-dsl-validator-maven-plugin`
   - `camel-zookeeper-master`
   
   </details>
   
   <details><summary>Modules with tests skipped (29)</summary>
   
   - `apache-camel`
   - `camel-allcomponents`
   - `camel-catalog`
   - `camel-catalog-console`
   - `camel-catalog-lucene`
   - `camel-catalog-maven`
   - `camel-catalog-suggest`
   - `camel-componentdsl`
   - `camel-csimple-maven-plugin`
   - `camel-endpointdsl`
   - `camel-endpointdsl-support`
   - `camel-itest`
   - `camel-jbang-core`
   - `camel-jbang-it`
   - `camel-jbang-main`
   - `camel-jbang-plugin-edit`
   - `camel-jbang-plugin-generate`
   - `camel-jbang-plugin-kubernetes`
   - `camel-jbang-plugin-test`
   - `camel-kamelet-main`
   - `camel-launcher`
   - `camel-report-maven-plugin`
   - `camel-route-parser`
   - `camel-yaml-dsl`
   - `camel-yaml-dsl-deserializers`
   - `camel-yaml-dsl-maven-plugin`
   - `coverage`
   - `docs`
   - `dummy-component`
   
   </details>
   
   > :information_source: Shadow mode — Scalpel observes but does not affect test execution. [Learn more](https://github.com/maveniverse/scalpel)
   
   </details>
   
   <details><summary>All tested modules (41 modules)</summary>
   
   - Camel :: All Components Sync point
   - Camel :: Assembly
   - Camel :: Catalog :: CSimple Maven Plugin (deprecated)
   - Camel :: Catalog :: Camel Catalog
   - Camel :: Catalog :: Camel Report Maven Plugin
   - Camel :: Catalog :: Camel Route Parser
   - Camel :: Catalog :: Console
   - Camel :: Catalog :: Dummy Component
   - Camel :: Catalog :: Lucene (deprecated)
   - Camel :: Catalog :: Maven
   - Camel :: Catalog :: Suggest
   - Camel :: Component DSL
   - Camel :: Coverage
   - Camel :: Docs
   - Camel :: Endpoint DSL
   - Camel :: Endpoint DSL :: Support
   - Camel :: Integration Tests
   - Camel :: JBang :: Core
   - Camel :: JBang :: Integration tests
   - Camel :: JBang :: MCP
   - Camel :: JBang :: Main
   - Camel :: JBang :: Plugin :: Edit
   - Camel :: JBang :: Plugin :: Generate
   - Camel :: JBang :: Plugin :: Kubernetes
   - Camel :: JBang :: Plugin :: MCP
   - Camel :: JBang :: Plugin :: Route Parser
   - Camel :: JBang :: Plugin :: TUI
   - Camel :: JBang :: Plugin :: Testing
   - Camel :: JBang :: Plugin :: Validate
   - Camel :: Kamelet Main
   - Camel :: Launcher
   - Camel :: Launcher :: Container
   - Camel :: Mail
   - Camel :: Mail :: Microsoft OAuth
   - Camel :: Quartz
   - Camel :: YAML DSL
   - Camel :: YAML DSL :: Deserializers
   - Camel :: YAML DSL :: Maven Plugins
   - Camel :: YAML DSL :: Validator
   - Camel :: YAML DSL :: Validator Maven Plugin
   - Camel :: Zookeeper Master
   
   </details>
   
   ---
   :gear: [View full build and test results](https://github.com/apache/camel/actions/runs/29305028140)


-- 
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: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-24055: QuartzEndpoint custom calendar name collision when multiple routes use customCalendar [camel]

Posted by "davsclaus (via GitHub)" <gi...@apache.org>.
davsclaus commented on code in PR #24670:
URL: https://github.com/apache/camel/pull/24670#discussion_r3577048471


##########
components/camel-quartz/src/main/java/org/apache/camel/component/quartz/QuartzEndpoint.java:
##########
@@ -328,15 +332,24 @@ protected void doStart() throws Exception {
             throw new IllegalArgumentException("Cannot have both options deleteJob and pauseJob enabled");
         }
         if (ObjectHelper.isNotEmpty(customCalendar)) {
-            getComponent().getScheduler().addCalendar(QuartzConstants.QUARTZ_CAMEL_CUSTOM_CALENDAR, customCalendar, true,
-                    false);
+            getComponent().getScheduler().addCalendar(customCalendarName(), customCalendar, true, false);
         }
         addJobInScheduler();
     }
 
     @Override
     protected void doStop() throws Exception {
         removeJobInScheduler();
+        if (deleteJob && ObjectHelper.isNotEmpty(customCalendar)) {
+            Scheduler scheduler = getComponent().getScheduler();
+            if (scheduler != null && !scheduler.isShutdown()) {
+                try {
+                    scheduler.deleteCalendar(customCalendarName());
+                } catch (SchedulerException e) {
+                    LOG.debug("Could not delete calendar {}: {}", customCalendarName(), e.getMessage());
+                }
+            }

Review Comment:
   (Minor suggestion) The existing `removeJobInScheduler()` skips unscheduling in clustered mode (`!isClustered` guard). The new calendar cleanup doesn't have this guard — so in clustered mode, the trigger isn't removed but `deleteCalendar()` is attempted. Quartz refuses to delete a calendar with active trigger references, so this will always throw and get caught at DEBUG level. Not a functional bug, but attempting and failing on every stop in clustered deployments is unnecessary.
   
   Consider adding the `isClustered` check for consistency:
   
   ```suggestion
           if (deleteJob && ObjectHelper.isNotEmpty(customCalendar)) {
               Scheduler scheduler = getComponent().getScheduler();
               if (scheduler != null && !scheduler.isShutdown()) {
                   boolean isClustered = scheduler.getMetaData().isJobStoreClustered();
                   if (!isClustered) {
                       try {
                           scheduler.deleteCalendar(customCalendarName());
                       } catch (SchedulerException e) {
                           LOG.debug("Could not delete calendar {}: {}", customCalendarName(), e.getMessage());
                       }
                   }
               }
           }
   ```



-- 
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: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-24055: QuartzEndpoint custom calendar name collision when multiple routes use customCalendar [camel]

Posted by "davsclaus (via GitHub)" <gi...@apache.org>.
davsclaus commented on code in PR #24670:
URL: https://github.com/apache/camel/pull/24670#discussion_r3576408159


##########
components/camel-quartz/src/main/java/org/apache/camel/component/quartz/QuartzEndpoint.java:
##########
@@ -328,14 +332,16 @@ protected void doStart() throws Exception {
             throw new IllegalArgumentException("Cannot have both options deleteJob and pauseJob enabled");
         }
         if (ObjectHelper.isNotEmpty(customCalendar)) {
-            getComponent().getScheduler().addCalendar(QuartzConstants.QUARTZ_CAMEL_CUSTOM_CALENDAR, customCalendar, true,
-                    false);
+            getComponent().getScheduler().addCalendar(customCalendarName(), customCalendar, true, false);
         }
         addJobInScheduler();
     }
 
     @Override
     protected void doStop() throws Exception {

Review Comment:
   **Bug:** `deleteCalendar()` is called before `removeJobInScheduler()`. Quartz's `RAMJobStore.removeCalendar()` iterates all triggers and throws `JobPersistenceException("Calender cannot be removed if it referenced by a Trigger!")` if any trigger still references the calendar name.
   
   Since `removeJobInScheduler()` (which calls `scheduler.unscheduleJob(triggerKey)`) hasn't run yet at this point, the trigger still exists and references the calendar — so this will throw on every endpoint stop with the default `deleteJob=true`.
   
   Additionally, `deleteCalendar` should only be attempted when the trigger was actually removed. When `deleteJob=false` (trigger is paused or left running), or when the scheduler is clustered (the `!isClustered` guard in `removeJobInScheduler` skips the unschedule), the trigger persists and `deleteCalendar` would also throw.
   
   ```suggestion
       protected void doStop() throws Exception {
           removeJobInScheduler();
           if (deleteJob && ObjectHelper.isNotEmpty(customCalendar)) {
               Scheduler scheduler = getComponent().getScheduler();
               if (scheduler != null && !scheduler.isShutdown()) {
                   try {
                       scheduler.deleteCalendar(customCalendarName());
                   } catch (SchedulerException e) {
                       LOG.debug("Could not delete calendar {}: {}", customCalendarName(), e.getMessage());
                   }
               }
           }
       }



-- 
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: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-24055: QuartzEndpoint custom calendar name collision when multiple routes use customCalendar [camel]

Posted by "prasanthrao (via GitHub)" <gi...@apache.org>.
prasanthrao commented on code in PR #24670:
URL: https://github.com/apache/camel/pull/24670#discussion_r3577080762


##########
components/camel-quartz/src/main/java/org/apache/camel/component/quartz/QuartzEndpoint.java:
##########
@@ -328,15 +332,24 @@ protected void doStart() throws Exception {
             throw new IllegalArgumentException("Cannot have both options deleteJob and pauseJob enabled");
         }
         if (ObjectHelper.isNotEmpty(customCalendar)) {
-            getComponent().getScheduler().addCalendar(QuartzConstants.QUARTZ_CAMEL_CUSTOM_CALENDAR, customCalendar, true,
-                    false);
+            getComponent().getScheduler().addCalendar(customCalendarName(), customCalendar, true, false);
         }
         addJobInScheduler();
     }
 
     @Override
     protected void doStop() throws Exception {
         removeJobInScheduler();
+        if (deleteJob && ObjectHelper.isNotEmpty(customCalendar)) {
+            Scheduler scheduler = getComponent().getScheduler();
+            if (scheduler != null && !scheduler.isShutdown()) {
+                try {
+                    scheduler.deleteCalendar(customCalendarName());
+                } catch (SchedulerException e) {
+                    LOG.debug("Could not delete calendar {}: {}", customCalendarName(), e.getMessage());
+                }
+            }

Review Comment:
   This commit should ideally fix the concerns with calender deletion https://github.com/apache/camel/commit/9e26f1502c245b4567c02a4e7b2fe9b54ed7c49a



-- 
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: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-24055: QuartzEndpoint custom calendar name collision when multiple routes use customCalendar [camel]

Posted by "gnodet (via GitHub)" <gi...@apache.org>.
gnodet commented on code in PR #24670:
URL: https://github.com/apache/camel/pull/24670#discussion_r3575930971


##########
components/camel-quartz/src/test/java/org/apache/camel/component/quartz/QuartzCustomCalendarCollisionTest.java:
##########
@@ -0,0 +1,78 @@
+/*
+ * 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.quartz;
+
+import java.util.Date;
+
+import org.apache.camel.BindToRegistry;
+import org.apache.camel.builder.RouteBuilder;
+import org.junit.jupiter.api.Test;
+import org.quartz.Calendar;
+import org.quartz.Scheduler;
+import org.quartz.impl.calendar.HolidayCalendar;
+
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNotSame;
+
+/**
+ * Regression test: two endpoints with different customCalendars must each register under a unique scheduler name so
+ * that the second addCalendar() does not overwrite the first.
+ */
+public class QuartzCustomCalendarCollisionTest extends BaseQuartzTest {
+
+    @BindToRegistry("calendarA")
+    public HolidayCalendar loadCalendarA() {
+        HolidayCalendar cal = new HolidayCalendar();
+        // Exclude today — this calendar should suppress triggers
+        cal.addExcludedDate(new Date());
+        return cal;
+    }
+
+    @BindToRegistry("calendarB")
+    public HolidayCalendar loadCalendarB() {
+        // No excluded dates — always-open calendar
+        return new HolidayCalendar();
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() {
+        return new RouteBuilder() {
+            public void configure() {
+                from("quartz://TimerA?customCalendar=#calendarA&cron=05+00+00+*+*+?").routeId("routeA").to("mock:a");
+                from("quartz://TimerB?customCalendar=#calendarB&cron=05+00+00+*+*+?").routeId("routeB").to("mock:b");
+            }
+        };
+    }
+
+    @Test
+    public void testEachEndpointRegistersItsOwnCalendar() throws Exception {
+        QuartzComponent component = context.getComponent("quartz", QuartzComponent.class);
+        Scheduler scheduler = component.getScheduler();
+
+        QuartzEndpoint endpointA = (QuartzEndpoint) context.getRoute("routeA").getConsumer().getEndpoint();
+        QuartzEndpoint endpointB = (QuartzEndpoint) context.getRoute("routeB").getConsumer().getEndpoint();
+
+        Calendar calA = scheduler.getCalendar(QuartzConstants.QUARTZ_CAMEL_CUSTOM_CALENDAR + "_" + endpointA.getGroupName()
+                                              + "_" + endpointA.getTriggerName());
+        Calendar calB = scheduler.getCalendar(QuartzConstants.QUARTZ_CAMEL_CUSTOM_CALENDAR + "_" + endpointB.getGroupName()
+                                              + "_" + endpointB.getTriggerName());
+
+        assertNotNull(calA, "Calendar for TimerA must be registered under its own unique name");
+        assertNotNull(calB, "Calendar for TimerB must be registered under its own unique name");
+        assertNotSame(calA, calB, "Each endpoint must register a distinct calendar object");

Review Comment:
   Nice regression test. The `assertNotSame` check confirms the two calendar objects are distinct instances. You might also consider adding `assertSame(calA, context.getRegistry().lookupByName("calendarA"))` to verify each endpoint's registered calendar is the _exact_ instance from the registry (not just a different instance), but the current assertions are sufficient to prevent the original collision bug.



##########
components/camel-quartz/src/main/java/org/apache/camel/component/quartz/QuartzEndpoint.java:
##########
@@ -310,6 +310,10 @@ public void setCustomCalendar(Calendar customCalendar) {
         this.customCalendar = customCalendar;
     }
 
+    private String customCalendarName() {

Review Comment:
   Good approach. Using the trigger key for the calendar name is the right choice -- it is set by `QuartzComponent.createEndpoint()` before `doStart()`, is unique within the scheduler, and is stable across restarts.
   
   Minor pre-existing observation (not from this PR): there is no corresponding `scheduler.deleteCalendar(customCalendarName())` in `doStop()` / `removeJobInScheduler()`. This means custom calendars accumulate in the scheduler and are never cleaned up. For in-memory job stores this is harmless, but for JDBC-backed stores it could leave stale rows. Not blocking -- just noting for a potential follow-up.



-- 
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: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-24055: QuartzEndpoint custom calendar name collision when multiple routes use customCalendar [camel]

Posted by "davsclaus (via GitHub)" <gi...@apache.org>.
davsclaus merged PR #24670:
URL: https://github.com/apache/camel/pull/24670


-- 
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: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org