Search in sources :

Example 41 with StopWatch

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

the class HeaderBasedRoutingPerformanceTest method testChoiceSimple.

@Test
public void testChoiceSimple() throws InterruptedException {
    template.setDefaultEndpointUri("direct:choice-simple");
    // warm up with 20.000 messages so that the JIT compiler kicks in
    execute(20000);
    resetMock(count);
    StopWatch watch = new StopWatch();
    execute(count);
    assertMockEndpointsSatisfied();
    log.warn("Ran {} tests in {}ms", count, watch.taken());
}
Also used : StopWatch(org.apache.camel.util.StopWatch) Test(org.junit.Test)

Example 42 with StopWatch

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

the class MustacheComponentTest method testMustachePerformance.

/**
     * Main test
     */
@Test
public void testMustachePerformance() throws Exception {
    int messageCount = 10000;
    endSimpleMock.expectedMessageCount(messageCount);
    StopWatch stopwatch = new StopWatch(true);
    for (int i = 0; i < messageCount; i++) {
        startSimpleProducerTemplate.sendBodyAndHeader("The Body", "someHeader", "Some Header");
    }
    assertMockEndpointsSatisfied();
    LoggerFactory.getLogger(getClass()).info("Mustache 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 43 with StopWatch

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

the class CamelSpringRunnerPlainTest method testStopwatch.

@Test
public void testStopwatch() {
    StopWatch stopWatch = StopWatchTestExecutionListener.getStopWatch();
    assertNotNull(stopWatch);
    assertTrue(stopWatch.taken() < 100);
}
Also used : StopWatch(org.apache.camel.util.StopWatch) Test(org.junit.Test)

Example 44 with StopWatch

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

the class SjmsBatchConsumerTest method testConsumption.

@Test
public void testConsumption() throws Exception {
    final int messageCount = 10000;
    final int consumerCount = 5;
    final String queueName = getQueueName();
    context.addRoutes(new TransactedSendHarness(queueName));
    context.addRoutes(new RouteBuilder() {

        public void configure() throws Exception {
            int completionTimeout = 1000;
            int completionSize = 200;
            fromF("sjms-batch:%s?completionTimeout=%s&completionSize=%s&consumerCount=%s&aggregationStrategy=#testStrategy", queueName, completionTimeout, completionSize, consumerCount).routeId("batchConsumer").startupOrder(10).autoStartup(false).split(body()).to("mock:split");
        }
    });
    context.start();
    MockEndpoint mockBefore = getMockEndpoint("mock:before");
    mockBefore.setExpectedMessageCount(messageCount);
    MockEndpoint mockSplit = getMockEndpoint("mock:split");
    mockSplit.setExpectedMessageCount(messageCount);
    LOG.info("Sending messages");
    template.sendBody("direct:in", generateStrings(messageCount));
    LOG.info("Send complete");
    StopWatch stopWatch = new StopWatch();
    context.startRoute("batchConsumer");
    assertMockEndpointsSatisfied();
    long time = stopWatch.stop();
    LOG.info("Processed {} messages in {} ms", messageCount, time);
    LOG.info("Average throughput {} msg/s", (long) (messageCount / (time / 1000d)));
}
Also used : RouteBuilder(org.apache.camel.builder.RouteBuilder) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) StopWatch(org.apache.camel.util.StopWatch) Test(org.junit.Test)

Example 45 with StopWatch

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

the class WebsocketProducer method sendToAll.

void sendToAll(WebsocketStore store, Object message, Exchange exchange) throws Exception {
    log.debug("Sending to all {}", message);
    Collection<DefaultWebsocket> websockets = store.getAll();
    Exception exception = null;
    List<Future> futures = new CopyOnWriteArrayList<>();
    for (DefaultWebsocket websocket : websockets) {
        try {
            Future<Void> future = sendMessage(websocket, message);
            if (future != null) {
                futures.add(future);
            }
        } catch (Exception e) {
            if (exception == null) {
                exception = new WebsocketSendException("Failed to deliver message to one or more recipients.", exchange, e);
            }
        }
    }
    // check if they are all done within the timed out period
    StopWatch watch = new StopWatch();
    int timeout = endpoint.getSendTimeout();
    while (!futures.isEmpty() && watch.taken() < timeout) {
        // remove all that are done/cancelled
        for (Future future : futures) {
            if (future.isDone() || future.isCancelled()) {
                futures.remove(future);
            }
            // if there are still more then we need to wait a little bit before checking again, to avoid burning cpu cycles in the while loop
            if (!futures.isEmpty()) {
                long interval = Math.min(1000, timeout);
                log.debug("Sleeping {} millis waiting for sendToAll to complete sending with timeout {} millis", interval, timeout);
                try {
                    Thread.sleep(interval);
                } catch (InterruptedException e) {
                    handleSleepInterruptedException(e, exchange);
                }
            }
        }
    }
    if (!futures.isEmpty()) {
        exception = new WebsocketSendException("Failed to deliver message within " + endpoint.getSendTimeout() + " millis to one or more recipients.", exchange);
    }
    if (exception != null) {
        throw exception;
    }
}
Also used : IOException(java.io.IOException) StopWatch(org.apache.camel.util.StopWatch) Future(java.util.concurrent.Future) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList)

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