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 2012/03/21 11:33:02 UTC

svn commit: r1303353 - in /camel/trunk/components/camel-quartz/src: main/java/org/apache/camel/routepolicy/quartz/ test/java/org/apache/camel/routepolicy/quartz/

Author: davsclaus
Date: Wed Mar 21 10:33:01 2012
New Revision: 1303353

URL: http://svn.apache.org/viewvc?rev=1303353&view=rev
Log:
Added test based on user forum issue

Added:
    camel/trunk/components/camel-quartz/src/test/java/org/apache/camel/routepolicy/quartz/MyRoutePolicy.java
Modified:
    camel/trunk/components/camel-quartz/src/main/java/org/apache/camel/routepolicy/quartz/ScheduledRoutePolicy.java
    camel/trunk/components/camel-quartz/src/test/java/org/apache/camel/routepolicy/quartz/CronScheduledRoutePolicyTest.java

Modified: camel/trunk/components/camel-quartz/src/main/java/org/apache/camel/routepolicy/quartz/ScheduledRoutePolicy.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-quartz/src/main/java/org/apache/camel/routepolicy/quartz/ScheduledRoutePolicy.java?rev=1303353&r1=1303352&r2=1303353&view=diff
==============================================================================
--- camel/trunk/components/camel-quartz/src/main/java/org/apache/camel/routepolicy/quartz/ScheduledRoutePolicy.java (original)
+++ camel/trunk/components/camel-quartz/src/main/java/org/apache/camel/routepolicy/quartz/ScheduledRoutePolicy.java Wed Mar 21 10:33:01 2012
@@ -52,6 +52,8 @@ public abstract class ScheduledRoutePoli
         } else if (action == Action.STOP) {
             if ((routeStatus == ServiceStatus.Started) || (routeStatus == ServiceStatus.Suspended)) {
                 stopRoute(route, getRouteStopGracePeriod(), getTimeUnit());
+            } else {
+                LOG.warn("Route is not in a started/suspended state and cannot be stopped. The current route state is {}", routeStatus);
             }
         } else if (action == Action.SUSPEND) {
             if (routeStatus == ServiceStatus.Started) {

Modified: camel/trunk/components/camel-quartz/src/test/java/org/apache/camel/routepolicy/quartz/CronScheduledRoutePolicyTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-quartz/src/test/java/org/apache/camel/routepolicy/quartz/CronScheduledRoutePolicyTest.java?rev=1303353&r1=1303352&r2=1303353&view=diff
==============================================================================
--- camel/trunk/components/camel-quartz/src/test/java/org/apache/camel/routepolicy/quartz/CronScheduledRoutePolicyTest.java (original)
+++ camel/trunk/components/camel-quartz/src/test/java/org/apache/camel/routepolicy/quartz/CronScheduledRoutePolicyTest.java Wed Mar 21 10:33:01 2012
@@ -185,6 +185,44 @@ public class CronScheduledRoutePolicyTes
     } 
     
     @Test
+    public void testScheduledStopRoutePolicyWithExtraPolicy() throws Exception {
+        boolean consumerStopped = false;
+
+        final MyRoutePolicy myPolicy = new MyRoutePolicy();
+
+        context.getComponent("quartz", QuartzComponent.class).setPropertiesFile("org/apache/camel/routepolicy/quartz/myquartz.properties");
+        context.addRoutes(new RouteBuilder() {
+            public void configure() {
+                CronScheduledRoutePolicy policy = new CronScheduledRoutePolicy();
+                policy.setRouteStopTime("*/3 * * * * ?");
+                policy.setRouteStopGracePeriod(0);
+                policy.setTimeUnit(TimeUnit.MILLISECONDS);
+
+                from("direct:start")
+                    .routeId("test")
+                    .routePolicy(policy, myPolicy)
+                    .to("mock:unreachable");
+            }
+        });
+        context.start();
+        
+        Thread.sleep(4000);
+
+        assertTrue(context.getRouteStatus("test") == ServiceStatus.Stopped);
+        
+        try {
+            template.sendBody("direct:start", "Ready or not, Here, I come");
+        } catch (CamelExecutionException e) {
+            consumerStopped = true;
+        }    
+        assertTrue(consumerStopped);
+        context.getComponent("quartz", QuartzComponent.class).stop();
+
+        assertTrue("Should have called onStart", myPolicy.isStart());
+        assertTrue("Should have called onStop", myPolicy.isStop());
+    }
+    
+    @Test
     public void testScheduledSuspendRoutePolicy() throws Exception {
         boolean consumerSuspended = false;
   

Added: camel/trunk/components/camel-quartz/src/test/java/org/apache/camel/routepolicy/quartz/MyRoutePolicy.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-quartz/src/test/java/org/apache/camel/routepolicy/quartz/MyRoutePolicy.java?rev=1303353&view=auto
==============================================================================
--- camel/trunk/components/camel-quartz/src/test/java/org/apache/camel/routepolicy/quartz/MyRoutePolicy.java (added)
+++ camel/trunk/components/camel-quartz/src/test/java/org/apache/camel/routepolicy/quartz/MyRoutePolicy.java Wed Mar 21 10:33:01 2012
@@ -0,0 +1,47 @@
+/**
+ * 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.routepolicy.quartz;
+
+import org.apache.camel.Route;
+import org.apache.camel.impl.RoutePolicySupport;
+
+/**
+ *
+ */
+public class MyRoutePolicy extends RoutePolicySupport {
+    
+    private boolean start;
+    private boolean stop;
+
+    @Override
+    public void onStart(Route route) {
+        start = true;
+    }
+
+    @Override
+    public void onStop(Route route) {
+        stop = true;
+    }
+
+    public boolean isStart() {
+        return start;
+    }
+
+    public boolean isStop() {
+        return stop;
+    }
+}