[jboss-cvs] JBoss Messaging SVN: r1791 - in trunk/tests/src/org/jboss/test/messaging: jms/clustering tools tools/jmx/rmi tools/jndi

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Dec 14 05:47:35 EST 2006


Author: ovidiu.feodorov at jboss.com
Date: 2006-12-14 05:47:31 -0500 (Thu, 14 Dec 2006)
New Revision: 1791

Modified:
   trunk/tests/src/org/jboss/test/messaging/jms/clustering/GroupManagementTest.java
   trunk/tests/src/org/jboss/test/messaging/tools/ServerManagement.java
   trunk/tests/src/org/jboss/test/messaging/tools/jmx/rmi/NamingDelegate.java
   trunk/tests/src/org/jboss/test/messaging/tools/jmx/rmi/RMINamingDelegate.java
   trunk/tests/src/org/jboss/test/messaging/tools/jndi/InVMContext.java
   trunk/tests/src/org/jboss/test/messaging/tools/jndi/RemoteContext.java
Log:
Added support for spawning new remote servers (and resurrecting killed remote servers)


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 08:58:42 UTC (rev 1790)
+++ trunk/tests/src/org/jboss/test/messaging/jms/clustering/GroupManagementTest.java	2006-12-14 10:47:31 UTC (rev 1791)
@@ -382,8 +382,52 @@
       }
    }
 
+   public void testSpawnServer() throws Exception
+   {
 
+      ObjectName postOfficeObjectName = new ObjectName("jboss.messaging:service=PostOffice");
+      ClusterEventNotificationListener clusterEvent = new ClusterEventNotificationListener();
 
+      try
+      {
+         // Start with a 1 node cluster
+
+         ServerManagement.start("all", 0);
+
+         Set view = ServerManagement.getServer(0).getNodeIDView();
+
+         assertEquals(1, view.size());
+         assertTrue(view.contains(new Integer(0)));
+
+         ServerManagement.addNotificationListener(0, postOfficeObjectName, clusterEvent);
+
+         ServerManagement.spawn(10);
+         ServerManagement.start("all", 10);
+
+         if (!clusterEvent.viewChanged(120000))
+         {
+            fail("Did not receive a VIEW_CHANGED event after spawning new server!");
+         }
+
+         view = ServerManagement.getServer(1).getNodeIDView();
+
+         assertEquals(2, view.size());
+         assertTrue(view.contains(new Integer(0)));
+         assertTrue(view.contains(new Integer(10)));
+
+         //ServerManagement.kill(10);
+
+      }
+      finally
+      {
+         ServerManagement.removeNotificationListener(0, postOfficeObjectName, clusterEvent);
+         ServerManagement.stop(0);
+      }
+   }
+
+
+
+
    // Package protected ---------------------------------------------
 
    // Protected -----------------------------------------------------

Modified: trunk/tests/src/org/jboss/test/messaging/tools/ServerManagement.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/tools/ServerManagement.java	2006-12-14 08:58:42 UTC (rev 1790)
+++ trunk/tests/src/org/jboss/test/messaging/tools/ServerManagement.java	2006-12-14 10:47:31 UTC (rev 1791)
@@ -236,8 +236,52 @@
    }
 
    /**
-    * Abruptly kills the VM running the specified server.
+    * For a local test, is a noop, but for a remote test, the method call spawns a new VM.
+    * 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
+   {
+      if (servers[index] != null)
+      {
+         throw new Exception("The server " + index + " has been created already!");
+      }
+
+      // 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(' ');
+
+      sb.append("-Dremote.test.suffix=-remote-").append(index).append(' ');
+
+      sb.append("-Dtest.server.index=").append(index).append(' ');
+
+      sb.append("-Dtest.bind.address=localhost").append(' ');
+
+      sb.append("-cp").append(' ').append(System.getProperty("java.class.path")).append(' ');
+
+      sb.append("org.jboss.test.messaging.tools.jmx.rmi.RMITestServer");
+
+      //System.out.println(sb.toString());
+
+      Runtime.getRuntime().exec(sb.toString());
+
+      log.info("VM for Server " + index + " spawned");
+   }
+
+   /**
+    * Abruptly kills the VM running the specified server, simulating a crash.
+    */
    public static synchronized void kill(int index) throws Exception
    {
       if (servers[index] == null)
@@ -247,8 +291,10 @@
       }
 
       servers[index].kill();
