[jboss-cvs] JBossAS SVN: r61771 - in branches/Branch_4_2/testsuite/src/main/org/jboss/test: ha/singleton and 1 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Mar 27 22:57:24 EDT 2007


Author: bstansberry at jboss.com
Date: 2007-03-27 22:57:23 -0400 (Tue, 27 Mar 2007)
New Revision: 61771

Modified:
   branches/Branch_4_2/testsuite/src/main/org/jboss/test/cluster/test/DRMTestCase.java
   branches/Branch_4_2/testsuite/src/main/org/jboss/test/ha/singleton/HASingletonSupportTester.java
   branches/Branch_4_2/testsuite/src/main/org/jboss/test/ha/singleton/test/HASingletonSupportUnitTestCase.java
Log:
[JBAS-4229] Restart singleton following cluster merge

Modified: branches/Branch_4_2/testsuite/src/main/org/jboss/test/cluster/test/DRMTestCase.java
===================================================================
--- branches/Branch_4_2/testsuite/src/main/org/jboss/test/cluster/test/DRMTestCase.java	2007-03-28 02:42:24 UTC (rev 61770)
+++ branches/Branch_4_2/testsuite/src/main/org/jboss/test/cluster/test/DRMTestCase.java	2007-03-28 02:57:23 UTC (rev 61771)
@@ -43,6 +43,7 @@
 import org.jboss.test.JBossClusteredTestCase;
 import org.jboss.test.cluster.drm.IReplicants;
 import org.jboss.test.cluster.drm.MockHAPartition;
+import org.jboss.ha.framework.interfaces.ClusterMergeStatus;
 import org.jboss.ha.framework.interfaces.ClusterNode;
 import org.jboss.ha.framework.interfaces.DistributedReplicantManager;
 import org.jboss.ha.framework.interfaces.DistributedReplicantManager.ReplicantListener;
@@ -504,6 +505,17 @@
       }
       
    }
+   
+   static class ClusterMergeStatusListener implements ReplicantListener
+   {
+      boolean wasMergeInProcess;
+      
+      public void replicantsChanged(String key, List newReplicants, 
+            int newReplicantsViewId)
+      {
+         wasMergeInProcess = ClusterMergeStatus.isMergeInProcess();
+      }
+   }
 
    private static Object lock = new Object();
    private static int LOOP_COUNT = 30;
@@ -1242,6 +1254,140 @@
       }
    }
    
