[jboss-cvs] JBossAS SVN: r62672 - in branches/JBoss_4_0_4_GA_CP/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
Mon Apr 30 18:34:51 EDT 2007
Author: bstansberry at jboss.com
Date: 2007-04-30 18:34:51 -0400 (Mon, 30 Apr 2007)
New Revision: 62672
Modified:
branches/JBoss_4_0_4_GA_CP/testsuite/src/main/org/jboss/test/cluster/test/DRMTestCase.java
branches/JBoss_4_0_4_GA_CP/testsuite/src/main/org/jboss/test/ha/singleton/HASingletonSupportTester.java
branches/JBoss_4_0_4_GA_CP/testsuite/src/main/org/jboss/test/ha/singleton/test/HASingletonSupportUnitTestCase.java
Log:
[ASPATCH-209] Support restart of HASingleton on cluster merge
Modified: branches/JBoss_4_0_4_GA_CP/testsuite/src/main/org/jboss/test/cluster/test/DRMTestCase.java
===================================================================
--- branches/JBoss_4_0_4_GA_CP/testsuite/src/main/org/jboss/test/cluster/test/DRMTestCase.java 2007-04-30 22:32:59 UTC (rev 62671)
+++ branches/JBoss_4_0_4_GA_CP/testsuite/src/main/org/jboss/test/cluster/test/DRMTestCase.java 2007-04-30 22:34:51 UTC (rev 62672)
@@ -1,24 +1,24 @@
/*
- * 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.
- */
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2007, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.cluster.test;
import java.rmi.RemoteException;
@@ -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 = 50;
@@ -1172,6 +1184,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/JBoss_4_0_4_GA_CP/testsuite/src/main/org/jboss/test/ha/singleton/HASingletonSupportTester.java
===================================================================
--- branches/JBoss_4_0_4_GA_CP/testsuite/src/main/org/jboss/test/ha/singleton/HASingletonSupportTester.java 2007-04-30 22:32:59 UTC (rev 62671)
+++ branches/JBoss_4_0_4_GA_CP/testsuite/src/main/org/jboss/test/ha/singleton/HASingletonSupportTester.java 2007-04-30 22:34:51 UTC (rev 62672)
@@ -1,24 +1,24 @@
/*
-* 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.
-*/
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2007, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.ha.singleton;
import java.util.Stack;
@@ -94,8 +94,13 @@
__invokationStack__.push("makeThisNodeMaster");
super.makeThisNodeMaster();
}
+
+ protected void restartMaster()
+ {
+ __invokationStack__.push("restartMaster");
+ super.restartMaster();
+ }
-
public void sendNotification(Notification notification)
{
return;
Modified: branches/JBoss_4_0_4_GA_CP/testsuite/src/main/org/jboss/test/ha/singleton/test/HASingletonSupportUnitTestCase.java
===================================================================
--- branches/JBoss_4_0_4_GA_CP/testsuite/src/main/org/jboss/test/ha/singleton/test/HASingletonSupportUnitTestCase.java 2007-04-30 22:32:59 UTC (rev 62671)
+++ branches/JBoss_4_0_4_GA_CP/testsuite/src/main/org/jboss/test/ha/singleton/test/HASingletonSupportUnitTestCase.java 2007-04-30 22:34:51 UTC (rev 62672)
@@ -1,30 +1,31 @@
/*
-* 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.
-*/
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2007, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.ha.singleton.test;
import java.util.ArrayList;
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
@@ -151,4 +158,154 @@
}
+ 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