User: slaboure
  Date: 02/04/13 08:24:58

  Added:       src/main/org/jboss/test JBossClusteredTestCase.java
                        JBossTestClusteredServices.java
                        JBossTestClusteredSetup.java
  Log:
  Extended test environment for clustering testing
  
  Revision  Changes    Path
  1.1                  jbosstest/src/main/org/jboss/test/JBossClusteredTestCase.java
  
  Index: JBossClusteredTestCase.java
  ===================================================================
  /*
   * JBoss, the OpenSource J2EE webOS
   *
   * Distributable under LGPL license.
   * See terms of license at gnu.org.
   */
  
  package org.jboss.test;
  
  import org.jboss.jmx.adaptor.rmi.RMIAdaptor;
  
  import junit.framework.Test;
  import junit.framework.TestSuite;
  
  /**
   * Derived implementation of JBossTestCase for cluster testing.
   *
   * @see org.jboss.test.JBossTestCase
   *
   * @author  <a href="mailto:[EMAIL PROTECTED]";>Sacha Labourey</a>.
   * @version $Revision: 1.1 $
   *
   * <p><b>Revisions:</b>
   *
   * <p><b>12 avril 2002 Sacha Labourey:</b>
   * <ul>
   * <li> First implementation </li>
   * </ul>
   */
  
  public class JBossClusteredTestCase extends JBossTestCase
  {
     
     // Constants -----------------------------------------------------
     
     // Attributes ----------------------------------------------------
     
     // Static --------------------------------------------------------
     
     // Constructors --------------------------------------------------
     
     public JBossClusteredTestCase(String name)
     {
        super (name);
     }
     
     public void initDelegate ()
     {
        delegate = new JBossTestClusteredServices(getClass().getName());
     }
     
     // Public --------------------------------------------------------
     
     public void testServerFound() throws Exception
     {
        if (deploymentException != null)
           throw deploymentException;
        assertTrue("Server was not found", getServers() != null);
     }
  
     // Z implementation ----------------------------------------------
     
     // Y overrides ---------------------------------------------------
     
     // Package protected ---------------------------------------------
     
     // Protected -----------------------------------------------------
     
     protected RMIAdaptor[] getServers() throws Exception
     {
        return ((JBossTestClusteredServices)delegate).getServers();
     }
  
     public static Test getDeploySetup(final Test test, final String jarName) throws 
Exception
     {
        JBossTestSetup wrapper = new JBossTestClusteredSetup(test)
           {
  
               protected void setUp() throws Exception
               {
                  deploymentException = null;
                  try {
                     this.deploy(jarName);
                     this.getLog().debug("deployed package: " + jarName);
                  } catch (Exception ex) {
                     // Throw this in testServerFound() instead.
                     deploymentException = ex;
                  }
               }
  
               protected void tearDown() throws Exception
               {
                  this.undeploy(jarName);
                  this.getLog().debug("undeployed package: " + jarName);
               }
            };
        return wrapper;
     }
  
     public static Test getDeploySetup(final Class clazz, final String jarName) throws 
Exception
     {
        TestSuite suite = new TestSuite();  
        suite.addTest(new TestSuite(clazz));
        return getDeploySetup(suite, jarName);
     }
  
     // Private -------------------------------------------------------
     
     // Inner classes -------------------------------------------------
     
  }
  
  
  
  1.1                  
