camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r1144306 - in /camel/trunk/components/camel-quartz/src: main/java/org/apache/camel/routepolicy/quartz/ test/java/org/apache/camel/routepolicy/quartz/
Date Fri, 08 Jul 2011 13:21:07 GMT
Author: davsclaus
Date: Fri Jul  8 13:21:07 2011
New Revision: 1144306

URL: http://svn.apache.org/viewvc?rev=1144306&view=rev
Log:
CAMEL-4197: scheduled route policy should not start quartz scheduler itself, but rely on QuartzComponent
doing that. Polished unit tests.

Modified:
    camel/trunk/components/camel-quartz/src/main/java/org/apache/camel/routepolicy/quartz/CronScheduledRoutePolicy.java
    camel/trunk/components/camel-quartz/src/test/java/org/apache/camel/routepolicy/quartz/CronScheduledRoutePolicyTest.java
    camel/trunk/components/camel-quartz/src/test/java/org/apache/camel/routepolicy/quartz/MultiplePoliciesOnRouteTest.java
    camel/trunk/components/camel-quartz/src/test/java/org/apache/camel/routepolicy/quartz/SimpleScheduledCombinedRoutePolicyTest.java
    camel/trunk/components/camel-quartz/src/test/java/org/apache/camel/routepolicy/quartz/SimpleScheduledRoutePolicyTest.java
    camel/trunk/components/camel-quartz/src/test/java/org/apache/camel/routepolicy/quartz/SpringCronScheduledRoutePolicyTest.java
    camel/trunk/components/camel-quartz/src/test/java/org/apache/camel/routepolicy/quartz/SpringMultiplePoliciesOnRouteTest.java
    camel/trunk/components/camel-quartz/src/test/java/org/apache/camel/routepolicy/quartz/SpringScheduledRoutePolicyTest.java
    camel/trunk/components/camel-quartz/src/test/java/org/apache/camel/routepolicy/quartz/SpringSimpleScheduledRoutePolicyTest.java

Modified: camel/trunk/components/camel-quartz/src/main/java/org/apache/camel/routepolicy/quartz/CronScheduledRoutePolicy.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-quartz/src/main/java/org/apache/camel/routepolicy/quartz/CronScheduledRoutePolicy.java?rev=1144306&r1=1144305&r2=1144306&view=diff
==============================================================================
--- camel/trunk/components/camel-quartz/src/main/java/org/apache/camel/routepolicy/quartz/CronScheduledRoutePolicy.java
(original)
+++ camel/trunk/components/camel-quartz/src/main/java/org/apache/camel/routepolicy/quartz/CronScheduledRoutePolicy.java
Fri Jul  8 13:21:07 2011
@@ -20,61 +20,64 @@ import java.util.concurrent.TimeUnit;
 
 import org.apache.camel.Route;
 import org.apache.camel.component.quartz.QuartzComponent;
