Search in sources :

Example 81 with StopWatch

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

the class DirectProducerBlockingTest method testProducerBlocksForSuspendedConsumer.

public void testProducerBlocksForSuspendedConsumer() throws Exception {
    DirectEndpoint endpoint = getMandatoryEndpoint("direct:suspended", DirectEndpoint.class);
    endpoint.getConsumer().suspend();
    StopWatch watch = new StopWatch();
    try {
        template.sendBody("direct:suspended?block=true&timeout=2000", "hello world");
        fail("Expected CamelExecutionException");
    } catch (CamelExecutionException e) {
        DirectConsumerNotAvailableException cause = assertIsInstanceOf(DirectConsumerNotAvailableException.class, e.getCause());
        assertIsInstanceOf(CamelExchangeException.class, cause);
        assertTrue(watch.taken() > 1500);
    }
}
Also used : CamelExecutionException(org.apache.camel.CamelExecutionException) CamelExchangeException(org.apache.camel.CamelExchangeException) StopWatch(org.apache.camel.util.StopWatch)

Example 82 with StopWatch

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

the class DirectProducerBlockingTest method testProducerBlocksWithNoConsumers.

public void testProducerBlocksWithNoConsumers() throws Exception {
    DirectEndpoint endpoint = getMandatoryEndpoint("direct:suspended", DirectEndpoint.class);
    endpoint.getConsumer().suspend();
    StopWatch watch = new StopWatch();
    try {
        template.sendBody("direct:start?block=true&timeout=2000", "hello world");
        fail("Expected CamelExecutionException");
    } catch (CamelExecutionException e) {
        DirectConsumerNotAvailableException cause = assertIsInstanceOf(DirectConsumerNotAvailableException.class, e.getCause());
        assertIsInstanceOf(CamelExchangeException.class, cause);
        assertTrue(watch.taken() > 1500);
    }
}
Also used : CamelExecutionException(org.apache.camel.CamelExecutionException) CamelExchangeException(org.apache.camel.CamelExchangeException) StopWatch(org.apache.camel.util.StopWatch)

Example 83 with StopWatch

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

the class BeanVsProcessorPerformanceTest method testProcessor.

public void testProcessor() throws Exception {
    StopWatch watch = new StopWatch();
    for (int i = 0; i < size; i++) {
        Object out = template.requestBody("direct:a", "" + i);
        assertEquals("Bye " + i, out);
    }
    log.info("Processor took {} ms ", watch.taken());
}
Also used : StopWatch(org.apache.camel.util.StopWatch)

Example 84 with StopWatch

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

the class BeanVsProcessorPerformanceTest method testBean.

public void testBean() throws Exception {
    StopWatch watch = new StopWatch();
    for (int i = 0; i < size; i++) {
        Object out = template.requestBody("direct:b", "" + i);
        assertEquals("Bye " + i, out);
    }
    log.info("Bean took {} ms ", watch.taken());
}
Also used : StopWatch(org.apache.camel.util.StopWatch)

Example 85 with StopWatch

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

the class TypeConverterConcurrencyIssueTest method testTypeConverter.

public void testTypeConverter() throws Exception {
    // add as type converter
    Method method = TypeConverterConcurrencyIssueTest.class.getMethod("toMyCamelBean", String.class);
    assertNotNull(method);
    context.getTypeConverterRegistry().addTypeConverter(MyCamelBean.class, String.class, new StaticMethodTypeConverter(method));
    ExecutorService pool = context.getExecutorServiceManager().newThreadPool(this, "test", 50, 50);
    final CountDownLatch latch = new CountDownLatch(size);
    StopWatch watch = new StopWatch();
    for (int i = 0; i < size; i++) {
        pool.submit(new Runnable() {

            @Override
            public void run() {
                try {
                    context.getTypeConverter().mandatoryConvertTo(MyCamelBean.class, "1;MyCamel");
                    latch.countDown();
                } catch (NoTypeConversionAvailableException e) {
                // ignore, as the latch will not be decremented anymore so that the assert below
                // will fail after the one minute timeout anyway
                }
            }
        });
    }
    assertTrue("The expected mandatory conversions failed!", latch.await(1, TimeUnit.MINUTES));
    log.info("Took " + watch.stop() + " millis to convert " + size + " objects");
}
Also used : NoTypeConversionAvailableException(org.apache.camel.NoTypeConversionAvailableException) ExecutorService(java.util.concurrent.ExecutorService) Method(java.lang.reflect.Method) CountDownLatch(java.util.concurrent.CountDownLatch) StaticMethodTypeConverter(org.apache.camel.impl.converter.StaticMethodTypeConverter) 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