You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ak...@apache.org on 2010/09/28 23:02:33 UTC
svn commit: r1002354 - in /camel/trunk/components/camel-quartz/src:
main/java/org/apache/camel/routepolicy/quartz/
test/java/org/apache/camel/routepolicy/quartz/
test/resources/org/apache/camel/routepolicy/quartz/
Author: akarpe
Date: Tue Sep 28 21:02:33 2010
New Revision: 1002354
URL: http://svn.apache.org/viewvc?rev=1002354&view=rev
Log:
CAMEL-2936 Updated ScheduledRoutePolicy to use Quartz Component. Also added Spring Unit Tests
Added:
camel/trunk/components/camel-quartz/src/test/java/org/apache/camel/routepolicy/quartz/SimpleDate.java (with props)
camel/trunk/components/camel-quartz/src/test/java/org/apache/camel/routepolicy/quartz/SpringCronScheduledRoutePolicyTest.java (with props)
camel/trunk/components/camel-quartz/src/test/java/org/apache/camel/routepolicy/quartz/SpringScheduledRoutePolicyTest.java (with props)
camel/trunk/components/camel-quartz/src/test/java/org/apache/camel/routepolicy/quartz/SpringSimpleScheduledRoutePolicyTest.java (with props)
camel/trunk/components/camel-quartz/src/test/resources/org/apache/camel/routepolicy/quartz/CronPolicies.xml (with props)
camel/trunk/components/camel-quartz/src/test/resources/org/apache/camel/routepolicy/quartz/SimplePolicies.xml (with props)
Modified:
camel/trunk/components/camel-quartz/src/main/java/org/apache/camel/routepolicy/quartz/CronScheduledRoutePolicy.java
camel/trunk/components/camel-quartz/src/main/java/org/apache/camel/routepolicy/quartz/ScheduledRoutePolicy.java
camel/trunk/components/camel-quartz/src/main/java/org/apache/camel/routepolicy/quartz/SimpleScheduledRoutePolicy.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/SimpleScheduledRoutePolicyTest.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=1002354&r1=1002353&r2=1002354&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 Tue Sep 28 21:02:33 2010
@@ -16,9 +16,10 @@
*/
package org.apache.camel.routepolicy.quartz;
-import java.util.Properties;
+import java.util.concurrent.TimeUnit;
import org.apache.camel.Route;
+import org.apache.camel.component.quartz.QuartzComponent;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.quartz.CronTrigger;
@@ -31,20 +32,19 @@ public class CronScheduledRoutePolicy ex
private String routeSuspendTime;
private String routeResumeTime;
- public CronScheduledRoutePolicy() {
- super();
- }
-
- public CronScheduledRoutePolicy(String propertiesFile) {
- super(propertiesFile);
- }
-
- public CronScheduledRoutePolicy(Properties properties) {
- super(properties);
- }
-
public void onInit(Route route) {
try {
+ QuartzComponent quartz = route.getRouteContext().getCamelContext().getComponent("quartz", QuartzComponent.class);
+ setScheduler(quartz.getScheduler());
+
+ if (getRouteStopGracePeriod() == 0) {
+ setRouteStopGracePeriod(10000);
+ }
+
+ if (getTimeUnit() == null) {
+ setTimeUnit(TimeUnit.MILLISECONDS);
+ }
+
if ((getRouteStartTime() == null) && (getRouteStopTime() == null) && (getRouteSuspendTime() == null) && (getRouteResumeTime() == null)) {
if (LOG.isWarnEnabled()) {
LOG.warn("Scheduled Route Policy for route " + route.getId() + " is not set since the no start, stop and/or suspend times are specified");
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=1002354&r1=1002353&r2=1002354&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 Tue Sep 28 21:02:33 2010
@@ -16,61 +16,24 @@
*/
package org.apache.camel.routepolicy.quartz;
-import java.util.Properties;
import java.util.concurrent.TimeUnit;
import org.apache.camel.Route;
import org.apache.camel.ServiceStatus;
import org.apache.camel.impl.RoutePolicySupport;
-import org.apache.camel.util.ObjectHelper;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.Trigger;
-import org.quartz.impl.StdSchedulerFactory;
public abstract class ScheduledRoutePolicy extends RoutePolicySupport implements ScheduledRoutePolicyConstants {
private static final transient Log LOG = LogFactory.getLog(ScheduledRoutePolicy.class);
protected ScheduledRouteDetails scheduledRouteDetails;
- private Properties properties;
- private StdSchedulerFactory schedulerFactory;
private Scheduler scheduler;
private int routeStopGracePeriod;
private TimeUnit timeUnit;
-
- public ScheduledRoutePolicy() {
- this(new Properties());
- }
-
- public ScheduledRoutePolicy(String propertiesFile) {
- try {
- properties = new Properties();
- properties.load(ObjectHelper.loadResourceAsStream(propertiesFile));
- schedulerFactory = new StdSchedulerFactory(properties);
- setScheduler(schedulerFactory.getScheduler());
- } catch (Exception e) {
- handleException(e);
- }
- setRouteStopGracePeriod(10000);
- setTimeUnit(TimeUnit.MILLISECONDS);
- }
-
- public ScheduledRoutePolicy(Properties properties) {
- try {
- if (properties.isEmpty()) {
- schedulerFactory = new StdSchedulerFactory();
- } else {
- schedulerFactory = new StdSchedulerFactory(properties);
- }
- setScheduler(schedulerFactory.getScheduler());
- } catch (Exception e) {
- handleException(e);
- }
- setRouteStopGracePeriod(10000);
- setTimeUnit(TimeUnit.MILLISECONDS);
- }
protected abstract Trigger createTrigger(Action action, Route route) throws Exception;
@@ -149,7 +112,9 @@ public abstract class ScheduledRoutePoli
String jobDetailName = retrieveJobDetailName(action);
String jobDetailGroup = retrieveJobDetailGroup(action);
- getScheduler().deleteJob(jobDetailName, jobDetailGroup);
+ if (!getScheduler().isShutdown()) {
+ getScheduler().deleteJob(jobDetailName, jobDetailGroup);
+ }
if (LOG.isDebugEnabled()) {
LOG.debug("Scheduled Job: " + jobDetailGroup + "." + jobDetailName + " has been deleted");
Modified: camel/trunk/components/camel-quartz/src/main/java/org/apache/camel/routepolicy/quartz/SimpleScheduledRoutePolicy.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-quartz/src/main/java/org/apache/camel/routepolicy/quartz/SimpleScheduledRoutePolicy.java?rev=1002354&r1=1002353&r2=1002354&view=diff
==============================================================================
--- camel/trunk/components/camel-quartz/src/main/java/org/apache/camel/routepolicy/quartz/SimpleScheduledRoutePolicy.java (original)
+++ camel/trunk/components/camel-quartz/src/main/java/org/apache/camel/routepolicy/quartz/SimpleScheduledRoutePolicy.java Tue Sep 28 21:02:33 2010
@@ -17,9 +17,10 @@
package org.apache.camel.routepolicy.quartz;
import java.util.Date;
-import java.util.Properties;
+import java.util.concurrent.TimeUnit;
import org.apache.camel.Route;
+import org.apache.camel.component.quartz.QuartzComponent;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.quartz.SimpleTrigger;
@@ -39,21 +40,20 @@ public class SimpleScheduledRoutePolicy
private Date routeResumeDate;
private int routeResumeRepeatCount;
private long routeResumeRepeatInterval;
-
- public SimpleScheduledRoutePolicy() {
- super();
- }
-
- public SimpleScheduledRoutePolicy(String propertiesFile) {
- super(propertiesFile);
- }
-
- public SimpleScheduledRoutePolicy(Properties properties) {
- super(properties);
- }
public void onInit(Route route) {
try {
+ QuartzComponent quartz = route.getRouteContext().getCamelContext().getComponent("quartz", QuartzComponent.class);
+ setScheduler(quartz.getScheduler());
+
+ if (getRouteStopGracePeriod() == 0) {
+ setRouteStopGracePeriod(10000);
+ }
+
+ if (getTimeUnit() == null) {
+ setTimeUnit(TimeUnit.MILLISECONDS);
+ }
+
if ((getRouteStartDate() == null) && (getRouteStopDate() == null) && (getRouteSuspendDate() == null) && (getRouteResumeDate() == null)) {
if (LOG.isWarnEnabled()) {
LOG.warn("Scheduled Route Policy for route " + route.getId() + " is not set since the no start, stop and/or suspend times are specified");
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=1002354&r1=1002353&r2=1002354&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 Tue Sep 28 21:02:33 2010
@@ -22,6 +22,7 @@ import org.apache.camel.CamelExecutionEx
import org.apache.camel.ServiceStatus;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.component.quartz.QuartzComponent;
import org.apache.camel.test.junit4.CamelTestSupport;
import org.apache.camel.util.ServiceHelper;
import org.apache.commons.logging.Log;
@@ -42,6 +43,14 @@ public class CronScheduledRoutePolicyTes
super.setUp();
}
+ /* (non-Javadoc)
+ * @see org.apache.camel.test.junit4.CamelTestSupport#isUseRouteBuilder()
+ */
+ @Override
+ public boolean isUseRouteBuilder() {
+ return false;
+ }
+
@Test
public void testScheduledStartRoutePolicy() throws Exception {
@@ -49,9 +58,11 @@ public class CronScheduledRoutePolicyTes
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("org/apache/camel/routepolicy/quartz/myquartz.properties");
+ CronScheduledRoutePolicy policy = new CronScheduledRoutePolicy();
policy.setRouteStartTime("*/3 * * * * ?");
from("direct:start")
@@ -67,6 +78,7 @@ public class CronScheduledRoutePolicyTes
assertTrue(context.getRouteStatus("test") == ServiceStatus.Started);
template.sendBody("direct:start", "Ready or not, Here, I come");
+ context.getComponent("quartz", QuartzComponent.class).stop();
success.assertIsSatisfied();
}
@@ -76,9 +88,11 @@ public class CronScheduledRoutePolicyTes
MockEndpoint unreachable = (MockEndpoint) context.getEndpoint("mock:unreachable");
+ 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("org/apache/camel/routepolicy/quartz/myquartz.properties");
+ CronScheduledRoutePolicy policy = new CronScheduledRoutePolicy();
policy.setRouteStopTime("*/3 * * * * ?");
policy.setRouteStopGracePeriod(0);
policy.setTimeUnit(TimeUnit.MILLISECONDS);
@@ -101,6 +115,7 @@ public class CronScheduledRoutePolicyTes
consumerStopped = true;
}
assertTrue(consumerStopped);
+ context.getComponent("quartz", QuartzComponent.class).stop();
}
@Test
@@ -109,9 +124,11 @@ public class CronScheduledRoutePolicyTes
MockEndpoint unreachable = (MockEndpoint) context.getEndpoint("mock:unreachable");
+ 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("org/apache/camel/routepolicy/quartz/myquartz.properties");
+ CronScheduledRoutePolicy policy = new CronScheduledRoutePolicy();
policy.setRouteSuspendTime("*/3 * * * * ?");
from("direct:start")
@@ -129,6 +146,7 @@ public class CronScheduledRoutePolicyTes
consumerSuspended = true;
}
assertTrue(consumerSuspended);
+ context.getComponent("quartz", QuartzComponent.class).stop();
}
@Test
@@ -138,9 +156,11 @@ public class CronScheduledRoutePolicyTes
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("org/apache/camel/routepolicy/quartz/myquartz.properties");
+ CronScheduledRoutePolicy policy = new CronScheduledRoutePolicy();
policy.setRouteResumeTime("*/3 * * * * ?");
from("direct:start")
@@ -157,9 +177,10 @@ public class CronScheduledRoutePolicyTes
LOG.debug("Consumer successfully suspended");
}
- Thread.currentThread().sleep(5000);
+ Thread.currentThread().sleep(4000);
template.sendBody("direct:start", "Ready or not, Here, I come");
+ context.getComponent("quartz", QuartzComponent.class).stop();
success.assertIsSatisfied();
}
Added: camel/trunk/components/camel-quartz/src/test/java/org/apache/camel/routepolicy/quartz/SimpleDate.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-quartz/src/test/java/org/apache/camel/routepolicy/quartz/SimpleDate.java?rev=1002354&view=auto
==============================================================================
--- camel/trunk/components/camel-quartz/src/test/java/org/apache/camel/routepolicy/quartz/SimpleDate.java (added)
+++ camel/trunk/components/camel-quartz/src/test/java/org/apache/camel/routepolicy/quartz/SimpleDate.java Tue Sep 28 21:02:33 2010
@@ -0,0 +1,33 @@
+/**
+ * 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 java.util.Date;
+
+public class SimpleDate extends Date {
+
+ private static final long serialVersionUID = 1L;
+
+ public SimpleDate() {
+ this(3000);
+ }
+
+ public SimpleDate(long milliseconds) {
+ super(System.currentTimeMillis() + milliseconds);
+ }
+
+}
Propchange: camel/trunk/components/camel-quartz/src/test/java/org/apache/camel/routepolicy/quartz/SimpleDate.java
------------------------------------------------------------------------------
svn:eol-style = native
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=1002354&r1=1002353&r2=1002354&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 Tue Sep 28 21:02:33 2010
@@ -23,6 +23,7 @@ import org.apache.camel.CamelExecutionEx
import org.apache.camel.ServiceStatus;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.component.quartz.QuartzComponent;
import org.apache.camel.test.junit4.CamelTestSupport;
import org.apache.camel.util.ServiceHelper;
import org.apache.commons.logging.Log;
@@ -42,6 +43,14 @@ public class SimpleScheduledRoutePolicyT
public void setUp() throws Exception {
super.setUp();
}
+
+ /* (non-Javadoc)
+ * @see org.apache.camel.test.junit4.CamelTestSupport#isUseRouteBuilder()
+ */
+ @Override
+ public boolean isUseRouteBuilder() {
+ return false;
+ }
@Test
public void testScheduledStartRoutePolicy() throws Exception {
@@ -49,9 +58,11 @@ public class SimpleScheduledRoutePolicyT
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("org/apache/camel/routepolicy/quartz/myquartz.properties");
+ SimpleScheduledRoutePolicy policy = new SimpleScheduledRoutePolicy();
long startTime = System.currentTimeMillis() + 3000L;
policy.setRouteStartDate(new Date(startTime));
policy.setRouteStartRepeatCount(1);
@@ -66,10 +77,11 @@ public class SimpleScheduledRoutePolicyT
context.start();
context.stopRoute("test", 0, TimeUnit.MILLISECONDS);
- Thread.currentThread().sleep(4000);
+ Thread.currentThread().sleep(5000);
assertTrue(context.getRouteStatus("test") == ServiceStatus.Started);
template.sendBody("direct:start", "Ready or not, Here, I come");
+ context.getComponent("quartz", QuartzComponent.class).stop();
success.assertIsSatisfied();
}
@@ -77,8 +89,10 @@ public class SimpleScheduledRoutePolicyT
public void testScheduledStopRoutePolicy() throws Exception {
boolean consumerStopped = false;
- MockEndpoint unreachable = (MockEndpoint) context.getEndpoint("mock:unreachable");
+ MockEndpoint unreachable = (MockEndpoint) context.getEndpoint("mock:unreachable");
+ 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();
@@ -105,6 +119,7 @@ public class SimpleScheduledRoutePolicyT
consumerStopped = true;
}
assertTrue(consumerStopped);
+ context.getComponent("quartz", QuartzComponent.class).stop();
}
@Test
@@ -113,6 +128,8 @@ public class SimpleScheduledRoutePolicyT
MockEndpoint unreachable = (MockEndpoint) context.getEndpoint("mock:unreachable");
+ 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();
@@ -136,6 +153,7 @@ public class SimpleScheduledRoutePolicyT
consumerSuspended = true;
}
assertTrue(consumerSuspended);
+ context.getComponent("quartz", QuartzComponent.class).stop();
}
@Test
@@ -145,6 +163,8 @@ public class SimpleScheduledRoutePolicyT
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();
@@ -170,6 +190,7 @@ public class SimpleScheduledRoutePolicyT
Thread.currentThread().sleep(4000);
template.sendBody("direct:start", "Ready or not, Here, I come");
+ context.getComponent("quartz", QuartzComponent.class).stop();
success.assertIsSatisfied();
}
Added: 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=1002354&view=auto
==============================================================================
--- camel/trunk/components/camel-quartz/src/test/java/org/apache/camel/routepolicy/quartz/SpringCronScheduledRoutePolicyTest.java (added)
+++ camel/trunk/components/camel-quartz/src/test/java/org/apache/camel/routepolicy/quartz/SpringCronScheduledRoutePolicyTest.java Tue Sep 28 21:02:33 2010
@@ -0,0 +1,52 @@
+/**
+ * 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.junit.Before;
+import org.junit.Test;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+public class SpringCronScheduledRoutePolicyTest extends
+ SpringScheduledRoutePolicyTest {
+
+ @Before
+ public void setUp() {
+ setApplicationContext(new ClassPathXmlApplicationContext("org/apache/camel/routepolicy/quartz/CronPolicies.xml"));
+ setTestType(TestType.CRON);
+ }
+
+ @Test
+ public void testScheduledStartRoutePolicy() throws Exception {
+ startTest();
+ }
+
+ @Test
+ public void testScheduledStopRoutePolicy() throws Exception {
+ stopTest();
+ }
+
+ @Test
+ public void testScheduledSuspendRoutePolicy() throws Exception {
+ suspendTest();
+ }
+
+ @Test
+ public void testScheduledResumeRoutePolicy() throws Exception {
+ resumeTest();
+ }
+
+}
Propchange: camel/trunk/components/camel-quartz/src/test/java/org/apache/camel/routepolicy/quartz/SpringCronScheduledRoutePolicyTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: 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=1002354&view=auto
==============================================================================
--- camel/trunk/components/camel-quartz/src/test/java/org/apache/camel/routepolicy/quartz/SpringScheduledRoutePolicyTest.java (added)
+++ camel/trunk/components/camel-quartz/src/test/java/org/apache/camel/routepolicy/quartz/SpringScheduledRoutePolicyTest.java Tue Sep 28 21:02:33 2010
@@ -0,0 +1,137 @@
+/**
+ * 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 java.util.ArrayList;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.CamelExecutionException;
+import org.apache.camel.ServiceStatus;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.impl.DefaultCamelContext;
+import org.apache.camel.model.RouteDefinition;
+import org.apache.camel.test.junit4.TestSupport;
+import org.apache.camel.util.ServiceHelper;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+/**
+ * @version $Revision$
+ */
+public abstract class SpringScheduledRoutePolicyTest extends TestSupport {
+ protected enum TestType {
+ SIMPLE, CRON
+ }
+ private ClassPathXmlApplicationContext applicationContext;
+ private TestType testType;
+
+ public void startTest() throws Exception {
+ CamelContext context = startRouteWithPolicy("startPolicy");
+
+ MockEndpoint mock = (MockEndpoint) context.getEndpoint("mock:success");
+ mock.expectedMinimumMessageCount(1);
+
+ context.stopRoute("testRoute", 0, TimeUnit.MILLISECONDS);
+
+ Thread.currentThread().sleep(4000);
+ assertTrue(context.getRouteStatus("testRoute") == ServiceStatus.Started);
+ context.createProducerTemplate().sendBody("direct:start", "Ready or not, Here, I come");
+
+ context.stop();
+ mock.assertIsSatisfied();
+ }
+
+
+ public void stopTest() throws Exception {
+ boolean consumerStopped = false;
+
+ CamelContext context = startRouteWithPolicy("stopPolicy");
+
+ Thread.currentThread().sleep(4000);
+ assertTrue(context.getRouteStatus("testRoute") == ServiceStatus.Stopped);
+ try {
+ context.createProducerTemplate().sendBody("direct:start", "Ready or not, Here, I come");
+ } catch (CamelExecutionException e) {
+ consumerStopped = true;
+ }
+ context.stop();
+ assertTrue(consumerStopped);
+ }
+
+
+ public void suspendTest() throws Exception {
+ boolean consumerSuspended = false;
+
+ CamelContext context = startRouteWithPolicy("suspendPolicy");
+
+ Thread.currentThread().sleep(4000);
+ try {
+ context.createProducerTemplate().sendBody("direct:start", "Ready or not, Here, I come");
+ } catch (CamelExecutionException e) {
+ consumerSuspended = true;
+ }
+
+ context.stop();
+ assertTrue(consumerSuspended);
+ }
+
+ public void resumeTest() throws Exception {
+ CamelContext context = startRouteWithPolicy("resumePolicy");
+
+ MockEndpoint mock = (MockEndpoint) context.getEndpoint("mock:success");
+ mock.expectedMinimumMessageCount(1);
+
+ ServiceHelper.suspendService(context.getRoute("testRoute").getConsumer());
+
+ Thread.currentThread().sleep(4000);
+ context.createProducerTemplate().sendBody("direct:start", "Ready or not, Here, I come");
+
+ context.stop();
+ mock.assertIsSatisfied();
+ }
+
+ private CamelContext startRouteWithPolicy(String policyBeanName) throws Exception {
+ CamelContext context = new DefaultCamelContext();
+ ArrayList<RouteDefinition> routes = (ArrayList<RouteDefinition>) applicationContext.getBean("testRouteContext");
+ if (getTestType() == TestType.SIMPLE) {
+ routes.get(0).setRoutePolicy((SimpleScheduledRoutePolicy) applicationContext.getBean(policyBeanName));
+ } else {
+ routes.get(0).setRoutePolicy((CronScheduledRoutePolicy) applicationContext.getBean(policyBeanName));
+ }
+ context.addRouteDefinitions(routes);
+ context.start();
+ return context;
+ }
+
+ public ClassPathXmlApplicationContext getApplicationContext() {
+ return applicationContext;
+ }
+
+ public void setApplicationContext(
+ ClassPathXmlApplicationContext applicationContext) {
+ this.applicationContext = applicationContext;
+ }
+
+ public TestType getTestType() {
+ return testType;
+ }
+
+ public void setTestType(TestType testType) {
+ this.testType = testType;
+ }
+
+}
Propchange: camel/trunk/components/camel-quartz/src/test/java/org/apache/camel/routepolicy/quartz/SpringScheduledRoutePolicyTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: 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=1002354&view=auto
==============================================================================
--- camel/trunk/components/camel-quartz/src/test/java/org/apache/camel/routepolicy/quartz/SpringSimpleScheduledRoutePolicyTest.java (added)
+++ camel/trunk/components/camel-quartz/src/test/java/org/apache/camel/routepolicy/quartz/SpringSimpleScheduledRoutePolicyTest.java Tue Sep 28 21:02:33 2010
@@ -0,0 +1,52 @@
+/**
+ * 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.junit.Before;
+import org.junit.Test;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+public class SpringSimpleScheduledRoutePolicyTest extends
+ SpringScheduledRoutePolicyTest {
+
+ @Before
+ public void setUp() {
+ setApplicationContext(new ClassPathXmlApplicationContext("org/apache/camel/routepolicy/quartz/SimplePolicies.xml"));
+ setTestType(TestType.SIMPLE);
+ }
+
+ @Test
+ public void testScheduledStartRoutePolicy() throws Exception {
+ startTest();
+ }
+
+ @Test
+ public void testScheduledStopRoutePolicy() throws Exception {
+ stopTest();
+ }
+
+ @Test
+ public void testScheduledSuspendRoutePolicy() throws Exception {
+ suspendTest();
+ }
+
+ @Test
+ public void testScheduledResumeRoutePolicy() throws Exception {
+ resumeTest();
+ }
+
+}
Propchange: camel/trunk/components/camel-quartz/src/test/java/org/apache/camel/routepolicy/quartz/SpringSimpleScheduledRoutePolicyTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: camel/trunk/components/camel-quartz/src/test/resources/org/apache/camel/routepolicy/quartz/CronPolicies.xml
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-quartz/src/test/resources/org/apache/camel/routepolicy/quartz/CronPolicies.xml?rev=1002354&view=auto
==============================================================================
--- camel/trunk/components/camel-quartz/src/test/resources/org/apache/camel/routepolicy/quartz/CronPolicies.xml (added)
+++ camel/trunk/components/camel-quartz/src/test/resources/org/apache/camel/routepolicy/quartz/CronPolicies.xml Tue Sep 28 21:02:33 2010
@@ -0,0 +1,52 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="
+ http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
+ http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
+ ">
+
+ <bean id="date" class="org.apache.camel.routepolicy.quartz.SimpleDate"/>
+
+ <bean id="defaultPolicy" class="org.apache.camel.routepolicy.quartz.CronScheduledRoutePolicy"/>
+
+ <bean id="startPolicy" class="org.apache.camel.routepolicy.quartz.CronScheduledRoutePolicy">
+ <property name="routeStartTime" value="*/3 * * * * ?"/>
+ </bean>
+
+ <bean id="stopPolicy" class="org.apache.camel.routepolicy.quartz.CronScheduledRoutePolicy">
+ <property name="routeStopTime" value="*/3 * * * * ?"/>
+ </bean>
+
+ <bean id="suspendPolicy" class="org.apache.camel.routepolicy.quartz.CronScheduledRoutePolicy">
+ <property name="routeSuspendTime" value="*/3 * * * * ?"/>
+ </bean>
+
+ <bean id="resumePolicy" class="org.apache.camel.routepolicy.quartz.CronScheduledRoutePolicy">
+ <property name="routeResumeTime" value="*/3 * * * * ?"/>
+ </bean>
+
+ <routeContext id="testRouteContext" xmlns="http://camel.apache.org/schema/spring">
+ <route id="testRoute" routePolicyRef="policy">
+ <from uri="direct:start"/>
+ <to uri="mock:success"/>
+ </route>
+ </routeContext>
+
+</beans>
Propchange: camel/trunk/components/camel-quartz/src/test/resources/org/apache/camel/routepolicy/quartz/CronPolicies.xml
------------------------------------------------------------------------------
svn:eol-style = native
Added: camel/trunk/components/camel-quartz/src/test/resources/org/apache/camel/routepolicy/quartz/SimplePolicies.xml
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-quartz/src/test/resources/org/apache/camel/routepolicy/quartz/SimplePolicies.xml?rev=1002354&view=auto
==============================================================================
--- camel/trunk/components/camel-quartz/src/test/resources/org/apache/camel/routepolicy/quartz/SimplePolicies.xml (added)
+++ camel/trunk/components/camel-quartz/src/test/resources/org/apache/camel/routepolicy/quartz/SimplePolicies.xml Tue Sep 28 21:02:33 2010
@@ -0,0 +1,60 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="
+ http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
+ http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
+ ">
+
+ <bean id="date" class="org.apache.camel.routepolicy.quartz.SimpleDate"/>
+
+ <bean id="defaultPolicy" class="org.apache.camel.routepolicy.quartz.SimpleScheduledRoutePolicy"/>
+
+ <bean id="startPolicy" class="org.apache.camel.routepolicy.quartz.SimpleScheduledRoutePolicy">
+ <property name="routeStartDate" ref="date"/>
+ <property name="routeStartRepeatCount" value="1"/>
+ <property name="routeStartRepeatInterval" value="3000"/>
+ </bean>
+
+ <bean id="stopPolicy" class="org.apache.camel.routepolicy.quartz.SimpleScheduledRoutePolicy">
+ <property name="routeStopDate" ref="date"/>
+ <property name="routeStopRepeatCount" value="1"/>
+ <property name="routeStopRepeatInterval" value="3000"/>
+ </bean>
+
+ <bean id="suspendPolicy" class="org.apache.camel.routepolicy.quartz.SimpleScheduledRoutePolicy">
+ <property name="routeSuspendDate" ref="date"/>
+ <property name="routeSuspendRepeatCount" value="1"/>
+ <property name="routeSuspendRepeatInterval" value="3000"/>
+ </bean>
+
+ <bean id="resumePolicy" class="org.apache.camel.routepolicy.quartz.SimpleScheduledRoutePolicy">
+ <property name="routeResumeDate" ref="date"/>
+ <property name="routeResumeRepeatCount" value="1"/>
+ <property name="routeResumeRepeatInterval" value="3000"/>
+ </bean>
+
+ <routeContext id="testRouteContext" xmlns="http://camel.apache.org/schema/spring">
+ <route id="testRoute" routePolicyRef="policy">
+ <from uri="direct:start"/>
+ <to uri="mock:success"/>
+ </route>
+ </routeContext>
+
+</beans>
Propchange: camel/trunk/components/camel-quartz/src/test/resources/org/apache/camel/routepolicy/quartz/SimplePolicies.xml
------------------------------------------------------------------------------
svn:eol-style = native