Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
package org.fuse.usecase;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.netty4.NettyComponent;
import org.junit.Test;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
public class Netty4HttpProducerConcurrentTest extends BaseNetty4Test {
public void testNoConcurrentProducers() throws Exception {
doSendMessages(1, 1);
public void testConcurrentProducers() throws Exception {
doSendMessages(10, 5);
private void doSendMessages(int files, int poolSize) throws Exception {
ExecutorService executor = Executors.newFixedThreadPool(poolSize);
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("netty4-http:http://localhost:{{port}}/echo", "" + index, String.class);
responses.put(index, out);
assertEquals(files, responses.size());
// get all responses
Set<String> unique = new HashSet<String>();
for (Future<String> future : responses.values()) {
// should be 'files' unique responses
assertEquals("Should be " + files + " unique responses", files, unique.size());
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
public void configure() throws Exception {
// expose a echo service
.log(">> Thread name : ${threadName}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.