Search in sources :

Example 86 with StopWatch

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

the class NotAllowRedeliveryWhileStoppingDeadLetterChannelTest method testRedelivery.

public void testRedelivery() throws Exception {
    StopWatch watch = new StopWatch();
    MockEndpoint before = getMockEndpoint("mock:foo");
    before.expectedMessageCount(1);
    template.sendBody("seda:start", "Hello World");
    assertMockEndpointsSatisfied();
    Thread.sleep(500);
    context.stopRoute("foo");
    // we should reject the task and stop quickly
    assertTrue("Should stop quickly: " + watch.taken(), watch.taken() < 5000);
    // should go to DLC
    Exchange dead = getMockEndpoint("mock:dead").getExchanges().get(0);
    assertNotNull(dead);
    Throwable cause = dead.getProperty(Exchange.EXCEPTION_CAUGHT, Throwable.class);
    assertNotNull(cause);
    assertIsInstanceOf(RejectedExecutionException.class, cause);
    assertEquals("Redelivery not allowed while stopping", cause.getMessage());
}
Also used : Exchange(org.apache.camel.Exchange) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) StopWatch(org.apache.camel.util.StopWatch)

Example 87 with StopWatch

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

the class NotAllowRedeliveryWhileStoppingTest method testRedelivery.

public void testRedelivery() throws Exception {
    StopWatch watch = new StopWatch();
    MockEndpoint before = getMockEndpoint("mock:foo");
    before.expectedMessageCount(1);
    template.sendBody("seda:start", "Hello World");
    assertMockEndpointsSatisfied();
    Thread.sleep(500);
    context.stop();
    // we should reject the task and stop quickly
    assertTrue("Should stop quickly: " + watch.taken(), watch.taken() < 5000);
}
Also used : MockEndpoint(org.apache.camel.component.mock.MockEndpoint) StopWatch(org.apache.camel.util.StopWatch)

Example 88 with StopWatch

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

the class AggregateSimpleExpressionIssueTest method xxxtestAggregateSimpleExpression.

// Enable me for manual unit testing
public void xxxtestAggregateSimpleExpression() throws Exception {
    // 10 files + 10 files * 100 batches
    int files = 10;
    int rows = 100000;
    int batches = rows / 1000;
    int total = files + (files * rows) + (files * batches);
    LOG.info("There are " + total + " exchanges");
    NotifyBuilder notify = new NotifyBuilder(context).whenDone(total).create();
    LOG.info("Writing 10 files with 100000 rows in each file");
    // write 10 files of 100k rows
    for (int i = 0; i < files; i++) {
        Writer out = IOHelper.buffered(new FileWriter(new File("target/files", "data" + i)));
        for (int j = 0; j < rows; j++) {
            out.write(DATA);
        }
        out.close();
    }
    // start the route
    StopWatch watch = new StopWatch();
    context.startRoute("foo");
    LOG.info("Waiting to process all the files");
    boolean matches = notify.matches(3, TimeUnit.MINUTES);
    LOG.info("Should process all files " + matches);
    LOG.info("Time taken " + watch.taken() + " ms");
}
Also used : NotifyBuilder(org.apache.camel.builder.NotifyBuilder) FileWriter(java.io.FileWriter) File(java.io.File) FileWriter(java.io.FileWriter) Writer(java.io.Writer) StopWatch(org.apache.camel.util.StopWatch)

Example 89 with StopWatch

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

the class ChunkComponentTest method testChunkPerformance.

/**
     * Performance test
     */
@Test
public void testChunkPerformance() throws Exception {
    int messageCount = 10000;
    endSimpleMock.expectedMessageCount(messageCount);
    StopWatch stopwatch = new StopWatch(true);
    for (int i = 0; i < messageCount; i++) {
        startSimpleProducerTemplate.sendBodyAndHeader("The Body", "name", "Andrew");
    }
    assertMockEndpointsSatisfied();
    LoggerFactory.getLogger(getClass()).info("Chunk performance: " + stopwatch.stop() + "ms for " + messageCount + " messages");
}
Also used : MockEndpoint(org.apache.camel.component.mock.MockEndpoint) StopWatch(org.apache.camel.util.StopWatch) Test(org.junit.Test)

Example 90 with StopWatch

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

the class DefaultCamelContext method doResume.

@Override
protected void doResume() throws Exception {
    try {
        EventHelper.notifyCamelContextResuming(this);
        log.info("Apache Camel " + getVersion() + " (CamelContext: " + getName() + ") is resuming");
        StopWatch watch = new StopWatch();
        // start the suspended routes (do not check for route clashes, and indicate)
        doStartOrResumeRoutes(suspendedRouteServices, false, true, true, false);
        // mark the route services as resumed (will be marked as started) as well
        for (RouteService service : suspendedRouteServices.values()) {
            if (routeSupportsSuspension(service.getId())) {
                service.resume();
            } else {
                service.start();
            }
        }
        watch.stop();
        if (log.isInfoEnabled()) {
            log.info("Resumed " + suspendedRouteServices.size() + " routes");
            log.info("Apache Camel " + getVersion() + " (CamelContext: " + getName() + ") resumed in " + TimeUtils.printDuration(watch.taken()));
        }
        // and clear the list as they have been resumed
        suspendedRouteServices.clear();
        EventHelper.notifyCamelContextResumed(this);
    } catch (Exception e) {
        EventHelper.notifyCamelContextResumeFailed(this, e);
        throw e;
    }
}
Also used : RuntimeCamelException(org.apache.camel.RuntimeCamelException) MalformedObjectNameException(javax.management.MalformedObjectNameException) VetoCamelContextStartException(org.apache.camel.VetoCamelContextStartException) IOException(java.io.IOException) LoadPropertiesException(org.apache.camel.util.LoadPropertiesException) NoSuchEndpointException(org.apache.camel.NoSuchEndpointException) ResolveEndpointFailedException(org.apache.camel.ResolveEndpointFailedException) NoFactoryAvailableException(org.apache.camel.NoFactoryAvailableException) FailedToStartRouteException(org.apache.camel.FailedToStartRouteException) 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