jbosstest/src/main/org/jboss/test/JBossTestClusteredServices.java
  
  Index: JBossTestClusteredServices.java
  ===================================================================
  /*
   * JBoss, the OpenSource J2EE webOS
   *
   * Distributable under LGPL license.
   * See terms of license at gnu.org.
   */
  
  package org.jboss.test;
  
  
  import java.util.Vector;
  import java.util.Hashtable;
  import java.net.InetAddress;
  
  import javax.management.ObjectName;
  import javax.naming.InitialContext;
  
  import org.jboss.jmx.adaptor.rmi.RMIAdaptor;
  
  /**
   * Derived implementation of JBossTestServices for cluster testing.
   *
   * @see org.jboss.test.JBossTestServices
   *
   * @author  <a href="mailto:[EMAIL PROTECTED]";>Sacha Labourey</a>.
   * @version $Revision: 1.1 $
   *
   * <p><b>Revisions:</b>
   *
   * <p><b>12 avril 2002 Sacha Labourey:</b>
   * <ul>
   * <li> First implementation </li>
   * </ul>
   */
  
  public class JBossTestClusteredServices extends JBossTestServices
  {
     
     // Constants -----------------------------------------------------
     
     // Attributes ----------------------------------------------------
     
     protected RMIAdaptor[] servers = null;
     
     // Static --------------------------------------------------------
     
     protected static String[] serverNames = {"jnp://localhost:1099", 
"jnp://localhost:11099"};
     protected static Hashtable[] targets = null;
     
     static 
     {
        // UGLY (but a good start...)
        Hashtable defProps = new Hashtable ();
        defProps.put ("java.naming.factory.initial", 
"org.jnp.interfaces.NamingContextFactory");
        defProps.put ("java.naming.factory.url.pkgs", "org.jnp.interfaces");
        
        Vector tgs = new Vector (serverNames.length);
        
        for (int i=0; i<serverNames.length; i++)
        {
           java.util.Hashtable aServer = (java.util.Hashtable)defProps.clone();
           aServer.put ("java.naming.provider.url", serverNames[i]);
           tgs.add (aServer);         
        }
        
        targets = new java.util.Hashtable[serverNames.length]; 
        targets = (java.util.Hashtable[])tgs.toArray (targets);
     }
     
     // Constructors --------------------------------------------------
     
     public JBossTestClusteredServices(String className)
     {
        super (className);
     }
     
     // Public --------------------------------------------------------
     
     // Z implementation ----------------------------------------------
     
     // Y overrides ---------------------------------------------------
     
     // Package protected ---------------------------------------------
     
     // Protected -----------------------------------------------------
     
     RMIAdaptor[] getServers () throws Exception
     {
        init();
        return servers;
     }
     
     protected Object invoke (ObjectName name, String method, Object[] args, String[] 
sig) throws Exception
     {
        System.out.println("in invoke!!");
        RMIAdaptor[] servers = getServers();
        
        Object result = null;
        for (int i=0; i<servers.length; i++)
        {
           result = invoke (servers[i], name, method, args, sig);
        }
        
        return result;
        
     }
     
     protected void init() throws Exception
     {
        if (initialContext == null)
        {
           initialContext = new InitialContext();
        }
        if (servers == null)
        {         
           String serverName = System.getProperty("jbosstest.server.name");
           if (serverName == null)
           {
              serverName = InetAddress.getLocalHost().getHostName();
           }
           
           java.util.Vector servList = new java.util.Vector (targets.length);
           for (int i=0; i<targets.length; i++)
           {
              InitialContext tmpCtx = new InitialContext (targets[i]);
              servList.add (tmpCtx.lookup ("jmx:" + serverName + ":rmi"));            
           }
           
           servers = new RMIAdaptor[targets.length]; 
           servers = (RMIAdaptor[])servList.toArray (servers);
        }
     }
  
     // Private -------------------------------------------------------
     
     // Inner classes -------------------------------------------------
     
  }
  
  
  
  1.1                  jbosstest/src/main/org/jboss/test/JBossTestClusteredSetup.java
  
  Index: JBossTestClusteredSetup.java
  ===================================================================
  /*
   * JBoss, the OpenSource J2EE webOS
   *
   * Distributable under LGPL license.
   * See terms of license at gnu.org.
   */
  
  package org.jboss.test;
  
  import junit.framework.Test;
  
  /**
   * Derived implementation of JBossTestSetup for cluster testing.
   *
   * @see org.jboss.test.JBossTestSetup
   *
   * @author  <a href="mailto:[EMAIL PROTECTED]";>Sacha Labourey</a>.
   * @version $Revision: 1.1 $
   *
   * <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 ----------------------------------------------------
     
     // Static --------------------------------------------------------
     
     // Constructors --------------------------------------------------
     
     public JBossTestClusteredSetup(Test test)
     {
        super(test);
     }
     
     
     // Public --------------------------------------------------------
     
     // Z implementation ----------------------------------------------
     
     // Y overrides ---------------------------------------------------
     
     // Package protected ---------------------------------------------
     
     // Protected -----------------------------------------------------
     
     protected JBossTestServices createTestServices()
     {
        return new JBossTestClusteredServices(getClass().getName());
     }
  
     // Private -------------------------------------------------------
     
     // Inner classes -------------------------------------------------
     
  }
  
  
  

_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development

Reply via email to