[jboss-cvs] JBossAS SVN: r82018 - trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/test.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Dec 3 15:34:41 EST 2008


Author: bstansberry at jboss.com
Date: 2008-12-03 15:34:41 -0500 (Wed, 03 Dec 2008)
New Revision: 82018

Modified:
   trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/test/HASingletonControllerBeanUnitTestCase.java
   trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/test/HASingletonDeployerTestCase.java
Log:
[JBAS-6279] Remove assumption about who master is from HA Singleton test cases

Modified: trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/test/HASingletonControllerBeanUnitTestCase.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/test/HASingletonControllerBeanUnitTestCase.java	2008-12-03 19:35:24 UTC (rev 82017)
+++ trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/test/HASingletonControllerBeanUnitTestCase.java	2008-12-03 20:34:41 UTC (rev 82018)
@@ -23,6 +23,8 @@
 
 import java.util.Properties;
 
+import javax.management.MBeanServerConnection;
+import javax.management.ObjectName;
 import javax.naming.Context;
 import javax.naming.InitialContext;
 import javax.naming.NamingException;
@@ -39,6 +41,8 @@
  */
 public class HASingletonControllerBeanUnitTestCase extends JBossClusteredTestCase
 {
+   public static final String SINGLETON_CONTROLLER_ONAME = "jboss.ha:service=TestHASingletonControllerBean";
+   
    public HASingletonControllerBeanUnitTestCase(String name)
    {
       super(name);      
@@ -51,19 +55,25 @@
 
    public void testBeanDeployment() throws Exception
    {
+      // JBAS-6279. Figure out who the master really is
+      MBeanServerConnection[] adaptors = getAdaptors();
+      boolean node0Master = isMaster(adaptors[0]);
+      assertFalse(node0Master == isMaster(adaptors[1]));
+      int masterIndex = node0Master ? 0 : 1;
+      int nonMasterIndex = node0Master ? 1 : 0;
       Properties env = new Properties();
       env.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
 
       String[] namingUrls = getNamingURLs();
       
-      String namingUrl = namingUrls[0];
+      String namingUrl = namingUrls[masterIndex];
       env.setProperty(Context.PROVIDER_URL, namingUrl);
       Context ctx = new InitialContext(env);
       HASingletonPojoExample pojo = (HASingletonPojoExample)ctx.lookup("test/cluster/hasingleton/simplepojo");
       
       assertTrue("Pojo in " + namingUrl + " should be deployed as HA singleton", pojo.isMasterNode());
       
-      namingUrl = namingUrls[1];
+      namingUrl = namingUrls[nonMasterIndex];
       env.setProperty(Context.PROVIDER_URL, namingUrl);
       ctx = new InitialContext(env);
       try
@@ -76,4 +86,17 @@
       }      
    }
    
+   private boolean isMaster(MBeanServerConnection server)
+   {
+      try
+      {
+         ObjectName oname = new ObjectName(SINGLETON_CONTROLLER_ONAME);
+         return ((Boolean) server.invoke(oname, "isMasterNode", new Object[]{}, new String[]{})).booleanValue();
+      }
+      catch (Exception e)
+      {
+         throw new RuntimeException(e);
+      }
+   }
+   
 }

Modified: trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/test/HASingletonDeployerTestCase.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/test/HASingletonDeployerTestCase.java	2008-12-03 19:35:24 UTC (rev 82017)
+++ trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/test/HASingletonDeployerTestCase.java	2008-12-03 20:34:41 UTC (rev 82018)
@@ -35,6 +35,7 @@
  */
 public class HASingletonDeployerTestCase extends JBossClusteredTestCase
 {
+   public static final String SINGLETON_DEPLOYER_ONAME = "jboss.ha:service=TestHASingletonDeployer";
    public static final String SINGLETON_DEPLOYMENT = "jboss.system:service=HASingletonTestThreadPool";
    public static final String SINGLETON_DEPLOYER = "test-deploy-hasingleton-jboss-beans.xml";
    
@@ -57,18 +58,23 @@
    {
       MBeanServerConnection[] adaptors = getAdaptors();
       
-      assertTrue(isDeployed(SINGLETON_DEPLOYMENT, adaptors[0]));
-      assertFalse(isDeployed(SINGLETON_DEPLOYMENT, adaptors[1]));
+      boolean node0Master = isMaster(adaptors[0]);
+      assertFalse(node0Master == isMaster(adaptors[1]));
+      int origMasterIndex = node0Master ? 0 : 1;
+      int origNonMasterIndex = node0Master ? 1 : 0;
       
-      undeploy(adaptors[0], SINGLETON_DEPLOYER);
+      assertTrue("singleton is not deployed on node " + origMasterIndex, isDeployed(SINGLETON_DEPLOYMENT, adaptors[origMasterIndex]));
+      assertFalse("singleton is deployed on node " + origNonMasterIndex, isDeployed(SINGLETON_DEPLOYMENT, adaptors[origNonMasterIndex]));
       
+      undeploy(adaptors[origMasterIndex], SINGLETON_DEPLOYER);
+      
       // The singleton is triggered asynchronously, so give it time to work
       sleep(1000);
       
-      assertTrue(isDeployed(SINGLETON_DEPLOYMENT, adaptors[1]));
-      assertFalse(isDeployed(SINGLETON_DEPLOYMENT, adaptors[0]));
+      assertTrue(isDeployed(SINGLETON_DEPLOYMENT, adaptors[origNonMasterIndex]));
+      assertFalse(isDeployed(SINGLETON_DEPLOYMENT, adaptors[origMasterIndex]));
       
-      undeploy(adaptors[1], SINGLETON_DEPLOYER);
+      undeploy(adaptors[origNonMasterIndex], SINGLETON_DEPLOYER);
       
       sleep(1000);
       
@@ -87,13 +93,26 @@
       sleep(1000);
       
       // per policy, node0 takes over as master
-      assertTrue(isDeployed(SINGLETON_DEPLOYMENT, adaptors[0]));
-      assertFalse(isDeployed(SINGLETON_DEPLOYMENT, adaptors[1]));
+      assertTrue(isDeployed(SINGLETON_DEPLOYMENT, adaptors[origMasterIndex]));
+      assertFalse(isDeployed(SINGLETON_DEPLOYMENT, adaptors[origNonMasterIndex]));
    }
    
    protected boolean isDeployed(String deployment, MBeanServerConnection server) throws Exception
    {
       return server.isRegistered(new ObjectName(deployment));
    }
+   
+   private boolean isMaster(MBeanServerConnection server)
+   {
+      try
+      {
+         ObjectName oname = new ObjectName(SINGLETON_DEPLOYER_ONAME);
+         return ((Boolean) server.invoke(oname, "isMasterNode", new Object[]{}, new String[]{})).booleanValue();
+      }
+      catch (Exception e)
+      {
+         throw new RuntimeException(e);
+      }
+   }
 
 }




More information about the jboss-cvs-commits mailing list