[jboss-cvs] JBossAS SVN: r65064 - projects/test/trunk/src/main/java/org/jboss/test.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Sep 4 16:16:30 EDT 2007


Author: bstansberry at jboss.com
Date: 2007-09-04 16:16:30 -0400 (Tue, 04 Sep 2007)
New Revision: 65064

Added:
   projects/test/trunk/src/main/java/org/jboss/test/JBossClusteredTestCase.java
   projects/test/trunk/src/main/java/org/jboss/test/JBossTestClusteredServices.java
   projects/test/trunk/src/main/java/org/jboss/test/JBossTestClusteredSetup.java
Log:
[JBAS-4125] Move clustering test support classes to jboss-test

Copied: projects/test/trunk/src/main/java/org/jboss/test/JBossClusteredTestCase.java (from rev 65057, trunk/testsuite/src/main/org/jboss/test/JBossClusteredTestCase.java)
===================================================================
--- projects/test/trunk/src/main/java/org/jboss/test/JBossClusteredTestCase.java	                        (rev 0)
+++ projects/test/trunk/src/main/java/org/jboss/test/JBossClusteredTestCase.java	2007-09-04 20:16:30 UTC (rev 65064)
@@ -0,0 +1,140 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+package org.jboss.test;
+
+import javax.management.MBeanServerConnection;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * Derived implementation of JBossTestCase for cluster testing.
+ *
+ * @author <a href="mailto:sacha.labourey at cogito-info.ch">Sacha Labourey</a>.
+ * @author Scott.Stark at jboss.org
+ * @version $Revision$
+ * @see org.jboss.test.JBossTestCase
+ */
+public class JBossClusteredTestCase extends JBossTestCase
+{
+   JBossTestClusteredServices clusterServices;
+   
+   // Static --------------------------------------------------------
+   
+   /**
+    * Overriden to return JBossTestServices as the test delegate.
+    */
+   public static AbstractTestDelegate getDelegate(Class clazz) throws Exception
+   {
+      AbstractTestDelegate delegate = new JBossTestClusteredServices(clazz);
+      return delegate;
+   }
+
+   public JBossClusteredTestCase(String name)
+   {
+      super(name);
+   }
+   
+   @Override
+   protected void setUp() throws Exception
+   {
+      super.setUp();
+      clusterServices = (JBossTestClusteredServices) delegate;
+   }
+   
+   // Public --------------------------------------------------------
+   
+   
+
+   public void testServerFound() throws Exception
+   {
+      if (deploymentException != null)
+         throw deploymentException;
+      assertTrue("Server was not found", getServers() != null);
+   }
+
+
+   public MBeanServerConnection[] getAdaptors() throws Exception
+   {
+      return clusterServices.getAdaptors();
+   }
+
+   public String[] getServers() throws Exception
+   {
+      return clusterServices.getServers();
+   }
+
+   public String[] getNamingURLs() throws Exception
+   {
+      return clusterServices.getNamingURLs();
+   }
+   public String[] getHANamingURLs() throws Exception
+   {
+      return clusterServices.getHANamingURLs();
+   }
+   public String[] getHttpURLs() throws Exception
+   {
+      return clusterServices.getHttpURLs();
+   }
+
+   protected void deploy(MBeanServerConnection server, String name) throws Exception
+   {
+      clusterServices.deploy(server, name);
+   }
+
+   protected void redeploy(MBeanServerConnection server, String name) throws Exception
+   {
+      clusterServices.redeploy(server, name);
+   }
+
+   protected void undeploy(MBeanServerConnection server, String name) throws Exception
+   {
+      clusterServices.undeploy(server, name);
+   }
+
+   public static Test getDeploySetup(final Test test, final String jarNames)
+      throws Exception
+   {
+      return new JBossTestClusteredSetup(test, jarNames);
+   }
+
+   public static Test getDeploySetup(final Class clazz, final String jarNames)
+      throws Exception
+   {
+      TestSuite suite = new TestSuite();
+      suite.addTest(new TestSuite(clazz));
+      return getDeploySetup(suite, jarNames);
+   }
+
+   /**
+    * anil
+    */
+   public void setServerNames(String[] snames) throws Exception
+   {
+      ((JBossTestClusteredServices) delegate).setServerNames(snames);
+   }
+
+   // Private -------------------------------------------------------
+   
+   // Inner classes -------------------------------------------------
+
+}

