use of org.springframework.context.support.ClassPathXmlApplicationContext 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);
}
use of org.springframework.context.support.ClassPathXmlApplicationContext 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);
}
use of org.springframework.context.support.ClassPathXmlApplicationContext in project camel by apache.
the class ServiceCallConfigurationTest method createContext.
protected SpringCamelContext createContext(String classpathConfigFile) {
ClassPathXmlApplicationContext appContext = new ClassPathXmlApplicationContext(classpathConfigFile);
SpringCamelContext camelContext = appContext.getBean(SpringCamelContext.class);
assertNotNull("No Camel Context in file: " + classpathConfigFile, camelContext);
return camelContext;
}
use of org.springframework.context.support.ClassPathXmlApplicationContext in project camel by apache.
the class AnotherCamelProxyTest method testAnotherCamelProxy.
public void testAnotherCamelProxy() throws Exception {
// START SNIPPET: e1
AbstractApplicationContext ac = new ClassPathXmlApplicationContext("org/apache/camel/spring/config/AnotherCamelProxyTest.xml");
MyProxySender sender = ac.getBean("myProxySender", MyProxySender.class);
String reply = sender.hello("Camel");
assertEquals("Bye Camel", reply);
// we're done so let's properly close the application context
IOHelper.close(ac);
// END SNIPPET: e1
}
use of org.springframework.context.support.ClassPathXmlApplicationContext in project camel by apache.
the class CamelContextAutoStartupTest method testAutoStartupFalse.
public void testAutoStartupFalse() throws Exception {
ac = new ClassPathXmlApplicationContext("org/apache/camel/spring/config/CamelContextAutoStartupTestFalse.xml");
SpringCamelContext camel = ac.getBeansOfType(SpringCamelContext.class).values().iterator().next();
assertNotNull(camel.getName());
assertEquals(true, camel.isStarted());
assertEquals(Boolean.FALSE, camel.isAutoStartup());
assertEquals(1, camel.getRoutes().size());
assertEquals(false, camel.getRouteStatus("foo").isStarted());
// now starting route manually
camel.startRoute("foo");
assertEquals(Boolean.FALSE, camel.isAutoStartup());
assertEquals(1, camel.getRoutes().size());
assertEquals(true, camel.getRouteStatus("foo").isStarted());
// and now we can send a message to the route and see that it works
MockEndpoint mock = camel.getEndpoint("mock:result", MockEndpoint.class);
mock.expectedMessageCount(1);
ProducerTemplate template = camel.createProducerTemplate();
template.start();
template.sendBody("direct:start", "Hello World");
template.stop();
mock.assertIsSatisfied();
}
Aggregations