river-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From peter_firmst...@apache.org
Subject svn commit: r1410320 - /river/jtsk/trunk/qa/src/com/sun/jini/test/share/BaseQATest.java
Date Fri, 16 Nov 2012 12:43:01 GMT
Author: peter_firmstone
Date: Fri Nov 16 12:43:01 2012
New Revision: 1410320

URL: http://svn.apache.org/viewvc?rev=1410320&view=rev
Log:
Attempt to fix what appear to be some synchronisation issues in test failures.

Modified:
    river/jtsk/trunk/qa/src/com/sun/jini/test/share/BaseQATest.java

Modified: river/jtsk/trunk/qa/src/com/sun/jini/test/share/BaseQATest.java
URL: http://svn.apache.org/viewvc/river/jtsk/trunk/qa/src/com/sun/jini/test/share/BaseQATest.java?rev=1410320&r1=1410319&r2=1410320&view=diff
==============================================================================
--- river/jtsk/trunk/qa/src/com/sun/jini/test/share/BaseQATest.java (original)
+++ river/jtsk/trunk/qa/src/com/sun/jini/test/share/BaseQATest.java Fri Nov 16 12:43:01 2012
@@ -1441,14 +1441,16 @@ abstract public class BaseQATest extends
      *  numbers when starting lookup services.
      */
     protected boolean portInUse(int port) {
-        for(int i=0;i<lookupsStarted.size();i++) {
-            LocatorGroupsPair pair = (LocatorGroupsPair)lookupsStarted.get(i);
-            int curPort = (pair.locator).getPort();
-            if(port == curPort) {
-                logger.log(Level.FINE, "port in use: " + port);
-                return true;
+        synchronized (lookupsStarted){
+            Iterator ls = lookupsStarted.iterator();
+            while (ls.hasNext()){
+                LocatorGroupsPair pair = (LocatorGroupsPair) ls.next();
+                if (port == pair.locator.getPort()){
+                    logger.log(Level.FINE, "port in use: " + port);
+                    return true;
+                }
             }
-        }//end loop
+        }
         return false;
     }//end portInUse
 
@@ -1526,8 +1528,14 @@ abstract public class BaseQATest extends
                 LocatorGroupsPair pair
                                = (LocatorGroupsPair)initLookupsToStart.get(i);
                 int port = (pair.locator).getPort();
-                if(portInUse(port)) port = 0;
-                String hostname = startLookup(i,port, pair.locator.getHost());
+                String hostname = null;
+                synchronized (lookupsStarted){
+                    // This synchronized block ensures that initialisation is
+                    // atomic, so two lookups cannot be started with the same
+                    // port.
+                    if(portInUse(port)) port = 0;
+                    hostname = startLookup(i,port, pair.locator.getHost());
+                }
 		logger.log(Level.FINEST, 
 			   "service host is '" + hostname 
 			   + "', this host is '" + config.getLocalHostName() + "'");



Mime
View raw message