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 156ff698c0e CAMEL-21471: camel-quartz ignores 
ignoreExpiredNextFireTime when endAt (#16380)
156ff698c0e is described below

commit 156ff698c0e841a914d3810359018d067822af09
Author: Prasanth Rao <[email protected]>
AuthorDate: Mon Nov 25 20:26:25 2024 +0530

    CAMEL-21471: camel-quartz ignores ignoreExpiredNextFireTime when endAt 
(#16380)
    
    is expired
---
 .../camel/component/quartz/QuartzEndpoint.java     |  9 +++-
 ...nRouteWithEmptyStartDateExpiredEndDateTest.java | 58 ++++++++++++++++++++++
 2 files changed, 65 insertions(+), 2 deletions(-)

diff --git 
a/components/camel-quartz/src/main/java/org/apache/camel/component/quartz/QuartzEndpoint.java
 
b/components/camel-quartz/src/main/java/org/apache/camel/component/quartz/QuartzEndpoint.java
index 1f6fb8cb3fe..aa228136170 100644
--- 
a/components/camel-quartz/src/main/java/org/apache/camel/component/quartz/QuartzEndpoint.java
+++ 
b/components/camel-quartz/src/main/java/org/apache/camel/component/quartz/QuartzEndpoint.java
@@ -485,14 +485,19 @@ public class QuartzEndpoint extends DefaultEndpoint {
         }
         if (cron != null) {
             LOG.debug("Creating CronTrigger: {}", cron);
-            final String startAt = (String) copy.get("startAt");
             SimpleDateFormat dateFormat = new 
SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssz");
+            final String startAt = (String) copy.get("startAt");
             if (startAt != null) {
                 triggerBuilder.startAt(dateFormat.parse(startAt));
             }
             final String endAt = (String) copy.get("endAt");
             if (endAt != null) {
-                triggerBuilder.endAt(dateFormat.parse(endAt));
+                Date endDate = dateFormat.parse(endAt);
+                if (endDate.before(new Date()) && startAt == null && 
isIgnoreExpiredNextFireTime()) {
+                    // Trigger Builder sets startAt to current time. Hence if 
startAt is null, necessary to add a valid value to honor 
ignoreExpiredNextFireTime
+                    
triggerBuilder.startAt(Date.from(endDate.toInstant().minusSeconds(1)));
+                }
+                triggerBuilder.endAt(endDate);
             }
             final String timeZone = (String) copy.get("timeZone");
             if (timeZone != null) {
diff --git 
a/components/camel-quartz/src/test/java/org/apache/camel/component/quartz/QuartzCronRouteWithEmptyStartDateExpiredEndDateTest.java
 
b/components/camel-quartz/src/test/java/org/apache/camel/component/quartz/QuartzCronRouteWithEmptyStartDateExpiredEndDateTest.java
new file mode 100644
index 00000000000..414173041e7
--- /dev/null
+++ 
b/components/camel-quartz/src/test/java/org/apache/camel/component/quartz/QuartzCronRouteWithEmptyStartDateExpiredEndDateTest.java
@@ -0,0 +1,58 @@
+/*
+ * 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.text.SimpleDateFormat;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.TimeZone;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.junit.jupiter.api.Test;
+
+/**
+ * This test the CronTrigger as a timer endpoint in a route.
+ */
+public class QuartzCronRouteWithEmptyStartDateExpiredEndDateTest extends 
BaseQuartzTest {
+
+    @Test
+    public void testQuartzCronRouteWithStartDateEndDateTest() throws Exception 
{
+        MockEndpoint mock = getMockEndpoint("mock:result");
+        mock.expectedMessageCount(0);
+        mock.await(2, TimeUnit.SECONDS);
+
+        MockEndpoint.assertIsSatisfied(context);
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() {
+        return new RouteBuilder() {
+            public void configure() {
+                SimpleDateFormat dateFormat = new 
SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssz");
+                Calendar calendar = Calendar.getInstance();
+                calendar.setTimeZone(TimeZone.getTimeZone("UTC"));
+                calendar.add(Calendar.YEAR, -2);
+                Date endDate = calendar.getTime();
+
+                fromF("quartz://myGroup/myTimerName?cron=0/1 * * * * 
?&ignoreExpiredNextFireTime=true&trigger.endAt=%s",
+                         dateFormat.format(endDate)).to("mock:result");
+            }
+        };
+    }
+}

Reply via email to