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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to