Search in sources :

Example 26 with RouteDefinition

use of org.apache.camel.model.RouteDefinition in project camel by apache.

the class RemoveRouteDefinitionTest method testShutdownRoute.

@SuppressWarnings("deprecation")
public void testShutdownRoute() throws Exception {
    // JMX tests dont work well on AIX CI servers (hangs them)
    if (isPlatform("aix")) {
        return;
    }
    MBeanServer mbeanServer = getMBeanServer();
    Set<ObjectName> set = mbeanServer.queryNames(new ObjectName("*:type=routes,*"), null);
    assertEquals(1, set.size());
    ObjectName on = set.iterator().next();
    boolean registered = mbeanServer.isRegistered(on);
    assertEquals("Should be registered", true, registered);
    RouteDefinition definition = context.getRouteDefinition("route1");
    List<RouteDefinition> routeDefinitions = new ArrayList<RouteDefinition>();
    routeDefinitions.add(definition);
    context.shutdownRoute("route1");
    // route is shutdown (= also removed), so its not longer in JMX
    set = mbeanServer.queryNames(new ObjectName("*:type=routes,*"), null);
    assertEquals(0, set.size());
}
Also used : RouteDefinition(org.apache.camel.model.RouteDefinition) ArrayList(java.util.ArrayList) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

Example 27 with RouteDefinition

use of org.apache.camel.model.RouteDefinition in project camel by apache.

the class RemoveRouteDefinitionTest method testStopAndRemoveRoute.

public void testStopAndRemoveRoute() throws Exception {
    // JMX tests dont work well on AIX CI servers (hangs them)
    if (isPlatform("aix")) {
        return;
    }
    MBeanServer mbeanServer = getMBeanServer();
    Set<ObjectName> set = mbeanServer.queryNames(new ObjectName("*:type=routes,*"), null);
    assertEquals(1, set.size());
    ObjectName on = set.iterator().next();
    boolean registered = mbeanServer.isRegistered(on);
    assertEquals("Should be registered", true, registered);
    RouteDefinition definition = context.getRouteDefinition("route1");
    List<RouteDefinition> routeDefinitions = new ArrayList<RouteDefinition>();
    routeDefinitions.add(definition);
    // must stop before we can remove
    context.stopRoute("route1");
    context.removeRoute("route1");
    // route is removed, so its not longer in JMX
    set = mbeanServer.queryNames(new ObjectName("*:type=routes,*"), null);
    assertEquals(0, set.size());
}
Also used : RouteDefinition(org.apache.camel.model.RouteDefinition) ArrayList(java.util.ArrayList) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

Example 28 with RouteDefinition

use of org.apache.camel.model.RouteDefinition in project camel by apache.

the class AdviceWithTwoRoutesOnExceptionTest method testAdviceWithA.

public void testAdviceWithA() throws Exception {
    RouteDefinition route = context.getRouteDefinition("a");
    route.adviceWith(context, new AdviceWithRouteBuilder() {

        @Override
        public void configure() throws Exception {
            interceptSendToEndpoint("mock://a").skipSendToOriginalEndpoint().throwException(new IllegalArgumentException("Forced"));
        }
    });
    getMockEndpoint("mock:a").expectedMessageCount(0);
    getMockEndpoint("mock:error").expectedMessageCount(1);
    getMockEndpoint("mock:error").message(0).exchangeProperty(Exchange.EXCEPTION_CAUGHT).isInstanceOf(IllegalArgumentException.class);
    template.sendBody("direct:a", "Hello World");
    assertMockEndpointsSatisfied();
}
Also used : RouteDefinition(org.apache.camel.model.RouteDefinition) AdviceWithRouteBuilder(org.apache.camel.builder.AdviceWithRouteBuilder)

Example 29 with RouteDefinition

use of org.apache.camel.model.RouteDefinition in project camel by apache.

the class AdviceWithTwoRoutesTest method testAdviceWithB.

public void testAdviceWithB() throws Exception {
    RouteDefinition route = context.getRouteDefinition("b");
    route.adviceWith(context, new AdviceWithRouteBuilder() {

        @Override
        public void configure() throws Exception {
            interceptSendToEndpoint("mock://b").skipSendToOriginalEndpoint().to("mock:detour");
        }
    });
    getMockEndpoint("mock:b").expectedMessageCount(0);
    getMockEndpoint("mock:detour").expectedMessageCount(1);
    template.sendBody("direct:b", "Hello World");
    assertMockEndpointsSatisfied();
}
Also used : RouteDefinition(org.apache.camel.model.RouteDefinition) AdviceWithRouteBuilder(org.apache.camel.builder.AdviceWithRouteBuilder)

Example 30 with RouteDefinition

use of org.apache.camel.model.RouteDefinition in project camel by apache.

the class AdviceWithTwoRoutesTest method testAdviceWithAB.

public void testAdviceWithAB() throws Exception {
    RouteDefinition route = context.getRouteDefinition("a");
    route.adviceWith(context, new AdviceWithRouteBuilder() {

        @Override
        public void configure() throws Exception {
            interceptSendToEndpoint("mock://a").skipSendToOriginalEndpoint().to("mock:detour");
        }
    });
    route = context.getRouteDefinition("b");
    route.adviceWith(context, new AdviceWithRouteBuilder() {

        @Override
        public void configure() throws Exception {
            interceptSendToEndpoint("mock://b").skipSendToOriginalEndpoint().to("mock:detour");
        }
    });
    getMockEndpoint("mock:a").expectedMessageCount(0);
    getMockEndpoint("mock:b").expectedMessageCount(0);
    getMockEndpoint("mock:detour").expectedMessageCount(2);
    template.sendBody("direct:a", "Hello World");
    template.sendBody("direct:b", "Bye World");
    assertMockEndpointsSatisfied();
}
Also used : RouteDefinition(org.apache.camel.model.RouteDefinition) AdviceWithRouteBuilder(org.apache.camel.builder.AdviceWithRouteBuilder)

Aggregations

RouteDefinition (org.apache.camel.model.RouteDefinition)102 AdviceWithRouteBuilder (org.apache.camel.builder.AdviceWithRouteBuilder)17 RouteBuilder (org.apache.camel.builder.RouteBuilder)17 Test (org.junit.Test)11 ArrayList (java.util.ArrayList)9 FromDefinition (org.apache.camel.model.FromDefinition)9 HashMap (java.util.HashMap)6 Processor (org.apache.camel.Processor)6 ConnectException (java.net.ConnectException)5 Exchange (org.apache.camel.Exchange)5 ProcessorDefinition (org.apache.camel.model.ProcessorDefinition)5 IOException (java.io.IOException)4 Map (java.util.Map)4 MBeanServer (javax.management.MBeanServer)4 ObjectName (javax.management.ObjectName)4 ChoiceDefinition (org.apache.camel.model.ChoiceDefinition)4 HystrixConfigurationDefinition (org.apache.camel.model.HystrixConfigurationDefinition)4 HystrixDefinition (org.apache.camel.model.HystrixDefinition)4 LogDefinition (org.apache.camel.model.LogDefinition)4 ModelCamelContext (org.apache.camel.model.ModelCamelContext)4