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);
}
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");
}
Aggregations