Search in sources :

Example 66 with DefaultCamelContext

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();
}
Also used : CamelContext(org.apache.camel.CamelContext) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) RouteBuilder(org.apache.camel.builder.RouteBuilder) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) MockEndpoint(org.apache.camel.component.mock.MockEndpoint)

Example 67 with DefaultCamelContext

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();
}
Also used : CamelContext(org.apache.camel.CamelContext) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) RouteBuilder(org.apache.camel.builder.RouteBuilder) Endpoint(org.apache.camel.Endpoint) Producer(org.apache.camel.Producer) CountDownLatch(java.util.concurrent.CountDownLatch) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext)

Example 68 with DefaultCamelContext

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();
}
Also used : CamelContext(org.apache.camel.CamelContext) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) RouteBuilder(org.apache.camel.builder.RouteBuilder) SimpleRegistry(org.apache.camel.impl.SimpleRegistry) ServiceCallConfigurationDefinition(org.apache.camel.model.cloud.ServiceCallConfigurationDefinition) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) Test(org.junit.Test)

Example 69 with DefaultCamelContext

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();
}
Also used : CamelContext(org.apache.camel.CamelContext) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) RouteBuilder(org.apache.camel.builder.RouteBuilder) ServiceCallConfigurationDefinition(org.apache.camel.model.cloud.ServiceCallConfigurationDefinition) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) Test(org.junit.Test)

Example 70 with DefaultCamelContext

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();
}
Also used : CamelContext(org.apache.camel.CamelContext) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) RouteBuilder(org.apache.camel.builder.RouteBuilder) ServiceCallConfigurationDefinition(org.apache.camel.model.cloud.ServiceCallConfigurationDefinition) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) Test(org.junit.Test)

Aggregations

DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)474 CamelContext (org.apache.camel.CamelContext)206 Test (org.junit.Test)183 DefaultExchange (org.apache.camel.impl.DefaultExchange)128 RouteBuilder (org.apache.camel.builder.RouteBuilder)101 Exchange (org.apache.camel.Exchange)91 Before (org.junit.Before)70 SimpleRegistry (org.apache.camel.impl.SimpleRegistry)61 RegisteredDelivery (org.jsmpp.bean.RegisteredDelivery)39 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)38 ESMClass (org.jsmpp.bean.ESMClass)30 ProducerTemplate (org.apache.camel.ProducerTemplate)27 CountDownLatch (java.util.concurrent.CountDownLatch)15 Endpoint (org.apache.camel.Endpoint)13 FailedToCreateRouteException (org.apache.camel.FailedToCreateRouteException)13 Processor (org.apache.camel.Processor)12 RouteStartupOrder (org.apache.camel.spi.RouteStartupOrder)12 Address (org.jsmpp.bean.Address)11 SubmitMultiResult (org.jsmpp.bean.SubmitMultiResult)11 Date (java.util.Date)10