You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@river.apache.org by pe...@apache.org on 2013/01/16 13:11:25 UTC
svn commit: r1433909 - in
/river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test: share/
spec/joinmanager/ spec/locatordiscovery/
Author: peter_firmstone
Date: Wed Jan 16 12:11:24 2013
New Revision: 1433909
URL: http://svn.apache.org/viewvc?rev=1433909&view=rev
Log:
Ongoing refactoring, fixed synchronization of shared state in BaseQATest and other tests.
Modified:
river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/share/BaseQATest.java
river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/share/LookupServices.java
river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/spec/joinmanager/AddAttributesPropNew.java
river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/spec/joinmanager/ModifyAttributesPropNew.java
river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/spec/joinmanager/RegisterProp.java
river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/spec/joinmanager/SetAttributesPropNew.java
river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/spec/joinmanager/TerminateDiscovery.java
river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/spec/locatordiscovery/DiscoveredStagger.java
Modified: river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/share/BaseQATest.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/share/BaseQATest.java?rev=1433909&r1=1433908&r2=1433909&view=diff
==============================================================================
--- river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/share/BaseQATest.java (original)
+++ river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/share/BaseQATest.java Wed Jan 16 12:11:24 2013
@@ -1030,89 +1030,6 @@ abstract public class BaseQATest extends
}//end changed
}//end class GroupChangeListener
- /** Thread in which a number of lookup services are started after various
- * time delays. This thread is intended to be used by tests that need to
- * simulate "late joiner" lookup services. After all of the requested
- * lookup services have been started, this thread will exit.
- */
- protected class StaggeredStartThread extends Thread {
- private final long[] waitTimes
- = { 5*1000, 10*1000, 20*1000, 30*1000, 60*1000,
- 2*60*1000,
- 60*1000, 30*1000, 20*1000, 10*1000, 5*1000 };
- private final int startIndx;
- private final List locGroupsList;
- /** Use this constructor if it is desired that all lookup services
- * be started in this thread. The locGroupsList parameter is an
- * ArrayList that should contain LocatorGroupsPair instances that
- * reference the locator and corresponding member groups of each
- * lookup service to start.
- */
- public StaggeredStartThread(List locGroupsList) {
- this(0,locGroupsList);
- }//end constructor
-
- /** Use this constructor if a number of lookup services (equal to the
- * value of the given startIndx) have already been started; and this
- * thread will start the remaining lookup services. The locGroupsList
- * parameter is an ArrayList that should contain LocatorGroupsPair
- * instances that reference the locator and corresponding member
- * groups of each lookup service to start.
- */
- public StaggeredStartThread(int startIndx,List locGroupsList) {
- super("StaggeredStartThread");
- setDaemon(true);
- this.startIndx = startIndx;
- this.locGroupsList = locGroupsList;
- }//end constructor
-
- public void run() {
- int n = waitTimes.length;
- for(int i=startIndx;((!isInterrupted())&&(i<locGroupsList.size()));
- i++)
- {
- long waitMS = ( i < n ? waitTimes[i] : waitTimes[n-1] );
- logger.log(Level.FINE,
- " waiting "+(waitMS/1000)+" seconds before "
- +"attempting to start the next lookup service");
- try {
- Thread.sleep(waitMS);
- } catch(InterruptedException e) {
- /* Need to re-interrupt this thread because catching
- * an InterruptedException clears the interrupted status
- * of this thread.
- *
- * If the sleep() call was not interrupted but was timed
- * out, this means that this thread should continue
- * processing; and the fact that the interrupted status
- * has been cleared is consistent with that fact. On the
- * other hand, if the sleep() was actually interrupted,
- * this means that some entity external to this thread
- * is signalling that this thread should exit. But the
- * code below that determines whether to exit or continue
- * processing bases its decision on the state of the
- * interrupted status. And since the interrupted status
- * was cleared when the InterruptedException was caught,
- * the interrupted status of this thread needs to be reset
- * to an interrupted state so that an exit will occur.
- */
- Thread.currentThread().interrupt();
- }
- LocatorGroupsPair pair
- = (LocatorGroupsPair)locGroupsList.get(i);
- LookupLocator l = pair.getLocator();
- int port = l.getPort();
- if(portInUse(port)) port = 0;
- if( isInterrupted() ) break;//exit this thread
- try {
- startLookup(i, port, l.getHost());
- } catch(Exception e) {
- e.printStackTrace();
- }
- }//end loop
- }//end run
- }//end class StaggeredStartThread
-
/* Protected instance variables */
protected volatile int testType = AUTOMATIC_LOCAL_TEST;
@@ -1553,17 +1470,6 @@ abstract public class BaseQATest extends
return ((Entry[])(attrsSet).toArray(new Entry[attrsSet.size()]) );
}//end addAttrsAndRemoveDups
- /** Method that compares the given port to the ports of all the lookup
- * services that have been currently started. Returns <code>true</code>
- * if the given port equals any of the ports referenced in the set
- * lookup services that have been started; <code>false</code>
- * otherwise. This method is useful for guaranteeing unique port
- * numbers when starting lookup services.
- */
- protected final boolean portInUse(int port) {
- return getLookupServices().portInUse(port);
- }//end portInUse
-
/** Constructs a <code>LookupLocator</code> using configuration information
* corresponding to the value of the given parameter <code>indx</code>.
* Useful when lookup services need to be started, or simply when
@@ -1627,23 +1533,6 @@ abstract public class BaseQATest extends
}
}//end startAddLookups
- /**
- * Start a lookup service with configuration referenced by the
- * given parameter values.
- *
- * @param indx the index of lookup services within the set of
- * lookups to start for this test
- * @param port the port the lookup service is to use
- * @return the name of the system the lookup service was started on
- * @throws Exception if something goes wrong
- */
- protected String startLookup(int indx, int port) throws Exception {
- return startLookup(indx, port, config.getLocalHostName());
- }
-
- protected String startLookup(int indx, int port, String serviceHost) throws Exception {
- return getLookupServices().startLookup(indx, port, serviceHost);
- }
/** Common code shared by each test that needs to wait for discovered
* events from the discovery helper utility, and verify that the
Modified: river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/share/LookupServices.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/share/LookupServices.java?rev=1433909&r1=1433908&r2=1433909&view=diff
==============================================================================
--- river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/share/LookupServices.java (original)
+++ river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/share/LookupServices.java Wed Jan 16 12:11:24 2013
@@ -45,7 +45,7 @@ import net.jini.discovery.DiscoveryManag
import net.jini.lookup.DiscoveryAdmin;
/**
- * This class was refactored out of BaseQATest, there are some minor issues
+ * This class was refactored from BaseQATest, there are some minor issues
* remaining:
*
* TODO: Ensure lookup service instances can only be started once.
@@ -466,7 +466,9 @@ public class LookupServices {
}//end startAddLookups
/**
- * Start next lookup.
+ * Start next lookup. If no configured lookups exists a new one is
+ * created dynamically and appended to the end of the lookup lists.
+ *
* @return index of lookup started.
* @throws Exception
*/
@@ -474,9 +476,15 @@ public class LookupServices {
synchronized (lock){
int indx = curLookupListSize(info);
LocatorGroupsPair pair = allLookupsToStart.get(indx);
- int port = (pair.getLocator()).getPort();
- if(portInUse(port)) port = 0;//use randomly chosen port
- startLookup(indx, port, pair.getLocator().getHost());
+ int port = 0;
+ if (pair != null){
+ port = (pair.getLocator()).getPort();
+ if(portInUse(port)) port = 0;//use randomly chosen port
+ startLookup(indx, port, pair.getLocator().getHost());
+ } else {
+ String host = config.getLocalHostName();
+ startLookup(indx, port, host);
+ }
if (port == 0) refreshLookupLocatorListsAt(indx);
return indx;
}
@@ -493,7 +501,7 @@ public class LookupServices {
* @return the name of the system the lookup service was started on
* @throws Exception if something goes wrong
*/
- protected String startLookup(int indx, int port, String serviceHost) throws Exception {
+ private String startLookup(int indx, int port, String serviceHost) throws Exception {
logger.log(Level.FINE, " starting lookup service {0}", indx);
/* retrieve the member groups with which to configure the lookup */
String[] memberGroups = memberGroupsList.get(indx);
@@ -591,8 +599,7 @@ public class LookupServices {
* @param port
* @return true if port in use.
*/
- public boolean portInUse(int port) {
- if (! Thread.holdsLock(lock)) throw new ConcurrentModificationException("calling thread doesn't hold lock");
+ private boolean portInUse(int port) {
for(int i=0;i<lookupsStarted.size();i++) {
LocatorGroupsPair pair = lookupsStarted.get(i);
int curPort = (pair.getLocator()).getPort();
@@ -602,7 +609,6 @@ public class LookupServices {
}//end portInUse
private void refreshLookupLocatorListsAt(int index){
- if (! Thread.holdsLock(lock)) throw new ConcurrentModificationException("calling thread doesn't hold lock");
LocatorGroupsPair locGroupsPair = lookupsStarted.get(index);
/* index range of init lookups */
int initLookupsBegin = nRemoteLookupServices + nAddRemoteLookupServices;
Modified: river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/spec/joinmanager/AddAttributesPropNew.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/spec/joinmanager/AddAttributesPropNew.java?rev=1433909&r1=1433908&r2=1433909&view=diff
==============================================================================
--- river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/spec/joinmanager/AddAttributesPropNew.java (original)
+++ river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/spec/joinmanager/AddAttributesPropNew.java Wed Jan 16 12:11:24 2013
@@ -21,6 +21,7 @@ package com.sun.jini.test.spec.joinmanag
import java.util.logging.Level;
import com.sun.jini.qa.harness.TestException;
+import com.sun.jini.test.share.LookupServices;
/**
* This class verifies that the <code>JoinManager</code> utility class
@@ -52,8 +53,9 @@ public class AddAttributesPropNew extend
/* Stagger-start additional lookup services */
logger.log(Level.FINE, "starting "+getnAddLookupServices()
+" additional lookup service(s) ...");
- StaggeredStartThread lookupsThread =
- new StaggeredStartThread(getLookupsStarted().size(), getAllLookupsToStart());
+ LookupServices lookups = getLookupServices();
+ Thread lookupsThread = lookups.staggeredStartThread(lookups.curLookupListSize());
+// new StaggeredStartThread(getLookupsStarted().size(), getAllLookupsToStart());
lookupsThread.start();
try {
mainListener.clearAllEventInfo();
Modified: river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/spec/joinmanager/ModifyAttributesPropNew.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/spec/joinmanager/ModifyAttributesPropNew.java?rev=1433909&r1=1433908&r2=1433909&view=diff
==============================================================================
--- river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/spec/joinmanager/ModifyAttributesPropNew.java (original)
+++ river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/spec/joinmanager/ModifyAttributesPropNew.java Wed Jan 16 12:11:24 2013
@@ -21,6 +21,7 @@ package com.sun.jini.test.spec.joinmanag
import java.util.logging.Level;
import com.sun.jini.qa.harness.TestException;
+import com.sun.jini.test.share.LookupServices;
/**
* This class verifies that the <code>JoinManager</code> utility class
@@ -53,8 +54,9 @@ public class ModifyAttributesPropNew ext
/* Stagger-start additional lookup services */
logger.log(Level.FINE, "starting "+getnAddLookupServices()
+" additional lookup service(s) ...");
- StaggeredStartThread lookupsThread =
- new StaggeredStartThread(getLookupsStarted().size(), getAllLookupsToStart());
+ LookupServices lookups = getLookupServices();
+ Thread lookupsThread = lookups.staggeredStartThread(lookups.curLookupListSize());
+// new StaggeredStartThread(getLookupsStarted().size(), getAllLookupsToStart());
lookupsThread.start();
try {
mainListener.clearAllEventInfo();
Modified: river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/spec/joinmanager/RegisterProp.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/spec/joinmanager/RegisterProp.java?rev=1433909&r1=1433908&r2=1433909&view=diff
==============================================================================
--- river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/spec/joinmanager/RegisterProp.java (original)
+++ river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/spec/joinmanager/RegisterProp.java Wed Jan 16 12:11:24 2013
@@ -21,6 +21,7 @@ package com.sun.jini.test.spec.joinmanag
import java.util.logging.Level;
import com.sun.jini.qa.harness.TestException;
+import com.sun.jini.test.share.LookupServices;
/**
* This class verifies that the <code>JoinManager</code> utility class
@@ -53,8 +54,9 @@ public class RegisterProp extends Regist
/* Stagger-start additional lookup services */
logger.log(Level.FINE, "starting "+getnAddLookupServices()
+" additional lookup service(s) ...");
- StaggeredStartThread lookupsThread =
- new StaggeredStartThread(getLookupsStarted().size(), getAllLookupsToStart());
+ LookupServices lookups = getLookupServices();
+ Thread lookupsThread = lookups.staggeredStartThread(lookups.curLookupListSize());
+// new StaggeredStartThread(getLookupsStarted().size(), getAllLookupsToStart());
lookupsThread.start();
try {
mainListener.clearAllEventInfo();
Modified: river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/spec/joinmanager/SetAttributesPropNew.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/spec/joinmanager/SetAttributesPropNew.java?rev=1433909&r1=1433908&r2=1433909&view=diff
==============================================================================
--- river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/spec/joinmanager/SetAttributesPropNew.java (original)
+++ river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/spec/joinmanager/SetAttributesPropNew.java Wed Jan 16 12:11:24 2013
@@ -21,6 +21,7 @@ package com.sun.jini.test.spec.joinmanag
import java.util.logging.Level;
import com.sun.jini.qa.harness.TestException;
+import com.sun.jini.test.share.LookupServices;
/**
* This class verifies that the <code>JoinManager</code> utility class
@@ -52,8 +53,9 @@ public class SetAttributesPropNew extend
/* Stagger-start additional lookup services */
logger.log(Level.FINE, "starting "+getnAddLookupServices()
+" additional lookup service(s) ...");
- StaggeredStartThread lookupsThread =
- new StaggeredStartThread(getLookupsStarted().size(), getAllLookupsToStart());
+ LookupServices lookups = getLookupServices();
+ Thread lookupsThread = lookups.staggeredStartThread(lookups.curLookupListSize());
+// new StaggeredStartThread(getLookupsStarted().size(), getAllLookupsToStart());
lookupsThread.start();
try {
mainListener.clearAllEventInfo();
Modified: river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/spec/joinmanager/TerminateDiscovery.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/spec/joinmanager/TerminateDiscovery.java?rev=1433909&r1=1433908&r2=1433909&view=diff
==============================================================================
--- river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/spec/joinmanager/TerminateDiscovery.java (original)
+++ river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/spec/joinmanager/TerminateDiscovery.java Wed Jan 16 12:11:24 2013
@@ -23,6 +23,7 @@ import java.util.logging.Level;
import com.sun.jini.qa.harness.QAConfig;
import com.sun.jini.qa.harness.Test;
import com.sun.jini.qa.harness.TestException;
+import com.sun.jini.test.share.LookupServices;
import net.jini.discovery.LookupDiscoveryManager;
import net.jini.lookup.JoinManager;
@@ -102,7 +103,9 @@ public class TerminateDiscovery extends
/* Start a new lookup service */
logger.log(Level.FINE, "starting another lookup service "
+" to verify discovery in the join manager ...");
- startLookup(curLookupListSize("TerminateDiscovery.run"),0);
+// startLookup(curLookupListSize("TerminateDiscovery.run"),0);
+ LookupServices lookups = getLookupServices();
+ lookups.startNextLookup("TerminateDiscovery.run");
/* Verify that the new lookup was discovered */
logger.log(Level.FINE, ""+": verifying the new lookup "
+"service is discovered ...");
@@ -115,7 +118,8 @@ public class TerminateDiscovery extends
/* Start new lookup services */
logger.log(Level.FINE, "starting another lookup service "
+"to verify discovery terminated ...");
- startLookup(curLookupListSize("TerminateDiscovery.run"),0);
+// startLookup(curLookupListSize("TerminateDiscovery.run"),0);
+ lookups.startNextLookup("TerminateDiscovery.run");
/* Verify that the new lookup was NOT discovered */
logger.log(Level.FINE, "verifying the new lookup "
+"service was NOT discovered ...");
Modified: river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/spec/locatordiscovery/DiscoveredStagger.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/spec/locatordiscovery/DiscoveredStagger.java?rev=1433909&r1=1433908&r2=1433909&view=diff
==============================================================================
--- river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/spec/locatordiscovery/DiscoveredStagger.java (original)
+++ river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/spec/locatordiscovery/DiscoveredStagger.java Wed Jan 16 12:11:24 2013
@@ -22,6 +22,7 @@ import java.util.logging.Level;
import com.sun.jini.qa.harness.Test;
import com.sun.jini.qa.harness.QAConfig;
import com.sun.jini.qa.harness.TestException;
+import com.sun.jini.test.share.LookupServices;
import net.jini.core.discovery.LookupLocator;
/**
@@ -86,16 +87,19 @@ public class DiscoveredStagger extends A
*/
boolean oldUseFastTimeout = useFastTimeout;
useFastTimeout = false;
- StaggeredStartThread lookupsThread =
- new StaggeredStartThread(1, getAllLookupsToStart());
+ LookupServices lookups = getLookupServices();
+ Thread lookupsThread = null;
+ // new StaggeredStartThread(1, getAllLookupsToStart());
try {
/* Start 1st lookup service (so it's up before discovery starts) */
- LocatorGroupsPair pair
- = (LocatorGroupsPair)getAllLookupsToStart().get(0);
- LookupLocator l = pair.getLocator();
- int port = l.getPort();
- if(portInUse(port)) port = 0;//use randomly chosen port
- startLookup(0, port, l.getHost());
+// LocatorGroupsPair pair
+// = (LocatorGroupsPair)getAllLookupsToStart().get(0);
+// LookupLocator l = pair.getLocator();
+// int port = l.getPort();
+// if(portInUse(port)) port = 0;//use randomly chosen port
+// startLookup(0, port, l.getHost());
+ int next = lookups.startNextLookup(null);
+ lookupsThread = lookups.staggeredStartThread(next);
/* Re-configure LookupLocatorDiscovery to discover given locators*/
logger.log(Level.FINE, "change LookupLocatorDiscovery to discover -- ");
LookupLocator[] locatorsToDiscover
@@ -120,7 +124,7 @@ public class DiscoveredStagger extends A
* to tell the thread to stop so that it doesn't continue running
* into the next test.
*/
- lookupsThread.interrupt();
+ if (lookupsThread != null) lookupsThread.interrupt();
useFastTimeout = oldUseFastTimeout;
}
}//end run