[jboss-cvs] JBoss Messaging SVN: r1798 - in trunk: . tests tests/src/org/jboss/test/messaging/jms/clustering tests/src/org/jboss/test/messaging/jms/clustering/base tests/src/org/jboss/test/messaging/tools tests/src/org/jboss/test/messaging/tools/ant tests/src/org/jboss/test/messaging/tools/jmx tests/src/org/jboss/test/messaging/tools/jmx/rmi tests/src/org/jboss/test/messaging/tools/jndi tests/src/org/jboss/test/messaging/util

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Dec 15 03:59:45 EST 2006


Author: ovidiu.feodorov at jboss.com
Date: 2006-12-15 03:59:37 -0500 (Fri, 15 Dec 2006)
New Revision: 1798

Added:
   trunk/tests/src/org/jboss/test/messaging/tools/ant/JUnitTestSuiteListener.java
Modified:
   trunk/messaging.iml
   trunk/messaging.ipr
   trunk/tests/build.sh
   trunk/tests/build.xml
   trunk/tests/src/org/jboss/test/messaging/jms/clustering/GroupManagementTest.java
   trunk/tests/src/org/jboss/test/messaging/jms/clustering/HATest.java
   trunk/tests/src/org/jboss/test/messaging/jms/clustering/SimpleClusteringTest.java
   trunk/tests/src/org/jboss/test/messaging/jms/clustering/base/ClusteringTestBase.java
   trunk/tests/src/org/jboss/test/messaging/tools/ServerManagement.java
   trunk/tests/src/org/jboss/test/messaging/tools/jmx/ServiceContainer.java
   trunk/tests/src/org/jboss/test/messaging/tools/jmx/rmi/LocalTestServer.java
   trunk/tests/src/org/jboss/test/messaging/tools/jmx/rmi/RMITestServer.java
   trunk/tests/src/org/jboss/test/messaging/tools/jmx/rmi/Server.java
   trunk/tests/src/org/jboss/test/messaging/tools/jmx/rmi/StopRMIServer.java
   trunk/tests/src/org/jboss/test/messaging/tools/jndi/RemoteContext.java
   trunk/tests/src/org/jboss/test/messaging/tools/jndi/RemoteInitialContextFactory.java
   trunk/tests/src/org/jboss/test/messaging/util/ServerManagementTest.java
Log:
Fixed a test server spawning bug that would lock up ant; at the end of the testsuite, all newly spawned servers are killed automatically

Modified: trunk/messaging.iml
===================================================================
--- trunk/messaging.iml	2006-12-14 21:28:22 UTC (rev 1797)
+++ trunk/messaging.iml	2006-12-15 08:59:37 UTC (rev 1798)
@@ -45,6 +45,8 @@
     <orderEntry type="library" name="jboss-jca" level="project" />
     <orderEntry type="library" name="jboss-local-jdbc" level="project" />
     <orderEntry type="library" name="jms-ra" level="project" />
+    <orderEntry type="library" name="ant" level="project" />
+    <orderEntry type="library" name="ant-junit" level="project" />
     <orderEntryProperties />
   </component>
   <component name="VcsManagerConfiguration">

Modified: trunk/messaging.ipr
===================================================================
--- trunk/messaging.ipr	2006-12-14 21:28:22 UTC (rev 1797)
+++ trunk/messaging.ipr	2006-12-15 08:59:37 UTC (rev 1798)
@@ -264,7 +264,9 @@
         <root url="jar://$PROJECT_DIR$/thirdparty/junit/lib/junit.jar!/" />
       </CLASSES>
       <JAVADOC />
-      <SOURCES />
+      <SOURCES>
+        <root url="jar://C:/work/src/junit3.8.1/src.jar!/" />
+      </SOURCES>
     </library>
     <library name="hsqldb">
       <CLASSES>
@@ -336,6 +338,25 @@
       <JAVADOC />
       <SOURCES />
     </library>
+    <library name="ant-junit">
+      <CLASSES>
+        <root url="jar://C:/apache-ant-1.6.5/lib/ant-junit.jar!/" />
+      </CLASSES>
+      <JAVADOC />
+      <SOURCES>
+        <root url="file://C:/work/src/apache-ant-1.6.5/src/main" />
+      </SOURCES>
+    </library>
+    <library name="ant">
+      <CLASSES>
+        <root url="jar://C:/apache-ant-1.6.5/lib/ant.jar!/" />
+      </CLASSES>
+      <JAVADOC />
+      <SOURCES>
+        <root url="file://C:/apache-ant-1.6.5/lib" />
+        <root url="file://C:/work/src/apache-ant-1.6.5/src/main" />
+      </SOURCES>
+    </library>
   </component>
   <component name="uidesigner-configuration">
     <option name="INSTRUMENT_CLASSES" value="true" />

Modified: trunk/tests/build.sh
===================================================================
--- trunk/tests/build.sh	2006-12-14 21:28:22 UTC (rev 1797)
+++ trunk/tests/build.sh	2006-12-15 08:59:37 UTC (rev 1798)
@@ -3,7 +3,7 @@
 
 reldir=`dirname $0`
 
-#export ANT_OPTS="-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_shmem,server=y,suspend=y,address=ant"
+#export ANT_OPTS="-Xmx1024m -Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_shmem,server=y,suspend=y,address=ant"
 export ANT_OPTS=-Xmx1024m
 $ANT_HOME/bin/ant -lib $reldir/../thirdparty/junit/lib/junit.jar "$@"
 

Modified: trunk/tests/build.xml
===================================================================
--- trunk/tests/build.xml	2006-12-14 21:28:22 UTC (rev 1797)
+++ trunk/tests/build.xml	2006-12-15 08:59:37 UTC (rev 1798)
@@ -715,6 +715,9 @@
          <sysproperty key="test.serialization" value="${functional.tests.serialization}"/>
          <sysproperty key="test.clustered" value="true"/>
          <jvmarg value="-Xmx512M"/>
+         <!--
+         <jvmarg line="-Xmx512M -Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_shmem,server=n,suspend=n,address=antjunit"/>
+          -->
 
          <classpath>
             <path refid="test.execution.classpath"/>
@@ -744,11 +747,19 @@
                     haltonfailure="${junit.batchtest.haltonfailure}"
                     haltonerror="${junit.batchtest.haltonerror}">
             <formatter type="plain" usefile="${junit.formatter.usefile}"/>
+            <!--
+                 I needed a way to intercept the end of a forked ant JUnit test run, in order to
+                 perform clean-up, and this is it: register a JUnitTestSuiteListener as a JUnit
+                 batchtest formatter, and it will get notified on a endTestSuite() event.
+            -->
+            <formatter classname="org.jboss.test.messaging.tools.ant.JUnitTestSuiteListener"/>
+
             <fileset dir="${build.tests.classes}">
-               <include name="**/jms/clustering/HATest.class"/>
                <!--
-               <include name="**/jms/clustering/SimpleClusteringTest.class"/>
+               <include name="**/jms/clustering/*Test.class"/>
+                <include name="org/jboss/test/messaging/util/ServerManagementTest.class"/>
                -->
+               <include name="**/jms/clustering/HATest.class"/>
             </fileset>
          </batchtest>
       </junit>

