use of org.apache.camel.util.StopWatch in project camel by apache.
the class JavaUuidGeneratorTest method testPerformance.
public void testPerformance() {
JavaUuidGenerator uuidGenerator = new JavaUuidGenerator();
StopWatch watch = new StopWatch();
LOG.info("First id: " + uuidGenerator.generateUuid());
for (int i = 0; i < 500000; i++) {
uuidGenerator.generateUuid();
}
LOG.info("Last id: " + uuidGenerator.generateUuid());
LOG.info("Took " + TimeUtils.printDuration(watch.stop()));
}
use of org.apache.camel.util.StopWatch in project camel by apache.
the class SimpleUuidGeneratorTest method testPerformance.
public void testPerformance() {
SimpleUuidGenerator uuidGenerator = new SimpleUuidGenerator();
StopWatch watch = new StopWatch();
LOG.info("First id: " + uuidGenerator.generateUuid());
for (int i = 0; i < 500000; i++) {
uuidGenerator.generateUuid();
}
LOG.info("Last id: " + uuidGenerator.generateUuid());
LOG.info("Took " + TimeUtils.printDuration(watch.stop()));
}
use of org.apache.camel.util.StopWatch in project camel by apache.
the class RedeliveryDeadLetterErrorHandlerNoRedeliveryOnShutdownTest method testRedeliveryErrorHandlerNoRedeliveryOnShutdown.
public void testRedeliveryErrorHandlerNoRedeliveryOnShutdown() throws Exception {
getMockEndpoint("mock:foo").expectedMessageCount(1);
getMockEndpoint("mock:deadLetter").expectedMessageCount(1);
getMockEndpoint("mock:deadLetter").setResultWaitTime(25000);
template.sendBody("seda:foo", "Hello World");
getMockEndpoint("mock:foo").assertIsSatisfied();
// should not take long to stop the route
StopWatch watch = new StopWatch();
// sleep 3 seconds to do some redeliveries before we stop
Thread.sleep(3000);
log.info("==== stopping route foo ====");
context.stopRoute("foo");
watch.stop();
getMockEndpoint("mock:deadLetter").assertIsSatisfied();
log.info("OnRedelivery processor counter {}", counter.get());
assertTrue("Should stop route faster, was " + watch.taken(), watch.taken() < 7000);
assertTrue("Redelivery counter should be >= 2 and < 12, was: " + counter.get(), counter.get() >= 2 && counter.get() < 12);
}
use of org.apache.camel.util.StopWatch in project camel by apache.
the class DefaultCamelContext method doSuspend.
@Override
protected void doSuspend() throws Exception {
EventHelper.notifyCamelContextSuspending(this);
log.info("Apache Camel " + getVersion() + " (CamelContext: " + getName() + ") is suspending");
StopWatch watch = new StopWatch();
// (so when we resume we only resume the routes which actually was suspended)
for (Map.Entry<String, RouteService> entry : getRouteServices().entrySet()) {
if (entry.getValue().getStatus().isStarted()) {
suspendedRouteServices.put(entry.getKey(), entry.getValue());
}
}
// assemble list of startup ordering so routes can be shutdown accordingly
List<RouteStartupOrder> orders = new ArrayList<RouteStartupOrder>();
for (Map.Entry<String, RouteService> entry : suspendedRouteServices.entrySet()) {
Route route = entry.getValue().getRoutes().iterator().next();
Integer order = entry.getValue().getRouteDefinition().getStartupOrder();
if (order == null) {
order = defaultRouteStartupOrder++;
}
orders.add(new DefaultRouteStartupOrder(order, route, entry.getValue()));
}
// suspend routes using the shutdown strategy so it can shutdown in correct order
// routes which doesn't support suspension will be stopped instead
getShutdownStrategy().suspend(this, orders);
// mark the route services as suspended or stopped
for (RouteService service : suspendedRouteServices.values()) {
if (routeSupportsSuspension(service.getId())) {
service.suspend();
} else {
service.stop();
}
}
watch.stop();
if (log.isInfoEnabled()) {
log.info("Apache Camel " + getVersion() + " (CamelContext: " + getName() + ") is suspended in " + TimeUtils.printDuration(watch.taken()));
}
EventHelper.notifyCamelContextSuspended(this);
}
use of org.apache.camel.util.StopWatch in project camel by apache.
the class BeanPerformanceTest method testBeanPerformance.
public void testBeanPerformance() throws Exception {
StopWatch watch = new StopWatch();
log.info("Invoking a bean in a route {} times", times);
for (int i = 0; i < times; i++) {
template.sendBody("direct:start", "Hello World");
}
log.info("Took {} to invoke the bean {} times", TimeUtils.printDuration(watch.stop()), times);
assertEquals(times, INVOKED.get());
}
Aggregations