Search in sources :

Example 1 with Breadcrumbs

use of io.fabric8.insight.camel.breadcrumb.Breadcrumbs in project fabric8 by jboss-fuse.

the class ContainerTest method testProfilerStrategy.

@Test
public void testProfilerStrategy() throws Exception {
    Profiler profiler = new Profiler();
    Breadcrumbs breadcrumbs = new Breadcrumbs();
    CamelContext context = new DefaultCamelContext();
    profiler.manage(context);
    breadcrumbs.manage(context);
    context.addRoutes(new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            from("direct:a").doTry().to("seda:polyglot").choice().when(body().isEqualTo("<hello/>")).to("seda:english").throwException(new Exception("Error processing exchange")).endChoice().when(body().isEqualTo("<hallo/>")).to("seda:dutch").delay(2).to("seda:german").endChoice().otherwise().to("seda:french").endDoTry().doCatch(Throwable.class).to("seda:errors");
            String[] eps = { "polyglot", "english", "dutch", "german", "french", "errors" };
            for (String s : eps) {
                from("seda:" + s).aggregate(constant("ok"), new BodyInAggregatingStrategy()).completionSize(3).to("mock:" + s);
            }
        }
    });
    context.start();
    final ProducerTemplate template = new DefaultProducerTemplate(context);
    template.start();
    final String[] values = { "<hello/>", "<hallo/>", "<bonjour/>" };
    final Random rnd = new Random();
    for (int i = 0; i < 100; i++) {
        template.sendBody("direct:a", values[rnd.nextInt(values.length)]);
    }
    profiler.reset();
    long t0 = System.nanoTime();
    int nbThreads = 10;
    final CountDownLatch latch = new CountDownLatch(nbThreads);
    for (int t = 0; t < nbThreads; t++) {
        new Thread() {

            public void run() {
                for (int i = 0; i < 1000; i++) {
                    template.sendBody("direct:a", values[rnd.nextInt(values.length)]);
                }
                latch.countDown();
            }
        }.start();
    }
    latch.await();
    long t1 = System.nanoTime();
    System.out.println("Total time: " + TimeUnit.MILLISECONDS.convert(t1 - t0, TimeUnit.NANOSECONDS));
    print(profiler.getStatistics());
    System.out.println();
    MBeanServer mbeanServer = context.getManagementStrategy().getManagementAgent().getMBeanServer();
    ObjectName on = context.getManagementStrategy().getManagementNamingStrategy().getObjectNameForCamelContext(context);
    String xml = (String) mbeanServer.invoke(on, "dumpRoutesStatsAsXml", new Object[] { false, true }, new String[] { "boolean", "boolean" });
    System.out.println(xml);
}
Also used : CamelContext(org.apache.camel.CamelContext) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) DefaultProducerTemplate(org.apache.camel.impl.DefaultProducerTemplate) ProducerTemplate(org.apache.camel.ProducerTemplate) RouteBuilder(org.apache.camel.builder.RouteBuilder) Breadcrumbs(io.fabric8.insight.camel.breadcrumb.Breadcrumbs) CountDownLatch(java.util.concurrent.CountDownLatch) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) DefaultProducerTemplate(org.apache.camel.impl.DefaultProducerTemplate) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) ObjectName(javax.management.ObjectName) Profiler(io.fabric8.insight.camel.profiler.Profiler) Random(java.util.Random) MBeanServer(javax.management.MBeanServer) Test(org.junit.Test)

Example 2 with Breadcrumbs

use of io.fabric8.insight.camel.breadcrumb.Breadcrumbs in project fabric8 by jboss-fuse.

the class ContainerTest method testLoadBalancer.

@Test
public void testLoadBalancer() throws Exception {
    Profiler profiler = new Profiler();
    Breadcrumbs breadcrumbs = new Breadcrumbs();
    CamelContext context = new DefaultCamelContext();
    profiler.manage(context);
    breadcrumbs.manage(context);
    context.addRoutes(new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            from("direct:a").loadBalance().failover().to("mock:out");
        }
    });
    context.start();
    final ProducerTemplate template = new DefaultProducerTemplate(context);
    template.start();
    template.sendBody("direct:a", "Hello");
}
Also used : CamelContext(org.apache.camel.CamelContext) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) DefaultProducerTemplate(org.apache.camel.impl.DefaultProducerTemplate) ProducerTemplate(org.apache.camel.ProducerTemplate) Profiler(io.fabric8.insight.camel.profiler.Profiler) RouteBuilder(org.apache.camel.builder.RouteBuilder) Breadcrumbs(io.fabric8.insight.camel.breadcrumb.Breadcrumbs) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) DefaultProducerTemplate(org.apache.camel.impl.DefaultProducerTemplate) Test(org.junit.Test)

Aggregations

Breadcrumbs (io.fabric8.insight.camel.breadcrumb.Breadcrumbs)2 Profiler (io.fabric8.insight.camel.profiler.Profiler)2 CamelContext (org.apache.camel.CamelContext)2 ProducerTemplate (org.apache.camel.ProducerTemplate)2 RouteBuilder (org.apache.camel.builder.RouteBuilder)2 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)2 DefaultProducerTemplate (org.apache.camel.impl.DefaultProducerTemplate)2 Test (org.junit.Test)2 Random (java.util.Random)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 MBeanServer (javax.management.MBeanServer)1 ObjectName (javax.management.ObjectName)1 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)1