Search in sources :

Example 6 with AbstractXmlApplicationContext

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

the class SpringQuartzPersistentStoreRestartAppChangeOptionsTest method testRestartAppChangeTriggerType.

@Test
public void testRestartAppChangeTriggerType() throws Exception {
    // Test creates application context twice with different simple trigger options in configuration xml.
    // Both times it retrieves back the option, accessing it via trigger (so, using value stored in DB).
    // After that it asserts that two options are not equal.
    // load spring app
    app = new ClassPathXmlApplicationContext("org/apache/camel/component/quartz2/SpringQuartzPersistentStoreRestartAppChangeCronExpressionTest1.xml");
    app.start();
    CamelContext camel = app.getBean("camelContext", CamelContext.class);
    assertNotNull(camel);
    assertTrue(getTrigger(camel, "quartzRoute") instanceof CronTrigger);
    app.stop();
    log.info("Restarting ...");
    log.info("Restarting ...");
    log.info("Restarting ...");
    // load spring app
    AbstractXmlApplicationContext app2 = new ClassPathXmlApplicationContext("org/apache/camel/component/quartz2/SpringQuartzPersistentStoreRestartAppChangeOptionsTest2.xml");
    app2.start();
    CamelContext camel2 = app2.getBean("camelContext", CamelContext.class);
    assertNotNull(camel2);
    assertTrue(getTrigger(camel2, "quartzRoute") instanceof SimpleTrigger);
    app2.stop();
    // we're done so let's properly close the application contexts, but close
    // the second app before the first one so that the quartz scheduler running
    // inside it can be properly shutdown
    IOHelper.close(app2, app);
}
Also used : CamelContext(org.apache.camel.CamelContext) CronTrigger(org.quartz.CronTrigger) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) AbstractXmlApplicationContext(org.springframework.context.support.AbstractXmlApplicationContext) SimpleTrigger(org.quartz.SimpleTrigger) Test(org.junit.Test)

Example 7 with AbstractXmlApplicationContext

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

the class SpringQuartzTwoAppsClusteredFailoverTest 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/routepolicy/quartz2/SpringQuartzClusteredAppDatabase.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/routepolicy/quartz2/SpringQuartzClusteredAppOne.xml");
    app.start();
    // 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/routepolicy/quartz2/SpringQuartzClusteredAppTwo.xml");
    app2.start();
    CamelContext camel = app.getBean("camelContext", CamelContext.class);
    MockEndpoint mock = camel.getEndpoint("mock:result", MockEndpoint.class);
    mock.expectedMessageCount(1);
    mock.expectedBodiesReceived("clustering PINGS!");
    // wait a bit to make sure the route has already been properly started through the given route policy
    Thread.sleep(5000);
    app.getBean("template", ProducerTemplate.class).sendBody("direct:start", "clustering");
    mock.assertIsSatisfied();
    // 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!");
    IOHelper.close(app);
    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 app ('app-two') gets started:
    // 2013-09-29 08:15:17,038 [main           ] WARN  tzTwoAppsClusteredFailoverTest:65   - Crashed...
    // 2013-09-29 08:15:17,038 [main           ] WARN  tzTwoAppsClusteredFailoverTest:66   - Crashed...
    // 2013-09-29 08:15:17,038 [main           ] WARN  tzTwoAppsClusteredFailoverTest:67   - Crashed...
    // 2013-09-29 08:15:32,001 [_ClusterManager] INFO  LocalDataSourceJobStore       :3567 - ClusterManager: detected 1 failed or restarted instances.
    // 2013-09-29 08:15:32,001 [_ClusterManager] INFO  LocalDataSourceJobStore       :3426 - ClusterManager: Scanning for instance "app-one"'s failed in-progress jobs.
    // 2013-09-29 08:15:32,024 [eduler_Worker-1] INFO  SpringCamelContext            :2183 - Route: myRoute started and consuming from: Endpoint[direct://start]
    CamelContext camel2 = app2.getBean("camelContext2", CamelContext.class);
    MockEndpoint mock2 = camel2.getEndpoint("mock:result", MockEndpoint.class);
    mock2.expectedMessageCount(1);
    mock2.expectedBodiesReceived("clustering PONGS!");
    app2.getBean("template", ProducerTemplate.class).sendBody("direct:start", "clustering");
    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) ProducerTemplate(org.apache.camel.ProducerTemplate) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) AbstractXmlApplicationContext(org.springframework.context.support.AbstractXmlApplicationContext) Test(org.junit.Test)

Example 8 with AbstractXmlApplicationContext

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

the class RouteRefPropertyPlaceholderMultipleCamelContextRefsTest method testSpringTwoCamelContextDirectEndpoint.

public void testSpringTwoCamelContextDirectEndpoint() throws Exception {
    AbstractXmlApplicationContext ac = createApplicationContext();
    ac.start();
    CamelContext camel1 = ac.getBean("myCamel-1", CamelContext.class);
    CamelContext camel2 = ac.getBean("myCamel-2", CamelContext.class);
    Endpoint start1 = camel1.getEndpoint("direct:start");
    Endpoint start2 = camel2.getEndpoint("direct:start");
    assertNotSame(start1, start2);
    MockEndpoint mock1 = camel1.getEndpoint("mock:end-1", MockEndpoint.class);
    mock1.expectedBodiesReceived("Hello World");
    MockEndpoint mock2 = camel2.getEndpoint("mock:end-2", MockEndpoint.class);
    mock2.expectedBodiesReceived("Bye World");
    camel1.createProducerTemplate().sendBody("direct:start", "Hello World");
    camel2.createProducerTemplate().sendBody("direct:start", "Bye World");
    mock1.assertIsSatisfied();
    mock2.assertIsSatisfied();
    ac.stop();
}
Also used : CamelContext(org.apache.camel.CamelContext) Endpoint(org.apache.camel.Endpoint) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) AbstractXmlApplicationContext(org.springframework.context.support.AbstractXmlApplicationContext)

Example 9 with AbstractXmlApplicationContext

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

the class SpringRouteNoOutputTest method createApplicationContext.

@Override
protected AbstractXmlApplicationContext createApplicationContext() {
    AbstractXmlApplicationContext answer;
    try {
        answer = new ClassPathXmlApplicationContext("org/apache/camel/spring/config/SpringRouteNoOutputTest.xml");
        fail("Should have thrown exception");
    } catch (Exception e) {
        IllegalArgumentException iae = (IllegalArgumentException) e.getCause();
        assertEquals("Route myRoute has no outputs: Route(myRoute)[[From[direct:start]] -> []]", iae.getMessage());
        return null;
    }
    return answer;
}
Also used : ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) AbstractXmlApplicationContext(org.springframework.context.support.AbstractXmlApplicationContext)

Example 10 with AbstractXmlApplicationContext

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

the class SpringRemotingRouteTest method testBeanRoutes.

public void testBeanRoutes() throws Exception {
    AbstractXmlApplicationContext applicationContext = createApplicationContext();
    CamelContext camelContext = SpringCamelContext.springCamelContext(applicationContext);
    // START SNIPPET: invoke
    ISay proxy = applicationContext.getBean("sayProxy", ISay.class);
    String rc = proxy.say();
    assertEquals("Hello", rc);
    // END SNIPPET: invoke
    camelContext.stop();
    IOHelper.close(applicationContext);
}
Also used : CamelContext(org.apache.camel.CamelContext) SpringCamelContext(org.apache.camel.spring.SpringCamelContext) AbstractXmlApplicationContext(org.springframework.context.support.AbstractXmlApplicationContext)

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