[jboss-cvs] JBossAS SVN: r57824 - in branches/Branch_4_0: cluster/src/main/org/jboss/ha/singleton testsuite testsuite/imports testsuite/imports/sections testsuite/src/main/org/jboss/test/cluster/test testsuite/src/resources testsuite/src/resources/ha testsuite/src/resources/ha/electionpolicy testsuite/src/resources/ha/electionpolicy/META-INF
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Oct 25 09:40:31 EDT 2006
Author: AlexFu.Novell
Date: 2006-10-25 09:40:26 -0400 (Wed, 25 Oct 2006)
New Revision: 57824
Added:
branches/Branch_4_0/cluster/src/main/org/jboss/ha/singleton/HASingletonElectionPolicyBase.java
branches/Branch_4_0/cluster/src/main/org/jboss/ha/singleton/HASingletonElectionPolicyMBean.java
branches/Branch_4_0/cluster/src/main/org/jboss/ha/singleton/HASingletonElectionPolicySimple.java
branches/Branch_4_0/cluster/src/main/org/jboss/ha/singleton/HASingletonElectionPolicySimpleMBean.java
branches/Branch_4_0/cluster/src/main/org/jboss/ha/singleton/HASingletonSupportMBean.java
branches/Branch_4_0/testsuite/imports/sections/hapolicy.xml
branches/Branch_4_0/testsuite/src/main/org/jboss/test/cluster/test/HASingletonElectionPolicyTestCase.java
branches/Branch_4_0/testsuite/src/resources/ha/
branches/Branch_4_0/testsuite/src/resources/ha/electionpolicy/
branches/Branch_4_0/testsuite/src/resources/ha/electionpolicy/META-INF/
branches/Branch_4_0/testsuite/src/resources/ha/electionpolicy/META-INF/jboss-service.xml
Modified:
branches/Branch_4_0/cluster/src/main/org/jboss/ha/singleton/HASingletonControllerMBean.java
branches/Branch_4_0/cluster/src/main/org/jboss/ha/singleton/HASingletonSupport.java
branches/Branch_4_0/testsuite/build.xml
branches/Branch_4_0/testsuite/imports/test-jars.xml
Log:
JBAS-3636: Port HASingletonElectionPolicy to Branch_4_0
Modified: branches/Branch_4_0/cluster/src/main/org/jboss/ha/singleton/HASingletonControllerMBean.java
===================================================================
--- branches/Branch_4_0/cluster/src/main/org/jboss/ha/singleton/HASingletonControllerMBean.java 2006-10-25 13:03:39 UTC (rev 57823)
+++ branches/Branch_4_0/cluster/src/main/org/jboss/ha/singleton/HASingletonControllerMBean.java 2006-10-25 13:40:26 UTC (rev 57824)
@@ -34,7 +34,7 @@
* @author <a href="mailto:dimitris at jboss.org">Dimitris Andreadis</a>
* @version $Revision$
*/
-public interface HASingletonControllerMBean extends HASingletonMBean
+public interface HASingletonControllerMBean extends HASingletonSupportMBean
{
/** The controlled target Singleton MBean */
ObjectName getTargetName();
Added: branches/Branch_4_0/cluster/src/main/org/jboss/ha/singleton/HASingletonElectionPolicyBase.java
===================================================================
--- branches/Branch_4_0/cluster/src/main/org/jboss/ha/singleton/HASingletonElectionPolicyBase.java 2006-10-25 13:03:39 UTC (rev 57823)
+++ branches/Branch_4_0/cluster/src/main/org/jboss/ha/singleton/HASingletonElectionPolicyBase.java 2006-10-25 13:40:26 UTC (rev 57824)
@@ -0,0 +1,97 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, 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.ha.singleton;
+
+
+import org.jboss.ha.framework.interfaces.HAPartition;
+import org.jboss.ha.framework.server.ClusterPartition;
+import org.jboss.logging.Logger;
+import org.jboss.system.ServiceMBeanSupport;
+
+/**
+ * A base class for policy service that decides which node in the cluster should be
+ * the master node to run certain HASingleton service.
+ *
+ * @author <a href="mailto:afu at novell.com">Alex Fu</a>
+ * @version $Revision: 46010 $
+ */
+public abstract class HASingletonElectionPolicyBase
+ extends ServiceMBeanSupport
+ implements HASingletonElectionPolicyMBean
+{
+ private Object mManagedSingleton;
+ private HAPartition mPartition;
+
+ /**
+ * @see HASingletonElectionPolicyMBean#setManagedSingleton(Object)
+ */
+ public void setManagedSingleton(Object singleton)
+ {
+ this.mManagedSingleton = singleton;
+ }
+
+ /**
+ * @see HASingletonElectionPolicyMBean#getManagedSingleton()
+ */
+ public Object getManagedSingleton()
+ {
+ return this.mManagedSingleton;
+ }
+
+ /**
+ * @see HASingletonElectionPolicyMBean#setHAPartition(HAPartition)
+ */
+ public void setHAPartition(HAPartition partition)
+ {
+ this.mPartition = partition;
+ }
+
+ /**
+ * @see HASingletonElectionPolicyMBean#getHAPartition()
+ */
+ public HAPartition getHAPartition()
+ {
+ return this.mPartition;
+ }
+
+ /**
+ * @see HASingletonElectionPolicyMBean#isElectedMaster()
+ */
+ public boolean isElectedMaster()
+ {
+ if (null == this.mPartition)
+ throw new IllegalStateException("HAPartition is not set");
+
+ return pickSingleton().equals(this.mPartition.getClusterNode());
+ }
+
+ /**
+ * @see HASingletonElectionPolicyMBean#isElectedMaster(HAPartition)
+ */
+ public boolean isElectedMaster(HAPartition partition)
+ {
+ if (null == partition)
+ throw new IllegalStateException("parameter cannot be null");
+
+ return pickSingleton(partition).equals(partition.getClusterNode());
+ }
+}
Added: branches/Branch_4_0/cluster/src/main/org/jboss/ha/singleton/HASingletonElectionPolicyMBean.java
===================================================================
--- branches/Branch_4_0/cluster/src/main/org/jboss/ha/singleton/HASingletonElectionPolicyMBean.java 2006-10-25 13:03:39 UTC (rev 57823)
+++ branches/Branch_4_0/cluster/src/main/org/jboss/ha/singleton/HASingletonElectionPolicyMBean.java 2006-10-25 13:40:26 UTC (rev 57824)
@@ -0,0 +1,82 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, 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.ha.singleton;
+
+
+import org.jboss.ha.framework.interfaces.ClusterNode;
+import org.jboss.ha.framework.interfaces.HAPartition;
+
+/**
+ * Management Bean for HASinigleton Election Policy.
+
+ * @author <a href="mailto:Alex.Fu at novell.com">Alex Fu</a>.
+ * @version $Revision: 46010 $
+ *
+ */
+public interface HASingletonElectionPolicyMBean
+ extends org.jboss.system.ServiceMBean
+{
+ /**
+ * Called by the HASingleton to provide the election policy a reference to
+ * itself. A policy that was designed to elect a particular kind of singleton
+ * could downcast this object to a particular type and then access the
+ * singleton for state information needed for the election decision.
+ */
+ void setManagedSingleton(Object singleton);
+ Object getManagedSingleton();
+
+ /**
+ * Sets the HAPartition; from this the election policy can gain
+ * access to the DistributedReplicantManager for tracking the
+ * deployment topology for the singleton service and to the HAPartition
+ * for making group RPC calls.
+ */
+ void setHAPartition(HAPartition partition);
+ HAPartition getHAPartition();
+
+ /**
+ * Return the elected master node.
+ * @return the master node
+ */
+ ClusterNode pickSingleton();
+
+ /**
+ * Given the HAPartition, return the elected master node.
+ * @param partition
+ * @return the master node
+ */
+ ClusterNode pickSingleton(HAPartition partition);
+
+ /**
+ * Conducts an election and returns whether the managed service
+ * is the master, based on the current view of partition.
+ * @return true only if the managed service is the master
+ */
+ public boolean isElectedMaster();
+
+ /**
+ * Given the HAPartition, return whether the managed service is the master.
+ * @param partition
+ * @return true only if the managed service is the master
+ */
+ public boolean isElectedMaster(HAPartition partiton);
+}
Added: branches/Branch_4_0/cluster/src/main/org/jboss/ha/singleton/HASingletonElectionPolicySimple.java
===================================================================
--- branches/Branch_4_0/cluster/src/main/org/jboss/ha/singleton/HASingletonElectionPolicySimple.java 2006-10-25 13:03:39 UTC (rev 57823)
+++ branches/Branch_4_0/cluster/src/main/org/jboss/ha/singleton/HASingletonElectionPolicySimple.java 2006-10-25 13:40:26 UTC (rev 57824)
@@ -0,0 +1,88 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, 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.ha.singleton;
+
+
+import org.jboss.ha.framework.interfaces.ClusterNode;
+import org.jboss.ha.framework.interfaces.HAPartition;
+
+/**
+ * A simple concrete policy service that decides which node in the cluster should be
+ * the master node to run certain HASingleton service based on attribute "Position".
+ * The value will be divided by partition size and only remainder will be used.
+ *
+ * Let's say partition size is n:
+ * 0 means the first oldest node.
+ * 1 means the 2nd oldest node.
+ * ...
+ * n-1 means the nth oldest node.
+ *
+ * -1 means the youngest node.
+ * -2 means the 2nd youngest node.
+ * ...
+ * -n means the nth youngest node.
+ *
+ * E.g. the following attribute says the singleton will be running on the 3rd oldest node of
+ * the current partition:
+ * <attribute name="Position">2</attribute>
+ *
+ * @author <a href="mailto:Alex.Fu at novell.com">Alex Fu</a>
+ * @version $Revision: 46010 $
+ */
+public class HASingletonElectionPolicySimple
+ extends HASingletonElectionPolicyBase
+ implements HASingletonElectionPolicySimpleMBean
+{
+ // Attributes
+ private int mPosition = 0; // Default
+
+ /**
+ * @see HASingletonElectionPolicySimpleMBean#setPosition(int)
+ */
+ public void setPosition(int pos)
+ {
+ this.mPosition = pos;
+ }
+
+ /**
+ * @see HASingletonElectionPolicySimpleMBean#getPosition()
+ */
+ public int getPosition()
+ {
+ return this.mPosition;
+ }
+
+ public ClusterNode pickSingleton()
+ {
+ return pickSingleton(getHAPartition());
+ }
+
+ public ClusterNode pickSingleton(HAPartition partition)
+ {
+ ClusterNode[] nodes = partition.getClusterNodes();
+
+ int size = nodes.length;
+ int remainder = ((this.mPosition % size) + size) % size;
+
+ return nodes[remainder];
+ }
+}
Added: branches/Branch_4_0/cluster/src/main/org/jboss/ha/singleton/HASingletonElectionPolicySimpleMBean.java
===================================================================
--- branches/Branch_4_0/cluster/src/main/org/jboss/ha/singleton/HASingletonElectionPolicySimpleMBean.java 2006-10-25 13:03:39 UTC (rev 57823)
+++ branches/Branch_4_0/cluster/src/main/org/jboss/ha/singleton/HASingletonElectionPolicySimpleMBean.java 2006-10-25 13:40:26 UTC (rev 57824)
@@ -0,0 +1,41 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, 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.ha.singleton;
+
+/**
+ * Management Bean for the simple Election Policy.
+
+ * @author <a href="mailto:Alex.Fu at novell.com">Alex Fu</a>.
+ * @version $Revision: 46010 $
+ *
+ */
+public interface HASingletonElectionPolicySimpleMBean
+ extends HASingletonElectionPolicyMBean
+{
+ /**
+ * Attribute: position.
+ * 0 means the oldest node, 1 means 2nd oldest, ...
+ * -1 means the youngest node, -2 means 2nd youngest, ...
+ */
+ void setPosition(int pos);
+ int getPosition();
+}
Modified: branches/Branch_4_0/cluster/src/main/org/jboss/ha/singleton/HASingletonSupport.java
===================================================================
--- branches/Branch_4_0/cluster/src/main/org/jboss/ha/singleton/HASingletonSupport.java 2006-10-25 13:03:39 UTC (rev 57823)
+++ branches/Branch_4_0/cluster/src/main/org/jboss/ha/singleton/HASingletonSupport.java 2006-10-25 13:40:26 UTC (rev 57824)
@@ -41,6 +41,7 @@
// Private Data --------------------------------------------------
private boolean isMasterNode = false;
+ private HASingletonElectionPolicyMBean mElectionPolicyMB = null;
// Constructors --------------------------------------------------
@@ -64,6 +65,22 @@
return isMasterNode;
}
+ /**
+ * @see HASingletonSupportMBean#setHASingletonElectionPolicyMBean(HASingletonElectionPolicyMBean)
+ */
+ public void setHASingletonElectionPolicyMBean(HASingletonElectionPolicyMBean mb)
+ {
+ this.mElectionPolicyMB = mb;
+ }
+
+ /**
+ * @see HASingletonSupportMBean#getHASingletonElectionPolicyMBean()
+ */
+ public HASingletonElectionPolicyMBean getHASingletonElectionPolicyMBean()
+ {
+ return this.mElectionPolicyMB;
+ }
+
// Public --------------------------------------------------------
/**
@@ -114,7 +131,11 @@
*/
public void partitionTopologyChanged(List newReplicants, int newViewID)
{
- boolean isElectedNewMaster = isDRMMasterReplica();
+ boolean isElectedNewMaster;
+ if (this.mElectionPolicyMB != null)
+ isElectedNewMaster = this.mElectionPolicyMB.isElectedMaster(this.getPartition());
+ else
+ isElectedNewMaster = isDRMMasterReplica();
if (log.isDebugEnabled())
{
Added: branches/Branch_4_0/cluster/src/main/org/jboss/ha/singleton/HASingletonSupportMBean.java
===================================================================
--- branches/Branch_4_0/cluster/src/main/org/jboss/ha/singleton/HASingletonSupportMBean.java 2006-10-25 13:03:39 UTC (rev 57823)
+++ branches/Branch_4_0/cluster/src/main/org/jboss/ha/singleton/HASingletonSupportMBean.java 2006-10-25 13:40:26 UTC (rev 57824)
@@ -0,0 +1,35 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, 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.ha.singleton;
+
+/**
+ * The management interface for the singleton support service.
+ *
+ * @author <a href="mailto:Alex.Fu at novell.com">Alex Fu</a>
+ * @version $Revision$
+ */
+public interface HASingletonSupportMBean extends HASingletonMBean
+{
+ /** The HASingleton election policy MBean */
+ void setHASingletonElectionPolicyMBean(HASingletonElectionPolicyMBean mb);
+ HASingletonElectionPolicyMBean getHASingletonElectionPolicyMBean();
+}
Modified: branches/Branch_4_0/testsuite/build.xml
===================================================================
--- branches/Branch_4_0/testsuite/build.xml 2006-10-25 13:03:39 UTC (rev 57823)
+++ branches/Branch_4_0/testsuite/build.xml 2006-10-25 13:40:26 UTC (rev 57824)
@@ -565,6 +565,7 @@
<exclude name="org/jboss/test/cluster/test/*FieldBasedTestCase.class"/>
<exclude name="org/jboss/test/cluster/test/StateTransferTestCase.class"/>
<exclude name="org/jboss/test/cluster/test/UndeployFieldTestCase.class"/>
+ <exclude name="org/jboss/test/cluster/test/HASingletonElectionPolicyTestCase.class"/>
</patternset>
<patternset id="cluster.http.jk.includes">
<include name="org/jboss/test/cluster/web/jk/test/*TestCase.class"/>
@@ -581,6 +582,7 @@
<include name="org/jboss/test/cluster/jmx/test/*TestCase.class"/>
<include name="org/jboss/test/testbeancluster/test/*TestCase.class"/>
<include name="org/jboss/test/ha/farm/test/*TestCase.class" />
+ <include name="org/jboss/test/cluster/test/HASingletonElectionPolicyTestCase.class"/>
</patternset>
<!-- With JG 2.2.7, only run this test with UDP; known failure with TCP -->
<patternset id="cluster.non.http.udp.includes">
Added: branches/Branch_4_0/testsuite/imports/sections/hapolicy.xml
===================================================================
--- branches/Branch_4_0/testsuite/imports/sections/hapolicy.xml 2006-10-25 13:03:39 UTC (rev 57823)
+++ branches/Branch_4_0/testsuite/imports/sections/hapolicy.xml 2006-10-25 13:40:26 UTC (rev 57824)
@@ -0,0 +1,14 @@
+<project name="tests-hapolicy-jars">
+ <!-- jmx test -->
+ <target name="_jars-hapolicy">
+ <mkdir dir="${build.lib}"/>
+
+ <!--build sar for testing mbean deployment -->
+ <jar destfile="${build.lib}/ha-electionpolicy.sar">
+ <fileset dir="${build.resources}/ha/electionpolicy">
+ <include name="META-INF/jboss-service.xml"/>
+ </fileset>
+ </jar>
+
+ </target>
+</project>
Modified: branches/Branch_4_0/testsuite/imports/test-jars.xml
===================================================================
--- branches/Branch_4_0/testsuite/imports/test-jars.xml 2006-10-25 13:03:39 UTC (rev 57823)
+++ branches/Branch_4_0/testsuite/imports/test-jars.xml 2006-10-25 13:40:26 UTC (rev 57824)
@@ -68,6 +68,7 @@
<import file="sections/xa.xml"/>
<import file="sections/xslt.xml"/>
<import file="sections/byvalue.xml"/>
+ <import file="sections/hapolicy.xml"/>
<!--
| Build all jar files.
@@ -147,7 +148,8 @@
_jars-wsrp,
_jars-xa,
_jars-xslt,
- _jars-byvalue
+ _jars-byvalue,
+ _jars-hapolicy
">
</target>
Added: branches/Branch_4_0/testsuite/src/main/org/jboss/test/cluster/test/HASingletonElectionPolicyTestCase.java
===================================================================
--- branches/Branch_4_0/testsuite/src/main/org/jboss/test/cluster/test/HASingletonElectionPolicyTestCase.java 2006-10-25 13:03:39 UTC (rev 57823)
+++ branches/Branch_4_0/testsuite/src/main/org/jboss/test/cluster/test/HASingletonElectionPolicyTestCase.java 2006-10-25 13:40:26 UTC (rev 57824)
@@ -0,0 +1,118 @@
+/*
+ * 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.
+ */
+package org.jboss.test.cluster.test;
+
+import javax.management.ObjectName;
+
+import junit.framework.Test;
+
+import org.jboss.jmx.adaptor.rmi.RMIAdaptor;
+import org.jboss.test.JBossClusteredTestCase;
+
+/**
+ * Unit tests for HASingletonElectionPolicy.
+ * The testing deployment is under resources/ha/electionpolicy.
+ *
+ * @author <a href="mailto:Alex.Fu at novell.com">Alex Fu</a>
+ * @version $Revision: 46010 $
+ *
+ */
+public class HASingletonElectionPolicyTestCase extends JBossClusteredTestCase
+{
+ public HASingletonElectionPolicyTestCase(String name)
+ {
+ super(name);
+ }
+
+ public static Test suite() throws Exception
+ {
+ // Refer to jboss-service.xml under resources/ha/electionpolicy
+ Test t1 = JBossClusteredTestCase.getDeploySetup(HASingletonElectionPolicyTestCase.class, "ha-electionpolicy.sar");
+ return t1;
+ }
+
+ public void testElectionPolicy() throws Exception
+ {
+ // Get MBeanServerConnections
+ RMIAdaptor[] adaptors = this.getAdaptors();
+ int size = adaptors.length;
+ assertTrue(size > 1); // cluster size must be at least 2
+
+ // Restart partition to ensure the ordering of the cluster, which is important for testing the simple policy
+ // This is to avoid the mis-ordering caused by partition restart unit test
+ for (int i = 0; i < size; i++)
+ restartPartition(adaptors[i]);
+
+ // First policy is to elect the oldest node (position = 0)
+ {
+ ObjectName mbean = new ObjectName("jboss.examples:service=HASingletonMBeanExample_1");
+
+ Boolean n1 = (Boolean)adaptors[0].getAttribute(mbean, "MasterNode");
+ Boolean n2 = (Boolean)adaptors[size - 1].getAttribute(mbean, "MasterNode");
+
+ assertEquals(n1, Boolean.TRUE);
+ assertEquals(n2, Boolean.FALSE);
+ }
+ // Second policy is the youngest (position = -1)
+ {
+ ObjectName mbean = new ObjectName("jboss.examples:service=HASingletonMBeanExample_2");
+
+ Boolean n1 = (Boolean)adaptors[0].getAttribute(mbean, "MasterNode");
+ Boolean n2 = (Boolean)adaptors[size - 1].getAttribute(mbean, "MasterNode");
+
+ assertEquals(n1, Boolean.FALSE);
+ assertEquals(n2, Boolean.TRUE);
+ }
+ // 3rd policy is the 2nd oldest (position = 1)
+ {
+ ObjectName mbean = new ObjectName("jboss.examples:service=HASingletonMBeanExample_3");
+
+ Boolean n1 = (Boolean)adaptors[0].getAttribute(mbean, "MasterNode");
+ Boolean n2 = (Boolean)adaptors[1].getAttribute(mbean, "MasterNode");
+
+ assertEquals(n1, Boolean.FALSE);
+ assertEquals(n2, Boolean.TRUE);
+ }
+ // 4th policy is not set, default is oldest
+ {
+ ObjectName mbean = new ObjectName("jboss.examples:service=HASingletonMBeanExample_4");
+
+ Boolean n1 = (Boolean)adaptors[0].getAttribute(mbean, "MasterNode");
+ Boolean n2 = (Boolean)adaptors[size - 1].getAttribute(mbean, "MasterNode");
+
+ assertEquals(n1, Boolean.TRUE);
+ assertEquals(n2, Boolean.FALSE);
+ }
+
+ return;
+ }
+
+ private void restartPartition(RMIAdaptor adaptor) throws Exception
+ {
+ ObjectName partition = new ObjectName("jboss:service=DefaultPartition");
+
+ Object[] params = new Object[0];
+ String[] types = new String[0];
+ adaptor.invoke(partition, "stop", params, types);
+ adaptor.invoke(partition, "start", params, types);
+ }
+}
Added: branches/Branch_4_0/testsuite/src/resources/ha/electionpolicy/META-INF/jboss-service.xml
===================================================================
--- branches/Branch_4_0/testsuite/src/resources/ha/electionpolicy/META-INF/jboss-service.xml 2006-10-25 13:03:39 UTC (rev 57823)
+++ branches/Branch_4_0/testsuite/src/resources/ha/electionpolicy/META-INF/jboss-service.xml 2006-10-25 13:40:26 UTC (rev 57824)
@@ -0,0 +1,89 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE server>
+<server>
+ <!-- First HASingleton, Election policy is to choose the oldest node as master -->
+ <mbean code="org.jboss.ha.singleton.examples.HASingletonMBeanExample"
+ name="jboss.examples:service=HASingletonMBeanExample_1">
+ </mbean>
+
+ <mbean code="org.jboss.ha.singleton.HASingletonElectionPolicySimple"
+ name="jboss.examples:service=HASingletonMBeanExample-HASingletonElectionPolicySimple_1">
+ <attribute name="Position">0</attribute>
+ </mbean>
+
+ <mbean code="org.jboss.ha.singleton.HASingletonController"
+ name="jboss.examples:service=HASingletonMBeanExample-HASingletonController_1">
+ <depends>jboss:service=${jboss.partition.name:DefaultPartition}</depends>
+ <depends>jboss.examples:service=HASingletonMBeanExample_1</depends>
+ <depends optional-attribute-name="HASingletonElectionPolicyMBean"
+ proxy-type="attribute">jboss.examples:service=HASingletonMBeanExample-HASingletonElectionPolicySimple_1</depends>
+ <attribute name="PartitionName">${jboss.partition.name:DefaultPartition}</attribute>
+ <attribute name="TargetName">jboss.examples:service=HASingletonMBeanExample_1</attribute>
+ <attribute name="TargetStartMethod">startSingleton</attribute>
+ <attribute name="TargetStopMethod">stopSingleton</attribute>
+ <attribute name="TargetStopMethodArgument">true</attribute>
+ </mbean>
+
+ <!-- Second HASingleton, Election policy is to choose the youngest node as master -->
+ <mbean code="org.jboss.ha.singleton.examples.HASingletonMBeanExample"
+ name="jboss.examples:service=HASingletonMBeanExample_2">
+ </mbean>
+
+ <mbean code="org.jboss.ha.singleton.HASingletonElectionPolicySimple"
+ name="jboss.examples:service=HASingletonMBeanExample-HASingletonElectionPolicySimple_2">
+ <attribute name="Position">-1</attribute>
+ </mbean>
+
+ <mbean code="org.jboss.ha.singleton.HASingletonController"
+ name="jboss.examples:service=HASingletonMBeanExample-HASingletonController_2">
+ <depends>jboss:service=${jboss.partition.name:DefaultPartition}</depends>
+ <depends>jboss.examples:service=HASingletonMBeanExample_2</depends>
+ <depends optional-attribute-name="HASingletonElectionPolicyMBean"
+ proxy-type="attribute">jboss.examples:service=HASingletonMBeanExample-HASingletonElectionPolicySimple_2</depends>
+ <attribute name="PartitionName">${jboss.partition.name:DefaultPartition}</attribute>
+ <attribute name="TargetName">jboss.examples:service=HASingletonMBeanExample_2</attribute>
+ <attribute name="TargetStartMethod">startSingleton</attribute>
+ <attribute name="TargetStopMethod">stopSingleton</attribute>
+ <attribute name="TargetStopMethodArgument">true</attribute>
+ </mbean>
+
+ <!-- Third HASingleton, Election policy is to choose the 2nd oldest node as master -->
+ <mbean code="org.jboss.ha.singleton.examples.HASingletonMBeanExample"
+ name="jboss.examples:service=HASingletonMBeanExample_3">
+ </mbean>
+
+ <mbean code="org.jboss.ha.singleton.HASingletonElectionPolicySimple"
+ name="jboss.examples:service=HASingletonMBeanExample-HASingletonElectionPolicySimple_3">
+ <attribute name="Position">1</attribute>
+ </mbean>
+
+ <mbean code="org.jboss.ha.singleton.HASingletonController"
+ name="jboss.examples:service=HASingletonMBeanExample-HASingletonController_3">
+ <depends>jboss:service=${jboss.partition.name:DefaultPartition}</depends>
+ <depends>jboss.examples:service=HASingletonMBeanExample_3</depends>
+ <depends optional-attribute-name="HASingletonElectionPolicyMBean"
+ proxy-type="attribute">jboss.examples:service=HASingletonMBeanExample-HASingletonElectionPolicySimple_3</depends>
+ <attribute name="PartitionName">${jboss.partition.name:DefaultPartition}</attribute>
+ <attribute name="TargetName">jboss.examples:service=HASingletonMBeanExample_3</attribute>
+ <attribute name="TargetStartMethod">startSingleton</attribute>
+ <attribute name="TargetStopMethod">stopSingleton</attribute>
+ <attribute name="TargetStopMethodArgument">true</attribute>
+ </mbean>
+
+ <!-- Fourth HASingleton, No election policy defined. By default, the oldest node is selected -->
+ <mbean code="org.jboss.ha.singleton.examples.HASingletonMBeanExample"
+ name="jboss.examples:service=HASingletonMBeanExample_4">
+ </mbean>
+
+ <mbean code="org.jboss.ha.singleton.HASingletonController"
+ name="jboss.examples:service=HASingletonMBeanExample-HASingletonController_4">
+ <depends>jboss:service=${jboss.partition.name:DefaultPartition}</depends>
+ <depends>jboss.examples:service=HASingletonMBeanExample_4</depends>
+ <attribute name="PartitionName">${jboss.partition.name:DefaultPartition}</attribute>
+ <attribute name="TargetName">jboss.examples:service=HASingletonMBeanExample_4</attribute>
+ <attribute name="TargetStartMethod">startSingleton</attribute>
+ <attribute name="TargetStopMethod">stopSingleton</attribute>
+ <attribute name="TargetStopMethodArgument">true</attribute>
+ </mbean>
+
+</server>
More information about the jboss-cvs-commits
mailing list