Updated Branches: refs/heads/camel-2.12.x 96a33ffae -> 1de943ff4
CAMEL-7029: Fixed quartz2 simple trigger default value for repeat counter to work as expected. Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/1de943ff Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/1de943ff Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/1de943ff Branch: refs/heads/camel-2.12.x Commit: 1de943ff4c3d01410d38460ae70e06b681820d64 Parents: 96a33ff Author: Claus Ibsen <davscl...@apache.org> Authored: Mon Dec 2 21:43:05 2013 +0100 Committer: Claus Ibsen <davscl...@apache.org> Committed: Mon Dec 2 21:43:57 2013 +0100 ---------------------------------------------------------------------- .../camel/component/quartz2/QuartzEndpoint.java | 25 ++++++---- .../quartz2/QuartzRepeatIntervalTest.java | 49 ++++++++++++++++++++ .../quartz2/QuartzRouteFireNowTest.java | 4 +- 3 files changed, 69 insertions(+), 9 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/1de943ff/components/camel-quartz2/src/main/java/org/apache/camel/component/quartz2/QuartzEndpoint.java ---------------------------------------------------------------------- diff --git a/components/camel-quartz2/src/main/java/org/apache/camel/component/quartz2/QuartzEndpoint.java b/components/camel-quartz2/src/main/java/org/apache/camel/component/quartz2/QuartzEndpoint.java index 891ee83..de94beb 100644 --- a/components/camel-quartz2/src/main/java/org/apache/camel/component/quartz2/QuartzEndpoint.java +++ b/components/camel-quartz2/src/main/java/org/apache/camel/component/quartz2/QuartzEndpoint.java @@ -256,7 +256,7 @@ public class QuartzEndpoint extends DefaultEndpoint { JobDataMap jobDataMap = jobDetail.getJobDataMap(); String camelContextName = getCamelContext().getManagementName(); String endpointUri = getEndpointUri(); - LOG.debug("Adding camelContextName={}, endpintUri={} into job data map.", camelContextName, endpointUri); + LOG.debug("Adding camelContextName={}, endpointUri={} into job data map.", camelContextName, endpointUri); jobDataMap.put(QuartzConstants.QUARTZ_CAMEL_CONTEXT_NAME, camelContextName); jobDataMap.put(QuartzConstants.QUARTZ_ENDPOINT_URI, endpointUri); } @@ -276,18 +276,27 @@ public class QuartzEndpoint extends DefaultEndpoint { .build(); } else { LOG.debug("Creating SimpleTrigger."); + int repeat = SimpleTrigger.REPEAT_INDEFINITELY; + String repeatString = (String) triggerParameters.get("repeatCount"); + if (repeatString != null) { + repeat = Integer.valueOf(repeatString); + } + + // default use 1 sec interval + long interval = 1000; + String intervalString = (String) triggerParameters.get("repeatInterval"); + if (intervalString != null) { + interval = Long.valueOf(intervalString); + } + TriggerBuilder<SimpleTrigger> triggerBuilder = TriggerBuilder.newTrigger() .withIdentity(triggerKey) .startAt(startTime) - .withSchedule(simpleSchedule().withMisfireHandlingInstructionFireNow()); + .withSchedule(simpleSchedule().withMisfireHandlingInstructionFireNow() + .withRepeatCount(repeat).withIntervalInMilliseconds(interval)); - // Enable trigger to fire now by setting startTime in the past. if (fireNow) { - String intervalString = (String) triggerParameters.get("repeatInterval"); - if (intervalString != null) { - long interval = Long.valueOf(intervalString); - triggerBuilder.startAt(new Date(System.currentTimeMillis() - interval)); - } + triggerBuilder.startNow(); } result = triggerBuilder.build(); http://git-wip-us.apache.org/repos/asf/camel/blob/1de943ff/components/camel-quartz2/src/test/java/org/apache/camel/component/quartz2/QuartzRepeatIntervalTest.java ---------------------------------------------------------------------- diff --git a/components/camel-quartz2/src/test/java/org/apache/camel/component/quartz2/QuartzRepeatIntervalTest.java b/components/camel-quartz2/src/test/java/org/apache/camel/component/quartz2/QuartzRepeatIntervalTest.java new file mode 100644 index 0000000..c1c6d78 --- /dev/null +++ b/components/camel-quartz2/src/test/java/org/apache/camel/component/quartz2/QuartzRepeatIntervalTest.java @@ -0,0 +1,49 @@ +/** + * 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.quartz2; + +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.mock.MockEndpoint; +import org.apache.camel.test.junit4.CamelTestSupport; +import org.junit.Test; + +/** + * @version + */ +public class QuartzRepeatIntervalTest extends CamelTestSupport { + protected MockEndpoint resultEndpoint; + + @Test + public void testRepeatInterval() throws Exception { + resultEndpoint = getMockEndpoint("mock:result"); + resultEndpoint.expectedMinimumMessageCount(5); + + // lets test the receive worked + resultEndpoint.assertIsSatisfied(); + } + + @Override + protected RouteBuilder createRouteBuilder() { + return new RouteBuilder() { + public void configure() { + from("quartz2://myGroup/myTimerName?trigger.repeatInterval=50").routeId("myRoute") + .to("log:result") + .to("mock:result"); + } + }; + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/1de943ff/components/camel-quartz2/src/test/java/org/apache/camel/component/quartz2/QuartzRouteFireNowTest.java ---------------------------------------------------------------------- diff --git a/components/camel-quartz2/src/test/java/org/apache/camel/component/quartz2/QuartzRouteFireNowTest.java b/components/camel-quartz2/src/test/java/org/apache/camel/component/quartz2/QuartzRouteFireNowTest.java index f6d1c63..b7e4273 100644 --- a/components/camel-quartz2/src/test/java/org/apache/camel/component/quartz2/QuartzRouteFireNowTest.java +++ b/components/camel-quartz2/src/test/java/org/apache/camel/component/quartz2/QuartzRouteFireNowTest.java @@ -28,7 +28,9 @@ public class QuartzRouteFireNowTest extends QuartzRouteTest { return new RouteBuilder() { public void configure() { // START SNIPPET: example - from("quartz2://myGroup/myTimerName?fireNow=true&trigger.repeatInterval=25000&trigger.repeatCount=2").to("mock:result"); + from("quartz2://myGroup/myTimerName?fireNow=true&trigger.repeatInterval=2000&trigger.repeatCount=2") + .to("log:quartz") + .to("mock:result"); // END SNIPPET: example } };