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);
}
}
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);
}
}
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());
}
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());
}
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");
}
Aggregations