[jboss-cvs] JBossAS SVN: r61875 - in branches/Branch_4_0/testsuite/src/main/org/jboss/test: ha/singleton and 1 other directory.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu Mar 29 21:45:00 EDT 2007
Author: bstansberry at jboss.com
Date: 2007-03-29 21:45:00 -0400 (Thu, 29 Mar 2007)
New Revision: 61875
Modified:
branches/Branch_4_0/testsuite/src/main/org/jboss/test/cluster/test/DRMTestCase.java
branches/Branch_4_0/testsuite/src/main/org/jboss/test/ha/singleton/HASingletonSupportTester.java
Log:
[JBAS-4262] Port JBAS-4229 fix to Branch_4_0
Modified: branches/Branch_4_0/testsuite/src/main/org/jboss/test/cluster/test/DRMTestCase.java
===================================================================
--- branches/Branch_4_0/testsuite/src/main/org/jboss/test/cluster/test/DRMTestCase.java 2007-03-30 01:44:09 UTC (rev 61874)
+++ branches/Branch_4_0/testsuite/src/main/org/jboss/test/cluster/test/DRMTestCase.java 2007-03-30 01:45:00 UTC (rev 61875)
@@ -42,6 +42,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;
@@ -485,6 +486,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;
@@ -1189,6 +1201,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_0/testsuite/src/main/org/jboss/test/ha/singleton/HASingletonSupportTester.java
===================================================================
--- branches/Branch_4_0/testsuite/src/main/org/jboss/test/ha/singleton/HASingletonSupportTester.java 2007-03-30 01:44:09 UTC (rev 61874)
+++ branches/Branch_4_0/testsuite/src/main/org/jboss/test/ha/singleton/HASingletonSupportTester.java 2007-03-30 01:45:00 UTC (rev 61875)
@@ -94,8 +94,13 @@
__invokationStack__.push("makeThisNodeMaster");
super.makeThisNodeMaster();
}
+
+ protected void restartMaster()
+ {
+ __invokationStack__.push("restartMaster");
+ super.restartMaster();
+ }
-
public void sendNotification(Notification notification)
{
return;
More information about the jboss-cvs-commits
mailing list