+   /**
+    * JBAS-4229. Tests that the ClusterMergeStatus thread
+    * local is properly set.
+    * 
+    * @throws Exception
+    */
+   public void testClusterMergeStatus() throws Exception
+   {
+      log.debug("+++ testClusterMergeStatus()");
+      
+      MBeanServer mbeanServer = 
+         MBeanServerFactory.createMBeanServer("mockPartition");
+      try {
+         ClusterNode localAddress = new ClusterNode(new IpAddress("127.0.0.1", 12345));
+         MockHAPartition partition = new MockHAPartition(localAddress);
+      
+         DistributedReplicantManagerImpl drm = 
+               new DistributedReplicantManagerImpl(partition, mbeanServer);
+
+         drm.init();
+         
+         // Create a fake view for the MockHAPartition
+         
+         Vector remoteAddresses = new Vector();
+         for (int i = 1; i < 5; i++)
+            remoteAddresses.add(new ClusterNode(new IpAddress("127.0.0.1", 12340 + i)));
+         
+         Vector allNodes = new Vector(remoteAddresses);
+         allNodes.add(localAddress);
+         partition.setCurrentViewClusterNodes(allNodes);
+         
+         // Pass fake state to DRMImpl
+      
+         HashMap replicants = new HashMap();
+         ArrayList remoteResponses = new ArrayList();
+         for (int i = 0; i < remoteAddresses.size(); i++)
+         {
+            ClusterNode node = (ClusterNode) remoteAddresses.elementAt(i);
+            Integer replicant = new Integer(i + 1);
+            replicants.put(node.getName(), replicant);
+            HashMap localReplicant = new HashMap();
+            localReplicant.put("Mock", replicant);
+            remoteResponses.add(new Object[] {node.getName(), localReplicant});
+         }
+         HashMap services = new HashMap();
+         services.put("Mock", replicants);
+         
+         int hash = 0;
+         for (int i = 1; i < 5; i++)
+            hash += (new Integer(i)).hashCode();
+         
+         HashMap intraviewIds = new HashMap();
+         intraviewIds.put("Mock", new Integer(hash));
+      
+         partition.setRemoteReplicants(remoteResponses);
+         
+         drm.setCurrentState(new Object[] {services, intraviewIds });
+         
+         drm.start();
+         
+         // add a local replicant
+         ClusterMergeStatusListener listener = new ClusterMergeStatusListener();
+         drm.registerListener("Mock", listener);
+         
+         drm.add("Mock", new Integer(5));
+         
+         // Should not have been treated as a merge
+         assertFalse("Adding ourself did not imply a merge", listener.wasMergeInProcess);
+         
+         // test that this node is not the master replica         
+         assertFalse("Local node is not master after startup", 
+                     drm.isMasterReplica("Mock")); 
+      
+         // simulate a split where this node is the coord
+         
+         Vector localOnly = new Vector();
+         localOnly.add(localAddress);
+         
+         partition.setCurrentViewClusterNodes(localOnly);
+         partition.setRemoteReplicants(new ArrayList());
+         
+         drm.membershipChanged(remoteAddresses, new Vector(), localOnly);
+         
+         // Should not have been treated as a merge
+         assertFalse("Normal view change did not imply a merge", listener.wasMergeInProcess);
+         
+         // test that this node is the master replica         
+         assertTrue("Local node is master after split", drm.isMasterReplica("Mock"));
+         
+         // Remove our local replicant
+         
+         drm.remove("Mock");
+         
+         // Should not have been treated as a merge
+         assertFalse("Removing ourself did not imply a merge", listener.wasMergeInProcess);
+         
+         // test that this node is not the master replica         
+         assertFalse("Local node is not master after dropping replicant", 
+                     drm.isMasterReplica("Mock"));
+         
+         // Restore the local replicant 
+         
+         drm.add("Mock", new Integer(5));
+         
+         // Should not have been treated as a merge
+         assertFalse("Re-adding ourself did not imply a merge", listener.wasMergeInProcess);
+         
+         // simulate a merge
+         
+         Vector mergeGroups = new Vector();
+         mergeGroups.add(remoteAddresses);
+         mergeGroups.add(localOnly);
+         
+         partition.setCurrentViewClusterNodes(allNodes);
+         partition.setRemoteReplicants(remoteResponses);
+         
+         drm.membershipChangedDuringMerge(new Vector(), remoteAddresses, 
+                                          allNodes, mergeGroups);         
+         
+         // Merge processing is done asynchronously, so pause a bit
+         sleepThread(100);
+         
+         // Should have been treated as a merge
+         assertTrue("Merge status was propagated", listener.wasMergeInProcess);
+         
+         // test that this node is not the master replica
+         assertFalse("Local node is not master after merge", 
+                     drm.isMasterReplica("Mock")); 
+      }
+      finally {
+         MBeanServerFactory.releaseMBeanServer(mbeanServer);
+      }
+   }
+   
    private void confirmReplicantList(List current, Object[] all, boolean[] added)
    {
       Iterator iter = current.iterator();

Modified: branches/Branch_4_2/testsuite/src/main/org/jboss/test/ha/singleton/HASingletonSupportTester.java
===================================================================
--- branches/Branch_4_2/testsuite/src/main/org/jboss/test/ha/singleton/HASingletonSupportTester.java	2007-03-28 02:42:24 UTC (rev 61770)
+++ branches/Branch_4_2/testsuite/src/main/org/jboss/test/ha/singleton/HASingletonSupportTester.java	2007-03-28 02:57:23 UTC (rev 61771)
@@ -94,8 +94,14 @@
     __invokationStack__.push("makeThisNodeMaster");
     super.makeThisNodeMaster();
   }
+  
+  @Override
+  protected void restartMaster()
+  {
+     __invokationStack__.push("restartMaster");
+     super.restartMaster();
+  }
 
