Updated Branches: refs/heads/master 02b31d00d -> 04e115a0d
CAMEL-6797: Added the test which we currently @Ignore. Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/04e115a0 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/04e115a0 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/04e115a0 Branch: refs/heads/master Commit: 04e115a0d1b37ba88bb38ded3b40640ab1d77d2a Parents: 02b31d0 Author: Babak Vahdat <[email protected]> Authored: Sun Sep 29 08:45:47 2013 +0200 Committer: Babak Vahdat <[email protected]> Committed: Sun Sep 29 08:45:47 2013 +0200 ---------------------------------------------------------------------- ...rtzConsumerTwoAppsClusteredFailoverTest.java | 110 +++++++++++++++++++ ...SpringQuartzConsumerClusteredAppDatabase.xml | 30 +++++ .../SpringQuartzConsumerClusteredAppOne.xml | 73 ++++++++++++ .../SpringQuartzConsumerClusteredAppTwo.xml | 71 ++++++++++++ 4 files changed, 284 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/04e115a0/components/camel-quartz2/src/test/java/org/apache/camel/component/quartz2/SpringQuartzConsumerTwoAppsClusteredFailoverTest.java ---------------------------------------------------------------------- diff --git a/components/camel-quartz2/src/test/java/org/apache/camel/component/quartz2/SpringQuartzConsumerTwoAppsClusteredFailoverTest.java b/components/camel-quartz2/src/test/java/org/apache/camel/component/quartz2/SpringQuartzConsumerTwoAppsClusteredFailoverTest.java new file mode 100644 index 0000000..5a6f607 --- /dev/null +++ b/components/camel-quartz2/src/test/java/org/apache/camel/component/quartz2/SpringQuartzConsumerTwoAppsClusteredFailoverTest.java @@ -0,0 +1,110 @@ +/** + * 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.quartz2; + +import org.apache.camel.CamelContext; +import org.apache.camel.Exchange; +import org.apache.camel.Predicate; +import org.apache.camel.component.mock.MockEndpoint; +import org.apache.camel.test.junit4.TestSupport; +import org.junit.Ignore; +import org.junit.Test; +import org.springframework.context.support.AbstractXmlApplicationContext; +import org.springframework.context.support.ClassPathXmlApplicationContext; + +/** + * Tests a Quartz based cluster setup of two Camel Apps being triggered through {@link QuartzConsumer}. + * + * @version + */ +@Ignore("CAMEL-6797") +public class SpringQuartzConsumerTwoAppsClusteredFailoverTest extends TestSupport { + + @Test + public void testQuartzPersistentStoreClusteredApp() throws Exception { + // boot up the database the two apps are going to share inside a clustered quartz setup + AbstractXmlApplicationContext db = new ClassPathXmlApplicationContext("org/apache/camel/component/quartz2/SpringQuartzConsumerClusteredAppDatabase.xml"); + db.start(); + + // now launch the first clustered app + AbstractXmlApplicationContext app = new ClassPathXmlApplicationContext("org/apache/camel/component/quartz2/SpringQuartzConsumerClusteredAppOne.xml"); + app.start(); + + // as well as the second one + AbstractXmlApplicationContext app2 = new ClassPathXmlApplicationContext("org/apache/camel/component/quartz2/SpringQuartzConsumerClusteredAppTwo.xml"); + app2.start(); + + CamelContext camel = app.getBean("camelContext", CamelContext.class); + + MockEndpoint mock = camel.getEndpoint("mock:result", MockEndpoint.class); + mock.expectedMinimumMessageCount(3); + mock.expectedMessagesMatches(new ClusteringPredicate(true)); + + // let the route run a bit... + Thread.sleep(5000); + + mock.assertIsSatisfied(); + + // now let's simulate a crash of the first app + log.warn("The first app is going to crash NOW!"); + app.close(); + + log.warn("Crashed..."); + log.warn("Crashed..."); + log.warn("Crashed..."); + + // wait long enough until the second app takes it over... + Thread.sleep(20000); + // inside the logs one can then clearly see how the route of the second CamelContext gets started: + // 2013-09-28 19:50:43,900 [main ] WARN ntTwoAppsClusteredFailoverTest - Crashed... + // 2013-09-28 19:50:43,900 [main ] WARN ntTwoAppsClusteredFailoverTest - Crashed... + // 2013-09-28 19:50:43,900 [main ] WARN ntTwoAppsClusteredFailoverTest - Crashed... + // 2013-09-28 19:50:58,892 [_ClusterManager] INFO LocalDataSourceJobStore - ClusterManager: detected 1 failed or restarted instances. + // 2013-09-28 19:50:58,892 [_ClusterManager] INFO LocalDataSourceJobStore - ClusterManager: Scanning for instance "app-one"'s failed in-progress jobs. + // 2013-09-28 19:50:58,913 [eduler_Worker-1] INFO triggered - Exchange[ExchangePattern: InOnly, BodyType: String, Body: clustering PONGS!] + + CamelContext camel2 = app2.getBean("camelContext2", CamelContext.class); + + MockEndpoint mock2 = camel2.getEndpoint("mock:result", MockEndpoint.class); + mock2.expectedMinimumMessageCount(3); + mock2.expectedMessagesMatches(new ClusteringPredicate(false)); + + mock2.assertIsSatisfied(); + + // stop the second app as we're already done + app2.close(); + + // and as the last step shutdown the database... + db.close(); + } + + private static class ClusteringPredicate implements Predicate { + + private final String expectedPayload; + + ClusteringPredicate(boolean pings) { + expectedPayload = pings ? "clustering PINGS!" : "clustering PONGS!"; + } + + @Override + public boolean matches(Exchange exchange) { + return exchange.getIn().getBody().equals(expectedPayload); + } + + } + +} http://git-wip-us.apache.org/repos/asf/camel/blob/04e115a0/components/camel-quartz2/src/test/resources/org/apache/camel/component/quartz2/SpringQuartzConsumerClusteredAppDatabase.xml ---------------------------------------------------------------------- diff --git a/components/camel-quartz2/src/test/resources/org/apache/camel/component/quartz2/SpringQuartzConsumerClusteredAppDatabase.xml b/components/camel-quartz2/src/test/resources/org/apache/camel/component/quartz2/SpringQuartzConsumerClusteredAppDatabase.xml new file mode 100644 index 0000000..ebcd7c2 --- /dev/null +++ b/components/camel-quartz2/src/test/resources/org/apache/camel/component/quartz2/SpringQuartzConsumerClusteredAppDatabase.xml @@ -0,0 +1,30 @@ +<?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" + xmlns:jdbc="http://www.springframework.org/schema/jdbc" + xsi:schemaLocation=" + http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd + http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd"> + + <!-- the embedded persistent storage for quartz --> + <jdbc:embedded-database id="quartz-db" type="DERBY"> + <jdbc:script location="classpath:tables_derby.sql"/> + </jdbc:embedded-database> + +</beans> http://git-wip-us.apache.org/repos/asf/camel/blob/04e115a0/components/camel-quartz2/src/test/resources/org/apache/camel/component/quartz2/SpringQuartzConsumerClusteredAppOne.xml ---------------------------------------------------------------------- diff --git a/components/camel-quartz2/src/test/resources/org/apache/camel/component/quartz2/SpringQuartzConsumerClusteredAppOne.xml b/components/camel-quartz2/src/test/resources/org/apache/camel/component/quartz2/SpringQuartzConsumerClusteredAppOne.xml new file mode 100644 index 0000000..6d6a224 --- /dev/null +++ b/components/camel-quartz2/src/test/resources/org/apache/camel/component/quartz2/SpringQuartzConsumerClusteredAppOne.xml @@ -0,0 +1,73 @@ +<?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" + xmlns:jdbc="http://www.springframework.org/schema/jdbc" + xsi:schemaLocation=" + http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd + http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd + http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd"> + + <bean id="quartzDataSource" class="org.apache.commons.dbcp.BasicDataSource"> + <property name="driverClassName" value="org.apache.derby.jdbc.EmbeddedDriver" /> + <!-- refer the embedded database we setup inside SpringQuartzConsumerClusteredAppDatabase.xml --> + <property name="url" value="jdbc:derby:memory:quartz-db" /> + <property name="username" value="sa" /> + <property name="password" value="" /> + </bean> + + <bean id="quartz2" class="org.apache.camel.component.quartz2.QuartzComponent"> + <property name="scheduler" ref="scheduler"/> + </bean> + + <bean id="scheduler" class="org.springframework.scheduling.quartz.SchedulerFactoryBean"> + <property name="dataSource" ref="quartzDataSource"/> + <property name="autoStartup" value="false"/> + <property name="schedulerContextAsMap"> + <!-- hook Camel into Quartz --> + <map> + <!-- CamelJob makes use of the following key below to find the same Job as we failover to 'app-two' --> + <!-- QuartzConstants.QUARTZ_CAMEL_CONTEXT + "-" + camelContextName --> + <entry key="CamelQuartzCamelContext-camelContext" value-ref="camelContext"/> + </map> + </property> + <property name="quartzProperties"> + <props> + <prop key="org.quartz.scheduler.instanceName">myscheduler</prop> + <prop key="org.quartz.scheduler.instanceId">app-one</prop> + <prop key="org.quartz.scheduler.skipUpdateCheck">true</prop> + <prop key="org.quartz.jobStore.driverDelegateClass">org.quartz.impl.jdbcjobstore.StdJDBCDelegate</prop> + <prop key="org.quartz.jobStore.isClustered">true</prop> + <prop key="org.quartz.jobStore.clusterCheckinInterval">5000</prop> + </props> + </property> + </bean> + + <camelContext id="camelContext" xmlns="http://camel.apache.org/schema/spring"> + <template id="template" /> + <route id="myRoute"> + <from uri="quartz2://app/test?trigger.repeatInterval=1000&trigger.repeatCount=-1" /> + <transform> + <simple>clustering PINGS!</simple> + </transform> + <to uri="log:triggered" /> + <to uri="mock:result" /> + </route> + </camelContext> + +</beans> http://git-wip-us.apache.org/repos/asf/camel/blob/04e115a0/components/camel-quartz2/src/test/resources/org/apache/camel/component/quartz2/SpringQuartzConsumerClusteredAppTwo.xml ---------------------------------------------------------------------- diff --git a/components/camel-quartz2/src/test/resources/org/apache/camel/component/quartz2/SpringQuartzConsumerClusteredAppTwo.xml b/components/camel-quartz2/src/test/resources/org/apache/camel/component/quartz2/SpringQuartzConsumerClusteredAppTwo.xml new file mode 100644 index 0000000..ecca2f6 --- /dev/null +++ b/components/camel-quartz2/src/test/resources/org/apache/camel/component/quartz2/SpringQuartzConsumerClusteredAppTwo.xml @@ -0,0 +1,71 @@ +<?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" + xmlns:jdbc="http://www.springframework.org/schema/jdbc" + xsi:schemaLocation=" + http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd + http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd + http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd"> + + <bean id="quartzDataSource" class="org.apache.commons.dbcp.BasicDataSource"> + <property name="driverClassName" value="org.apache.derby.jdbc.EmbeddedDriver" /> + <!-- refer the embedded database we setup inside SpringQuartzConsumerClusteredAppDatabase.xml --> + <property name="url" value="jdbc:derby:memory:quartz-db" /> + <property name="username" value="sa" /> + <property name="password" value="" /> + </bean> + + <bean id="quartz2" class="org.apache.camel.component.quartz2.QuartzComponent"> + <property name="scheduler" ref="scheduler"/> + </bean> + + <bean id="scheduler" class="org.springframework.scheduling.quartz.SchedulerFactoryBean"> + <property name="dataSource" ref="quartzDataSource"/> + <property name="autoStartup" value="false"/> + <property name="schedulerContextAsMap"> + <!-- hook Camel into Quartz --> + <map> + <entry key="CamelQuartzCamelContext-camelContext2" value-ref="camelContext2"/> + </map> + </property> + <property name="quartzProperties"> + <props> + <prop key="org.quartz.scheduler.instanceName">myscheduler</prop> + <prop key="org.quartz.scheduler.instanceId">app-two</prop> + <prop key="org.quartz.scheduler.skipUpdateCheck">true</prop> + <prop key="org.quartz.jobStore.driverDelegateClass">org.quartz.impl.jdbcjobstore.StdJDBCDelegate</prop> + <prop key="org.quartz.jobStore.isClustered">true</prop> + <prop key="org.quartz.jobStore.clusterCheckinInterval">5000</prop> + </props> + </property> + </bean> + + <camelContext id="camelContext2" xmlns="http://camel.apache.org/schema/spring"> + <template id="template" /> + <route id="myRoute"> + <from uri="quartz2://app/test?trigger.repeatInterval=1000&trigger.repeatCount=-1" /> + <transform> + <simple>clustering PONGS!</simple> + </transform> + <to uri="log:triggered" /> + <to uri="mock:result" /> + </route> + </camelContext> + +</beans>
