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