Search in sources :

Example 76 with StopWatch

use of org.apache.camel.util.StopWatch in project camel by apache.

the class FailoverLoadBalancerBreakoutDuringShutdownTest method testFailover.

public void testFailover() throws Exception {
    getMockEndpoint("mock:before").expectedMessageCount(1);
    getMockEndpoint("mock:after").expectedMessageCount(0);
    template.sendBody("seda:start", "Hello World");
    assertMockEndpointsSatisfied();
    // use a stop watch to time how long it takes to force the shutdown
    StopWatch watch = new StopWatch();
    // force quicker shutdown
    context.getShutdownStrategy().setTimeout(1);
    context.stop();
    // should take less than 5 seconds
    assertTrue("Should take less than 5 seconds, was " + watch.taken(), watch.stop() < 5000);
}
Also used : StopWatch(org.apache.camel.util.StopWatch)

Example 77 with StopWatch

use of org.apache.camel.util.StopWatch in project camel by apache.

the class SplitterParallelBigFileTest method xxxtestSplitParallelBigFile.

// disabled due manual test
public void xxxtestSplitParallelBigFile() throws Exception {
    StopWatch watch = new StopWatch();
    NotifyBuilder builder = new NotifyBuilder(context).whenDone(lines + 1).create();
    boolean done = builder.matches(120, TimeUnit.SECONDS);
    log.info("Took " + TimeUtils.printDuration(watch.stop()));
    if (!done) {
        throw new CamelException("Could not split file in 2 minutes");
    }
// need a little sleep for capturing memory profiling
// Thread.sleep(60 * 1000);
}
Also used : NotifyBuilder(org.apache.camel.builder.NotifyBuilder) CamelException(org.apache.camel.CamelException) StopWatch(org.apache.camel.util.StopWatch)

Example 78 with StopWatch

use of org.apache.camel.util.StopWatch in project camel by apache.

the class PropertyEditorTypeConverterIssueTest method testPropertyEditorTypeConverter.

public void testPropertyEditorTypeConverter() throws Exception {
    // test that converters a custom object (MyBean) to a String which causes
    // PropertyEditorTypeConverter to be used. And this test times how fast
    // this is. As we want to optimize PropertyEditorTypeConverter to be faster
    MyBean bean = new MyBean();
    bean.setBar("Hello");
    StopWatch watch = new StopWatch();
    for (int i = 0; i < 500; i++) {
        String s = context.getTypeConverter().convertTo(String.class, bean);
        log.debug(s);
        assertNotNull(s);
    }
    log.info("Time taken: " + watch.stop());
}
Also used : StopWatch(org.apache.camel.util.StopWatch)

Example 79 with StopWatch

use of org.apache.camel.util.StopWatch in project camel by apache.

the class TypeConverterRegistryPerformanceTest method disbledtestPerformance.

public void disbledtestPerformance() throws Exception {
    // force converter to be loaded on startup
    Document dom = context.getTypeConverter().convertTo(Document.class, "<hello>World</hello>");
    assertNotNull(dom);
    StopWatch watch = new StopWatch();
    latch = new CountDownLatch(size);
    executorService = Executors.newFixedThreadPool(pool);
    for (int i = 0; i < size; i++) {
        executorService.submit(new Runnable() {

            @Override
            public void run() {
                for (int j = 0; j < inner; j++) {
                    Document dom = context.getTypeConverter().convertTo(Document.class, "<hello>World</hello>");
                    assertNotNull(dom);
                }
                latch.countDown();
            }
        });
    }
    assertTrue("Should all work", latch.await(2, TimeUnit.MINUTES));
    log.info("Took " + watch.taken());
    executorService.shutdownNow();
}
Also used : Document(org.w3c.dom.Document) CountDownLatch(java.util.concurrent.CountDownLatch) StopWatch(org.apache.camel.util.StopWatch)

Example 80 with StopWatch

use of org.apache.camel.util.StopWatch in project camel by apache.

the class MockEndpoint method waitForCompleteLatch.

protected void waitForCompleteLatch() throws InterruptedException {
    if (latch == null) {
        fail("Should have a latch!");
    }
    StopWatch watch = new StopWatch();
    waitForCompleteLatch(resultWaitTime);
    long delta = watch.stop();
    LOG.debug("Took {} millis to complete latch", delta);
    if (resultMinimumWaitTime > 0 && delta < resultMinimumWaitTime) {
        fail("Expected minimum " + resultMinimumWaitTime + " millis waiting on the result, but was faster with " + delta + " millis.");
    }
}
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