Modified: trunk/tests/src/org/jboss/test/messaging/jms/clustering/GroupManagementTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/clustering/GroupManagementTest.java	2006-12-14 21:28:22 UTC (rev 1797)
+++ trunk/tests/src/org/jboss/test/messaging/jms/clustering/GroupManagementTest.java	2006-12-15 08:59:37 UTC (rev 1798)
@@ -44,7 +44,7 @@
    {
       try
       {
-         ServerManagement.start("all", 0);
+         ServerManagement.start(0, "all");
 
          Set view = ServerManagement.getServer(0).getNodeIDView();
 
@@ -64,7 +64,7 @@
 
       try
       {
-         ServerManagement.start("all", 0);
+         ServerManagement.start(0, "all");
 
          log.info("Server 0 started");
 
@@ -72,7 +72,7 @@
 
          log.info("NotificationListener added to server 0");
 
-         ServerManagement.start("all", 1);
+         ServerManagement.start(1, "all");
 
          log.info("Blocking to receive notification ...");
 
@@ -99,14 +99,14 @@
    {
       try
       {
-         ServerManagement.start("all", 0);
+         ServerManagement.start(0, "all");
 
          Set view = ServerManagement.getServer(0).getNodeIDView();
 
          assertEquals(1, view.size());
          assertTrue(view.contains(new Integer(0)));
 
-         ServerManagement.start("all", 1);
+         ServerManagement.start(1, "all");
 
          view = ServerManagement.getServer(0).getNodeIDView();
 
@@ -133,14 +133,14 @@
    {
       try
       {
-         ServerManagement.start("all", 0);
+         ServerManagement.start(0, "all");
 
          Set view = ServerManagement.getServer(0).getNodeIDView();
 
          assertEquals(1, view.size());
          assertTrue(view.contains(new Integer(0)));
 
-         ServerManagement.start("all", 1);
+         ServerManagement.start(1, "all");
 
          view = ServerManagement.getServer(0).getNodeIDView();
 
@@ -154,7 +154,7 @@
          assertTrue(view.contains(new Integer(0)));
          assertTrue(view.contains(new Integer(1)));
 
-         ServerManagement.start("all", 3);
+         ServerManagement.start(3, "all");
 
          view = ServerManagement.getServer(0).getNodeIDView();
 
@@ -194,9 +194,9 @@
       {
          // Start with a 3 node cluster
 
-         ServerManagement.start("all", 0);
-         ServerManagement.start("all", 1);
-         ServerManagement.start("all", 2);
+         ServerManagement.start(0, "all");
+         ServerManagement.start(1, "all");
+         ServerManagement.start(2, "all");
 
          Set view = ServerManagement.getServer(0).getNodeIDView();
 
@@ -226,7 +226,7 @@
 
          // Reuse the "hollow" RMI server 0 to start another cluster node
 
-         ServerManagement.start("all", 0);
+         ServerManagement.start(0, "all");
 
          view = ServerManagement.getServer(0).getNodeIDView();
 
@@ -237,7 +237,7 @@
 
          // Reuse the "hollow" RMI server 2 to start another cluster node
 
-         ServerManagement.start("all", 2);
+         ServerManagement.start(1, "all");
 
          view = ServerManagement.getServer(2).getNodeIDView();
 
@@ -264,8 +264,8 @@
       {
          // Start with a 2 node cluster
 
-         ServerManagement.start("all", 0);
-         ServerManagement.start("all", 1);
+         ServerManagement.start(0, "all");
+         ServerManagement.start(1, "all");
 
          Set view = ServerManagement.getServer(0).getNodeIDView();
 
@@ -313,9 +313,9 @@
       {
          // Start with a 3 node cluster
 
-         ServerManagement.start("all", 0);
-         ServerManagement.start("all", 1);
-         ServerManagement.start("all", 2);
+         ServerManagement.start(0, "all");
+         ServerManagement.start(1, "all");
+         ServerManagement.start(2, "all");
 
          Set view = ServerManagement.getServer(0).getNodeIDView();
 
@@ -392,7 +392,7 @@
       {
          // Start with a 1 node cluster
 
-         ServerManagement.start("all", 0);
+         ServerManagement.start(0, "all");
 
          Set view = ServerManagement.getServer(0).getNodeIDView();
 
@@ -401,8 +401,7 @@
 
          ServerManagement.addNotificationListener(0, postOfficeObjectName, clusterEvent);
 
-         ServerManagement.spawn(10);
-         ServerManagement.start("all", 10);
+         ServerManagement.start(10, "all");
 
          if (!clusterEvent.viewChanged(120000))
          {

Modified: trunk/tests/src/org/jboss/test/messaging/jms/clustering/HATest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/clustering/HATest.java	2006-12-14 21:28:22 UTC (rev 1797)
+++ trunk/tests/src/org/jboss/test/messaging/jms/clustering/HATest.java	2006-12-15 08:59:37 UTC (rev 1798)
@@ -26,11 +26,11 @@
 import java.util.Set;
 
 import javax.jms.Connection;
-import javax.jms.Message;
 import javax.jms.MessageConsumer;
 import javax.jms.MessageProducer;
 import javax.jms.Session;
 import javax.jms.TextMessage;
+import javax.jms.Message;
 
 import org.jboss.jms.client.JBossConnection;
 import org.jboss.jms.client.JBossConnectionFactory;
@@ -48,6 +48,7 @@
  *
  * @author <a href="mailto:clebert.suconic at jboss.org">Clebert Suconic</a>
  * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ * @author <a href="mailto:ovidiu at jboss.org">Ovidiu Feodorov</a>
  * @version <tt>$Revision: 1.1 $</tt>
  *
  * $Id$
@@ -78,89 +79,89 @@
    public void testRoundRobinConnectionCreation() throws Exception
    {
       JBossConnectionFactory factory =  (JBossConnectionFactory )ic[0].lookup("/ConnectionFactory");
-      
+
       ClusteredClientConnectionFactoryDelegate delegate =
          (ClusteredClientConnectionFactoryDelegate)factory.getDelegate();
-      
+
       log.info ("number of delegates = " + delegate.getDelegates().length);
       log.info ("number of servers = " + ServerManagement.getServer(0).getNodeIDView().size());
-      
+
       assertEquals(3, delegate.getDelegates().length);
-      
+
       ClientConnectionFactoryDelegate cf1 = delegate.getDelegates()[0];
-      
+
       ClientConnectionFactoryDelegate cf2 = delegate.getDelegates()[1];
-      
+
       ClientConnectionFactoryDelegate cf3 = delegate.getDelegates()[2];
-      
+
       assertEquals(0, cf1.getServerID());
-      
+
       assertEquals(1, cf2.getServerID());
-      
+
       assertEquals(2, cf3.getServerID());
-      
+
       assertEquals(3, ServerManagement.getServer(0).getNodeIDView().size());
-      
+
       Connection conn1 = null;
-      
+
       Connection conn2 = null;
-      
+
       Connection conn3 = null;
-      
+
       Connection conn4 = null;
-      
+
       Connection conn5 = null;
-      
+
       try
-      {         
+      {
          conn1 = factory.createConnection();  //server 0
-         
+
          conn2 = factory.createConnection();  //server 1
-         
+
          conn3 = factory.createConnection();  //server 2
-         
+
          conn4 = factory.createConnection();  //server 0
-         
+
          conn5 = factory.createConnection();  //server 1
-         
+
          ConnectionState state1 = (ConnectionState)(((DelegateSupport)((JBossConnection)conn1).getDelegate()).getState());
-         
+
          ConnectionState state2 = (ConnectionState)(((DelegateSupport)((JBossConnection)conn2).getDelegate()).getState());
-         
+
          ConnectionState state3 = (ConnectionState)(((DelegateSupport)((JBossConnection)conn3).getDelegate()).getState());
-         
+
          ConnectionState state4 = (ConnectionState)(((DelegateSupport)((JBossConnection)conn4).getDelegate()).getState());
-         
+
          ConnectionState state5 = (ConnectionState)(((DelegateSupport)((JBossConnection)conn5).getDelegate()).getState());
-         
+
          int serverID1 = state1.getServerID();
-         
+
          int serverID2 = state2.getServerID();
-         
+
          int serverID3 = state3.getServerID();
-         
+
          int serverID4 = state4.getServerID();
-         
+
          int serverID5 = state5.getServerID();
-         
+
          log.info("server id 1: " + serverID1);
-         
+
          log.info("server id 2: " + serverID2);
-         
+
          log.info("server id 3: " + serverID3);
-         
+
          log.info("server id 4: " + serverID4);
-         
+
          log.info("server id 5: " + serverID5);
-         
+
          assertEquals(0, serverID1);
-         
+
          assertEquals(1, serverID2);
-         
+
          assertEquals(2, serverID3);
-         
+
          assertEquals(0, serverID4);
-         
+
          assertEquals(1, serverID5);
       }
       finally
@@ -169,376 +170,374 @@
          {
             conn1.close();
          }
-         
+
          if (conn2 != null)
          {
             conn2.close();
          }
-         
+
          if (conn3 != null)
          {
             conn3.close();
          }
-         
+
          if (conn4 != null)
          {
             conn4.close();
          }
-         
+
          if (conn5 != null)
          {
             conn5.close();
          }
       }
-      
+
    }
- 
+
    /*
     * Test that the failover mapping is created correctly and updated properly when nodes leave
     * or join
     */
    public void testDefaultFailoverMap() throws Exception
-   {     
+   {
       {
          JBossConnectionFactory factory =  (JBossConnectionFactory )ic[0].lookup("/ConnectionFactory");
-         
+
          ClusteredClientConnectionFactoryDelegate delegate =
             (ClusteredClientConnectionFactoryDelegate)factory.getDelegate();
-         
+
          assertEquals(3, ServerManagement.getServer(0).getNodeIDView().size());
-         
+
          ClientConnectionFactoryDelegate[] delegates = delegate.getDelegates();
-         
+
          ClientConnectionFactoryDelegate cf1 = delegate.getDelegates()[0];
-         
+
          ClientConnectionFactoryDelegate cf2 = delegate.getDelegates()[1];
-         
+
          ClientConnectionFactoryDelegate cf3 = delegate.getDelegates()[2];
-         
+
          //The order here depends on the order the servers were started in
-         
+
          //If any servers get stopped and then started then the order will change
-    
+
          log.info("cf1 serverid=" + cf1.getServerID());
-         
+
          log.info("cf2 serverid=" + cf2.getServerID());
-         
+
          log.info("cf3 serverid=" + cf3.getServerID());
-         
-         
+
+
          assertEquals(0, cf1.getServerID());
-         
+
          assertEquals(1, cf2.getServerID());
-         
+
          assertEquals(2, cf3.getServerID());
-         
+
          Map failoverMap = delegate.getFailoverMap();
-         
+
          assertEquals(3, delegates.length);
-         
+
          assertEquals(3, failoverMap.size());
-         
+
          // Default failover policy just chooses the node to the right
-         
+
          assertEquals(cf2.getServerID(), ((Integer)failoverMap.get(new Integer(cf1.getServerID()))).intValue());
-         
+
          assertEquals(cf3.getServerID(), ((Integer)failoverMap.get(new Integer(cf2.getServerID()))).intValue());
-         
+
          assertEquals(cf1.getServerID(), ((Integer)failoverMap.get(new Integer(cf3.getServerID()))).intValue());
       }
-      
+
       //Now cleanly stop one of the servers
-            
+
       log.info("************** STOPPING SERVER 0");
       ServerManagement.stop(0);
-      
+
       log.info("server stopped");
-      
+
       assertEquals(2, ServerManagement.getServer(1).getNodeIDView().size());
-      
-      {         
+
+      {
          //Lookup another connection factory
-         
+
          JBossConnectionFactory factory =  (JBossConnectionFactory )ic[1].lookup("/ConnectionFactory");
-         
+
          log.info("Got connection factory");
-         
+
          ClusteredClientConnectionFactoryDelegate delegate =
             (ClusteredClientConnectionFactoryDelegate)factory.getDelegate();
-         
+
          ClientConnectionFactoryDelegate[] delegates = delegate.getDelegates();
-         
+
          Map failoverMap = delegate.getFailoverMap();
-         
+
          log.info("Got failover map");
-         
+
          assertEquals(2, delegates.length);
-         
+
          ClientConnectionFactoryDelegate cf1 = delegate.getDelegates()[0];
-         
+
          ClientConnectionFactoryDelegate cf2 = delegate.getDelegates()[1];
-         
+
          //Order here depends on order servers were started in
-         
+
          log.info("cf1 serverid=" + cf1.getServerID());
-         
+
          log.info("cf2 serverid=" + cf2.getServerID());
-         
+
          assertEquals(1, cf1.getServerID());
-         
+
          assertEquals(2, cf2.getServerID());
-         
-         
+
+
          assertEquals(2, failoverMap.size());
-         
+
          assertEquals(cf2.getServerID(), ((Integer)failoverMap.get(new Integer(cf1.getServerID()))).intValue());
-         
+
          assertEquals(cf1.getServerID(), ((Integer)failoverMap.get(new Integer(cf2.getServerID()))).intValue());
       }
-      
+
       //Cleanly stop another server
-      
+
       log.info("Server 1 is started: " + ServerManagement.getServer(1).isServerPeerStarted());
-      
+
       ServerManagement.stop(1);
-      
+
       assertEquals(1, ServerManagement.getServer(2).getNodeIDView().size());
-      
-      {         
+
+      {
          //Lookup another connection factory
-         
+
          JBossConnectionFactory factory =  (JBossConnectionFactory )ic[2].lookup("/ConnectionFactory");
-         
+
          ClusteredClientConnectionFactoryDelegate delegate =
             (ClusteredClientConnectionFactoryDelegate)factory.getDelegate();
-         
+
          ClientConnectionFactoryDelegate[] delegates = delegate.getDelegates();
-         
+
          Map failoverMap = delegate.getFailoverMap();
-         
+
          assertEquals(1, delegates.length);
-         
+
          ClientConnectionFactoryDelegate cf1 = delegate.getDelegates()[0];
-         
+
          assertEquals(2, cf1.getServerID());
-         
-         
+
+
          assertEquals(1, failoverMap.size());
-         
+
          assertEquals(cf1.getServerID(), ((Integer)failoverMap.get(new Integer(cf1.getServerID()))).intValue());
       }
-            
+
       //Restart server 0
-      
-      ServerManagement.start("all", 0);
-      
+
+      ServerManagement.start(0, "all");
+
       {
          JBossConnectionFactory factory =  (JBossConnectionFactory )ic[0].lookup("/ConnectionFactory");
-         
+
          log.info("Got connection factory");
-         
+
          ClusteredClientConnectionFactoryDelegate delegate =
             (ClusteredClientConnectionFactoryDelegate)factory.getDelegate();
-         
+
          ClientConnectionFactoryDelegate[] delegates = delegate.getDelegates();
-         
+
          Map failoverMap = delegate.getFailoverMap();
-         
+
          log.info("Got failover map");
-         
+
          assertEquals(2, delegates.length);
-         
+
          ClientConnectionFactoryDelegate cf1 = delegate.getDelegates()[0];
-         
+
          ClientConnectionFactoryDelegate cf2 = delegate.getDelegates()[1];
-         
+
          log.info("cf1 serverid=" + cf1.getServerID());
-         
+
          log.info("cf2 serverid=" + cf2.getServerID());
-         
+
          assertEquals(0, cf1.getServerID());
-         
+
          assertEquals(2, cf2.getServerID());
-         
-         
+
+
          assertEquals(2, failoverMap.size());
-         
+
          assertEquals(cf2.getServerID(), ((Integer)failoverMap.get(new Integer(cf1.getServerID()))).intValue());
-         
+
          assertEquals(cf1.getServerID(), ((Integer)failoverMap.get(new Integer(cf2.getServerID()))).intValue());
       }
-      
-      
+
+
       //Restart server 1
-      
-      ServerManagement.start("all", 1);
-      
+
+      ServerManagement.start(1, "all");
+
       {
          JBossConnectionFactory factory =  (JBossConnectionFactory )ic[1].lookup("/ConnectionFactory");
-         
+
          log.info("Got connection factory");
-         
+
          ClusteredClientConnectionFactoryDelegate delegate =
             (ClusteredClientConnectionFactoryDelegate)factory.getDelegate();
-         
+
          ClientConnectionFactoryDelegate[] delegates = delegate.getDelegates();
-         
+
          Map failoverMap = delegate.getFailoverMap();
-         
+
          log.info("Got failover map");
-         
+
          assertEquals(3, delegates.length);
-         
+
          ClientConnectionFactoryDelegate cf1 = delegate.getDelegates()[0];
-         
+
          ClientConnectionFactoryDelegate cf2 = delegate.getDelegates()[1];
-         
+
          ClientConnectionFactoryDelegate cf3 = delegate.getDelegates()[2];
-         
+
          log.info("cf1 serverid=" + cf1.getServerID());
-         
+
          log.info("cf2 serverid=" + cf2.getServerID());
-         
+
          log.info("cf3 serverid=" + cf3.getServerID());
-         
+
          assertEquals(0, cf1.getServerID());
-         
+
          assertEquals(1, cf2.getServerID());
-         
+
          assertEquals(2, cf3.getServerID());
-         
-         
+
+
          assertEquals(3, failoverMap.size());
-         
+
          assertEquals(cf2.getServerID(), ((Integer)failoverMap.get(new Integer(cf1.getServerID()))).intValue());
-         
+
          assertEquals(cf3.getServerID(), ((Integer)failoverMap.get(new Integer(cf2.getServerID()))).intValue());
-         
+
          assertEquals(cf1.getServerID(), ((Integer)failoverMap.get(new Integer(cf3.getServerID()))).intValue());
-      }            
+      }
    }
-   
+
    public void testSimpleFailover() throws Exception
    {
       JBossConnectionFactory factory =  (JBossConnectionFactory )ic[0].lookup("/ConnectionFactory");
-      
+
       ClusteredClientConnectionFactoryDelegate delegate =
          (ClusteredClientConnectionFactoryDelegate)factory.getDelegate();
 
       Set nodeIDView = ServerManagement.getServer(0).getNodeIDView();
       assertEquals(3, nodeIDView.size());
-      
+
       ClientConnectionFactoryDelegate[] delegates = delegate.getDelegates();
-      
+
       ClientConnectionFactoryDelegate cf1 = delegates[0];
-      
+
       ClientConnectionFactoryDelegate cf2 = delegates[1];
-      
+
       ClientConnectionFactoryDelegate cf3 = delegates[2];
-      
+
       int server0Id = cf1.getServerID();
-      
+
       int server1Id = cf2.getServerID();
-      
+
       int server2Id = cf3.getServerID();
 
       log.info("server 0 id: " + server0Id);
-      
+
       log.info("server 1 id: " + server1Id);
-      
+
       log.info("server 2 id: " + server2Id);
-                  
+
       Map failoverMap = delegate.getFailoverMap();
-      
+
       log.info(failoverMap.get(new Integer(server0Id)));
       log.info(failoverMap.get(new Integer(server1Id)));
       log.info(failoverMap.get(new Integer(server2Id)));
-      
+
       int server1FailoverId = ((Integer)failoverMap.get(new Integer(server1Id))).intValue();
-      
+
       // server 1 should failover onto server 2
-      
+
       assertEquals(server2Id, server1FailoverId);
-      
+
       Connection conn = null;
-      
-      boolean killed =  false;
-            
+
       try
-      {      
+      {
          conn = factory.createConnection(); //connection on server 0
-         
+
          conn.close();
-         
+
          conn = factory.createConnection(); //connection on server 1
-                          
+
          JBossConnection jbc = (JBossConnection)conn;
-         
+
          ClientConnectionDelegate del = (ClientConnectionDelegate)jbc.getDelegate();
-         
+
          ConnectionState state = (ConnectionState)del.getState();
-         
+
          int initialServerID = state.getServerID();
-         
+
          assertEquals(1, initialServerID);
-                           
+
          Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
-         
+
          MessageProducer prod = sess.createProducer(queue[1]);
-         
+
          MessageConsumer cons = sess.createConsumer(queue[1]);
-         
+
          final int NUM_MESSAGES = 100;
-         
+
          for (int i = 0; i < NUM_MESSAGES; i++)
          {
             TextMessage tm = sess.createTextMessage("message:" + i);
-            
+
             prod.send(tm);
          }
-         
+
          //So now, messages should be in queue[1] on server 1
          //So we now kill server 1
          //Which should cause transparent failover of connection conn onto server 1
-         
-         log.info("************ KILLING (CRASHING) SERVER 1");
-         
+
+         log.info("######");
+         log.info("###### KILLING (CRASHING) SERVER 1");
+         log.info("######");
+
          ServerManagement.kill(1);
-         
-         killed = true;
-         
+
          log.info("killed server, now waiting");
-         
+
          Thread.sleep(5000);
-         
+
          log.info("done wait");
-         
+
          state = (ConnectionState)del.getState();
-         
+
          int finalServerID = state.getServerID();
-         
+
          log.info("final server id= " + finalServerID);
-         
+
          //server id should now be 2
-         
+
          assertEquals(2, finalServerID);
-         
+
          conn.start();
-         
+
          for (int i = 0; i < NUM_MESSAGES; i++)
          {
             TextMessage tm = (TextMessage)cons.receive(1000);
-            
-            log.info("message is " + tm);
-            
+
+            log.debug("message is " + tm);
+
             assertNotNull(tm);
-            
+
             assertEquals("message:" + i, tm.getText());
          }
          log.info("done");
       }
       finally
-      {         
+      {
          if (conn != null)
          {
             try
@@ -548,178 +547,174 @@
             catch (Exception e)
             {
                e.printStackTrace();
-            }         
+            }
          }
-         
-         //Resurrect dead server
-         if (killed)
-         {
-            ServerManagement.spawn(1);
-         }
+
+         ServerManagement.start(1, "all");
       }
-      
    }
-   
-   
+
    public void testFailoverWithUnackedMessagesClientAcknowledge() throws Exception
    {
       JBossConnectionFactory factory =  (JBossConnectionFactory )ic[0].lookup("/ConnectionFactory");
-      
+
       ClusteredClientConnectionFactoryDelegate delegate =
          (ClusteredClientConnectionFactoryDelegate)factory.getDelegate();
 
       Set nodeIDView = ServerManagement.getServer(0).getNodeIDView();
       assertEquals(3, nodeIDView.size());
-      
+
       ClientConnectionFactoryDelegate[] delegates = delegate.getDelegates();
-      
+
       ClientConnectionFactoryDelegate cf1 = delegates[0];
-      
+
       ClientConnectionFactoryDelegate cf2 = delegates[1];
-      
+
       ClientConnectionFactoryDelegate cf3 = delegates[2];
-      
+
       int server0Id = cf1.getServerID();
-      
+
       int server1Id = cf2.getServerID();
-      
+
       int server2Id = cf3.getServerID();
-      
+
       log.info("server 0 id: " + server0Id);
-      
+
       log.info("server 1 id: " + server1Id);
-      
+
       log.info("server 2 id: " + server2Id);
-                  
+
       Map failoverMap = delegate.getFailoverMap();
-      
+
       log.info(failoverMap.get(new Integer(server0Id)));
       log.info(failoverMap.get(new Integer(server1Id)));
       log.info(failoverMap.get(new Integer(server2Id)));
-      
+
       int server1FailoverId = ((Integer)failoverMap.get(new Integer(server1Id))).intValue();
-      
+
       // server 1 should failover onto server 2
-      
+
       assertEquals(server2Id, server1FailoverId);
-      
+
       Connection conn = null;
-      
+
       boolean killed = false;
-      
+
       try
-      {      
+      {
          conn = factory.createConnection(); //connection on server 0
-         
+
          conn.close();
-         
+
          conn = factory.createConnection(); //connection on server 1
-         
+
          JBossConnection jbc = (JBossConnection)conn;
-         
+
          ClientConnectionDelegate del = (ClientConnectionDelegate)jbc.getDelegate();
-         
+
          ConnectionState state = (ConnectionState)del.getState();
-         
+
          int initialServerID = state.getServerID();
-         
+
          assertEquals(1, initialServerID);
-                           
+
          Session sess = conn.createSession(false, Session.CLIENT_ACKNOWLEDGE);
-         
+
          MessageProducer prod = sess.createProducer(queue[1]);
-         
+
          MessageConsumer cons = sess.createConsumer(queue[1]);
-         
+
          final int NUM_MESSAGES = 100;
-         
+
          for (int i = 0; i < NUM_MESSAGES; i++)
          {
             TextMessage tm = sess.createTextMessage("message:" + i);
-            
+
             prod.send(tm);
          }
-         
+
          conn.start();
-         
-         //Now consume half of the messages but don't ack them these will end up in 
+
+         //Now consume half of the messages but don't ack them these will end up in
          //client side toAck list
-         
+
          for (int i = 0; i < NUM_MESSAGES / 2; i++)
          {
             TextMessage tm = (TextMessage)cons.receive(500);
-            
+
             assertNotNull(tm);
-            
+
             assertEquals("message:" + i, tm.getText());
          }
-         
+
          //So now, messages should be in queue[1] on server 1
          //So we now kill server 1
          //Which should cause transparent failover of connection conn onto server 1
-         
-         log.info("************ KILLING (CRASHING) SERVER 1");
-         
+
+         log.info("######");
+         log.info("###### KILLING (CRASHING) SERVER 1");
+         log.info("######");
+
          ServerManagement.kill(1);
-         
+
          killed = true;
-         
+
          log.info("killed server, now waiting");
-         
+
          Thread.sleep(10000);
-         
+
          log.info("done wait");
-         
+
          state = (ConnectionState)del.getState();
-         
+
          int finalServerID = state.getServerID();
-         
+
          log.info("final server id= " + finalServerID);
-         
+
          //server id should now be 2
-         
+
          assertEquals(2, finalServerID);
-         
+
          conn.start();
-         
+
          //Now should be able to consume the rest of the messages
-         
+
          log.info("here1");
-         
+
          TextMessage tm = null;
-         
+
          for (int i = NUM_MESSAGES / 2; i < NUM_MESSAGES; i++)
          {
             tm = (TextMessage)cons.receive(500);
-                                    
+
             log.info("message is " + tm.getText());
-            
+
             assertNotNull(tm);
-            
+
             assertEquals("message:" + i, tm.getText());
          }
-         
+
          log.info("here2");
-         
+
          //Now should be able to acknowledge them
-         
+
          tm.acknowledge();
-         
+
          //Now check there are no more messages there
          sess.close();
-         
+
          sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
-         
+
          cons = sess.createConsumer(queue[1]);
-         
+
          Message m = cons.receive(500);
-         
+
          assertNull(m);
-         
+
          log.info("got to end of test");
       }
       finally
-      {         
+      {
          if (conn != null)
          {
             try
@@ -731,199 +726,202 @@
                e.printStackTrace();
             }
          }
-         
+
          // Resurrect dead server
          if (killed)
          {
-            ServerManagement.spawn(1);
+            ServerManagement.start(1, "all");
          }
       }
-      
-   }
-   
-   public void testFailoverWithUnackedMessagesTransactional() throws Exception
-   {
-      JBossConnectionFactory factory =  (JBossConnectionFactory )ic[0].lookup("/ConnectionFactory");
-      
-      ClusteredClientConnectionFactoryDelegate delegate =
-         (ClusteredClientConnectionFactoryDelegate)factory.getDelegate();
 
-      Set nodeIDView = ServerManagement.getServer(0).getNodeIDView();
-      assertEquals(3, nodeIDView.size());
-      
-      ClientConnectionFactoryDelegate[] delegates = delegate.getDelegates();
-      
-      ClientConnectionFactoryDelegate cf1 = delegates[0];
-      
-      ClientConnectionFactoryDelegate cf2 = delegates[1];
-      
-      ClientConnectionFactoryDelegate cf3 = delegates[2];
-      
-      int server0Id = cf1.getServerID();
-      
-      int server1Id = cf2.getServerID();
-      
-      int server2Id = cf3.getServerID();
-      
-      log.info("server 0 id: " + server0Id);
-      
-      log.info("server 1 id: " + server1Id);
-      
-      log.info("server 2 id: " + server2Id);
-                  
-      Map failoverMap = delegate.getFailoverMap();
-      
-      log.info(failoverMap.get(new Integer(server0Id)));
-      log.info(failoverMap.get(new Integer(server1Id)));
-      log.info(failoverMap.get(new Integer(server2Id)));
-      
-      int server1FailoverId = ((Integer)failoverMap.get(new Integer(server1Id))).intValue();
-      
-      // server 1 should failover onto server 2
-      
-      assertEquals(server2Id, server1FailoverId);
-      
-      Connection conn = null;
-      
-      boolean killed = false;
-      
-      try
-      {      
-         //Get a connection on server 1
-         conn = factory.createConnection(); //connection on server 0
-         
-         conn.close();
-         
-         conn = factory.createConnection(); //connection on server 1
-         
-         JBossConnection jbc = (JBossConnection)conn;
-         
-         ClientConnectionDelegate del = (ClientConnectionDelegate)jbc.getDelegate();
-         
-         ConnectionState state = (ConnectionState)del.getState();
-         
-         int initialServerID = state.getServerID();
-         
-         assertEquals(1, initialServerID);
-                           
-         Session sess = conn.createSession(true, Session.SESSION_TRANSACTED);
-         
-         MessageProducer prod = sess.createProducer(queue[1]);
-         
-         MessageConsumer cons = sess.createConsumer(queue[1]);
-         
-         final int NUM_MESSAGES = 100;
-         
-         for (int i = 0; i < NUM_MESSAGES; i++)
-         {
-            TextMessage tm = sess.createTextMessage("message:" + i);
-            
-            prod.send(tm);
-         }
-         
-         sess.commit();
-         
-         conn.start();
-         
-         //Now consume half of the messages but don't commit them these will end up in 
-         //client side resource manager
-         
-         for (int i = 0; i < NUM_MESSAGES / 2; i++)
-         {
-            TextMessage tm = (TextMessage)cons.receive(500);
-            
-            assertNotNull(tm);
-            
-            assertEquals("message:" + i, tm.getText());
-         }
-         
-         //So now, messages should be in queue[1] on server 1
-         //So we now kill server 1
-         //Which should cause transparent failover of connection conn onto server 1
-         
-         log.info("************ KILLING (CRASHING) SERVER 1");
-         
-         ServerManagement.kill(1);
-         
-         killed = true;
-
-         log.info("killed server, now waiting");
-         
-         Thread.sleep(5000);
-         
-         log.info("done wait");
-         
-         state = (ConnectionState)del.getState();
-         
-         int finalServerID = state.getServerID();
-         
-         log.info("final server id= " + finalServerID);
-         
-         //server id should now be 2
-         
-         assertEquals(2, finalServerID);
-         
-         conn.start();
-         
-         //Now should be able to consume the rest of the messages
-         
-         log.info("here1");
-         
-         TextMessage tm = null;
-         
-         for (int i = NUM_MESSAGES / 2; i < NUM_MESSAGES; i++)
-         {
-            tm = (TextMessage)cons.receive(500);
-                                    
-            log.info("message is " + tm.getText());
-            
-            assertNotNull(tm);
-            
-            assertEquals("message:" + i, tm.getText());
-         }
-         
-         log.info("here2");
-         
-         //Now should be able to commit them
-         
-         sess.commit();
-         
-         //Now check there are no more messages there
-         sess.close();
-         
-         sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
-         
-         cons = sess.createConsumer(queue[1]);
-         
-         Message m = cons.receive(500);
-         
-         assertNull(m);
-         
-         log.info("got to end of test");
-      }
-      finally
-      {         
-         if (conn != null)
-         {
-            try
-            {
-               conn.close();
-            }
-            catch (Exception e)
-            {
-               e.printStackTrace();
-            }
-         }
-         
-         if (killed)
-         {
-            ServerManagement.spawn(1);
-         }
-      }
-      
    }
+
    
+//   public void testFailoverWithUnackedMessagesTransactional() throws Exception
+//   {
+//      JBossConnectionFactory factory =  (JBossConnectionFactory )ic[0].lookup("/ConnectionFactory");
+//
+//      ClusteredClientConnectionFactoryDelegate delegate =
+//         (ClusteredClientConnectionFactoryDelegate)factory.getDelegate();
+//
+//      Set nodeIDView = ServerManagement.getServer(0).getNodeIDView();
+//      assertEquals(3, nodeIDView.size());
+//
+//      ClientConnectionFactoryDelegate[] delegates = delegate.getDelegates();
+//
+//      ClientConnectionFactoryDelegate cf1 = delegates[0];
+//
+//      ClientConnectionFactoryDelegate cf2 = delegates[1];
+//
+//      ClientConnectionFactoryDelegate cf3 = delegates[2];
+//
+//      int server0Id = cf1.getServerID();
+//
+//      int server1Id = cf2.getServerID();
+//
+//      int server2Id = cf3.getServerID();
+//
+//      log.info("server 0 id: " + server0Id);
+//
+//      log.info("server 1 id: " + server1Id);
+//
+//      log.info("server 2 id: " + server2Id);
+//
+//      Map failoverMap = delegate.getFailoverMap();
+//
+//      log.info(failoverMap.get(new Integer(server0Id)));
+//      log.info(failoverMap.get(new Integer(server1Id)));
+//      log.info(failoverMap.get(new Integer(server2Id)));
+//
+//      int server1FailoverId = ((Integer)failoverMap.get(new Integer(server1Id))).intValue();
+//
+//      // server 1 should failover onto server 2
+//
+//      assertEquals(server2Id, server1FailoverId);
+//
+//      Connection conn = null;
+//
+//      boolean killed = false;
+//
+//      try
+//      {
+//         //Get a connection on server 1
+//         conn = factory.createConnection(); //connection on server 0
+//
+//         conn.close();
+//
+//         conn = factory.createConnection(); //connection on server 1
+//
+//         JBossConnection jbc = (JBossConnection)conn;
+//
+//         ClientConnectionDelegate del = (ClientConnectionDelegate)jbc.getDelegate();
+//
+//         ConnectionState state = (ConnectionState)del.getState();
+//
+//         int initialServerID = state.getServerID();
+//
+//         assertEquals(1, initialServerID);
+//
+//         Session sess = conn.createSession(true, Session.SESSION_TRANSACTED);
+//
+//         MessageProducer prod = sess.createProducer(queue[1]);
+//
+//         MessageConsumer cons = sess.createConsumer(queue[1]);
+//
+//         final int NUM_MESSAGES = 100;
+//
+//         for (int i = 0; i < NUM_MESSAGES; i++)
+//         {
+//            TextMessage tm = sess.createTextMessage("message:" + i);
+//
+//            prod.send(tm);
+//         }
+//
+//         sess.commit();
+//
+//         conn.start();
+//
+//         //Now consume half of the messages but don't commit them these will end up in
+//         //client side resource manager
+//
+//         for (int i = 0; i < NUM_MESSAGES / 2; i++)
+//         {
+//            TextMessage tm = (TextMessage)cons.receive(500);
+//
+//            assertNotNull(tm);
+//
+//            assertEquals("message:" + i, tm.getText());
+//         }
+//
+//         //So now, messages should be in queue[1] on server 1
+//         //So we now kill server 1
+//         //Which should cause transparent failover of connection conn onto server 1
+//
+//         log.info("######");
+//         log.info("###### KILLING (CRASHING) SERVER 1");
+//         log.info("######");
+//
+//         ServerManagement.kill(1);
+//
+//         killed = true;
+//
+//         log.info("killed server, now waiting");
+//
+//         Thread.sleep(5000);
+//
+//         log.info("done wait");
+//
+//         state = (ConnectionState)del.getState();
+//
+//         int finalServerID = state.getServerID();
+//
+//         log.info("final server id= " + finalServerID);
+//
+//         //server id should now be 2
+//
+//         assertEquals(2, finalServerID);
+//
+//         conn.start();
+//
+//         //Now should be able to consume the rest of the messages
+//
+//         log.info("here1");
+//
+//         TextMessage tm = null;
+//
+//         for (int i = NUM_MESSAGES / 2; i < NUM_MESSAGES; i++)
+//         {
+//            tm = (TextMessage)cons.receive(500);
+//
+//            log.info("message is " + tm.getText());
+//
+//            assertNotNull(tm);
+//
+//            assertEquals("message:" + i, tm.getText());
+//         }
+//
+//         log.info("here2");
+//
+//         //Now should be able to commit them
+//
+//         sess.commit();
+//
+//         //Now check there are no more messages there
+//         sess.close();
+//
+//         sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+//
+//         cons = sess.createConsumer(queue[1]);
+//
+//         Message m = cons.receive(500);
+//
+//         assertNull(m);
+//
+//         log.info("got to end of test");
+//      }
+//      finally
+//      {
+//         if (conn != null)
+//         {
+//            try
+//            {
+//               conn.close();
+//            }
+//            catch (Exception e)
+//            {
+//               e.printStackTrace();
+//            }
+//         }
+//
+//         if (killed)
+//         {
+//            ServerManagement.spawn(1);
+//         }
+//      }
+//
+//   }
    
+   
 // public void testConnectionFactoryConnect() throws Exception
 // {
 // try

Modified: trunk/tests/src/org/jboss/test/messaging/jms/clustering/SimpleClusteringTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/clustering/SimpleClusteringTest.java	2006-12-14 21:28:22 UTC (rev 1797)
+++ trunk/tests/src/org/jboss/test/messaging/jms/clustering/SimpleClusteringTest.java	2006-12-15 08:59:37 UTC (rev 1798)
@@ -52,7 +52,7 @@
 
       // We start programatically the fourth node.
 
-      ServerManagement.start("all", 3);
+      ServerManagement.start(4, "all");
 
       // TODO - verify that the cluster formed correctly assertion
 
@@ -97,7 +97,7 @@
 
       // We get the first node to re-join
 
-      ServerManagement.start("all", 0);
+      ServerManagement.start(0, "all");
 
    }
    

Modified: trunk/tests/src/org/jboss/test/messaging/jms/clustering/base/ClusteringTestBase.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/clustering/base/ClusteringTestBase.java	2006-12-14 21:28:22 UTC (rev 1797)
+++ trunk/tests/src/org/jboss/test/messaging/jms/clustering/base/ClusteringTestBase.java	2006-12-15 08:59:37 UTC (rev 1798)
@@ -91,7 +91,9 @@
 
       for(int i = 0; i < nodeCount; i++)
       {
-         ServerManagement.start("all", i);
+         // make sure all servers are created and started
+         ServerManagement.start(i, "all");
+
          ServerManagement.deployClusteredQueue("testDistributedQueue", i);
          ServerManagement.deployClusteredTopic("testDistributedTopic", i);
 
@@ -122,6 +124,8 @@
          ic[i].close();
       }
 
+      //ServerManagement.destroySpawnedServers();
+
       super.tearDown();
    }
 

Modified: trunk/tests/src/org/jboss/test/messaging/tools/ServerManagement.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/tools/ServerManagement.java	2006-12-14 21:28:22 UTC (rev 1797)
+++ trunk/tests/src/org/jboss/test/messaging/tools/ServerManagement.java	2006-12-15 08:59:37 UTC (rev 1798)
@@ -28,6 +28,9 @@
 import java.util.Map;
 import java.util.List;
 import java.util.Iterator;
+import java.util.ArrayList;
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
 import javax.management.ObjectName;
 import javax.management.NotificationListener;
 import javax.management.Notification;
@@ -76,12 +79,8 @@
 
    private static Logger log = Logger.getLogger(ServerManagement.class);
 
-   private static final int RMI_SERVER_LOOKUP_RETRIES = 10;
+   private static ServerHolder[] servers = new ServerHolder[MAX_SERVER_COUNT];
 
-   private static Server[] servers = new Server[MAX_SERVER_COUNT];
-   
-   private static boolean[] killed = new boolean[MAX_SERVER_COUNT];
-   
    // Map<NotificationListener - NotificationListenerPoller>
    private static Map notificationListenerPollers = new HashMap();
 
@@ -100,128 +99,104 @@
       return "true".equals(System.getProperty("test.clustered"));
    }
 
-   public static synchronized boolean isKilled(int index)
+   /**
+    * May return null if the server is not initialized.
+    */
+   public synchronized static Server getServer()
    {
-      return killed[index];
+      return getServer(0);
    }
 
-   public static synchronized boolean isStarted(int index)
+   /**
+    * May return null if the corresponding server is not initialized.
+    */
+   public synchronized static Server getServer(int i)
    {
-      Server s = servers[index];
-
-      if (s == null)
+      if (servers[i] == null)
       {
-         return false;
+         return null;
       }
-
-      try
+      else
       {
-         return s.isStarted();
+         return ((ServerHolder)servers[i]).getServer();
       }
-      catch(Exception e)
-      {
-         return false;
-      }
    }
 
-   public static Server getServer()
+   public static synchronized Server create() throws Exception
    {
-      return getServer(0);
+      return create(0);
    }
-   
-   public static Server getServer(int i)
-   {
-      if (killed[i])
-      {
-         log.warn("Server " + i + " cannot be got since it has been killed");
-      }
-      
-      Server s = servers[i];
-      
-      if (s == null)
-      {
-         throw new IllegalStateException("Server " + i + " is not started!");
-      }
-      
-      return s;
-   }
-   
-   public static synchronized void create() throws Exception
-   {
-      create(0);
-   }
 
-   public static synchronized void create(int index) throws Exception
+   /**
+    * Makes sure that a "hollow" TestServer (either local or remote, depending on the nature of the
+    * test), exists and it's ready to be started.
+    */
+   public static synchronized Server create(int i) throws Exception
    {
-      if (killed[index])
+      if (servers[i] == null)
       {
-         log.warn("Server " + index + " cannot created since it has been killed");
-         
-         return;
-      }
-      
-      if (servers[index] != null)
-      {
-         return;
-      }
+         if (isLocal())
+         {
+            servers[i] = new ServerHolder(new LocalTestServer(i), false);
+         }
+         else
+         {
+            Server s = acquireRemote(1, i, true);
 
-      if (isLocal())
-      {
-         servers[index] = new LocalTestServer(index);
-         return;
+            if (s != null)
+            {
+               servers[i] = new ServerHolder(s, false);
+            }
+            else
+            {
+               // most likely the remote server is not started, so spawn it
+               servers[i] = new ServerHolder(ServerManagement.spawn(i), true);
+               log.info("server " + i + " online");
+            }
+         }
       }
 
-      servers[index] = acquireRemote(RMI_SERVER_LOOKUP_RETRIES, index);
+      return servers[i].getServer();
+   }
 
-      if (servers[index] != null)
-      {
-         // RMI server started
-         return;
 
-      }
+   public static synchronized void start(String config) throws Exception
+   {
+      start(0, config);
+   }
 
-      // the remote RMI server is not started
+   /**
+    * When this method correctly completes, the server (local or remote) is started and fully
+    * operational (the service container and the server peer are created and started)
+    */
+   public static synchronized void start(int i, String config) throws Exception
+   {
+      Server s = create(i);
 
-      // I could attempt to start the remote server VM from the test itself (see commented out code)
-      // but when running such a test from a forking ant, ant blocks forever waiting for *this* VM
-      // to exit. That's why I require the remote server to be started in advance.
+      MessageIdGeneratorFactory.instance.clear();
 
-      throw new IllegalStateException("The RMI server " + index + " doesn't seem to be started. " +
-                                      "Start it and re-run the test.");
+      log.info("starting server " + i);
 
+      s.start(config);
+
+      log.info("server " + i + " started");
    }
-   
-   public static synchronized void start(String config) throws Exception
-   {
-      start(config, 0);
-   }
 
-   public static synchronized void start(String config, int index) throws Exception
+   public static synchronized boolean isStarted(int i)
    {
-      if (killed[index])
+      if (servers[i] == null)
       {
-         log.warn("Server " + index + " cannot been started since it has been killed");
-         
-         return;
+         return false;
       }
-      
-      create(index);
 
-      if (isLocal())
+      try
       {
-         log.info("IN-VM TEST");
+         return servers[i].getServer().isStarted();
       }
-      else
+      catch(Exception e)
       {
-         log.info("REMOTE TEST");
+         return false;
       }
-      
-      MessageIdGeneratorFactory.instance.clear();      
-
-      // Now start the server
-      servers[index].start(config);
-
-      log.debug("server started");
    }
 
    public static synchronized void stop() throws Exception
@@ -229,124 +204,240 @@
       stop(0);
    }
 
-   public static synchronized void stop(int index) throws Exception
+   /**
+    * The method stops the local or remote server, bringing it to a "hollow" state. A stopped
+    * server is identical with a server that has just been created, but not started.
+    */
+   public static synchronized void stop(int i) throws Exception
    {
-      if (killed[index])
+      if (servers[i] == null)
       {
-         log.warn("Server " + index + " cannot been stopped since it has been killed");
-         
-         return;
+         log.warn("Server " + i + " has not been created, so it cannot be stopped");
       }
-      
-      if (servers[index] == null)
+      else
       {
-         log.warn("Server " + index + " has not been created, so it cannot be stopped");
-         return;
+         servers[i].getServer().stop();
       }
+   }
 
-      if (!servers[index].isStarted())
+   /**
+    * Abruptly kills the VM running the specified server, simulating a crash. A local server
+    * cannot be killed, the method is a noop if this is the case.
+    */
+   public static synchronized void kill(int i) throws Exception
+   {
+      if (servers[i] == null)
       {
-         log.warn("Server " + index + " either has not been started, or it is stopped already");
-         return;
+         log.warn("Server " + i + " has not been created, so it cannot be killed");
       }
-
-      servers[index].stop();
+      else
+      {
+         servers[i].getServer().kill();
+         log.info("Server " + i + " killed");
+         servers[i] = null;
+      }
    }
 
    /**
-    * TODO - this methods should be removed, to not be confused with kill(index)
-    * @deprecated
+    * This method make sure that all servers that have been implicitely spawned when as a side
+    * effect of create() and/or start() are killed. The method is important because a forked
+    * ant junit task won't exit if processes created by it are still active. If you run tests
+    * from ant, always call killSpawnedServers() in tearDown().
+    *
+    * The servers created directed invoking spawn() are not subject to destroySpawnedServers(); they
+    * need to be explicitely killed.
+    *
+    * @return a List<Integer> containing the indexes of the destroyed servers.
+    *
     */
-   public static synchronized void destroy() throws Exception
+   public static synchronized List destroySpawnedServers() throws Exception
    {
-      stop();
-      servers[0].kill();
-      servers[0] = null;
+      List destroyed = new ArrayList();
+
+      for(int i = 0; i < servers.length; i++)
+      {
+         if (servers[i] != null && servers[i].isSpawned())
+         {
+            Server s = servers[i].getServer();
+            destroyed.add(new Integer(s.getServerID()));
+            s.stop();
+            s.kill();
+            servers[i] = null;
+         }
+      }
+
+      return destroyed;
    }
 
    /**
-    * For a local test, is a noop, but for a remote test, the method call spawns a new VM.
+    * For a local test, is a noop, but for a remote test, the method call spawns a new VM,
+    * irrespective of the fact that a server with same index may already exist (if you want to
+    * avoid conflicts, you need to check this externally).
+    *
     * The remote server so created is no different from a server started using start-rmi-server
     * script.
     */
-   public static synchronized void spawn(int index) throws Exception
+   private static synchronized Server spawn(final int i) throws Exception
    {
-      if (servers[index] != null)
+      if(isLocal())
       {
-         throw new Exception("The server " + index + " has been created already!");
+         return null;
       }
 
-      // in the remote case, make sure the VM with the given index isn't already up
-      if (isRemote() && acquireRemote(3, index) != null)
-      {
-         throw new Exception("The remote server " + index + " seems to be already up!");
-      }
-
-
       StringBuffer sb = new StringBuffer();
 
       sb.append("java").append(' ');
 
       sb.append("-Xmx512M").append(' ');
 
-      sb.append("-Dmodule.output=./../output").append(' ');
+      String moduleOutput = System.getProperty("module.output");
+      if (moduleOutput == null)
+      {
+         moduleOutput = "./output";
+      }
+      
+      sb.append("-Dmodule.output=").append(moduleOutput).append(' ');
 
-      sb.append("-Dremote.test.suffix=-remote-").append(index).append(' ');
+      sb.append("-Dremote.test.suffix=-remote-").append(i).append(' ');
 
-      sb.append("-Dtest.server.index=").append(index).append(' ');
+      sb.append("-Dtest.server.index=").append(i).append(' ');
 
       sb.append("-Dtest.bind.address=localhost").append(' ');
 
-      sb.append("-cp").append(' ').append(System.getProperty("java.class.path")).append(' ');
+      String database = System.getProperty("test.database");
+      if (database != null)
+      {
+         sb.append("-Dtest.database=").append(database).append(' ');
+      }
 
+      String serialization = System.getProperty("test.serialization");
+      if (serialization != null)
+      {
+         sb.append("-Dtest.serialization=").append(serialization).append(' ');
+      }
+
+      String clustered = System.getProperty("test.clustered");
+      if (clustered != null)
+      {
+         sb.append("-Dtest.clustered=").append(clustered).append(' ');
+      }
+
+      String remoting = System.getProperty("test.remoting");
+      if (remoting != null)
+      {
+         sb.append("-Dtest.remoting=").append(remoting).append(' ');
+      }
+
+      String classPath = System.getProperty("java.class.path");
+
+      //System.out.println("CLASSPATH: " + classPath);
+
+      sb.append("-cp").append(" \"").append(classPath).append("\" ");
+
       sb.append("org.jboss.test.messaging.tools.jmx.rmi.RMITestServer");
 
-      //System.out.println(sb.toString());
+      String commandLine = sb.toString();
 
-      Runtime.getRuntime().exec(sb.toString());
+      //System.out.println(commandLine);
 
-      killed[index] = false;
+      Process process = Runtime.getRuntime().exec(commandLine);
 
-      log.info("VM for Server " + index + " spawned");
-   }
+      log.trace("process: " + process);
 
-   /**
-    * Abruptly kills the VM running the specified server, simulating a crash.
-    */
-   public static synchronized void kill(int index) throws Exception
-   {
-      if (servers[index] == null)
+      // if you ever need to debug the spawing process, turn this flag to true:
+
+      final boolean verbose = false;
+
+      final BufferedReader rs = new BufferedReader(new InputStreamReader(process.getInputStream()));
+      final BufferedReader re = new BufferedReader(new InputStreamReader(process.getErrorStream()));
+
+      new Thread(new Runnable()
       {
-         log.warn("Server " + index + " has not been created, so it cannot be killed");
-         return;
-      }
+         public void run()
+         {
+            try
+            {
+               String line;
 
-      servers[index].kill();
+               while((line = rs.readLine()) != null)
+               {
+                  if (verbose)
+                  {
+                     System.out.println("SERVER " + i + " STDOUT: " + line);
+                  }
+               }
+            }
+            catch(Exception e)
+            {
+               log.error("exception", e);
+            }
+         }
 
-      log.info("Server " + index + " killed");
+      }, "Server " + i + " STDOUT reader thread").start();
 
-      servers[index] = null;
-      killed[index] = true;
-   }
-   
-   public static void disconnect() throws Exception
-   {
-      if (isRemote())
+      new Thread(new Runnable()
       {
-         servers[0] = null;
+         public void run()
+         {
+            try
+            {
+               String line;
+
+               while((line = re.readLine()) != null)
+               {
+                  if (verbose)
+                  {
+                     System.out.println("SERVER " + i + " STDERR: " + line);
+                  }
+               }
+            }
+            catch(Exception e)
+            {
+               log.error("exception", e);
+            }
+         }
+
+      }, "Server " + i + " STDERR reader thread").start();
+
+
+      // put the invoking thread on wait until the server is actually up and running and bound
+      // in the RMI registry
+
+      long maxWaitTime = 30; // seconds
+      long startTime = System.currentTimeMillis();
+      Server s = null;
+
+      log.info("spawned server " + i + ", waiting for it to come online");
+
+      while(System.currentTimeMillis() - startTime < maxWaitTime * 1000)
+      {
+         s = acquireRemote(1, i, true);
+         if (s != null)
+         {
+            break;
+         }
       }
+
+      if (s == null)
+      {
+         log.error("Cannot contact newly spawned server " + i + ", most likely the attempt failed, timing out ...");
+         throw new Exception("Cannot contact newly spawned server " + i + ", most likely the attempt failed, timing out ...");
+      }
+
+      return s;
    }
 
+
    public static ObjectName deploy(String mbeanConfiguration) throws Exception
    {
       insureStarted();
-      return servers[0].deploy(mbeanConfiguration);
+      return servers[0].getServer().deploy(mbeanConfiguration);
    }
 
    public static void undeploy(ObjectName on) throws Exception
    {
       insureStarted();
-      servers[0].undeploy(on);
+      servers[0].getServer().undeploy(on);
    }
 
    public static Object getAttribute(ObjectName on, String attribute) throws Exception
@@ -358,7 +449,7 @@
       throws Exception
    {
       insureStarted(serverIndex);
-      return servers[serverIndex].getAttribute(on, attribute);
+      return servers[serverIndex].getServer().getAttribute(on, attribute);
    }
 
 
@@ -366,32 +457,25 @@
       throws Exception
    {
       insureStarted();
-      servers[0].setAttribute(on, name, valueAsString);
+      servers[0].getServer().setAttribute(on, name, valueAsString);
    }
 
    public static Object invoke(ObjectName on, String operationName,
                                Object[] params, String[] signature) throws Exception
    {
       insureStarted();
-      return servers[0].invoke(on, operationName, params, signature);
+      return servers[0].getServer().invoke(on, operationName, params, signature);
    }
 
    public static void addNotificationListener(int serverIndex, ObjectName on,
                                               NotificationListener listener) throws Exception
    {
-      if (killed[serverIndex])
-      {
-         log.warn("Server " + serverIndex + " cannot addNotificationListener it has been killed");
-         
-         return;
-      }
-      
       insureStarted(serverIndex);
 
       if (isLocal())
       {
          // add the listener directly to the server
-         servers[serverIndex].addNotificationListener(on, listener);
+         servers[serverIndex].getServer().addNotificationListener(on, listener);
       }
       else
       {
@@ -411,19 +495,12 @@
    public static void removeNotificationListener(int serverIndex, ObjectName on,
                                                  NotificationListener listener) throws Exception
    {
-      if (killed[serverIndex])
-      {
-         log.warn("Server " + serverIndex + " cannot removeNotificationListener it has been killed");
-         
-         return;
-      }
-      
       insureStarted(serverIndex);
 
       if (isLocal())
       {
          // remove the listener directly
-         servers[serverIndex].removeNotificationListener(on, listener);
+         servers[serverIndex].getServer().removeNotificationListener(on, listener);
       }
       else
       {
@@ -446,13 +523,13 @@
    public static Set query(ObjectName pattern) throws Exception
    {
       insureStarted();
-      return servers[0].query(pattern);
+      return servers[0].getServer().query(pattern);
    }
 
    public static UserTransaction getUserTransaction() throws Exception
    {
       insureStarted();
-      return servers[0].getUserTransaction();
+      return servers[0].getServer().getUserTransaction();
    }
    
    public static void log(int level, String text)
@@ -462,13 +539,6 @@
 
    public static void log(int level, String text, int index)
    {
-      if (killed[index])
-      {
-         log.warn("Server " + index + " cannot log it has been killed");
-         
-         return;
-      }
-      
       if (isRemote())
       {
          if (servers[index] == null)
@@ -480,7 +550,7 @@
 
          try
          {
-            servers[index].log(level, text);
+            servers[index].getServer().log(level, text);
          }
          catch(Exception e)
          {
@@ -504,25 +574,26 @@
                                       String defaultTopicJNDIContext) throws Exception
    {
       insureStarted();
-      servers[0].startServerPeer(serverPeerID, defaultQueueJNDIContext, defaultTopicJNDIContext, false);
+      servers[0].getServer().
+         startServerPeer(serverPeerID, defaultQueueJNDIContext, defaultTopicJNDIContext, false);
    }
 
    public static void stopServerPeer() throws Exception
    {
       insureStarted();
-      servers[0].stopServerPeer();
+      servers[0].getServer().stopServerPeer();
    }
 
    public static boolean isServerPeerStarted() throws Exception
    {
       insureStarted();
-      return servers[0].isServerPeerStarted();
+      return servers[0].getServer().isServerPeerStarted();
    }
 
    public static ObjectName getServerPeerObjectName() throws Exception
    {
       insureStarted();
-      return servers[0].getServerPeerObjectName();
+      return servers[0].getServer().getServerPeerObjectName();
    }
 
    /**
@@ -532,7 +603,7 @@
    public static Set getConnectorSubsystems() throws Exception
    {
       insureStarted();
-      return servers[0].getConnectorSubsystems();
+      return servers[0].getServer().getConnectorSubsystems();
    }
 
    /**
@@ -543,7 +614,7 @@
                                                  ServerInvocationHandler handler) throws Exception
    {
       insureStarted();
-      servers[0].addServerInvocationHandler(subsystem, handler);
+      servers[0].getServer().addServerInvocationHandler(subsystem, handler);
    }
 
    /**
@@ -554,46 +625,46 @@
       throws Exception
    {
       insureStarted();
-      servers[0].removeServerInvocationHandler(subsystem);
+      servers[0].getServer().removeServerInvocationHandler(subsystem);
    }
 
    public static MessageStore getMessageStore() throws Exception
    {
       insureStarted();
-      return servers[0].getMessageStore();
+      return servers[0].getServer().getMessageStore();
    }
 
    public static DestinationManager getDestinationManager()
       throws Exception
    {
       insureStarted();
-      return servers[0].getDestinationManager();
+      return servers[0].getServer().getDestinationManager();
    }
 
    public static PersistenceManager getPersistenceManager()
       throws Exception
    {
       insureStarted();
-      return servers[0].getPersistenceManager();
+      return servers[0].getServer().getPersistenceManager();
    }
 
    public static void configureSecurityForDestination(String destName, String config)
       throws Exception
    {
       insureStarted();
-      servers[0].configureSecurityForDestination(destName, config);
+      servers[0].getServer().configureSecurityForDestination(destName, config);
    }
 
    public static void setDefaultSecurityConfig(String config) throws Exception
    {
       insureStarted();
-      servers[0].setDefaultSecurityConfig(config);
+      servers[0].getServer().setDefaultSecurityConfig(config);
    }
 
    public static String getDefaultSecurityConfig() throws Exception
    {
       insureStarted();
-      return servers[0].getDefaultSecurityConfig();
+      return servers[0].getServer().getDefaultSecurityConfig();
    }
    
    /**
@@ -601,13 +672,8 @@
     */
    public static void deployClusteredTopic(String name, int serverIndex) throws Exception
    {
-      if (killed[serverIndex])
-      {
-         log.warn("Server " + serverIndex + " cannot deployClusteredTopic it has been killed");
-      }
-      
       insureStarted(serverIndex);
-      servers[serverIndex].deployTopic(name, null, true);
+      servers[serverIndex].getServer().deployTopic(name, null, true);
    }
 
    /**
@@ -624,7 +690,7 @@
    public static void deployTopic(String name, String jndiName) throws Exception
    {
       insureStarted();
-      servers[0].deployTopic(name, jndiName, false);
+      servers[0].getServer().deployTopic(name, jndiName, false);
    }
 
    /**
@@ -643,7 +709,7 @@
                                   int downCacheSize) throws Exception
    {
       insureStarted();
-      servers[0].deployTopic(name, jndiName, fullSize, pageSize, downCacheSize, false);
+      servers[0].getServer().deployTopic(name, jndiName, fullSize, pageSize, downCacheSize, false);
    }
 
    /**
@@ -659,11 +725,6 @@
     */
    public static void undeployTopic(String name, int serverIndex) throws Exception
    {
-      if (killed[serverIndex])
-      {
-         log.warn("Server " + serverIndex + " cannot undeployTopic it has been killed");
-      }
-      
       undeployDestination(false, name, serverIndex);
    }
 
@@ -673,7 +734,7 @@
    public static void createTopic(String name, String jndiName) throws Exception
    {
       insureStarted();
-      servers[0].createTopic(name, jndiName);
+      servers[0].getServer().createTopic(name, jndiName);
    }
 
    /**
@@ -681,7 +742,7 @@
     */
    public static boolean destroyTopic(String name) throws Exception
    {
-      return servers[0].destroyDestination(false, name);
+      return servers[0].getServer().destroyDestination(false, name);
    }
    
    /**
@@ -689,13 +750,8 @@
     */
    public static void deployClusteredQueue(String name, int serverIndex) throws Exception
    {
-      if (killed[serverIndex])
-      {
-         log.warn("Server " + serverIndex + " cannot deployClusteredQueue it has been killed");
-      }
-      
       insureStarted(serverIndex);
-      servers[serverIndex].deployQueue(name, null, true);
+      servers[serverIndex].getServer().deployQueue(name, null, true);
    }
 
    /**
@@ -712,7 +768,7 @@
    public static void deployQueue(String name, String jndiName) throws Exception
    {
       insureStarted();
-      servers[0].deployQueue(name, jndiName, false);
+      servers[0].getServer().deployQueue(name, jndiName, false);
    }
 
    /**
@@ -731,7 +787,7 @@
                                   int downCacheSize) throws Exception
    {
       insureStarted();
-      servers[0].deployQueue(name, jndiName, fullSize, pageSize, downCacheSize, false);
+      servers[0].getServer().deployQueue(name, jndiName, fullSize, pageSize, downCacheSize, false);
    }
 
    /**
@@ -747,11 +803,6 @@
     */
    public static void undeployQueue(String name, int serverIndex) throws Exception
    {
-      if (killed[serverIndex])
-      {
-         log.warn("Server " + serverIndex + " cannot undeplyQueue it has been killed");
-      }
-      
       undeployDestination(true, name, serverIndex);
    }
 
@@ -761,7 +812,7 @@
    public static void createQueue(String name, String jndiName) throws Exception
    {
       insureStarted();
-      servers[0].createQueue(name, jndiName);
+      servers[0].getServer().createQueue(name, jndiName);
    }
 
    /**
@@ -769,7 +820,7 @@
     */
    public static boolean destroyQueue(String name) throws Exception
    {
-      return servers[0].destroyDestination(true, name);
+      return servers[0].getServer().destroyDestination(true, name);
    }
 
    /**
@@ -779,7 +830,7 @@
    private static void undeployDestination(boolean isQueue, String name) throws Exception
    {
       insureStarted();
-      servers[0].undeployDestination(isQueue, name);
+      servers[0].getServer().undeployDestination(isQueue, name);
    }
    
    /**
@@ -790,7 +841,7 @@
       throws Exception
    {
       insureStarted(serverIndex);
-      servers[serverIndex].undeployDestination(isQueue, name);
+      servers[serverIndex].getServer().undeployDestination(isQueue, name);
    }
                                                                                                                 
    public static void deployConnectionFactory(String objectName,
@@ -801,12 +852,12 @@
                                               int defaultTempQueueDownCacheSize)
       throws Exception
    {
-      servers[0].deployConnectionFactory(objectName,
-                                     jndiBindings,
-                                     prefetchSize,
-                                     defaultTempQueueFullSize,
-                                     defaultTempQueuePageSize,
-                                     defaultTempQueueDownCacheSize);
+      servers[0].getServer().deployConnectionFactory(objectName,
+                                                     jndiBindings,
+                                                     prefetchSize,
+                                                     defaultTempQueueFullSize,
+                                                     defaultTempQueuePageSize,
+                                                     defaultTempQueueDownCacheSize);
    }
 
    public static void deployConnectionFactory(String objectName,
@@ -814,19 +865,19 @@
                                               int prefetchSize)
       throws Exception
    {
-      servers[0].deployConnectionFactory(objectName, jndiBindings, prefetchSize);
+      servers[0].getServer().deployConnectionFactory(objectName, jndiBindings, prefetchSize);
    }
    
    public static void deployConnectionFactory(String objectName,
                                               String[] jndiBindings)
       throws Exception
    {
-      servers[0].deployConnectionFactory(objectName, jndiBindings);
+      servers[0].getServer().deployConnectionFactory(objectName, jndiBindings);
    }
 
    public static void undeployConnectionFactory(ObjectName objectName) throws Exception
    {
-      servers[0].undeployConnectionFactory(objectName);
+      servers[0].getServer().undeployConnectionFactory(objectName);
    }
 
    public static Hashtable getJNDIEnvironment()
@@ -846,37 +897,8 @@
       }
    }
 
-   // Attributes ----------------------------------------------------
-
-   // Constructors --------------------------------------------------
-
-   // Public --------------------------------------------------------
-
-   // Package protected ---------------------------------------------
-
-   // Protected -----------------------------------------------------
-
-   // Private -------------------------------------------------------
-
-   private static void insureStarted() throws Exception
+   public static Server acquireRemote(int initialRetries, int index, boolean quiet)
    {
-      insureStarted(0);
-   }
-   
-   private static void insureStarted(int index) throws Exception
-   {
-      if (servers[index] == null)
-      {
-         throw new Exception("The server " + index + " has not been created!");
-      }
-      if (!servers[index].isStarted())
-      {
-         throw new Exception("The server " + index + " has not been started!");
-      }
-   }
-
-   private static Server acquireRemote(int initialRetries, int index)
-   {
       String name =
          "//localhost:" + RMITestServer.DEFAULT_REGISTRY_PORT + "/" +
          RMITestServer.RMI_SERVER_PREFIX + index;
@@ -889,21 +911,30 @@
          int attempt = initialRetries - retries + 1;
          try
          {
-            log.info("trying to connect to the remote RMI server " + index + 
-                     (attempt == 1 ? "" : ", attempt " + attempt));
+            String msg = "trying to connect to the remote RMI server " + index +
+               (attempt == 1 ? "" : ", attempt " + attempt);
 
+            if(quiet)
+            {
+               log.debug(msg);
+            }
+            else
+            {
+               log.info(msg);
+            }
+
             s = (Server)Naming.lookup(name);
 
-            log.info("connected to the remote server");
+            log.debug("connected to remote server " + index);
          }
          catch(Exception e)
          {
             log.debug("failed to get the RMI server stub, attempt " +
-                      (initialRetries - retries + 1), e);
+               (initialRetries - retries + 1), e);
 
             try
             {
-               Thread.sleep(1500);
+               Thread.sleep(500);
             }
             catch(InterruptedException e2)
             {
@@ -913,147 +944,41 @@
             retries--;
          }
       }
+
       return s;
    }
 
+   // Attributes ----------------------------------------------------
 
-   // Inner classes -------------------------------------------------
+   // Constructors --------------------------------------------------
 
-//   static class VMStarter implements Runnable
-//   {
-//      public void run()
-//      {
-//         // start a remote java process that runs a TestServer
-//
-//         String userDir = System.getProperty("user.dir");
-//         String javaClassPath = System.getProperty("java.class.path");
-//         String fileSeparator = System.getProperty("file.separator");
-//         String javaHome = System.getProperty("java.home");
-//         String moduleOutput = System.getProperty("module.output");
-//
-//         String osName = System.getProperty("os.name").toLowerCase();
-//         boolean isWindows = osName.indexOf("windows") != -1;
-//
-//         String javaExecutable =
-//            javaHome + fileSeparator + "bin" + fileSeparator + "java" + (isWindows ? ".exe" : "");
-//
-//         String[] cmdarray = new String[]
-//         {
-//            javaExecutable,
-//            "-cp",
-//            javaClassPath,
-//            "-Dmodule.output=" + moduleOutput,
-//            "-Dremote.test.suffix=-remote",
-//            "org.jboss.test.messaging.tools.jmx.rmi.TestServer",
-//         };
-//
-//         String[] environment;
-//         if (isWindows)
-//         {
-//            environment = new String[]
-//            {
-//               "SYSTEMROOT=C:\\WINDOWS" // TODO get this from environment, as it may be diffrent on different machines
-//            };
-//         }
-//         else
-//         {
-//            environment = new String[0];
-//         }
-//
-//         Runtime runtime = Runtime.getRuntime();
-//
-//         try
-//         {
-//            log.debug("creating external process");
-//
-//            Thread stdoutLogger = new Thread(new RemoteProcessLogger(RemoteProcessLogger.STDOUT),
-//                                             "Remote VM STDOUT Logging Thread");
-//            Thread stderrLogger = new Thread(new RemoteProcessLogger(RemoteProcessLogger.STDERR),
-//                                             "Remote VM STDERR Logging Thread");
-//
-//            stdoutLogger.setDaemon(true);
-//            stdoutLogger.setDaemon(true);
-//            stdoutLogger.start();
-//            stderrLogger.start();
-//
-//            process = runtime.exec(cmdarray, environment, new File(userDir));
-//         }
-//         catch(Exception e)
-//         {
-//            log.error("Error spawning remote server", e);
-//         }
-//      }
-//   }
-//
-//   /**
-//    * This logger is used to get and display the output generated at stdout or stderr by the
-//    * RMI server VM.
-//    */
-//   static class RemoteProcessLogger implements Runnable
-//   {
-//      public static final int STDOUT = 0;
-//      public static final int STDERR = 1;
-//
-//      private int type;
-//      private BufferedReader br;
-//      private PrintStream out;
-//
-//      public RemoteProcessLogger(int type)
-//      {
-//         this.type = type;
-//
-//         if (type == STDOUT)
-//         {
-//            out = System.out;
-//         }
-//         else if (type == STDERR)
-//         {
-//            out = System.err;
-//         }
-//         else
-//         {
-//            throw new IllegalArgumentException("Unknown type " + type);
-//         }
-//      }
-//
-//      public void run()
-//      {
-//         while(process == null)
-//         {
-//            try
-//            {
-//               Thread.sleep(50);
-//            }
-//            catch(InterruptedException e)
-//            {
-//               // OK
-//            }
-//         }
-//
-//         if (type == STDOUT)
-//         {
-//            br = new BufferedReader(new InputStreamReader(process.getInputStream()));
-//         }
-//         else if (type == STDERR)
-//         {
-//            br = new BufferedReader(new InputStreamReader(process.getErrorStream()));
-//         }
-//
-//         String line;
-//         try
-//         {
-//            while((line = br.readLine()) != null)
-//            {
-//               out.println(line);
-//            }
-//         }
-//         catch(Exception e)
-//         {
-//            log.error("failed to read from process " + process, e);
-//         }
-//      }
-//   }
+   // Public --------------------------------------------------------
 
+   // Package protected ---------------------------------------------
+
+   // Protected -----------------------------------------------------
+
+   // Private -------------------------------------------------------
+
+   private static void insureStarted() throws Exception
+   {
+      insureStarted(0);
+   }
+   
+   private static void insureStarted(int i) throws Exception
+   {
+      if (servers[i] == null)
+      {
+         throw new Exception("The server " + i + " has not been created!");
+      }
+      if (!servers[i].getServer().isStarted())
+      {
+         throw new Exception("The server " + i + " has not been started!");
+      }
+   }
+
+   // Inner classes -------------------------------------------------
+
    private static long listenerIDCounter = 0;
 
    static class NotificationListenerPoller implements Runnable
@@ -1112,4 +1037,26 @@
       }
    }
 
+   private static class ServerHolder
+   {
+      private Server server;
+      private boolean spawned;
+
+      ServerHolder(Server server, boolean spawned)
+      {
+         this.server = server;
+         this.spawned = spawned;
+      }
+
+      public Server getServer()
+      {
+         return server;
+      }
+
+      public boolean isSpawned()
+      {
+         return spawned;
+      }
+   }
+
 }

Added: trunk/tests/src/org/jboss/test/messaging/tools/ant/JUnitTestSuiteListener.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/tools/ant/JUnitTestSuiteListener.java	2006-12-14 21:28:22 UTC (rev 1797)
+++ trunk/tests/src/org/jboss/test/messaging/tools/ant/JUnitTestSuiteListener.java	2006-12-15 08:59:37 UTC (rev 1798)
@@ -0,0 +1,122 @@
+/**
+ * JBoss, Home of Professional Open Source
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package org.jboss.test.messaging.tools.ant;
+
+import org.apache.tools.ant.taskdefs.optional.junit.JUnitResultFormatter;
+import org.apache.tools.ant.taskdefs.optional.junit.JUnitTest;
+import org.apache.tools.ant.BuildException;
+import org.jboss.test.messaging.tools.ServerManagement;
+
+import java.io.OutputStream;
+import java.util.List;
+import java.util.Iterator;
+
+import junit.framework.Test;
+import junit.framework.AssertionFailedError;
+
+/**
+ * This class is a hack.
+ *
+ * I needed a way to intercept the end of a forked ant JUnit test run, in order to perform some
+ * clean-up, and this is it: register this class as a JUnit batchtest formatter, and it will get
+ * notified on a endTestSuite() event. Very important, it is run in the same address space as the
+ * tests themselves.
+ *
+ * @author <a href="mailto:ovidiu at jboss.org">Ovidiu Feodorov</a>
+ * @version <tt>$Revision$</tt>
+ * $Id$
+ */
+public class JUnitTestSuiteListener implements JUnitResultFormatter
+{
+   // Constants -----------------------------------------------------
+
+   // Static --------------------------------------------------------
+
+   // Attributes ----------------------------------------------------
+
+   // Constructors --------------------------------------------------
+
+   // JUnitResultFormatter implementation ---------------------------
+
+   public void endTestSuite(JUnitTest suite) throws BuildException
+   {
+      try
+      {
+         List destroyed = ServerManagement.destroySpawnedServers();
+         if (destroyed.size() > 0)
+         {
+            StringBuffer sb = new StringBuffer("Destroyed spawned test servers ");
+            for(Iterator i = destroyed.iterator(); i.hasNext();)
+            {
+               sb.append(i.next());
+               if (i.hasNext())
+               {
+                  sb.append(',');
+               }
+            }
+            System.out.println(sb);
+         }
+      }
+      catch(Throwable t)
+      {
+         t.printStackTrace();
+      }
+   }
+
+   public void startTestSuite(JUnitTest suite) throws BuildException
+   {
+      // noop
+   }
+
+   public void setOutput(OutputStream out)
+   {
+      // noop
+   }
+
+   public void setSystemOutput(String out)
+   {
+      // noop
+   }
+
+   public void setSystemError(String err)
+   {
+      // noop
+   }
+
+   // TestListener implementation -----------------------------------
+
+   public void addError(Test test, Throwable t)
+   {
+      // noop
+   }
+
+   public void addFailure(Test test, AssertionFailedError t)
+   {
+      // noop
+   }
+
+   public void endTest(Test test)
+   {
+      // noop
+   }
+
+   public void startTest(Test test)
+   {
+      // noop
+   }
+
+   // Public --------------------------------------------------------
+
+   // Package protected ---------------------------------------------
+
+   // Protected -----------------------------------------------------
+
+   // Private -------------------------------------------------------
+
+   // Inner classes -------------------------------------------------
+
+}

Modified: trunk/tests/src/org/jboss/test/messaging/tools/jmx/ServiceContainer.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/tools/jmx/ServiceContainer.java	2006-12-14 21:28:22 UTC (rev 1797)
+++ trunk/tests/src/org/jboss/test/messaging/tools/jmx/ServiceContainer.java	2006-12-15 08:59:37 UTC (rev 1798)
@@ -398,6 +398,8 @@
 
          loadJNDIContexts();
 
+         log.debug("loaded JNDI context");
+
          String transport = config.getRemotingTransport();
 
          log.info("Remoting type: ........... " + (remoting ? transport : "DISABLED"));
@@ -1251,6 +1253,8 @@
 
          int rows = ps.executeUpdate();
 
+         log.debug("JMS_POSTOFFICE: deleted " + rows);
+
          ps.close();
 
          sql = "DELETE FROM JMS_MESSAGE_REFERENCE";
@@ -1258,7 +1262,7 @@
 
          rows = ps.executeUpdate();
 
-         log.debug("deleted " + rows);
+         log.debug("JMS_MESSAGE_REFERENCE: deleted " + rows);
 
          ps.close();
 
@@ -1267,7 +1271,7 @@
 
          rows = ps.executeUpdate();
 
-         log.debug("deleted " + rows);
+         log.debug("JMS_MESSAGE: deleted " + rows);
 
          ps.close();
 
@@ -1276,7 +1280,7 @@
 
          rows = ps.executeUpdate();
 
-         log.debug("deleted " + rows);
+         log.debug("JMS_TRANSACTION: deleted " + rows);
 
          ps.close();
 
@@ -1285,7 +1289,7 @@
 
          rows = ps.executeUpdate();
 
-         log.debug("deleted " + rows);
+         log.debug("JMS_COUNTER: deleted " + rows);
 
          ps.close();
 
@@ -1294,17 +1298,21 @@
 
          rows = ps.executeUpdate();
 
-         log.debug("deleted " + rows);
+         log.debug("JMS_USER: deleted " + rows);
 
          ps.close();
          conn.close();
 
          mgr.commit();
 
+         log.debug("committed");
+
          if (txOld != null)
          {
             mgr.resume(txOld);
          }
+
+         log.debug("done with the database");
       }
       catch (SQLException e)
       {

Modified: trunk/tests/src/org/jboss/test/messaging/tools/jmx/rmi/LocalTestServer.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/tools/jmx/rmi/LocalTestServer.java	2006-12-14 21:28:22 UTC (rev 1797)
+++ trunk/tests/src/org/jboss/test/messaging/tools/jmx/rmi/LocalTestServer.java	2006-12-15 08:59:37 UTC (rev 1798)
@@ -108,6 +108,11 @@
 
    // Server implementation -----------------------------------------
 
+   public int getServerID()
+   {
+      return serverIndex;
+   }
+
    public synchronized void start(String containerConfig) throws Exception
    {
       if (isStarted())
@@ -833,11 +838,6 @@
 
    // Public --------------------------------------------------------
 
-   public int getServerIndex()
-   {
-      return serverIndex;
-   }
-
    // Package protected ---------------------------------------------
 
    ServiceContainer getServiceContainer()

Modified: trunk/tests/src/org/jboss/test/messaging/tools/jmx/rmi/RMITestServer.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/tools/jmx/rmi/RMITestServer.java	2006-12-14 21:28:22 UTC (rev 1797)
+++ trunk/tests/src/org/jboss/test/messaging/tools/jmx/rmi/RMITestServer.java	2006-12-15 08:59:37 UTC (rev 1798)
@@ -135,6 +135,11 @@
 
    // Server implementation -----------------------------------------
 
+   public int getServerID()
+   {
+      return server.getServerID();
+   }
+
    public void start(String containerConfig) throws Exception
    {
       server.start(containerConfig);
@@ -459,11 +464,14 @@
             // unregister myself from the RMI registry
 
             Registry registry = LocateRegistry.getRegistry(DEFAULT_REGISTRY_PORT);
-            registry.unbind(RMI_SERVER_PREFIX + server.getServerIndex());
 
-            log.info("unregistred from " + registry);
+            String name = RMI_SERVER_PREFIX + server.getServerID();
+            registry.unbind(name);
+            log.info("unregistred " + name + " from registry");
 
-
+            name = NAMING_SERVER_PREFIX + server.getServerID();
+            registry.unbind(name);
+            log.info("unregistred " + name + " from registry");
          }
          catch(Exception e)
          {

Modified: trunk/tests/src/org/jboss/test/messaging/tools/jmx/rmi/Server.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/tools/jmx/rmi/Server.java	2006-12-14 21:28:22 UTC (rev 1797)
+++ trunk/tests/src/org/jboss/test/messaging/tools/jmx/rmi/Server.java	2006-12-15 08:59:37 UTC (rev 1798)
@@ -31,7 +31,6 @@
 import org.jboss.jms.server.ServerPeer;
 import org.jboss.messaging.core.plugin.contract.MessageStore;
 import org.jboss.messaging.core.plugin.contract.PersistenceManager;
-import org.jboss.messaging.core.plugin.contract.PostOffice;
 import org.jboss.remoting.ServerInvocationHandler;
 
 /**
@@ -44,6 +43,8 @@
  */
 public interface Server extends Remote
 {
+   int getServerID() throws Exception;
+
    void start(String containerConfig) throws Exception;
 
    void stop() throws Exception;

Modified: trunk/tests/src/org/jboss/test/messaging/tools/jmx/rmi/StopRMIServer.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/tools/jmx/rmi/StopRMIServer.java	2006-12-14 21:28:22 UTC (rev 1797)
+++ trunk/tests/src/org/jboss/test/messaging/tools/jmx/rmi/StopRMIServer.java	2006-12-15 08:59:37 UTC (rev 1798)
@@ -23,6 +23,8 @@
 
 import java.rmi.ConnectException;
 import java.rmi.Naming;
+import java.rmi.NotBoundException;
+
 import org.jboss.logging.Logger;
 
 /**
@@ -78,6 +80,11 @@
          log.info("Cannot contact the registry, the server is probably shut down already");
          return;
       }
+      catch(NotBoundException e)
+      {
+         log.info("Cannot lookup " + name + ", the server is probably shut down already");
+         return;
+      }
 
       // We should shut down cleanly - not kill the process like we are currently doing
       

Modified: trunk/tests/src/org/jboss/test/messaging/tools/jndi/RemoteContext.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/tools/jndi/RemoteContext.java	2006-12-14 21:28:22 UTC (rev 1797)
+++ trunk/tests/src/org/jboss/test/messaging/tools/jndi/RemoteContext.java	2006-12-15 08:59:37 UTC (rev 1798)
@@ -56,9 +56,9 @@
          "//localhost:" + RMITestServer.DEFAULT_REGISTRY_PORT + "/" +
           RMITestServer.NAMING_SERVER_PREFIX + remoteServerIndex;
       
-      log.info("Using this url for rmi server lookup " + n);
-      
       namingDelegate = (NamingDelegate)Naming.lookup(n);
+
+      log.info("remote context for server " + remoteServerIndex + " acquired from rmi:" + n);
    }
 
    // Context implementation ----------------------------------------

Modified: trunk/tests/src/org/jboss/test/messaging/tools/jndi/RemoteInitialContextFactory.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/tools/jndi/RemoteInitialContextFactory.java	2006-12-14 21:28:22 UTC (rev 1797)
+++ trunk/tests/src/org/jboss/test/messaging/tools/jndi/RemoteInitialContextFactory.java	2006-12-15 08:59:37 UTC (rev 1798)
@@ -47,8 +47,6 @@
     */
    public static Hashtable getJNDIEnvironment(int serverIndex)
    {
-      log.info("Returning remote context... server index:" + serverIndex);
-      
       Hashtable env = new Hashtable();
       env.put("java.naming.factory.initial",
               "org.jboss.test.messaging.tools.jndi.RemoteInitialContextFactory");
@@ -74,8 +72,6 @@
                                             "entry for " + Constants.SERVER_INDEX_PROPERTY_NAME);
       }
 
-      log.info("Created initial context for " + s);
-
       int remoteServerIndex = Integer.parseInt(s);
 
       try

Modified: trunk/tests/src/org/jboss/test/messaging/util/ServerManagementTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/util/ServerManagementTest.java	2006-12-14 21:28:22 UTC (rev 1797)
+++ trunk/tests/src/org/jboss/test/messaging/util/ServerManagementTest.java	2006-12-15 08:59:37 UTC (rev 1798)
@@ -35,56 +35,34 @@
 
    // Public --------------------------------------------------------
 
-   public void testFailureToSpawnStartedServer() throws Exception
+   public void testSpawnServer() throws Exception
    {
       try
       {
-         ServerManagement.start("all", 0);
+         ServerManagement.start(0, "all");
 
-         try
-         {
-            ServerManagement.spawn(0);
-            fail("It should have failed!");
-         }
-         catch(Exception e)
-         {
-            // OK
-         }
+         ServerManagement.start(0, "all");
       }
       finally
       {
-         ServerManagement.stop(0);
+         ServerManagement.kill(0);
       }
    }
 
-   public void testFailureToSpawnExistingRemoteServer() throws Exception
+   public void testSimpleSpawn() throws Exception
    {
-      if (ServerManagement.isLocal())
+      if (!ServerManagement.isRemote())
       {
-         // irrelevant for a colocated configuration
-         return;
+         fail("This test must be run in remote mode!");
       }
 
-      // this assumes that the remote server 0 has been started externally by and or by a script
-
       try
       {
-         ServerManagement.spawn(0);
-         fail("This should have failed!");
-      }
-      catch(Exception e)
-      {
-         // OK
-      }
-   }
+         log.info("Waiting for server 7 to start ...");
 
-   public void testSimpleSpawn() throws Exception
-   {
-      try
-      {
-         ServerManagement.spawn(7);
+         ServerManagement.start(7, "all");
 
-         ServerManagement.start("all", 7);
+         log.info("Server 7 started");
 
          Integer index = (Integer)ServerManagement.
             getAttribute(7, new ObjectName("jboss.messaging:service=ServerPeer"), "serverPeerID");
@@ -99,43 +77,62 @@
       }
       finally
       {
+         log.info("Killing server 7");
          ServerManagement.kill(7);
       }
    }
 
-   /**
-    * Needs to be run in clustered mode.
-    */
    public void testRessurect() throws Exception
    {
-
-      if (!ServerManagement.isClustered())
+      if (!ServerManagement.isRemote())
       {
-         fail("This test must be run in clustered mode!");
+         fail("This test must be run in remote mode!");
       }
 
-      ServerManagement.start("all", 1);
+      try
+      {
+         ServerManagement.start(1, "all");
 
-      ServerManagement.kill(1);
+         ServerManagement.kill(1);
 
-      // wait a bit for the server to die
-      
-      log.info("Sleeping for 10 seconds ...");
+         // wait a bit for the server to die
 
-      Thread.sleep(10000);
+         log.info("Sleeping for 10 seconds ...");
 
-      // resurrect the server
+         Thread.sleep(10000);
 
-      ServerManagement.spawn(1);
-      ServerManagement.start("all", 1);
+         // resurrect the server
 
-      Integer index = (Integer)ServerManagement.
-         getAttribute(1, new ObjectName("jboss.messaging:service=ServerPeer"), "serverPeerID");
+         ServerManagement.start(1, "all");
 
-      assertEquals(1, index.intValue());
+         Integer index = (Integer)ServerManagement.
+            getAttribute(1, new ObjectName("jboss.messaging:service=ServerPeer"), "serverPeerID");
+
+         assertEquals(1, index.intValue());
+
+         InitialContext ic = new InitialContext(ServerManagement.getJNDIEnvironment(1));
+
+         ic.bind("/xxx", "yyy");
+
+         assertEquals("yyy", ic.lookup("/xxx"));
+      }
+      finally
+      {
+         ServerManagement.kill(1);
+      }
    }
 
+   public void testA()
+   {
+      System.out.println("A");
+   }
 
+   public void testB()
+   {
+      System.out.println("B");
+   }
+
+
    // Package protected ---------------------------------------------
 
    // Protected -----------------------------------------------------
@@ -150,6 +147,9 @@
    protected void tearDown() throws Exception
    {
       super.tearDown();
+
+      // TODO: clean up spawned servers
+
    }
 
    // Private -------------------------------------------------------




More information about the jboss-cvs-commits mailing list