Copied: projects/test/trunk/src/main/java/org/jboss/test/JBossTestClusteredServices.java (from rev 65057, trunk/testsuite/src/main/org/jboss/test/JBossTestClusteredServices.java)
===================================================================
--- projects/test/trunk/src/main/java/org/jboss/test/JBossTestClusteredServices.java	                        (rev 0)
+++ projects/test/trunk/src/main/java/org/jboss/test/JBossTestClusteredServices.java	2007-09-04 20:16:30 UTC (rev 65064)
@@ -0,0 +1,328 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test;
+
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Hashtable;
+
+import javax.management.MBeanServerConnection;
+import javax.management.ObjectName;
+import javax.naming.InitialContext;
+
+/**
+ * Derived implementation of JBossTestServices for cluster testing.
+ *
+ * @author <a href="mailto:sacha.labourey at cogito-info.ch">Sacha Labourey</a>.
+ * @author Scott.Stark at jboss.org
+ * @version $Revision$
+ * @see org.jboss.test.JBossTestServices
+ */
+public class JBossTestClusteredServices extends JBossTestServices
+{
+   protected ArrayList adaptors = null;
+   protected ArrayList servers = null;
+   protected ArrayList namingURLs = null;
+   protected ArrayList namingURLsHA = null;
+   protected ArrayList httpURLs = null;
+   
+   // Constructors --------------------------------------------------
+   
+   public JBossTestClusteredServices(Class clazz)
+   {
+      super(clazz);
+   }
+   
+   
+
+   @Override
+   public void setUp() throws Exception
+   {
+      super.setUp();
+   }
+
+   @Override
+   public void tearDown() throws Exception
+   {
+      super.tearDown();
+   }
+
+
+
+   int getServerCount()
+   {
+      return servers.size();
+   }
+
+   MBeanServerConnection[] getAdaptors() throws Exception
+   {
+//      init();
+      MBeanServerConnection[] tmp = new MBeanServerConnection[adaptors.size()];
+      adaptors.toArray(tmp);
+      return tmp;
+   }
+   MBeanServerConnection getAdaptor(int index) throws Exception
+   {
+//      init();
+      MBeanServerConnection adaptor = (MBeanServerConnection) adaptors.get(index);
+      return adaptor;
+   }
+
+   String[] getServers() throws Exception
+   {
+//      init();
+      String[] tmp = new String[servers.size()];
+      servers.toArray(tmp);
+      return tmp;
+   }
+   String getServer(int index) throws Exception
+   {
+//      init();
+      String server = (String) servers.get(index);
+      return server;
+   }
+
+   /** Get the JNDI provider urls for the cluster nodes
+    * @return
+    * @throws Exception
+    */ 
+   String[] getNamingURLs() throws Exception
+   {
+//      init();
+      String[] tmp = new String[namingURLs.size()];
+      namingURLs.toArray(tmp);
+      return tmp;
+   }
+   String getNamingURL(int index) throws Exception
+   {
+//      init();
+      String server = (String) namingURLs.get(index);
+      return server;
+   }
+
+   /** Get the JNDI provider urls for the cluster nodes
+    * @return
+    * @throws Exception
+    */ 
+   String[] getHANamingURLs() throws Exception
+   {
+//      init();
+      String[] tmp = new String[namingURLsHA.size()];
+      namingURLsHA.toArray(tmp);
+      return tmp;
+   }
+   String getHANamingURL(int index) throws Exception
+   {
+//      init();
+      String server = (String) namingURLsHA.get(index);
+      return server;
+   }
+
+   /** Get the default web container urls for the cluster nodes
+    * @return
+    * @throws Exception
+    */ 
+   String[] getHttpURLs() throws Exception
+   {
+//      init();
+      String[] tmp = new String[httpURLs.size()];
+      httpURLs.toArray(tmp);
+      return tmp;
+   }
+   String getHttpURL(int index) throws Exception
+   {
+//      init();
+      String server = (String) httpURLs.get(index);
+      return server;
+   }
+
+   /**
+    * Deploy a package on the given server with the main deployer. The supplied 
+    * name is interpreted as a url, or as a filename in jbosstest.deploy.lib or 
+    * ../lib.
+    *
+    * @param server         server on which the package should be deployed
+    * @param name           filename/url of package to deploy.
+    * @exception Exception  Description of Exception
+    */
+   public void deploy(MBeanServerConnection server, String name) throws Exception
+   {
+      if (Boolean.getBoolean("jbosstest.nodeploy") == true)
+      {
+         log.debug("Skipping deployment of: " + name);
+         return;
+      }
+
+      URL deployURL = getDeployURL(name);
+      log.debug("Deploying " + name + ", url=" + deployURL  + " to " + server);
+      invoke(server,
+            getDeployerName(),
+            "deploy",
+            new Object[]{deployURL},
+            new String[]{"java.net.URL"});
+   }
+   
+   public void redeploy(MBeanServerConnection server, String name) throws Exception
+   {
+      if (Boolean.getBoolean("jbosstest.nodeploy") == true)
+      {
+         log.debug("Skipping redeployment of: " + name);
+         return;
+      }
+
+      URL deployURL = getDeployURL(name);
+      log.debug("Deploying " + name + ", url=" + deployURL);
+      invoke(server,
+         getDeployerName(),
+         "redeploy",
+         new Object[]{deployURL},
+         new String[]{"java.net.URL"});
+   }
+
+   /**
+    * Undeploy a package from the given server with the main deployer. 
+    * The supplied name is interpreted as a url, or as a filename in 
+    * jbosstest.deploy.lib or ../lib.
+    *
+    * @param server         server on which the package should be deployed
+    * @param name           filename/url of package to undeploy.
+    * @exception Exception  Description of Exception
+    */
+   public void undeploy(MBeanServerConnection server, String name) throws Exception
+   {
+      if (Boolean.getBoolean("jbosstest.nodeploy") == true)
+         return;
+      URL deployURL = getDeployURL(name);
+      log.debug("Undeploying " + name + ", url=" + deployURL);
+      Object[] args = {deployURL};
+      String[] sig = {"java.net.URL"};
+      invoke(server, getDeployerName(), "undeploy", args, sig);
+   }
+
+   /**
+    * Override to invoke the operation on all servers
+    *
+    * @param name
+    * @param method
+    * @param args
+    * @param sig
+    * @return
+    * @throws Exception
+    */
+   protected Object invoke(ObjectName name, String method, Object[] args,
+      String[] sig)
+      throws Exception
+   {
+      MBeanServerConnection[] adaptors = getAdaptors();
+
+      Object result = null;
+      for (int i = 0; i < adaptors.length; i++)
+      {
+         MBeanServerConnection adaptor = adaptors[i];
+         log.debug("Using MBeanServerConnection: "+adaptor);
+         result = invoke(adaptor, name, method, args, sig);
+      }
+
+      return result;
+
+   }
+
+   public void init() throws Exception
+   {
+      super.init();
+      
+      if (initialContext == null)
+      {
+         initialContext = new InitialContext();
+      }
+      if (adaptors == null)
+      {
+         adaptors = new ArrayList();
+         servers = new ArrayList();
+         namingURLs = new ArrayList();
+         namingURLsHA = new ArrayList();
+         httpURLs = new ArrayList();
+         String adaptorName = System.getProperty("jbosstest.server.name");
+         if (adaptorName == null)
+            adaptorName = "jmx/invoker/RMIAdaptor";
+
+         Hashtable env = new Hashtable();
+         env.put("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
+         env.put("java.naming.factory.url.pkgs", "org.jnp.interfaces");
+
+         // Look for jbosstest.cluster.nodeN properties for the server names
+         String node = "jbosstest.cluster.node";
+         int count = 0;
+         while (count < 10)
+         {
+            String prop = node + count;
+            String host = System.getProperty(prop);
+            count++;
+            if (host == null)
+               break;
+            log.info(prop + " = " + host);
+            servers.add(host);
+            // See if there is a jbosstest.cluster.nodeN.jndi.url
+            String urlProp = prop + ".jndi.url";
+            String urlDefault = "jnp://" + host + ":1099";
+            String urlValue = System.getProperty(urlProp, urlDefault);
+            log.debug("JNDI Url for node=" + count + " is:" + urlValue);
+            namingURLs.add(urlValue);
+            env.put("java.naming.provider.url", urlValue);
+            // Lookup the adaptor
+            InitialContext tmpCtx = new InitialContext(env);
+            MBeanServerConnection adaptor = (MBeanServerConnection) tmpCtx.lookup(adaptorName);
+            adaptors.add(adaptor);
+
+            // See if there is a jbosstest.cluster.nodeN.hajndi.url
+            urlProp = prop + ".hajndi.url";
+            urlDefault = "jnp://" + host + ":1100";
+            urlValue = System.getProperty(urlProp, urlDefault);
+            log.debug("HA-JNDI Url for node=" + count + " is:" + urlValue);
+            namingURLsHA.add(urlValue);
+            
+            // See if there is a jbosstest.cluster.nodeN.http.url
+            urlProp = prop + ".http.url";
+            urlDefault = "http://" + host + ":8080";
+            urlValue = System.getProperty(urlProp, urlDefault);
+            log.debug("Http Url for node=" + count + " is:" + urlValue);
+            httpURLs.add(urlValue);
+         }
+
+         if (adaptors.size() == 0)
+            throw new IllegalStateException("No jbosstest.cluster.node values found");
+      }
+   }
+
+   /**
+    * This method gives overriding testcases to set the cluster servernames
+    */
+   public void setServerNames(String[] snames)
+   {
+      if (snames == null) return;
+      for (int i = 0; i < snames.length; i++)
+      {
+         servers.add(snames[i]);
+      }
+   }
+
+}

Copied: projects/test/trunk/src/main/java/org/jboss/test/JBossTestClusteredSetup.java (from rev 65057, trunk/testsuite/src/main/org/jboss/test/JBossTestClusteredSetup.java)
===================================================================
--- projects/test/trunk/src/main/java/org/jboss/test/JBossTestClusteredSetup.java	                        (rev 0)
+++ projects/test/trunk/src/main/java/org/jboss/test/JBossTestClusteredSetup.java	2007-09-04 20:16:30 UTC (rev 65064)
@@ -0,0 +1,141 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+package org.jboss.test;
+
+import java.util.StringTokenizer;
+
+import junit.framework.Test;
+
+/**
+ * Derived implementation of JBossTestSetup for cluster testing.
+ *
+ * @see org.jboss.test.JBossTestSetup
+ *
+ * @author  <a href="mailto:sacha.labourey at cogito-info.ch">Sacha Labourey</a>.
+ * @version $Revision$
+ *
+ * <p><b>Revisions:</b>
+ *
+ * <p><b>12 avril 2002 Sacha Labourey:</b>
+ * <ul>
+ * <li> First implementation </li>
+ * </ul>
+ */
+
+public class JBossTestClusteredSetup extends JBossTestSetup
+{
+   
+   // Constants -----------------------------------------------------
+   
+   // Attributes ----------------------------------------------------
+   
+   private String jarNames;
+   // Static --------------------------------------------------------
+   
+   // Constructors --------------------------------------------------
+   
+   public JBossTestClusteredSetup(Test test, String jarNames) throws Exception
+   {
+      super(JBossClusteredTestCase.class, test);
+      this.jarNames = jarNames;
+   }
+   
+   
+   // Public --------------------------------------------------------
+   
+   // Z implementation ----------------------------------------------
+   
+   // Y overrides ---------------------------------------------------
+   
+   // Package protected ---------------------------------------------
+   
+   // Protected -----------------------------------------------------
+   
+   protected JBossTestServices createTestServices()
+   {
+      return new JBossTestClusteredServices(getClass());
+   }
+   
+   protected void setUp() throws Exception
+   {      
+      super.setUp();
+      
+      if (jarNames == null) return;
+      JBossTestCase.deploymentException = null;
+      try
+      {
+         // deploy the comma seperated list of jars
+         StringTokenizer st = new StringTokenizer(jarNames, ", ");
+         while (st != null && st.hasMoreTokens())
+         {
+            String jarName = st.nextToken();
+            this.redeploy(jarName);
+            this.getLog().debug("deployed package: " + jarName);
+         }
+      }
+      catch (Exception ex)
+      {
+         // Throw this in testServerFound() instead.
+         JBossTestCase.deploymentException = ex;
+      }
+          
+      // wait a few seconds so that the cluster stabilize
+      synchronized (this)
+      {
+         wait(2000);
+      }
+   }
+
+   protected void tearDown() throws Exception
+   {
+      try
+      {
+         if (jarNames != null)
+         {
+            // deploy the comma seperated list of jars
+            StringTokenizer st = new StringTokenizer(jarNames, ", ");
+            String[] depoyments = new String[st.countTokens()];
+            for (int i = depoyments.length - 1; i >= 0; i--)
+               depoyments[i] = st.nextToken();
+            for (int i = 0; i < depoyments.length; i++)
+            {
+               String jarName = depoyments[i];
+               this.getLog().debug("Attempt undeploy of " + jarName);
+               this.undeploy(jarName);
+               this.getLog().debug("undeployed package: " + jarName);
+            }            
+         }
+         super.tearDown();
+      }
+      finally
+      {
+         AbstractTestSetup.delegate = null;
+      }
+     
+   }
+   
+
+   // Private -------------------------------------------------------
+   
+   // Inner classes -------------------------------------------------
+   
+}




More information about the jboss-cvs-commits mailing list