Author: davsclaus
Date: Tue Aug  3 05:31:36 2010
New Revision: 981740

URL: http://svn.apache.org/viewvc?rev=981740&view=rev
Log:
Fixed test on other boxes.

Modified:
    
camel/trunk/components/camel-netty/src/test/java/org/apache/camel/component/netty/Netty2978IssueTest.java

Modified: 
camel/trunk/components/camel-netty/src/test/java/org/apache/camel/component/netty/Netty2978IssueTest.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-netty/src/test/java/org/apache/camel/component/netty/Netty2978IssueTest.java?rev=981740&r1=981739&r2=981740&view=diff
==============================================================================
--- 
camel/trunk/components/camel-netty/src/test/java/org/apache/camel/component/netty/Netty2978IssueTest.java
 (original)
+++ 
camel/trunk/components/camel-netty/src/test/java/org/apache/camel/component/netty/Netty2978IssueTest.java
 Tue Aug  3 05:31:36 2010
@@ -24,6 +24,7 @@ import java.util.concurrent.Callable;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
 import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
 
 import org.apache.camel.CamelContext;
 import org.apache.camel.Endpoint;
@@ -43,39 +44,45 @@ public class Netty2978IssueTest extends 
     @Test
     public void testNetty2978() throws Exception {
         CamelClient client = new CamelClient();
-        for (int i = 0; i < 2000; i++) {
-            Object reply = client.lookup(i);
-            assertEquals("Bye " + i, reply);
+        try {
+            for (int i = 0; i < 1000; i++) {
+                Object reply = client.lookup(i);
+                assertEquals("Bye " + i, reply);
+            }
+        } finally {
+            client.close();
         }
-        client.close();
     }
 
     @Test
     public void testNetty2978Concurrent() throws Exception {
         final CamelClient client = new CamelClient();
+        try {
+            final List<Callable<String>> callables = new 
ArrayList<Callable<String>>();
+            for (int count = 0; count < 1000; count++) {
+                final int i = count;
+                callables.add(new Callable<String>() {
+                    public String call() {
+                        return client.lookup(i);
+                    }
+                });
+            }
 
-        final List<Callable<String>> callables = new 
ArrayList<Callable<String>>();
-        for (int count = 0; count < 2000; count++) {
-            final int i = count;
-            callables.add(new Callable<String>() {
-                public String call() {
-                    return client.lookup(i);
-                }
-            });
-        }
+            final ExecutorService executorService = 
Executors.newFixedThreadPool(10);
+            final List<Future<String>> results = 
executorService.invokeAll(callables);
+            final Set<String> replies = new HashSet<String>();
+            for (Future<String> future : results) {
+                // wait at most 60 sec to not hang test
+                String reply = future.get(60, TimeUnit.SECONDS);
+                assertTrue(reply.startsWith("Bye "));
+                replies.add(reply);
+            }
 
-        final ExecutorService executorService = 
Executors.newFixedThreadPool(20);
-        final List<Future<String>> results = 
executorService.invokeAll(callables);
-        final Set<String> replies = new HashSet<String>();
-        for (Future<String> future : results) {
-            String reply = future.get();
-            assertTrue(reply.startsWith("Bye "));
-            replies.add(reply);
+            // should be 1000 unique replies
+            assertEquals(1000, replies.size());
+        } finally {
+            client.close();
         }
-        client.close();
-
-        // should be 2000 unique replies
-        assertEquals(2000, replies.size());
     }
 
     @Override
@@ -83,7 +90,7 @@ public class Netty2978IssueTest extends 
         return new RouteBuilder() {
             @Override
             public void configure() throws Exception {
-                from("netty:tcp://localhost:2048?sync=true")
+                from("netty:tcp://localhost:22048?sync=true")
                         .process(new Processor() {
                             public void process(final Exchange exchange) {
                                 String body = 
exchange.getIn().getBody(String.class);
@@ -101,7 +108,7 @@ public class Netty2978IssueTest extends 
 
         public CamelClient() {
             this.context = new DefaultCamelContext();
-            this.endpoint = 
context.getEndpoint("netty:tcp://localhost:2048?sync=true");
+            this.endpoint = 
context.getEndpoint("netty:tcp://localhost:22048?sync=true");
             this.producerTemplate = context.createProducerTemplate();
         }
 
@@ -113,8 +120,6 @@ public class Netty2978IssueTest extends 
         public String lookup(int num) {
             return producerTemplate.requestBody(endpoint, num, String.class);
         }
-
     }
 
-
 }


Reply via email to