You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by cm...@apache.org on 2012/09/09 19:08:30 UTC

svn commit: r1382540 - in /camel/trunk/components/camel-quartz/src: main/java/org/apache/camel/component/quartz/ test/java/org/apache/camel/component/quartz/

Author: cmueller
Date: Sun Sep  9 17:08:30 2012
New Revision: 1382540

URL: http://svn.apache.org/viewvc?rev=1382540&view=rev
Log:
CAMEL-5577: camel-quartz - Support the URL option startDelayedSeconds

Added:
    camel/trunk/components/camel-quartz/src/test/java/org/apache/camel/component/quartz/QuartzStartDelayedOptionTest.java
      - copied, changed from r1382523, camel/trunk/components/camel-quartz/src/test/java/org/apache/camel/component/quartz/QuartzStartDelayedTest.java
Modified:
    camel/trunk/components/camel-quartz/src/main/java/org/apache/camel/component/quartz/QuartzComponent.java
    camel/trunk/components/camel-quartz/src/test/java/org/apache/camel/component/quartz/QuartzStartDelayedTest.java

Modified: camel/trunk/components/camel-quartz/src/main/java/org/apache/camel/component/quartz/QuartzComponent.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-quartz/src/main/java/org/apache/camel/component/quartz/QuartzComponent.java?rev=1382540&r1=1382539&r2=1382540&view=diff
==============================================================================
--- camel/trunk/components/camel-quartz/src/main/java/org/apache/camel/component/quartz/QuartzComponent.java (original)
+++ camel/trunk/components/camel-quartz/src/main/java/org/apache/camel/component/quartz/QuartzComponent.java Sun Sep  9 17:08:30 2012
@@ -88,13 +88,23 @@ public class QuartzComponent extends Def
 
     @Override
     protected QuartzEndpoint createEndpoint(final String uri, final String remaining, final Map<String, Object> parameters) throws Exception {
-
         // lets split the remaining into a group/name
         URI u = new URI(uri);
         String path = ObjectHelper.after(u.getPath(), "/");
         String host = u.getHost();
         String cron = getAndRemoveParameter(parameters, "cron", String.class);
         Boolean fireNow = getAndRemoveParameter(parameters, "fireNow", Boolean.class, Boolean.FALSE);
+        Integer startDelayedSeconds = getAndRemoveParameter(parameters, "startDelayedSeconds", Integer.class);
+        if (startDelayedSeconds != null) {
+            if (scheduler.isStarted()) {
+                LOG.warn("A Quartz job is already started. Cannot apply the 'startDelayedSeconds' configuration!");
+            } else if (this.startDelayedSeconds != 0 && !(this.startDelayedSeconds == startDelayedSeconds)) {
+                LOG.warn("A Quartz job is already configured with a different 'startDelayedSeconds' configuration! "
+                    + "All Quartz jobs must share the same 'startDelayedSeconds' configuration! Cannot apply the 'startDelayedSeconds' configuration!");
+            } else {
+                this.startDelayedSeconds = startDelayedSeconds;
+            }
+        }
 
         // host can be null if the uri did contain invalid host characters such as an underscore
         if (host == null) {

Copied: camel/trunk/components/camel-quartz/src/test/java/org/apache/camel/component/quartz/QuartzStartDelayedOptionTest.java (from r1382523, camel/trunk/components/camel-quartz/src/test/java/org/apache/camel/component/quartz/QuartzStartDelayedTest.java)
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-quartz/src/test/java/org/apache/camel/component/quartz/QuartzStartDelayedOptionTest.java?p2=camel/trunk/components/camel-quartz/src/test/java/org/apache/camel/component/quartz/QuartzStartDelayedOptionTest.java&p1=camel/trunk/components/camel-quartz/src/test/java/org/apache/camel/component/quartz/QuartzStartDelayedTest.java&r1=1382523&r2=1382540&rev=1382540&view=diff
==============================================================================
--- camel/trunk/components/camel-quartz/src/test/java/org/apache/camel/component/quartz/QuartzStartDelayedTest.java (original)
+++ camel/trunk/components/camel-quartz/src/test/java/org/apache/camel/component/quartz/QuartzStartDelayedOptionTest.java Sun Sep  9 17:08:30 2012
@@ -19,25 +19,18 @@ package org.apache.camel.component.quart
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
 import org.apache.camel.test.junit4.CamelTestSupport;
-import org.apache.camel.util.StopWatch;
 import org.junit.Test;
 
-/**
- * @version 
- */
-public class QuartzStartDelayedTest extends CamelTestSupport {
+public class QuartzStartDelayedOptionTest extends CamelTestSupport {
 
     @Test
     public void testStartDelayed() throws Exception {
-        StopWatch watch = new StopWatch();
-
         MockEndpoint mock = getMockEndpoint("mock:result");
+        mock.setMinimumResultWaitTime(1900);
+        mock.setResultWaitTime(3000);
         mock.expectedMessageCount(2);
 
         assertMockEndpointsSatisfied();
-
-        long time = watch.stop();
-        assertTrue("Should take longer than 3 seconds, was: " + time + " millis.", time > 2500);
     }
 
     @Override
@@ -45,10 +38,8 @@ public class QuartzStartDelayedTest exte
         return new RouteBuilder() {
             @Override
             public void configure() throws Exception {
-                QuartzComponent quartz = context.getComponent("quartz", QuartzComponent.class);
-                quartz.setStartDelayedSeconds(3);
-
-                from("quartz://myGroup/myTimerName?trigger.repeatInterval=2&trigger.repeatCount=1").routeId("myRoute").to("mock:result");
+                from("quartz://myGroup/myTimerName?startDelayedSeconds=2&trigger.repeatInterval=2&trigger.repeatCount=1").routeId("myRoute")
+                    .to("mock:result");
             }
         };
     }

Modified: camel/trunk/components/camel-quartz/src/test/java/org/apache/camel/component/quartz/QuartzStartDelayedTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-quartz/src/test/java/org/apache/camel/component/quartz/QuartzStartDelayedTest.java?rev=1382540&r1=1382539&r2=1382540&view=diff
==============================================================================
--- camel/trunk/components/camel-quartz/src/test/java/org/apache/camel/component/quartz/QuartzStartDelayedTest.java (original)
+++ camel/trunk/components/camel-quartz/src/test/java/org/apache/camel/component/quartz/QuartzStartDelayedTest.java Sun Sep  9 17:08:30 2012
@@ -19,25 +19,18 @@ package org.apache.camel.component.quart
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
 import org.apache.camel.test.junit4.CamelTestSupport;
-import org.apache.camel.util.StopWatch;
 import org.junit.Test;
 
-/**
- * @version 
- */
 public class QuartzStartDelayedTest extends CamelTestSupport {
 
     @Test
     public void testStartDelayed() throws Exception {
-        StopWatch watch = new StopWatch();
-
         MockEndpoint mock = getMockEndpoint("mock:result");
+        mock.setMinimumResultWaitTime(1900);
+        mock.setResultWaitTime(3000);
         mock.expectedMessageCount(2);
 
         assertMockEndpointsSatisfied();
-
-        long time = watch.stop();
-        assertTrue("Should take longer than 3 seconds, was: " + time + " millis.", time > 2500);
     }
 
     @Override
@@ -46,7 +39,7 @@ public class QuartzStartDelayedTest exte
             @Override
             public void configure() throws Exception {
                 QuartzComponent quartz = context.getComponent("quartz", QuartzComponent.class);
-                quartz.setStartDelayedSeconds(3);
+                quartz.setStartDelayedSeconds(2);
 
                 from("quartz://myGroup/myTimerName?trigger.repeatInterval=2&trigger.repeatCount=1").routeId("myRoute").to("mock:result");
             }