Author: davsclaus
Date: Sat Oct  6 13:31:50 2012
New Revision: 1395047

URL: http://svn.apache.org/viewvc?rev=1395047&view=rev
Log:
CAMEL-5689: Added unit tests.

Modified:
    
camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/netty/NettyAsyncRequestReplyTest.java
    camel/trunk/tests/camel-itest/src/test/resources/log4j.properties

Modified: 
camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/netty/NettyAsyncRequestReplyTest.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/netty/NettyAsyncRequestReplyTest.java?rev=1395047&r1=1395046&r2=1395047&view=diff
==============================================================================
--- 
camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/netty/NettyAsyncRequestReplyTest.java
 (original)
+++ 
camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/netty/NettyAsyncRequestReplyTest.java
 Sat Oct  6 13:31:50 2012
@@ -16,6 +16,15 @@
  */
 package org.apache.camel.itest.netty;
 
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
 import javax.naming.Context;
 
 import org.apache.activemq.camel.component.ActiveMQComponent;
@@ -36,6 +45,41 @@ public class NettyAsyncRequestReplyTest 
     public void testNetty() throws Exception {
         String out = template.requestBody("netty:tcp://localhost:" + port + 
"?textline=true?sync=true", "World", String.class);
         assertEquals("Bye World", out);
+
+        String out2 = template.requestBody("netty:tcp://localhost:" + port + 
"?textline=true?sync=true", "Camel", String.class);
+        assertEquals("Bye Camel", out2);
+    }
+
+    @Test
+    public void testConcurrent() throws Exception {
+        int size = 1000;
+
+        ExecutorService executor = Executors.newFixedThreadPool(20);
+        Map<Integer, Future<String>> responses = new 
ConcurrentHashMap<Integer, Future<String>>();
+        for (int i = 0; i < size; 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 + 
"?textline=true?sync=true", index, String.class);
+                    log.info("Sent {} received {}", index, reply);
+                    assertEquals("Bye " + index, reply);
+                    return reply;
+                }
+            });
+            responses.put(index, out);
+        }
+
+        // get all responses
+        Set<Object> unique = new HashSet<Object>();
+        for (Future<String> future : responses.values()) {
+            String reply = future.get(30, TimeUnit.SECONDS);
+            assertNotNull("Should get a reply", reply);
+            unique.add(reply);
+        }
+
+        // should be 10 unique responses
+        assertEquals("Should be " + size + " unique responses", size, 
unique.size());
+        executor.shutdownNow();
     }
 
     @Override

Modified: camel/trunk/tests/camel-itest/src/test/resources/log4j.properties
URL: 
http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest/src/test/resources/log4j.properties?rev=1395047&r1=1395046&r2=1395047&view=diff
==============================================================================
--- camel/trunk/tests/camel-itest/src/test/resources/log4j.properties (original)
+++ camel/trunk/tests/camel-itest/src/test/resources/log4j.properties Sat Oct  
6 13:31:50 2012
@@ -25,6 +25,7 @@ log4j.rootLogger=INFO, file
 #log4j.logger.org.apache.camel=TRACE
 #log4j.logger.org.apache.camel=DEBUG
 #log4j.logger.org.apache.camel.component.file=TRACE
+#log4j.logger.org.apache.camel.component.netty=DEBUG
 #log4j.logger.org.apache.camel.processor.DefaultErrorHandler=TRACE
 
 # CONSOLE appender not used by default


Reply via email to