[infinispan-commits] Infinispan SVN: r1989 - trunk/client/hotrod-client/src/test/java/org/infinispan/client/hotrod.

infinispan-commits at lists.jboss.org infinispan-commits at lists.jboss.org
Tue Jul 6 10:25:33 EDT 2010


Author: galder.zamarreno at jboss.com
Date: 2010-07-06 10:25:33 -0400 (Tue, 06 Jul 2010)
New Revision: 1989

Modified:
   trunk/client/hotrod-client/src/test/java/org/infinispan/client/hotrod/TestHelper.java
Log:
Temporary fix to get around Hot Rod server bind issues.

Modified: trunk/client/hotrod-client/src/test/java/org/infinispan/client/hotrod/TestHelper.java
===================================================================
--- trunk/client/hotrod-client/src/test/java/org/infinispan/client/hotrod/TestHelper.java	2010-07-06 12:44:43 UTC (rev 1988)
+++ trunk/client/hotrod-client/src/test/java/org/infinispan/client/hotrod/TestHelper.java	2010-07-06 14:25:33 UTC (rev 1989)
@@ -4,7 +4,11 @@
 import org.infinispan.manager.EmbeddedCacheManager;
 import org.infinispan.server.hotrod.HotRodServer;
 import org.infinispan.server.hotrod.test.HotRodTestingUtil;
+import org.infinispan.util.logging.Log;
+import org.infinispan.util.logging.LogFactory;
+import org.jboss.netty.channel.ChannelException;
 
+import java.net.BindException;
 import java.util.concurrent.atomic.AtomicInteger;
 
 /**
@@ -13,13 +17,31 @@
  */
 public class TestHelper {
 
+   private static final Log log = LogFactory.getLog(TestHelper.class);
+
    /**
     * This needs to be different than the one used in the server tests in order to make sure that there's no clash.
     */
    private static final AtomicInteger uniquePort = new AtomicInteger(11312);
 
    public static HotRodServer startHotRodServer(EmbeddedCacheManager cacheManager) {
-      return HotRodTestingUtil.startHotRodServer(cacheManager, uniquePort.incrementAndGet());
+      // TODO: This is very rudimentary!! HotRodTestingUtil needs a more robust solution where ports are generated randomly and retries if already bound
+      HotRodServer server = null;
+      int maxTries = 5;
+      int currentTries = 0;
+      while (server == null && currentTries < maxTries) {
+         try {
+            server = HotRodTestingUtil.startHotRodServer(cacheManager, uniquePort.incrementAndGet());
+         } catch (ChannelException e) {
+            if (!(e.getCause() instanceof BindException)) {
+               throw e;
+            } else {
+               log.debug("Address already in use: [" + e.getMessage() + "], so let's try next port");
+               currentTries++;
+            }
+         }
+      }
+      return server;
    }
 
    public static String getServersString(HotRodServer... servers) {



More information about the infinispan-commits mailing list