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 2017/05/29 11:45:50 UTC
[2/3] camel git commit: CAMEL-11355: Timer consumer should be
suspendable so it can shutdown graceful in a better way.
CAMEL-11355: Timer consumer should be suspendable so it can shutdown graceful in a better way.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/1d6bde9d
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/1d6bde9d
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/1d6bde9d
Branch: refs/heads/camel-2.19.x
Commit: 1d6bde9deaf4a5bca069b9dcaf49de3d63689a57
Parents: 480239b
Author: Claus Ibsen <da...@apache.org>
Authored: Mon May 29 13:43:41 2017 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Mon May 29 13:45:25 2017 +0200
----------------------------------------------------------------------
.../camel/component/timer/TimerConsumer.java | 3 +-
.../timer/TimerGracefulShutdownTest.java | 90 ++++++++++++++++++++
2 files changed, 92 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/1d6bde9d/camel-core/src/main/java/org/apache/camel/component/timer/TimerConsumer.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/component/timer/TimerConsumer.java b/camel-core/src/main/java/org/apache/camel/component/timer/TimerConsumer.java
index eedcd18..8908cfa 100644
--- a/camel-core/src/main/java/org/apache/camel/component/timer/TimerConsumer.java
+++ b/camel-core/src/main/java/org/apache/camel/component/timer/TimerConsumer.java
@@ -27,6 +27,7 @@ import org.apache.camel.CamelContext;
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.apache.camel.StartupListener;
+import org.apache.camel.Suspendable;
import org.apache.camel.impl.DefaultConsumer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -36,7 +37,7 @@ import org.slf4j.LoggerFactory;
*
* @version
*/
-public class TimerConsumer extends DefaultConsumer implements StartupListener {
+public class TimerConsumer extends DefaultConsumer implements StartupListener, Suspendable {
private static final Logger LOG = LoggerFactory.getLogger(TimerConsumer.class);
private final TimerEndpoint endpoint;
private volatile TimerTask task;
http://git-wip-us.apache.org/repos/asf/camel/blob/1d6bde9d/camel-core/src/test/java/org/apache/camel/component/timer/TimerGracefulShutdownTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/component/timer/TimerGracefulShutdownTest.java b/camel-core/src/test/java/org/apache/camel/component/timer/TimerGracefulShutdownTest.java
new file mode 100644
index 0000000..825d8f4
--- /dev/null
+++ b/camel-core/src/test/java/org/apache/camel/component/timer/TimerGracefulShutdownTest.java
@@ -0,0 +1,90 @@
+/**
+ * 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.timer;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.impl.JndiRegistry;
+import org.apache.camel.spi.ExceptionHandler;
+
+/**
+ * @version
+ */
+public class TimerGracefulShutdownTest extends ContextTestSupport {
+
+ private MyExceptionHandler eh = new MyExceptionHandler();
+
+ @Override
+ protected JndiRegistry createRegistry() throws Exception {
+ JndiRegistry jndi = super.createRegistry();
+ jndi.bind("eh", eh);
+ return jndi;
+ }
+
+ public void testTimerShutdown() throws Exception {
+ MockEndpoint mock = getMockEndpoint("mock:result");
+ mock.expectedMinimumMessageCount(1);
+
+ assertMockEndpointsSatisfied();
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ super.tearDown();
+
+ assertFalse("Should not throw exception during graceful shutdown", eh.isError());
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("timer:foo?period=100&exceptionHandler=#eh")
+ .delay(200)
+ .to("log:time")
+ .to("mock:result");
+ }
+ };
+ }
+
+ private static final class MyExceptionHandler implements ExceptionHandler {
+
+ private volatile boolean error;
+
+ @Override
+ public void handleException(Throwable exception) {
+ error = true;
+ }
+
+ @Override
+ public void handleException(String message, Throwable exception) {
+ error = true;
+ }
+
+ @Override
+ public void handleException(String message, Exchange exchange, Throwable exception) {
+ error = true;
+ }
+
+ public boolean isError() {
+ return error;
+ }
+ }
+}