+import org.apache.camel.util.ObjectHelper;
 import org.quartz.CronTrigger;
 import org.quartz.Trigger;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 public class CronScheduledRoutePolicy extends ScheduledRoutePolicy implements ScheduledRoutePolicyConstants
{
-    private static final transient Logger LOG = LoggerFactory.getLogger(CronScheduledRoutePolicy.class);
     private String routeStartTime;
     private String routeStopTime;
     private String routeSuspendTime;
     private String routeResumeTime;
     
-    public void onInit(Route route) {   
-        try {       
-            QuartzComponent quartz = route.getRouteContext().getCamelContext().getComponent("quartz",
QuartzComponent.class);
-            setScheduler(quartz.getScheduler());
-            
-            if (getRouteStopGracePeriod() == 0) {
-                setRouteStopGracePeriod(10000);
+    public void onInit(Route route) {
+        try {
+            doOnInit(route);
+        } catch (Exception e) {
+            throw ObjectHelper.wrapRuntimeCamelException(e);
+        }
+    }
+
+    protected void doOnInit(Route route) throws Exception {
+        QuartzComponent quartz = route.getRouteContext().getCamelContext().getComponent("quartz",
QuartzComponent.class);
+        setScheduler(quartz.getScheduler());
+
+        // Important: do not start scheduler as QuartzComponent does that automatic
+        // when CamelContext has been fully initialized and started
+
+        if (getRouteStopGracePeriod() == 0) {
+            setRouteStopGracePeriod(10000);
+        }
+
+        if (getTimeUnit() == null) {
+            setTimeUnit(TimeUnit.MILLISECONDS);
+        }
+
+        // validate time options has been configured
+        if ((getRouteStartTime() == null) && (getRouteStopTime() == null) &&
(getRouteSuspendTime() == null) && (getRouteResumeTime() == null)) {
+            throw new IllegalArgumentException("Scheduled Route Policy for route {} has no
stop/stop/suspend/resume times specified");
+        }
+
+        if (scheduledRouteDetails == null) {
+            scheduledRouteDetails = new ScheduledRouteDetails();
+            scheduledRouteDetails.setRoute(route);
+
+            if (getRouteStartTime() != null) {
+                scheduleRoute(Action.START);
             }
-            
-            if (getTimeUnit() == null) {
-                setTimeUnit(TimeUnit.MILLISECONDS);
+
+            if (getRouteStopTime() != null) {
+                scheduleRoute(Action.STOP);
             }
 
-            // validate time options has been configured
-            if ((getRouteStartTime() == null) && (getRouteStopTime() == null) &&
(getRouteSuspendTime() == null) && (getRouteResumeTime() == null)) {
-                throw new IllegalArgumentException("Scheduled Route Policy for route {} has
no stop/stop/suspend/resume times specified");
+            if (getRouteSuspendTime() != null) {
+                scheduleRoute(Action.SUSPEND);
             }
-        
-            if (scheduledRouteDetails == null) {
-                scheduledRouteDetails = new ScheduledRouteDetails();
-                scheduledRouteDetails.setRoute(route);
-                
-                if (getRouteStartTime() != null) {
-                    scheduleRoute(Action.START); 
-                }
-
-                if (getRouteStopTime() != null) {
-                    scheduleRoute(Action.STOP);
-                }
-                
-                if (getRouteSuspendTime() != null) {
-                    scheduleRoute(Action.SUSPEND);
-                }
-                if (getRouteResumeTime() != null) {
-                    scheduleRoute(Action.RESUME);
-                }
+            if (getRouteResumeTime() != null) {
+                scheduleRoute(Action.RESUME);
             }
-
-            getScheduler().start();
-        } catch (Exception e) {
-            handleException(e);
-        }        
-    }   
+        }
+    }
 
     @Override
     protected void doStop() throws Exception {

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=1144306&r1=1144305&r2=1144306&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
Fri Jul  8 13:21:07 2011
@@ -35,17 +35,6 @@ import org.slf4j.LoggerFactory;
 public class CronScheduledRoutePolicyTest extends CamelTestSupport {
     private static final transient Logger LOG = LoggerFactory.getLogger(CronScheduledRoutePolicyTest.class);
     
-    /* (non-Javadoc)
-     * @see org.apache.camel.test.junit4.CamelTestSupport#s;etUp()
-     */
-    @Override
-    public void setUp() throws Exception {
-        super.setUp();
-    }
-
-    /* (non-Javadoc)
-     * @see org.apache.camel.test.junit4.CamelTestSupport#isUseRouteBuilder()
-     */
     @Override
     public boolean isUseRouteBuilder() {
         return false;
@@ -53,13 +42,11 @@ public class CronScheduledRoutePolicyTes
 
     @Test
     public void testScheduledStartRoutePolicy() throws Exception {
-
-        MockEndpoint success = (MockEndpoint) context.getEndpoint("mock:success");      
 
-        
+        MockEndpoint success = (MockEndpoint) context.getEndpoint("mock:success");
         success.expectedMessageCount(1);
         
         context.getComponent("quartz", QuartzComponent.class).setPropertiesFile("org/apache/camel/routepolicy/quartz/myquartz.properties");
-        context.getComponent("quartz", QuartzComponent.class).start();
+
         context.addRoutes(new RouteBuilder() {
             public void configure() {    
                 CronScheduledRoutePolicy policy = new CronScheduledRoutePolicy();
@@ -87,7 +74,6 @@ public class CronScheduledRoutePolicyTes
         boolean consumerStopped = false;
         
         context.getComponent("quartz", QuartzComponent.class).setPropertiesFile("org/apache/camel/routepolicy/quartz/myquartz.properties");
-        context.getComponent("quartz", QuartzComponent.class).start();
         context.addRoutes(new RouteBuilder() {
             public void configure() {
                 CronScheduledRoutePolicy policy = new CronScheduledRoutePolicy();
@@ -121,7 +107,6 @@ public class CronScheduledRoutePolicyTes
         boolean consumerSuspended = false;
   
         context.getComponent("quartz", QuartzComponent.class).setPropertiesFile("org/apache/camel/routepolicy/quartz/myquartz.properties");
-        context.getComponent("quartz", QuartzComponent.class).start();
         context.addRoutes(new RouteBuilder() {
             public void configure() {
                 CronScheduledRoutePolicy policy = new CronScheduledRoutePolicy();
@@ -147,13 +132,10 @@ public class CronScheduledRoutePolicyTes
     
     @Test
     public void testScheduledResumeRoutePolicy() throws Exception {
-  
-        MockEndpoint success = (MockEndpoint) context.getEndpoint("mock:success");      
 
-        
+        MockEndpoint success = (MockEndpoint) context.getEndpoint("mock:success");
         success.expectedMessageCount(1);
         
         context.getComponent("quartz", QuartzComponent.class).setPropertiesFile("org/apache/camel/routepolicy/quartz/myquartz.properties");
-        context.getComponent("quartz", QuartzComponent.class).start();
         context.addRoutes(new RouteBuilder() {
             public void configure() {
                 CronScheduledRoutePolicy policy = new CronScheduledRoutePolicy();
@@ -166,6 +148,7 @@ public class CronScheduledRoutePolicyTes
             } 
         });
         context.start();
+
         ServiceHelper.suspendService(context.getRoute("test").getConsumer());
         try {
             template.sendBody("direct:start", "Ready or not, Here, I come");

Modified: camel/trunk/components/camel-quartz/src/test/java/org/apache/camel/routepolicy/quartz/MultiplePoliciesOnRouteTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-quartz/src/test/java/org/apache/camel/routepolicy/quartz/MultiplePoliciesOnRouteTest.java?rev=1144306&r1=1144305&r2=1144306&view=diff
==============================================================================
--- camel/trunk/components/camel-quartz/src/test/java/org/apache/camel/routepolicy/quartz/MultiplePoliciesOnRouteTest.java
(original)
+++ camel/trunk/components/camel-quartz/src/test/java/org/apache/camel/routepolicy/quartz/MultiplePoliciesOnRouteTest.java
Fri Jul  8 13:21:07 2011
@@ -37,14 +37,6 @@ public class MultiplePoliciesOnRouteTest
     private String url = "seda:foo?concurrentConsumers=20";
     private int size = 100;
     
-    /* (non-Javadoc)
-     * @see org.apache.camel.test.junit4.CamelTestSupport#s;etUp()
-     */
-    @Override
-    public void setUp() throws Exception {
-        super.setUp();
-    }
-
     @Override
     protected JndiRegistry createRegistry() throws Exception {
         JndiRegistry registry = new JndiRegistry(createJndiContext());
@@ -53,9 +45,6 @@ public class MultiplePoliciesOnRouteTest
         return registry;
     }
     
-    /* (non-Javadoc)
-     * @see org.apache.camel.test.junit4.CamelTestSupport#isUseRouteBuilder()
-     */
     @Override
     public boolean isUseRouteBuilder() {
         return false;
@@ -80,11 +69,9 @@ public class MultiplePoliciesOnRouteTest
     @Test
     public void testMultiplePoliciesOnRoute() throws Exception {
         MockEndpoint success = (MockEndpoint) context.getEndpoint("mock:success");      
 
-        
         success.expectedMinimumMessageCount(size - 10);
         
         context.getComponent("quartz", QuartzComponent.class).setPropertiesFile("org/apache/camel/routepolicy/quartz/myquartz.properties");
-        context.getComponent("quartz", QuartzComponent.class).start();
         context.addRoutes(new RouteBuilder() {
             public void configure() {   
                 from(url)
@@ -95,6 +82,7 @@ public class MultiplePoliciesOnRouteTest
             }
         });
         context.start();
+
         assertTrue(context.getRouteStatus("test") == ServiceStatus.Started);
         for (int i = 0; i < size; i++) {
             template.sendBody(url, "Message " + i);

Modified: camel/trunk/components/camel-quartz/src/test/java/org/apache/camel/routepolicy/quartz/SimpleScheduledCombinedRoutePolicyTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-quartz/src/test/java/org/apache/camel/routepolicy/quartz/SimpleScheduledCombinedRoutePolicyTest.java?rev=1144306&r1=1144305&r2=1144306&view=diff
==============================================================================
--- camel/trunk/components/camel-quartz/src/test/java/org/apache/camel/routepolicy/quartz/SimpleScheduledCombinedRoutePolicyTest.java
(original)
+++ camel/trunk/components/camel-quartz/src/test/java/org/apache/camel/routepolicy/quartz/SimpleScheduledCombinedRoutePolicyTest.java
Fri Jul  8 13:21:07 2011
@@ -32,17 +32,6 @@ import org.slf4j.LoggerFactory;
  */
 public class SimpleScheduledCombinedRoutePolicyTest extends CamelTestSupport {
     
-    /* (non-Javadoc)
-     * @see org.apache.camel.test.junit4.CamelTestSupport#s;etUp()
-     */
-    @Override
-    public void setUp() throws Exception {
-        super.setUp();
-    }
-    
-    /* (non-Javadoc)
-     * @see org.apache.camel.test.junit4.CamelTestSupport#isUseRouteBuilder()
-     */
     @Override
     public boolean isUseRouteBuilder() {
         return false;
@@ -51,11 +40,9 @@ public class SimpleScheduledCombinedRout
     @Test
     public void testScheduledStartAndStopRoutePolicy() throws Exception {
         MockEndpoint success = (MockEndpoint) context.getEndpoint("mock:success");      
 
-        
         success.expectedMessageCount(1);
         
         context.getComponent("quartz", QuartzComponent.class).setPropertiesFile("org/apache/camel/routepolicy/quartz/myquartz.properties");
-        context.getComponent("quartz", QuartzComponent.class).start();
         context.addRoutes(new RouteBuilder() {
             public void configure() {   
                 SimpleScheduledRoutePolicy policy = new SimpleScheduledRoutePolicy();

Modified: camel/trunk/components/camel-quartz/src/test/java/org/apache/camel/routepolicy/quartz/SimpleScheduledRoutePolicyTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-quartz/src/test/java/org/apache/camel/routepolicy/quartz/SimpleScheduledRoutePolicyTest.java?rev=1144306&r1=1144305&r2=1144306&view=diff
==============================================================================
--- camel/trunk/components/camel-quartz/src/test/java/org/apache/camel/routepolicy/quartz/SimpleScheduledRoutePolicyTest.java
(original)
+++ camel/trunk/components/camel-quartz/src/test/java/org/apache/camel/routepolicy/quartz/SimpleScheduledRoutePolicyTest.java
Fri Jul  8 13:21:07 2011
@@ -36,17 +36,6 @@ import org.slf4j.LoggerFactory;
 public class SimpleScheduledRoutePolicyTest extends CamelTestSupport {
     private static final transient Logger LOG = LoggerFactory.getLogger(SimpleScheduledRoutePolicyTest.class);
     
-    /* (non-Javadoc)
-     * @see org.apache.camel.test.junit4.CamelTestSupport#s;etUp()
-     */
-    @Override
-    public void setUp() throws Exception {
-        super.setUp();
-    }
-    
-    /* (non-Javadoc)
-     * @see org.apache.camel.test.junit4.CamelTestSupport#isUseRouteBuilder()
-     */
     @Override
     public boolean isUseRouteBuilder() {
         return false;
@@ -55,11 +44,9 @@ public class SimpleScheduledRoutePolicyT
     @Test
     public void testScheduledStartRoutePolicy() throws Exception {
         MockEndpoint success = (MockEndpoint) context.getEndpoint("mock:success");      
 
-        
         success.expectedMessageCount(1);
         
         context.getComponent("quartz", QuartzComponent.class).setPropertiesFile("org/apache/camel/routepolicy/quartz/myquartz.properties");
-        context.getComponent("quartz", QuartzComponent.class).start();
         context.addRoutes(new RouteBuilder() {
             public void configure() {   
                 SimpleScheduledRoutePolicy policy = new SimpleScheduledRoutePolicy();
@@ -90,7 +77,6 @@ public class SimpleScheduledRoutePolicyT
         boolean consumerStopped = false;
   
         context.getComponent("quartz", QuartzComponent.class).setPropertiesFile("org/apache/camel/routepolicy/quartz/myquartz.properties");
-        context.getComponent("quartz", QuartzComponent.class).start();
         context.addRoutes(new RouteBuilder() {
             public void configure() {
                 SimpleScheduledRoutePolicy policy = new SimpleScheduledRoutePolicy();
@@ -125,7 +111,6 @@ public class SimpleScheduledRoutePolicyT
         boolean consumerSuspended = false;
        
         context.getComponent("quartz", QuartzComponent.class).setPropertiesFile("org/apache/camel/routepolicy/quartz/myquartz.properties");
-        context.getComponent("quartz", QuartzComponent.class).start();
         context.addRoutes(new RouteBuilder() {
             public void configure() {
                 SimpleScheduledRoutePolicy policy = new SimpleScheduledRoutePolicy();
@@ -154,13 +139,10 @@ public class SimpleScheduledRoutePolicyT
     
     @Test
     public void testScheduledResumeRoutePolicy() throws Exception {
-  
-        MockEndpoint success = (MockEndpoint) context.getEndpoint("mock:success");      
 
-        
+        MockEndpoint success = (MockEndpoint) context.getEndpoint("mock:success");
         success.expectedMessageCount(1);
         
         context.getComponent("quartz", QuartzComponent.class).setPropertiesFile("org/apache/camel/routepolicy/quartz/myquartz.properties");
-        context.getComponent("quartz", QuartzComponent.class).start();
         context.addRoutes(new RouteBuilder() {
             public void configure() {
                 SimpleScheduledRoutePolicy policy = new SimpleScheduledRoutePolicy();
@@ -176,6 +158,7 @@ public class SimpleScheduledRoutePolicyT
             } 
         });
         context.start();
+
         ServiceHelper.suspendService(context.getRoute("test").getConsumer());
         try {
             template.sendBody("direct:start", "Ready or not, Here, I come");

Modified: camel/trunk/components/camel-quartz/src/test/java/org/apache/camel/routepolicy/quartz/SpringCronScheduledRoutePolicyTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-quartz/src/test/java/org/apache/camel/routepolicy/quartz/SpringCronScheduledRoutePolicyTest.java?rev=1144306&r1=1144305&r2=1144306&view=diff
==============================================================================
--- camel/trunk/components/camel-quartz/src/test/java/org/apache/camel/routepolicy/quartz/SpringCronScheduledRoutePolicyTest.java
(original)
+++ camel/trunk/components/camel-quartz/src/test/java/org/apache/camel/routepolicy/quartz/SpringCronScheduledRoutePolicyTest.java
Fri Jul  8 13:21:07 2011
@@ -20,8 +20,7 @@ import org.junit.Before;
 import org.junit.Test;
 import org.springframework.context.support.ClassPathXmlApplicationContext;
 
-public class SpringCronScheduledRoutePolicyTest extends
-        SpringScheduledRoutePolicyTest { 
+public class SpringCronScheduledRoutePolicyTest extends SpringScheduledRoutePolicyTest {
 
     @Before
     public void setUp() {

Modified: camel/trunk/components/camel-quartz/src/test/java/org/apache/camel/routepolicy/quartz/SpringMultiplePoliciesOnRouteTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-quartz/src/test/java/org/apache/camel/routepolicy/quartz/SpringMultiplePoliciesOnRouteTest.java?rev=1144306&r1=1144305&r2=1144306&view=diff
==============================================================================
--- camel/trunk/components/camel-quartz/src/test/java/org/apache/camel/routepolicy/quartz/SpringMultiplePoliciesOnRouteTest.java
(original)
+++ camel/trunk/components/camel-quartz/src/test/java/org/apache/camel/routepolicy/quartz/SpringMultiplePoliciesOnRouteTest.java
Fri Jul  8 13:21:07 2011
@@ -44,12 +44,8 @@ public class SpringMultiplePoliciesOnRou
         assertMockEndpointsSatisfied();
     }
 
-    /* (non-Javadoc)
-     * @see org.apache.camel.test.CamelSpringTestSupport#createApplicationContext()
-     */
     @Override
     protected AbstractApplicationContext createApplicationContext() {
-        // TODO Auto-generated method stub
         return new ClassPathXmlApplicationContext("org/apache/camel/routepolicy/quartz/MultiplePolicies.xml");
     }
     

Modified: camel/trunk/components/camel-quartz/src/test/java/org/apache/camel/routepolicy/quartz/SpringScheduledRoutePolicyTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-quartz/src/test/java/org/apache/camel/routepolicy/quartz/SpringScheduledRoutePolicyTest.java?rev=1144306&r1=1144305&r2=1144306&view=diff
==============================================================================
--- camel/trunk/components/camel-quartz/src/test/java/org/apache/camel/routepolicy/quartz/SpringScheduledRoutePolicyTest.java
(original)
+++ camel/trunk/components/camel-quartz/src/test/java/org/apache/camel/routepolicy/quartz/SpringScheduledRoutePolicyTest.java
Fri Jul  8 13:21:07 2011
@@ -123,8 +123,7 @@ public abstract class SpringScheduledRou
         return applicationContext;
     }
 
-    public void setApplicationContext(
-            ClassPathXmlApplicationContext applicationContext) {
+    public void setApplicationContext(ClassPathXmlApplicationContext applicationContext)
{
         this.applicationContext = applicationContext;
     }
 

Modified: camel/trunk/components/camel-quartz/src/test/java/org/apache/camel/routepolicy/quartz/SpringSimpleScheduledRoutePolicyTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-quartz/src/test/java/org/apache/camel/routepolicy/quartz/SpringSimpleScheduledRoutePolicyTest.java?rev=1144306&r1=1144305&r2=1144306&view=diff
==============================================================================
--- camel/trunk/components/camel-quartz/src/test/java/org/apache/camel/routepolicy/quartz/SpringSimpleScheduledRoutePolicyTest.java
(original)
+++ camel/trunk/components/camel-quartz/src/test/java/org/apache/camel/routepolicy/quartz/SpringSimpleScheduledRoutePolicyTest.java
Fri Jul  8 13:21:07 2011
@@ -20,8 +20,7 @@ import org.junit.Before;
 import org.junit.Test;
 import org.springframework.context.support.ClassPathXmlApplicationContext;
 
-public class SpringSimpleScheduledRoutePolicyTest extends
-        SpringScheduledRoutePolicyTest { 
+public class SpringSimpleScheduledRoutePolicyTest extends SpringScheduledRoutePolicyTest
{
     
     @Before
     public void setUp() {



Mime
View raw message