+
+      log.info("Server " + index + " killed");
+
       servers[index] = null;
-      
       killed[index] = true;
    }
    
@@ -279,10 +325,17 @@
 
    public static Object getAttribute(ObjectName on, String attribute) throws Exception
    {
-      insureStarted();
-      return servers[0].getAttribute(on, attribute);
+      return getAttribute(0, on, attribute);
    }
 
+   public static Object getAttribute(int serverIndex, ObjectName on, String attribute)
+      throws Exception
+   {
+      insureStarted(serverIndex);
+      return servers[serverIndex].getAttribute(on, attribute);
+   }
+
+
    public static void setAttribute(ObjectName on, String name, String valueAsString)
       throws Exception
    {

Modified: trunk/tests/src/org/jboss/test/messaging/tools/jmx/rmi/NamingDelegate.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/tools/jmx/rmi/NamingDelegate.java	2006-12-14 08:58:42 UTC (rev 1790)
+++ trunk/tests/src/org/jboss/test/messaging/tools/jmx/rmi/NamingDelegate.java	2006-12-14 10:47:31 UTC (rev 1791)
@@ -34,4 +34,6 @@
 public interface NamingDelegate extends Remote
 {
    Object lookup(String name) throws Exception;
+
+   void bind(String name, Object obj) throws Exception;
 }

Modified: trunk/tests/src/org/jboss/test/messaging/tools/jmx/rmi/RMINamingDelegate.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/tools/jmx/rmi/RMINamingDelegate.java	2006-12-14 08:58:42 UTC (rev 1790)
+++ trunk/tests/src/org/jboss/test/messaging/tools/jmx/rmi/RMINamingDelegate.java	2006-12-14 10:47:31 UTC (rev 1791)
@@ -61,6 +61,11 @@
       return getInitialContext().lookup(name);
    }
 
+   public void bind(String name, Object obj) throws Exception
+   {
+      getInitialContext().bind(name, obj);
+   }
+
    // Public --------------------------------------------------------
 
    public void reset()

Modified: trunk/tests/src/org/jboss/test/messaging/tools/jndi/InVMContext.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/tools/jndi/InVMContext.java	2006-12-14 08:58:42 UTC (rev 1790)
+++ trunk/tests/src/org/jboss/test/messaging/tools/jndi/InVMContext.java	2006-12-14 10:47:31 UTC (rev 1791)
@@ -41,6 +41,7 @@
 import java.util.Iterator;
 import java.util.List;
 import java.util.ArrayList;
+import java.io.Serializable;
 
 
 /**
@@ -49,12 +50,14 @@
  *
  * $Id$
  */
-public class InVMContext implements Context
+public class InVMContext implements Context, Serializable
 {
    // Constants -----------------------------------------------------
 
+   private static final long serialVersionUID = 385743957345L;
+
    // Static --------------------------------------------------------
-   
+
    // Attributes ----------------------------------------------------
 
    protected Map map;
@@ -283,9 +286,9 @@
    // Public --------------------------------------------------------
 
    // Package protected ---------------------------------------------
-   
+
    // Protected -----------------------------------------------------
-   
+
    // Private -------------------------------------------------------
 
    private String trimSlashes(String s)

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 08:58:42 UTC (rev 1790)
+++ trunk/tests/src/org/jboss/test/messaging/tools/jndi/RemoteContext.java	2006-12-14 10:47:31 UTC (rev 1791)
@@ -88,7 +88,15 @@
 
    public void bind(String name, Object obj) throws NamingException
    {
-      throw new NotYetImplementedException();
+      try
+      {
+         namingDelegate.bind(name, obj);
+      }
+      catch(Exception e)
+      {
+         log.error("naming operation failed", e);
+         throw new NamingException(e.getMessage());
+      }
    }
 
    public void rebind(Name name, Object obj) throws NamingException




More information about the jboss-cvs-commits mailing list