use of org.apache.camel.util.StopWatch in project camel by apache.
the class NettyConcurrentTest method doSendMessages.
private void doSendMessages(int files, int poolSize) throws Exception {
StopWatch watch = new StopWatch();
NotifyBuilder notify = new NotifyBuilder(context).whenDone(files).create();
ExecutorService executor = Executors.newFixedThreadPool(poolSize);
// we access the responses Map below only inside the main thread,
// so no need for a thread-safe Map implementation
Map<Integer, Future<String>> responses = new HashMap<Integer, Future<String>>();
for (int i = 0; i < files; i++) {
final int index = i;
Future<String> out = executor.submit(new Callable<String>() {
public String call() throws Exception {
String reply = template.requestBody("netty:tcp://localhost:{{port}}", index, String.class);
log.debug("Sent {} received {}", index, reply);
assertEquals("Bye " + index, reply);
return reply;
}
});
responses.put(index, out);
}
notify.matches(2, TimeUnit.MINUTES);
log.info("Took " + watch.taken() + " millis to process " + files + " messages using " + poolSize + " client threads.");
assertEquals(files, responses.size());
// get all responses
Set<String> unique = new HashSet<String>();
for (Future<String> future : responses.values()) {
unique.add(future.get());
}
// should be 'files' unique responses
assertEquals("Should be " + files + " unique responses", files, unique.size());
executor.shutdownNow();
}
use of org.apache.camel.util.StopWatch in project camel by apache.
the class DisruptorVmInOutChainedTimeoutTest method testDisruptorVmInOutChainedTimeout.
public void testDisruptorVmInOutChainedTimeout() throws Exception {
StopWatch watch = new StopWatch();
try {
template2.requestBody("disruptor-vm:a?timeout=1000", "Hello World");
fail("Should have thrown an exception");
} catch (CamelExecutionException e) {
// the chained vm caused the timeout
ExchangeTimedOutException cause = assertIsInstanceOf(ExchangeTimedOutException.class, e.getCause());
assertEquals(200, cause.getTimeout());
}
long delta = watch.stop();
assertTrue("Should be faster than 1 sec, was: " + delta, delta < 1100);
}
use of org.apache.camel.util.StopWatch in project camel by apache.
the class JettyAsyncContinuationTimeoutTest 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 3-4 sec.
assertTrue("Timeout should occur faster than " + taken, taken < 4500);
}
assertMockEndpointsSatisfied();
}
use of org.apache.camel.util.StopWatch in project camel by apache.
the class JmsRequestReplyExclusiveReplyToComponentTest method testJmsRequestReplyExclusiveFixedReplyTo.
@Test
public void testJmsRequestReplyExclusiveFixedReplyTo() throws Exception {
StopWatch watch = new StopWatch();
assertEquals("Hello A", template.requestBody("activemq:queue:foo?replyTo=bar", "A"));
assertEquals("Hello B", template.requestBody("activemq:queue:foo?replyTo=bar", "B"));
assertEquals("Hello C", template.requestBody("activemq:queue:foo?replyTo=bar", "C"));
assertEquals("Hello D", template.requestBody("activemq:queue:foo?replyTo=bar", "D"));
assertEquals("Hello E", template.requestBody("activemq:queue:foo?replyTo=bar", "E"));
long delta = watch.stop();
assertTrue("Should be faster than about 4 seconds, was: " + delta, delta < 4200);
}
use of org.apache.camel.util.StopWatch in project camel by apache.
the class JmsRequestReplyExclusiveReplyToConcurrentTest method testJmsRequestReplyExclusiveFixedReplyTo.
@Test
public void testJmsRequestReplyExclusiveFixedReplyTo() throws Exception {
StopWatch watch = new StopWatch();
ExecutorService executor = Executors.newFixedThreadPool(10);
for (int i = 0; i < size; i++) {
final Integer num = i;
executor.submit(new Runnable() {
@Override
public void run() {
String reply = template.requestBody("direct:start", "" + num, String.class);
log.info("Sent {} expecting reply 'Hello {}' got --> {}", new Object[] { num, num, reply });
assertNotNull(reply);
assertEquals("Hello " + num, reply);
latch.countDown();
}
});
}
log.info("Waiting to process {} messages...", size);
// if any of the assertions above fails then the latch will not get decremented
assertTrue("All assertions outside the main thread above should have passed", latch.await(3, TimeUnit.SECONDS));
long delta = watch.stop();
log.info("Took {} millis", delta);
// just sleep a bit before shutting down
Thread.sleep(1000);
executor.shutdownNow();
}
Aggregations