Search in sources :

Example 51 with RouteDefinition

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

the class HystrixRouteConfigMaximumSizeTest method testGroupKeyAndThreadPoolKeyConfigFlagsDoNotScrapHystrixConfiguration.

@Test
public void testGroupKeyAndThreadPoolKeyConfigFlagsDoNotScrapHystrixConfiguration() throws Exception {
    // dummy route
    RouteBuilder rb = new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            from("direct:foo").hystrix().hystrixConfiguration().groupKey("test1").metricsHealthSnapshotIntervalInMilliseconds(99999).end().groupKey("test2").to("log:hello").end();
        }
    };
    rb.configure();
    RouteDefinition route = rb.getRouteCollection().getRoutes().get(0);
    assertEquals(HystrixDefinition.class, route.getOutputs().get(0).getClass());
    HystrixConfigurationDefinition config = ((HystrixDefinition) route.getOutputs().get(0)).getHystrixConfiguration();
    assertEquals("test2", config.getGroupKey());
    assertEquals(99999, config.getMetricsHealthSnapshotIntervalInMilliseconds().intValue());
}
Also used : RouteBuilder(org.apache.camel.builder.RouteBuilder) RouteDefinition(org.apache.camel.model.RouteDefinition) HystrixConfigurationDefinition(org.apache.camel.model.HystrixConfigurationDefinition) HystrixDefinition(org.apache.camel.model.HystrixDefinition) Test(org.junit.Test)

Example 52 with RouteDefinition

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

the class HystrixRouteConfigTest method testGroupKeyAndThreadPoolKeyConfigFlagsDoNotScrapHystrixConfiguration.

@Test
public void testGroupKeyAndThreadPoolKeyConfigFlagsDoNotScrapHystrixConfiguration() throws Exception {
    // dummy route
    RouteBuilder rb = new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            from("direct:foo").hystrix().hystrixConfiguration().groupKey("test1").metricsHealthSnapshotIntervalInMilliseconds(99999).end().groupKey("test2").to("log:hello").end();
        }
    };
    rb.configure();
    RouteDefinition route = rb.getRouteCollection().getRoutes().get(0);
    assertEquals(HystrixDefinition.class, route.getOutputs().get(0).getClass());
    HystrixConfigurationDefinition config = ((HystrixDefinition) route.getOutputs().get(0)).getHystrixConfiguration();
    assertEquals("test2", config.getGroupKey());
    assertEquals(99999, config.getMetricsHealthSnapshotIntervalInMilliseconds().intValue());
}
Also used : RouteBuilder(org.apache.camel.builder.RouteBuilder) RouteDefinition(org.apache.camel.model.RouteDefinition) HystrixConfigurationDefinition(org.apache.camel.model.HystrixConfigurationDefinition) HystrixDefinition(org.apache.camel.model.HystrixDefinition) Test(org.junit.Test)

Example 53 with RouteDefinition

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

the class SpringHystrixRouteHierarchicalConfigTest method testHystrix.

@Test
public void testHystrix() throws Exception {
    RouteDefinition routeDefinition = context.getRouteDefinition("hystrix-route");
    HystrixDefinition hystrixDefinition = findHystrixDefinition(routeDefinition);
    Assert.assertNotNull(hystrixDefinition);
    HystrixProcessorFactory factory = new HystrixProcessorFactory();
    HystrixConfigurationDefinition config = factory.buildHystrixConfiguration(context, hystrixDefinition);
    Assert.assertEquals("local-conf-group-key", config.getGroupKey());
    Assert.assertEquals("global-thread-key", config.getThreadPoolKey());
    Assert.assertEquals(new Integer(5), config.getCorePoolSize());
    getMockEndpoint("mock:result").expectedBodiesReceived("Bye World");
    template.sendBody("direct:start", "Hello World");
    assertMockEndpointsSatisfied();
}
Also used : RouteDefinition(org.apache.camel.model.RouteDefinition) HystrixDefinition(org.apache.camel.model.HystrixDefinition) HystrixConfigurationDefinition(org.apache.camel.model.HystrixConfigurationDefinition) Test(org.junit.Test)

Example 54 with RouteDefinition

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

the class DefaultManagementLifecycleStrategy method onRouteContextCreate.

public void onRouteContextCreate(RouteContext routeContext) {
    if (!initialized) {
        return;
    }
    // Create a map (ProcessorType -> PerformanceCounter)
    // to be passed to InstrumentationInterceptStrategy.
    Map<ProcessorDefinition<?>, PerformanceCounter> registeredCounters = new HashMap<ProcessorDefinition<?>, PerformanceCounter>();
    // Each processor in a route will have its own performance counter.
    // These performance counter will be embedded to InstrumentationProcessor
    // and wrap the appropriate processor by InstrumentationInterceptStrategy.
    RouteDefinition route = routeContext.getRoute();
    // register performance counters for all processors and its children
    for (ProcessorDefinition<?> processor : route.getOutputs()) {
        registerPerformanceCounters(routeContext, processor, registeredCounters);
    }
    // set this managed intercept strategy that executes the JMX instrumentation for performance metrics
    // so our registered counters can be used for fine grained performance instrumentation
    routeContext.setManagedInterceptStrategy(new InstrumentationInterceptStrategy(registeredCounters, wrappedProcessors));
}
Also used : RouteDefinition(org.apache.camel.model.RouteDefinition) HashMap(java.util.HashMap) ProcessorDefinition(org.apache.camel.model.ProcessorDefinition) PerformanceCounter(org.apache.camel.api.management.PerformanceCounter)

Example 55 with RouteDefinition

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

the class ValidateIdTest method testValidateId.

public void testValidateId() throws Exception {
    getMockEndpoint("mock:result").expectedMessageCount(1);
    template.sendBody("direct:start", "Hello World");
    assertMockEndpointsSatisfied();
    RouteDefinition route = context.getRouteDefinition("myRoute");
    assertNotNull(route);
    // mock:result should be the only with the result as id
    assertTrue(route.getOutputs().get(0).getId().equals("myValidate"));
    assertFalse(route.getOutputs().get(1).getId().equals("result"));
    assertTrue(route.getOutputs().get(2).getId().equals("result"));
    assertTrue(route.getOutputs().get(3).getId().equals("after"));
}
Also used : RouteDefinition(org.apache.camel.model.RouteDefinition)

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