use of org.apache.camel.impl.DefaultCamelContext in project camel by apache.
the class VmMultipleConsumersMultipleContextTest method testVmMultipleConsumersMultipleContext.
public void testVmMultipleConsumersMultipleContext() throws Exception {
// start context 1
CamelContext consumerContext1 = new DefaultCamelContext();
consumerContext1.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from("vm:producer?multipleConsumers=true").routeId("route1").to("mock:route1");
}
});
consumerContext1.start();
MockEndpoint route1Mock = (MockEndpoint) consumerContext1.getEndpoint("mock:route1");
route1Mock.expectedMessageCount(100);
// start up context 2
CamelContext consumerContext2 = new DefaultCamelContext();
consumerContext2.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from("vm:producer?multipleConsumers=true").routeId("route2").to("mock:route2");
}
});
consumerContext2.start();
MockEndpoint route2Mock = (MockEndpoint) consumerContext2.getEndpoint("mock:route2");
route2Mock.expectedMessageCount(100);
// use context part of contextTestSupport to send in messages
for (int i = 0; i < 100; i++) {
template.sendBody("vm:producer?multipleConsumers=true", i);
}
route1Mock.assertIsSatisfied();
route2Mock.assertIsSatisfied();
consumerContext1.stop();
consumerContext2.stop();
}
use of org.apache.camel.impl.DefaultCamelContext in project camel by apache.
the class SedaRouteTest method testThatShowsEndpointResolutionIsNotConsistent.
public void testThatShowsEndpointResolutionIsNotConsistent() throws Exception {
final CountDownLatch latch = new CountDownLatch(1);
CamelContext context = new DefaultCamelContext();
// lets add some routes
context.addRoutes(new RouteBuilder() {
public void configure() {
from("seda:test.a").to("seda:test.b");
from("seda:test.b").process(new Processor() {
public void process(Exchange e) {
log.debug("Received exchange: " + e.getIn());
latch.countDown();
}
});
}
});
context.start();
// now lets fire in a message
Endpoint endpoint = context.getEndpoint("seda:test.a");
Exchange exchange = endpoint.createExchange();
exchange.getIn().setHeader("cheese", 123);
Producer producer = endpoint.createProducer();
producer.process(exchange);
// now lets sleep for a while
assertTrue(latch.await(5, TimeUnit.SECONDS));
context.stop();
}
use of org.apache.camel.impl.DefaultCamelContext in project camel by apache.
the class ServiceCallConfigurationTest method testDefaultConfigurationFromRegistryWithDefaultName.
@Test
public void testDefaultConfigurationFromRegistryWithDefaultName() throws Exception {
StaticServiceDiscovery sd = new StaticServiceDiscovery();
sd.addServer("127.0.0.1:8080");
sd.addServer("127.0.0.1:8081");
BlacklistServiceFilter sf = new BlacklistServiceFilter();
sf.addServer("127.0.0.1:8080");
ServiceCallConfigurationDefinition conf = new ServiceCallConfigurationDefinition();
conf.setServiceDiscovery(sd);
conf.serviceFilter(sf);
SimpleRegistry reg = new SimpleRegistry();
reg.put(org.apache.camel.model.cloud.ServiceCallConstants.DEFAULT_SERVICE_CALL_CONFIG_ID, conf);
CamelContext context = new DefaultCamelContext(reg);
context.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from("direct:start").routeId("default").serviceCall().name("scall").component("file").end();
}
});
context.start();
DefaultServiceCallProcessor proc = findServiceCallProcessor(context.getRoute("default"));
Assert.assertNotNull(proc);
Assert.assertTrue(proc.getLoadBalancer() instanceof DefaultLoadBalancer);
DefaultLoadBalancer loadBalancer = (DefaultLoadBalancer) proc.getLoadBalancer();
Assert.assertEquals(sd, loadBalancer.getServiceDiscovery());
Assert.assertEquals(sf, loadBalancer.getServiceFilter());
context.stop();
}
use of org.apache.camel.impl.DefaultCamelContext in project camel by apache.
the class ServiceCallConfigurationTest method testDefaultConfigurationFromCamelContext.
// ****************************************
// test default resolution
// ****************************************
@Test
public void testDefaultConfigurationFromCamelContext() throws Exception {
StaticServiceDiscovery sd = new StaticServiceDiscovery();
sd.addServer("127.0.0.1:8080");
sd.addServer("127.0.0.1:8081");
BlacklistServiceFilter sf = new BlacklistServiceFilter();
sf.addServer("127.0.0.1:8080");
ServiceCallConfigurationDefinition conf = new ServiceCallConfigurationDefinition();
conf.setServiceDiscovery(sd);
conf.setServiceFilter(sf);
CamelContext context = new DefaultCamelContext();
context.setServiceCallConfiguration(conf);
context.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from("direct:start").routeId("default").serviceCall().name("scall").component("file").end();
}
});
context.start();
DefaultServiceCallProcessor proc = findServiceCallProcessor(context.getRoute("default"));
Assert.assertNotNull(proc);
Assert.assertTrue(proc.getLoadBalancer() instanceof DefaultLoadBalancer);
DefaultLoadBalancer loadBalancer = (DefaultLoadBalancer) proc.getLoadBalancer();
Assert.assertEquals(sd, loadBalancer.getServiceDiscovery());
Assert.assertEquals(sf, loadBalancer.getServiceFilter());
context.stop();
}
use of org.apache.camel.impl.DefaultCamelContext in project camel by apache.
the class ServiceCallConfigurationTest method testMixedConfiguration.
// ****************************************
// test mixed resolution
// ****************************************
@Test
public void testMixedConfiguration() throws Exception {
// Default
StaticServiceDiscovery defaultServiceDiscovery = new StaticServiceDiscovery();
defaultServiceDiscovery.addServer("127.0.0.1:8080");
defaultServiceDiscovery.addServer("127.0.0.1:8081");
defaultServiceDiscovery.addServer("127.0.0.1:8082");
BlacklistServiceFilter defaultServiceFilter = new BlacklistServiceFilter();
defaultServiceFilter.addServer("127.0.0.1:8080");
ServiceCallConfigurationDefinition defaultConfiguration = new ServiceCallConfigurationDefinition();
defaultConfiguration.setServiceDiscovery(defaultServiceDiscovery);
defaultConfiguration.serviceFilter(defaultServiceFilter);
// Named
BlacklistServiceFilter namedServiceFilter = new BlacklistServiceFilter();
namedServiceFilter.addServer("127.0.0.1:8081");
ServiceCallConfigurationDefinition namedConfiguration = new ServiceCallConfigurationDefinition();
namedConfiguration.serviceFilter(namedServiceFilter);
// Local
StaticServiceDiscovery localServiceDiscovery = new StaticServiceDiscovery();
localServiceDiscovery.addServer("127.0.0.1:8080");
localServiceDiscovery.addServer("127.0.0.1:8081");
localServiceDiscovery.addServer("127.0.0.1:8082");
localServiceDiscovery.addServer("127.0.0.1:8084");
// Camel context
CamelContext context = new DefaultCamelContext();
context.setServiceCallConfiguration(defaultConfiguration);
context.addServiceCallConfiguration("named", namedConfiguration);
context.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from("direct:default").id("default").serviceCall().name("default-scall").component("file").end();
from("direct:named").id("named").serviceCall().serviceCallConfiguration("named").name("named-scall").component("file").end();
from("direct:local").id("local").serviceCall().serviceCallConfiguration("named").name("local-scall").component("file").serviceDiscovery(localServiceDiscovery).end();
}
});
context.start();
{
// Default
DefaultServiceCallProcessor proc = findServiceCallProcessor(context.getRoute("default"));
Assert.assertNotNull(proc);
Assert.assertTrue(proc.getLoadBalancer() instanceof DefaultLoadBalancer);
DefaultLoadBalancer loadBalancer = (DefaultLoadBalancer) proc.getLoadBalancer();
Assert.assertEquals(defaultServiceDiscovery, loadBalancer.getServiceDiscovery());
Assert.assertEquals(defaultServiceFilter, loadBalancer.getServiceFilter());
}
{
// Named
DefaultServiceCallProcessor proc = findServiceCallProcessor(context.getRoute("named"));
Assert.assertNotNull(proc);
Assert.assertTrue(proc.getLoadBalancer() instanceof DefaultLoadBalancer);
DefaultLoadBalancer loadBalancer = (DefaultLoadBalancer) proc.getLoadBalancer();
Assert.assertEquals(defaultServiceDiscovery, loadBalancer.getServiceDiscovery());
Assert.assertEquals(namedServiceFilter, loadBalancer.getServiceFilter());
}
{
// Local
DefaultServiceCallProcessor proc = findServiceCallProcessor(context.getRoute("local"));
Assert.assertNotNull(proc);
Assert.assertTrue(proc.getLoadBalancer() instanceof DefaultLoadBalancer);
DefaultLoadBalancer loadBalancer = (DefaultLoadBalancer) proc.getLoadBalancer();
Assert.assertEquals(localServiceDiscovery, loadBalancer.getServiceDiscovery());
Assert.assertEquals(namedServiceFilter, loadBalancer.getServiceFilter());
}
context.stop();
}
Aggregations