camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r1309945 - in /camel/trunk/camel-core/src: main/java/org/apache/camel/component/timer/ test/java/org/apache/camel/component/timer/
Date Thu, 05 Apr 2012 17:04:04 GMT
Author: davsclaus
Date: Thu Apr  5 17:04:04 2012
New Revision: 1309945

URL: http://svn.apache.org/viewvc?rev=1309945&view=rev
Log:
CAMEL-5137: Fixed timer component suspend/resume issue.

Added:
    camel/trunk/camel-core/src/test/java/org/apache/camel/component/timer/TimerSuspendCamelContextTest.java
      - copied, changed from r1309939, camel/trunk/camel-core/src/test/java/org/apache/camel/component/timer/TimerRestartTest.java
Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/component/timer/TimerConsumer.java
    camel/trunk/camel-core/src/test/java/org/apache/camel/component/timer/TimerRestartTest.java

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/timer/TimerConsumer.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/timer/TimerConsumer.java?rev=1309945&r1=1309944&r2=1309945&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/timer/TimerConsumer.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/timer/TimerConsumer.java
Thu Apr  5 17:04:04 2012
@@ -50,6 +50,11 @@ public class TimerConsumer extends Defau
 
             @Override
             public void run() {
+                if (!isTaskRunAllowed()) {
+                    // do not run timer task as it was not allowed
+                    return;
+                }
+
                 try {
                     long count = counter.incrementAndGet();
 
@@ -80,6 +85,14 @@ public class TimerConsumer extends Defau
         task = null;
     }
 
+    /**
+     * Whether the timer task is allow to run or not
+     */
+    protected boolean isTaskRunAllowed() {
+        // only allow running the timer task if we can run and are not suspended
+        return isRunAllowed() && !isSuspended();
+    }
+
     protected void configureTask(TimerTask task, Timer timer) {
         if (endpoint.isFixedRate()) {
             if (endpoint.getTime() != null) {

Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/component/timer/TimerRestartTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/component/timer/TimerRestartTest.java?rev=1309945&r1=1309944&r2=1309945&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/component/timer/TimerRestartTest.java
(original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/component/timer/TimerRestartTest.java
Thu Apr  5 17:04:04 2012
@@ -31,7 +31,11 @@ public class TimerRestartTest extends Co
 
         assertMockEndpointsSatisfied();
 
+        mock.reset();
+        mock.expectedMessageCount(0);
+
         context.stop();
+        Thread.sleep(2000);
 
         mock.reset();
 

Copied: camel/trunk/camel-core/src/test/java/org/apache/camel/component/timer/TimerSuspendCamelContextTest.java
(from r1309939, camel/trunk/camel-core/src/test/java/org/apache/camel/component/timer/TimerRestartTest.java)
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/component/timer/TimerSuspendCamelContextTest.java?p2=camel/trunk/camel-core/src/test/java/org/apache/camel/component/timer/TimerSuspendCamelContextTest.java&p1=camel/trunk/camel-core/src/test/java/org/apache/camel/component/timer/TimerRestartTest.java&r1=1309939&r2=1309945&rev=1309945&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/component/timer/TimerRestartTest.java
(original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/component/timer/TimerSuspendCamelContextTest.java
Thu Apr  5 17:04:04 2012
@@ -23,22 +23,26 @@ import org.apache.camel.component.mock.M
 /**
  * @version 
  */
-public class TimerRestartTest extends ContextTestSupport {
+public class TimerSuspendCamelContextTest extends ContextTestSupport {
 
-    public void testTimerRestart() throws Exception {
+    public void testTimerSuspendResume() throws Exception {
         MockEndpoint mock = getMockEndpoint("mock:result");
         mock.expectedMinimumMessageCount(1);
 
         assertMockEndpointsSatisfied();
 
-        context.stop();
-
         mock.reset();
+        mock.expectedMessageCount(0);
+
+        context.suspend();
+        Thread.sleep(2000);
 
-        context.start();
+        assertMockEndpointsSatisfied();
 
+        mock.reset();
         mock.expectedMinimumMessageCount(1);
 
+        context.resume();
         assertMockEndpointsSatisfied();
     }
 



Mime
View raw message