doSendMessages(250000, 100);
}
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);
Map<Integer, Future<String>> responses = new ConcurrentHashMap<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<Object> unique = new HashSet<Object>();