use of java.util.concurrent.Future 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()));
}
}
use of java.util.concurrent.Future in project camel by apache.
the class JdbcProducerConcurrenctTest method doSendMessages.
@SuppressWarnings("rawtypes")
private void doSendMessages(int files, int poolSize) throws Exception {
mock.expectedMessageCount(files);
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<List<?>>> responses = new HashMap<Integer, Future<List<?>>>();
for (int i = 0; i < files; i++) {
final int index = i;
Future<List<?>> out = executor.submit(new Callable<List<?>>() {
public List<?> call() throws Exception {
int id = (index % 2) + 1;
return template.requestBody("direct:start", "select * from customer where id = 'cust" + id + "'", List.class);
}
});
responses.put(index, out);
}
assertMockEndpointsSatisfied();
assertEquals(files, responses.size());
for (int i = 0; i < files; i++) {
List<?> rows = responses.get(i).get();
Map columns = (Map) rows.get(0);
if (i % 2 == 0) {
assertEquals("jstrachan", columns.get("NAME"));
} else {
assertEquals("nsandhu", columns.get("NAME"));
}
}
executor.shutdownNow();
}
use of java.util.concurrent.Future in project camel by apache.
the class HttpProducerConcurrentTest method doSendMessages.
private void doSendMessages(int files, int poolSize) throws Exception {
getMockEndpoint("mock:result").expectedMessageCount(files);
getMockEndpoint("mock:result").assertNoDuplicates(body());
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 {
return template.requestBody("http://localhost:{{port}}/echo", "" + index, String.class);
}
});
responses.put(index, out);
}
assertMockEndpointsSatisfied();
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 java.util.concurrent.Future in project camel by apache.
the class JpaProducerConcurrentTest method doSendMessages.
private void doSendMessages(int files, int poolSize) throws Exception {
getMockEndpoint("mock:result").expectedMessageCount(files);
getMockEndpoint("mock:result").assertNoDuplicates(body());
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<SendEmail>> responses = new HashMap<Integer, Future<SendEmail>>();
for (int i = 0; i < files; i++) {
final int index = i;
Future<SendEmail> out = executor.submit(new Callable<SendEmail>() {
public SendEmail call() throws Exception {
return template.requestBody("direct:start", new SendEmail("user" + index + "@somewhere.org"), SendEmail.class);
}
});
responses.put(index, out);
}
assertMockEndpointsSatisfied(30, TimeUnit.SECONDS);
assertEquals(files, responses.size());
// get them so they are complete
for (Future<SendEmail> future : responses.values()) {
SendEmail sendEmail = future.get();
assertNotNull(sendEmail);
log.info("Persisted the SendEmail entity with the id {} and the address {}", sendEmail.getId(), sendEmail.getAddress());
}
// assert in the database
assertEntityInDB(files);
executor.shutdownNow();
}
use of java.util.concurrent.Future in project camel by apache.
the class MinaProducerConcurrentTest method doSendMessages.
private void doSendMessages(int files, int poolSize) throws Exception {
getMockEndpoint("mock:result").expectedMessageCount(files);
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 {
return template.requestBody("mina:tcp://localhost:{{port}}?sync=true", index, String.class);
}
});
responses.put(index, out);
}
assertMockEndpointsSatisfied();
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();
}
Aggregations