Search in sources :

Example 21 with StopWatch

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

the class TimerDrivenTimePatternConverterTest method testTimerUsingStopWatch.

public void testTimerUsingStopWatch() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedMinimumMessageCount(2);
    StopWatch watch = new StopWatch();
    assertMockEndpointsSatisfied();
    long interval = watch.stop();
    LOG.trace("Should take approx 2000 milliseconds, was: {}", interval);
    assertTrue("Should take approx 2000 milliseconds, was: " + interval, interval >= 1700);
}
Also used : MockEndpoint(org.apache.camel.component.mock.MockEndpoint) StopWatch(org.apache.camel.util.StopWatch)

Example 22 with StopWatch

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

the class PrimitiveTypeConverterIssueTest method testPrimitiveTypeConverter.

public void testPrimitiveTypeConverter() throws Exception {
    StopWatch watch = new StopWatch();
    for (int i = 0; i < 10000; i++) {
        int num = context.getTypeConverter().convertTo(int.class, "123");
        assertEquals(123, num);
    }
    log.info("Time taken: " + watch.stop());
}
Also used : StopWatch(org.apache.camel.util.StopWatch)

Example 23 with StopWatch

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

the class SplitterParallelAggregateTest method timeSplitRoutes.

protected void timeSplitRoutes(int numberOfRequests) throws Exception {
    String[] endpoints = new String[] { "direct:splitSynchronizedAggregation", "direct:splitUnsynchronizedAggregation" };
    List<Future<File>> futures = new ArrayList<Future<File>>();
    StopWatch stopWatch = new StopWatch(false);
    for (String endpoint : endpoints) {
        stopWatch.restart();
        for (int requestIndex = 0; requestIndex < numberOfRequests; requestIndex++) {
            futures.add(template.asyncRequestBody(endpoint, null, File.class));
        }
        for (int i = 0; i < futures.size(); i++) {
            Future<File> future = futures.get(i);
            future.get();
        }
        stopWatch.stop();
        log.info(String.format("test%d.%s=%d\n", numberOfRequests, endpoint, stopWatch.taken()));
    }
}
Also used : ArrayList(java.util.ArrayList) Future(java.util.concurrent.Future) File(java.io.File) StopWatch(org.apache.camel.util.StopWatch)

Example 24 with StopWatch

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

the class JettyAsyncDefaultContinuationTimeoutTest method testJettyAsyncTimeout.

@Test
public void testJettyAsyncTimeout() throws Exception {
    getMockEndpoint("mock:result").expectedBodiesReceived("Bye World");
    StopWatch watch = new StopWatch();
    try {
        template.requestBody("http://localhost:{{port}}/myservice", null, String.class);
        fail("Should have thrown an exception");
    } catch (CamelExecutionException e) {
        log.info("Timeout hit and client got reply with failure status code");
        long taken = watch.stop();
        HttpOperationFailedException cause = assertIsInstanceOf(HttpOperationFailedException.class, e.getCause());
        assertEquals(504, cause.getStatusCode());
        // should be approx 30-34 sec.
        assertTrue("Timeout should occur faster than " + taken, taken < 34000);
    }
    assertMockEndpointsSatisfied(2, TimeUnit.MINUTES);
}
Also used : CamelExecutionException(org.apache.camel.CamelExecutionException) HttpOperationFailedException(org.apache.camel.http.common.HttpOperationFailedException) StopWatch(org.apache.camel.util.StopWatch) BaseJettyTest(org.apache.camel.component.jetty.BaseJettyTest) Test(org.junit.Test)

Example 25 with StopWatch

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

the class JmsRequestReplySharedReplyToTest method testJmsRequestReplySharedReplyTo.

@Test
public void testJmsRequestReplySharedReplyTo() throws Exception {
    StopWatch watch = new StopWatch();
    // shared is more slower than exclusive, due it need to use a JMS Message Selector
    // and has a receiveTimeout of 1 sec per default, so it react slower to new messages
    assertEquals("Hello A", template.requestBody("activemq:queue:foo?replyTo=bar&replyToType=Shared", "A"));
    assertEquals("Hello B", template.requestBody("activemq:queue:foo?replyTo=bar&replyToType=Shared", "B"));
    assertEquals("Hello C", template.requestBody("activemq:queue:foo?replyTo=bar&replyToType=Shared", "C"));
    assertEquals("Hello D", template.requestBody("activemq:queue:foo?replyTo=bar&replyToType=Shared", "D"));
    assertEquals("Hello E", template.requestBody("activemq:queue:foo?replyTo=bar&replyToType=Shared", "E"));
    long delta = watch.stop();
    assertTrue("Should be slower than about 2 seconds, was: " + delta, delta > 2000);
}
Also used : StopWatch(org.apache.camel.util.StopWatch) Test(org.junit.Test)

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