Search in sources :

Example 26 with AbstractXmlApplicationContext

use of org.springframework.context.support.AbstractXmlApplicationContext in project camel by apache.

the class SpringQuartzConsumerTwoAppsClusteredRecoveryTest method testQuartzPersistentStoreClusteredApp.

@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 which will acquire the quartz database lock and become the master
    AbstractXmlApplicationContext app = new ClassPathXmlApplicationContext("org/apache/camel/component/quartz2/SpringQuartzConsumerRecoveryClusteredAppOne.xml");
    app.start();
    // now let's simulate a crash of the first app (the quartz instance 'app-one')
    log.warn("The first app is going to crash NOW!");
    log.warn("Crashed...");
    log.warn("Crashed...");
    log.warn("Crashed...");
    Thread.sleep(2000);
    // as well as the second one which will run in slave mode as it will not be able to acquire the same lock
    AbstractXmlApplicationContext app2 = new ClassPathXmlApplicationContext("org/apache/camel/component/quartz2/SpringQuartzConsumerRecoveryClusteredAppTwo.xml");
    app2.start();
    // 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 app ('app-two') starts consuming:
    // 2013-09-30 11:22:20,349 [main           ] WARN  erTwoAppsClusteredFailoverTest - Crashed...
    // 2013-09-30 11:22:20,349 [main           ] WARN  erTwoAppsClusteredFailoverTest - Crashed...
    // 2013-09-30 11:22:20,349 [main           ] WARN  erTwoAppsClusteredFailoverTest - Crashed...
    // 2013-09-30 11:22:35,340 [_ClusterManager] INFO  LocalDataSourceJobStore        - ClusterManager: detected 1 failed or restarted instances.
    // 2013-09-30 11:22:35,340 [_ClusterManager] INFO  LocalDataSourceJobStore        - ClusterManager: Scanning for instance "app-one"'s failed in-progress jobs.
    // 2013-09-30 11:22:35,369 [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(2);
    mock2.expectedMessagesMatches(new ClusteringPredicate(false));
    mock2.assertIsSatisfied();
    // and as the last step shutdown the second app as well as the database
    IOHelper.close(app2, db);
}
Also used : CamelContext(org.apache.camel.CamelContext) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) AbstractXmlApplicationContext(org.springframework.context.support.AbstractXmlApplicationContext) Test(org.junit.Test)

Example 27 with AbstractXmlApplicationContext

use of org.springframework.context.support.AbstractXmlApplicationContext in project camel by apache.

the class CamelJaxbNoNamespaceSchemaLocationSpringTest method createCamelContext.

protected CamelContext createCamelContext() throws Exception {
    setUseRouteBuilder(false);
    final AbstractXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext("org/apache/camel/jaxb/CamelJaxbNoNamespaceSchemaLocationTest.xml");
    setCamelContextService(new Service() {

        public void start() throws Exception {
            applicationContext.start();
        }

        public void stop() throws Exception {
            applicationContext.stop();
        }
    });
    return SpringCamelContext.springCamelContext(applicationContext);
}
Also used : ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) Service(org.apache.camel.Service) AbstractXmlApplicationContext(org.springframework.context.support.AbstractXmlApplicationContext)

Example 28 with AbstractXmlApplicationContext

use of org.springframework.context.support.AbstractXmlApplicationContext in project camel by apache.

the class JibxDataFormatSpringDslTest method createCamelContext.

protected CamelContext createCamelContext() throws Exception {
    setUseRouteBuilder(false);
    final AbstractXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext("org/apache/camel/dataformat/jibx/SpringJibxConfigurationTest.xml");
    setCamelContextService(new Service() {

        public void start() throws Exception {
            applicationContext.start();
        }

        public void stop() throws Exception {
            applicationContext.stop();
        }
    });
    return SpringCamelContext.springCamelContext(applicationContext);
}
Also used : ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) Service(org.apache.camel.Service) AbstractXmlApplicationContext(org.springframework.context.support.AbstractXmlApplicationContext) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException)

Aggregations

AbstractXmlApplicationContext (org.springframework.context.support.AbstractXmlApplicationContext)28 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)22 CamelContext (org.apache.camel.CamelContext)17 Test (org.junit.Test)11 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)10 Service (org.apache.camel.Service)8 SimpleTrigger (org.quartz.SimpleTrigger)4 Endpoint (org.apache.camel.Endpoint)3 SpringCamelContext (org.apache.camel.spring.SpringCamelContext)3 ProducerTemplate (org.apache.camel.ProducerTemplate)2 CronTrigger (org.quartz.CronTrigger)2 IOException (java.io.IOException)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 SAXException (org.xml.sax.SAXException)1