-
   public void sendNotification(Notification notification)
   {
     return;

Modified: branches/Branch_4_2/testsuite/src/main/org/jboss/test/ha/singleton/test/HASingletonSupportUnitTestCase.java
===================================================================
--- branches/Branch_4_2/testsuite/src/main/org/jboss/test/ha/singleton/test/HASingletonSupportUnitTestCase.java	2007-03-28 02:42:24 UTC (rev 61770)
+++ branches/Branch_4_2/testsuite/src/main/org/jboss/test/ha/singleton/test/HASingletonSupportUnitTestCase.java	2007-03-28 02:57:23 UTC (rev 61771)
@@ -25,6 +25,7 @@
 
 import junit.framework.TestCase;
 
+import org.jboss.ha.framework.interfaces.ClusterMergeStatus;
 import org.jboss.test.ha.singleton.HASingletonSupportTester;
 
 /**
@@ -46,11 +47,17 @@
   public void setUp()
   {
     singletonSupportTester = new HASingletonSupportTester();
+    // We want to port this test from 4.2 to CP releases where 
+    // the default for restartOnMerge will be false; so set
+    // the property to the 4.2 default, allowing the remaining
+    // tests to go unchanged yet still run as they do in 4.2
+    singletonSupportTester.setRestartOnMerge(true);
   }
   
   public void tearDown() 
   {
     singletonSupportTester = null;
+    ClusterMergeStatus.endMergeProcess();
   }
   
   public void testStartService() throws Exception
@@ -144,11 +151,161 @@
     // since the only node (this one) in the partition is now removed, the replicants list should be empty 
     singletonSupportTester.partitionTopologyChanged(new ArrayList(0), 1);
     
-    assertTrue("expected to have made a call to _stopOldMater(), thus become slave", !singletonSupportTester.isMasterNode() );
+    assertTrue("expected to have made a call to _stopOldMaster(), thus become slave", !singletonSupportTester.isMasterNode() );
     
     assertEquals("method not invoked as expected",
       singletonSupportTester.__invokationStack__.pop(), "stopSingleton");  
       
   }
   
+  public void testStartServiceWithRestartOff() throws Exception
+  {
+     singletonSupportTester.setRestartOnMerge(false);
+     testStartService();
+  }
+
+  public void testStopServiceWithRestartOff() throws Exception
+  {
+     singletonSupportTester.setRestartOnMerge(false);
+     testStopService();
+  }
+  
+  public void testBecomeMasterNodeWithRestartOff() throws Exception
+  {
+    singletonSupportTester.setRestartOnMerge(false);
+    testBecomeMasterNode();     
+  }
+  
+  public void testBecomeSlaveNodeWithAnotherMasterWithRestartOff() throws Exception
+  {
+     singletonSupportTester.setRestartOnMerge(false);
+     testBecomeSlaveNodeWithAnotherMaster();
+  }
+  
+  public void testStartServiceWithBogusRestart() throws Exception
+  {
+     try
+     {
+        ClusterMergeStatus.startMergeProcess();
+        testStartService();
+     }
+     finally
+     {
+        ClusterMergeStatus.endMergeProcess();
+     }
+  }
+  
+  public void testStopServiceWithBogusRestart() throws Exception
+  {
+     try
+     {
+        ClusterMergeStatus.startMergeProcess();
+        testStopService();
+     }
+     finally
+     {
+        ClusterMergeStatus.endMergeProcess();
+     }
+  }
+  
+  public void testBecomeMasterNodeDuringMerge() throws Exception
+  {  
+     try
+     {
+        ClusterMergeStatus.startMergeProcess();
+        testBecomeMasterNode();
+     }
+     finally
+     {
+        ClusterMergeStatus.endMergeProcess();
+     }     
+  }
+  
+  public void testMasterRestartDuringMerge() throws Exception
+  {
+     // Just run the BecomeMaster test to get ourself set up as master
+     testBecomeMasterNode();
+     
+     // Drain off any un-popped events
+     singletonSupportTester.__invokationStack__.clear();
+     
+     try
+     {
+        ClusterMergeStatus.startMergeProcess();
+        singletonSupportTester.partitionTopologyChanged( new ArrayList(3), 2);
+     }
+     finally
+     {
+        ClusterMergeStatus.endMergeProcess();
+     }
+
+     // test whether it's still master    
+     assertTrue("expected to remain master", singletonSupportTester.isMasterNode());
+     
+     // test whether the election sequence was followed correctly  
+     assertEquals("method not invoked as expected",
+           "startSingleton", singletonSupportTester.__invokationStack__.pop());  
+     assertEquals("method not invoked as expected",
+           "stopSingleton", singletonSupportTester.__invokationStack__.pop());
+     assertEquals("method not invoked as expected",
+           "restartMaster", singletonSupportTester.__invokationStack__.pop());
+  }
+  
+  public void testBecomeSlaveNodeWithAnotherMasterDuringMerge() throws Exception
+  {
+     // Just run the BecomeMaster test to get ourself set up as master
+     testBecomeMasterNode();
+     
+     // Drain off any un-popped events
+     singletonSupportTester.__invokationStack__.clear();
+     
+     singletonSupportTester.__isDRMMasterReplica__ = false;
+     try
+     {
+        ClusterMergeStatus.startMergeProcess();
+        singletonSupportTester.partitionTopologyChanged( new ArrayList(3), 2);
+     }
+     finally
+     {
+        ClusterMergeStatus.endMergeProcess();
+     }
+     
+     // now it should be slave
+     assertFalse("expected to be slave", singletonSupportTester.isMasterNode());
+     
+     assertEquals("this node was the old master, but method not invoked as expected",
+         singletonSupportTester.__invokationStack__.pop(), "stopSingleton");     
+  }
+
+  
+  public void testMasterRestartDuringMergeWithRestartOff() throws Exception
+  {
+     singletonSupportTester.setRestartOnMerge(false);
+     
+     // Just run the BecomeMaster test to get ourself set up as master
+     testBecomeMasterNode();
+     
+     // Drain off any un-popped events
+     singletonSupportTester.__invokationStack__.clear();
+     
+     try
+     {
+        ClusterMergeStatus.startMergeProcess();
+        singletonSupportTester.partitionTopologyChanged( new ArrayList(3), 2);
+     }
+     finally
+     {
+        ClusterMergeStatus.endMergeProcess();
+     }
+
+     // test whether it's still master    
+     assertTrue("expected to remain master", singletonSupportTester.isMasterNode());
+     
+     // test whether the election sequence was followed correctly   
+     assertEquals("method not invoked as expected",
+           "isDRMMasterReplica", singletonSupportTester.__invokationStack__.pop());  
+     assertEquals("method not invoked as expected",
+                  0, singletonSupportTester.__invokationStack__.size()); 
+  }
+  
 }




More information about the jboss-cvs-commits mailing list