You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2013/08/07 10:43:21 UTC
[2/2] git commit: CAMEL-6614: Fixed suspend/resume quartz routes
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/12b3d114
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/12b3d114
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/12b3d114
Branch: refs/heads/camel-2.10.x
Commit: 12b3d1147c1672e141593b0a5595f96e5d995769
Parents: 606dccf
Author: Claus Ibsen <da...@apache.org>
Authored: Wed Aug 7 10:40:32 2013 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Wed Aug 7 10:42:58 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/12b3d114/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/12b3d114/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/12b3d114/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