Search in sources :

Example 16 with StopWatch

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()));
}
Also used : StopWatch(org.apache.camel.util.StopWatch)

Example 17 with StopWatch

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()));
}
Also used : StopWatch(org.apache.camel.util.StopWatch)

Example 18 with StopWatch

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);
}
Also used : StopWatch(org.apache.camel.util.StopWatch)

Example 19 with StopWatch

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);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) RouteStartupOrder(org.apache.camel.spi.RouteStartupOrder) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) TreeMap(java.util.TreeMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ShutdownRoute(org.apache.camel.ShutdownRoute) Route(org.apache.camel.Route) StopWatch(org.apache.camel.util.StopWatch)

Example 20 with StopWatch

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());
}
Also used : StopWatch(org.apache.camel.util.StopWatch)

Aggregations

StopWatch (org.apache.camel.util.StopWatch)101 Test (org.junit.Test)40 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)14 CamelExecutionException (org.apache.camel.CamelExecutionException)10 Exchange (org.apache.camel.Exchange)8 CamelExchangeException (org.apache.camel.CamelExchangeException)6 File (java.io.File)5 ExecutorService (java.util.concurrent.ExecutorService)5 AsyncProcessor (org.apache.camel.AsyncProcessor)5 Producer (org.apache.camel.Producer)5 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 Future (java.util.concurrent.Future)4 AsyncCallback (org.apache.camel.AsyncCallback)4 Endpoint (org.apache.camel.Endpoint)4 ExchangeTimedOutException (org.apache.camel.ExchangeTimedOutException)4 NotifyBuilder (org.apache.camel.builder.NotifyBuilder)4 Date (java.util.Date)3 GenericFile (org.apache.camel.component.file.GenericFile)3