CAMEL-6614: Fixed suspend/resume quartz routes
Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/bef0be5b Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/bef0be5b Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/bef0be5b Branch: refs/heads/master Commit: bef0be5b7a935ef3d445ed49ec47f9b55662b6f7 Parents: ed7e7c9 Author: Claus Ibsen <davscl...@apache.org> Authored: Wed Aug 7 10:40:32 2013 +0200 Committer: Claus Ibsen <davscl...@apache.org> Committed: Wed Aug 7 10:43:31 2013 +0200 ---------------------------------------------------------------------- .../camel/component/quartz/QuartzConsumer.java | 12 ++++ .../component/quartz/QuartzStopRouteTest.java | 69 ++++++++++++++++++++ .../quartz/QuartzSuspendRouteTest.java | 69 ++++++++++++++++++++ 3 files changed, 150 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/bef0be5b/components/camel-quartz/src/main/java/org/apache/camel/component/quartz/QuartzConsumer.java ---------------------------------------------------------------------- diff --git a/components/camel-quartz/src/main/java/org/apache/camel/component/quartz/QuartzConsumer.java b/components/camel-quartz/src/main/java/org/apache/camel/component/quartz/QuartzConsumer.java index 436d626..fe88eac 100644 --- a/components/camel-quartz/src/main/java/org/apache/camel/component/quartz/QuartzConsumer.java +++ b/components/camel-quartz/src/main/java/org/apache/camel/component/quartz/QuartzConsumer.java @@ -40,8 +40,20 @@ public class QuartzConsumer extends DefaultConsumer { } @Override + protected void doResume() throws Exception { + super.doResume(); + getEndpoint().consumerStarted(this); + } + + @Override protected void doStop() throws Exception { getEndpoint().consumerStopped(this); super.doStop(); } + + @Override + protected void doSuspend() throws Exception { + getEndpoint().consumerStopped(this); + super.doSuspend(); + } } http://git-wip-us.apache.org/repos/asf/camel/blob/bef0be5b/components/camel-quartz/src/test/java/org/apache/camel/component/quartz/QuartzStopRouteTest.java ---------------------------------------------------------------------- diff --git a/components/camel-quartz/src/test/java/org/apache/camel/component/quartz/QuartzStopRouteTest.java b/components/camel-quartz/src/test/java/org/apache/camel/component/quartz/QuartzStopRouteTest.java new file mode 100644 index 0000000..6fd3da3 --- /dev/null +++ b/components/camel-quartz/src/test/java/org/apache/camel/component/quartz/QuartzStopRouteTest.java @@ -0,0 +1,69 @@ +/** + * 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 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 QuartzStopRouteTest extends CamelTestSupport { + + @Test + public void testQuartzStop() throws Exception { + MockEndpoint mock = getMockEndpoint("mock:result"); + mock.expectedMinimumMessageCount(1); + + assertMockEndpointsSatisfied(); + + context.stopRoute("foo"); + + int size = mock.getReceivedCounter(); + + resetMocks(); + + mock.expectedMessageCount(0); + mock.assertIsSatisfied(3000); + + assertEquals("Should not schedule when stopped", size, size); + + resetMocks(); + mock.expectedMinimumMessageCount(1); + + context.startRoute("foo"); + + assertMockEndpointsSatisfied(); + } + + @Override + protected RouteBuilder createRouteBuilder() { + return new RouteBuilder() { + public void configure() { + // START SNIPPET: e1 + // triggers every second at precise 00,01,02,03..59 + // notice we must use + as space when configured using URI parameter + from("quartz://myGroup/myTimerName?cron=0/1+*+*+*+*+?") + .routeId("foo") + .to("log:result", "mock:result"); + // END SNIPPET: e1 + } + }; + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/bef0be5b/components/camel-quartz/src/test/java/org/apache/camel/component/quartz/QuartzSuspendRouteTest.java ---------------------------------------------------------------------- diff --git a/components/camel-quartz/src/test/java/org/apache/camel/component/quartz/QuartzSuspendRouteTest.java b/components/camel-quartz/src/test/java/org/apache/camel/component/quartz/QuartzSuspendRouteTest.java new file mode 100644 index 0000000..3632cbc --- /dev/null +++ b/components/camel-quartz/src/test/java/org/apache/camel/component/quartz/QuartzSuspendRouteTest.java @@ -0,0 +1,69 @@ +/** + * 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 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 QuartzSuspendRouteTest extends CamelTestSupport { + + @Test + public void testQuartzSuspend() throws Exception { + MockEndpoint mock = getMockEndpoint("mock:result"); + mock.expectedMinimumMessageCount(1); + + assertMockEndpointsSatisfied(); + + context.suspendRoute("foo"); + + int size = mock.getReceivedCounter(); + + resetMocks(); + + mock.expectedMessageCount(0); + mock.assertIsSatisfied(3000); + + assertEquals("Should not schedule when suspended", size, size); + + resetMocks(); + mock.expectedMinimumMessageCount(1); + + context.resumeRoute("foo"); + + assertMockEndpointsSatisfied(); + } + + @Override + protected RouteBuilder createRouteBuilder() { + return new RouteBuilder() { + public void configure() { + // START SNIPPET: e1 + // triggers every second at precise 00,01,02,03..59 + // notice we must use + as space when configured using URI parameter + from("quartz://myGroup/myTimerName?cron=0/1+*+*+*+*+?") + .routeId("foo") + .to("log:result", "mock:result"); + // END SNIPPET: e1 + } + }; + } +} \ No newline at end of file