[jboss-cvs] JBossAS SVN: r69775 - in trunk/testsuite/src: resources/cluster/hasingleton/electionpolicy and 1 other directory.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Mon Feb 11 13:51:24 EST 2008
Author: galder.zamarreno at jboss.com
Date: 2008-02-11 13:51:24 -0500 (Mon, 11 Feb 2008)
New Revision: 69775
Added:
trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/test/PreferredMasterElectionPolicyUnitTestCase.java
Modified:
trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/test/HASingletonElectionPolicyTestCase.java
trunk/testsuite/src/resources/cluster/hasingleton/electionpolicy/ha-electionpolicy-beans.xml
Log:
[JBAS-5161] Preferred master election policy standalone unit test case has been added to check election of singleton node based on different inputs. Existing in-container singleton election policy test and resources have been modified to cope with new preferred master election policy definition.
Modified: trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/test/HASingletonElectionPolicyTestCase.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/test/HASingletonElectionPolicyTestCase.java 2008-02-11 18:49:03 UTC (rev 69774)
+++ trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/test/HASingletonElectionPolicyTestCase.java 2008-02-11 18:51:24 UTC (rev 69775)
@@ -157,6 +157,12 @@
shouldHaveHaSingletonDeployed(namingUrls[0], exampleNumber);
shouldNotHaveHaSingletonDeployed(namingUrls[size - 1], exampleNumber);
+ // 5th policy is the oldest (position = 0)
+ // however, preferred master is set to 127.0.0.1:1099 (which is the 1st node)
+ exampleNumber = 5;
+ shouldHaveHaSingletonDeployed(namingUrls[0], exampleNumber);
+ shouldNotHaveHaSingletonDeployed(namingUrls[size - 1], exampleNumber);
+
// 6th policy is the youngest (position = -1)
// however, preferred master is set to 127.0.0.1:1099 (which is the 1st node)
exampleNumber = 6;
Added: trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/test/PreferredMasterElectionPolicyUnitTestCase.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/test/PreferredMasterElectionPolicyUnitTestCase.java (rev 0)
+++ trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/test/PreferredMasterElectionPolicyUnitTestCase.java 2008-02-11 18:51:24 UTC (rev 69775)
@@ -0,0 +1,125 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, 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.defaultcfg.test;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.jboss.ha.framework.interfaces.ClusterNode;
+import org.jboss.ha.framework.server.ClusterNodeImpl;
+import org.jboss.ha.singleton.PreferredMasterElectionPolicy;
+import org.jboss.ha.singleton.PreferredMasterElectionPolicyMBean;
+import org.jgroups.stack.IpAddress;
+
+import junit.framework.TestCase;
+
+/**
+ * Unit tests for the preferred master election policy. The tested policy has
+ * been configured with position 0 which means that the first member of the
+ * candidate list will be chosen if the preferred master is malformed or
+ * missing. So, when we expect the preferred master to be chosen, we assert
+ * against the second candidate. Different test methods will test different
+ * ways to define the preferred master.
+ *
+ * @author <a href="mailto:galder.zamarreno at jboss.com">Galder Zamarreno</a>
+ */
+public class PreferredMasterElectionPolicyUnitTestCase extends TestCase
+{
+ private final List<ClusterNode> candidates = new ArrayList<ClusterNode>(2);
+
+ private PreferredMasterElectionPolicyMBean policy;
+
+ @Override
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+
+ ClusterNode cn1 = new ClusterNodeImpl(new IpAddress("127.0.0.1", 1099));
+ ClusterNode cn2 = new ClusterNodeImpl(new IpAddress("127.0.0.1", 1199));
+
+ candidates.add(cn1);
+ candidates.add(cn2);
+
+ policy = new PreferredMasterElectionPolicy()
+ {
+ @Override
+ protected List<ClusterNode> getCandidates()
+ {
+ return candidates;
+ }
+ };
+
+ policy.setPosition(0);
+ }
+
+ public void testIpPort() throws Exception
+ {
+ policy.setPreferredMaster("127.0.0.1:1199");
+ assertEquals(candidates.get(1), policy.elect());
+ }
+
+ public void testHostPort() throws Exception
+ {
+ policy.setPreferredMaster("localhost:1199");
+ assertEquals(candidates.get(1), policy.elect());
+ }
+
+ public void testOnlyPort() throws Exception
+ {
+ policy.setPreferredMaster(":1199");
+ /* invalid preferred master definiton, so 1st candidate in the list
+ * should be chosen */
+ assertEquals(candidates.get(0), policy.elect());
+ }
+
+ public void testNonNumericPort() throws Exception
+ {
+ policy.setPreferredMaster("localhost:abcd");
+ /* invalid preferred master definiton, so 1st candidate in the list
+ * should be chosen */
+ assertEquals(candidates.get(0), policy.elect());
+ }
+
+ public void testUnknownHost() throws Exception
+ {
+ policy.setPreferredMaster("onceuponatimeinalandfarfarawaylivedamancalledgalder:1199");
+ /* invalid preferred master definiton, so 1st candidate in the list
+ * should be chosen */
+ assertEquals(candidates.get(0), policy.elect());
+ }
+
+ public void testEmpty() throws Exception
+ {
+ policy.setPreferredMaster("");
+ /* invalid preferred master definiton, so 1st candidate in the list
+ * should be chosen */
+ assertEquals(candidates.get(0), policy.elect());
+ }
+
+ public void testGarbage() throws Exception
+ {
+ policy.setPreferredMaster("%^$%&%^&$%$£");
+ /* invalid preferred master definiton, so 1st candidate in the list
+ * should be chosen */
+ assertEquals(candidates.get(0), policy.elect());
+ }
+}
Modified: trunk/testsuite/src/resources/cluster/hasingleton/electionpolicy/ha-electionpolicy-beans.xml
===================================================================
--- trunk/testsuite/src/resources/cluster/hasingleton/electionpolicy/ha-electionpolicy-beans.xml 2008-02-11 18:49:03 UTC (rev 69774)
+++ trunk/testsuite/src/resources/cluster/hasingleton/electionpolicy/ha-electionpolicy-beans.xml 2008-02-11 18:51:24 UTC (rev 69775)
@@ -102,8 +102,8 @@
<annotation>@org.jboss.aop.microcontainer.aspects.jmx.JMX(name="jboss.examples:service=HASingletonMBeanExample_5", exposedInterface=org.jboss.ha.singleton.examples.HASingletonMBeanExampleMBean.class, registerDirectly=true)</annotation>
</bean>
- <bean class="org.jboss.ha.singleton.HASingletonElectionPolicySimple"
- name="HASingletonElectionPolicySimple_5">
+ <bean class="org.jboss.ha.singleton.PreferredMasterElectionPolicy"
+ name="PreferredMasterElectionPolicy_1">
<property name="position">0</property>
<property name="preferredMaster">${node0.bind.address:127.0.0.1}:1099</property>
</bean>
@@ -114,7 +114,7 @@
<annotation>@org.jboss.aop.microcontainer.aspects.jmx.JMX(name="test:service=HASingletonController_5", exposedInterface=org.jboss.ha.singleton.HASingletonControllerMBean.class, registerDirectly=true)</annotation>
<property name="clusterPartition"><inject bean="ElectionPolicyTestPartition"/></property>
- <property name="electionPolicy"><inject bean="HASingletonElectionPolicySimple_5"/></property>
+ <property name="electionPolicy"><inject bean="PreferredMasterElectionPolicy_1"/></property>
<property name="target"><inject bean="HASingletonMBeanExample_5"/></property>
<property name="targetStartMethod">startSingleton</property>
<property name="targetStopMethod">stopSingleton</property>
@@ -127,8 +127,8 @@
<annotation>@org.jboss.aop.microcontainer.aspects.jmx.JMX(name="jboss.examples:service=HASingletonMBeanExample_6", exposedInterface=org.jboss.ha.singleton.examples.HASingletonMBeanExampleMBean.class, registerDirectly=true)</annotation>
</bean>
- <bean class="org.jboss.ha.singleton.HASingletonElectionPolicySimple"
- name="HASingletonElectionPolicySimple_6">
+ <bean class="org.jboss.ha.singleton.PreferredMasterElectionPolicy"
+ name="PreferredMasterElectionPolicy_2">
<property name="position">-1</property>
<property name="preferredMaster">${node0.bind.address:127.0.0.1}:1099</property>
</bean>
@@ -139,12 +139,13 @@
<annotation>@org.jboss.aop.microcontainer.aspects.jmx.JMX(name="test:service=HASingletonController_6", exposedInterface=org.jboss.ha.singleton.HASingletonControllerMBean.class, registerDirectly=true)</annotation>
<property name="clusterPartition"><inject bean="ElectionPolicyTestPartition"/></property>
- <property name="electionPolicy"><inject bean="HASingletonElectionPolicySimple_6"/></property>
+ <property name="electionPolicy"><inject bean="PreferredMasterElectionPolicy_2"/></property>
<property name="target"><inject bean="HASingletonMBeanExample_6"/></property>
<property name="targetStartMethod">startSingleton</property>
<property name="targetStopMethod">stopSingleton</property>
<property name="targetStopMethodArgument">true</property>
</bean>
+
<!-- ==================================================================== -->
<!-- Pojo style HA singleton election definition -->
<!-- ==================================================================== -->
@@ -210,8 +211,25 @@
<property name="target"><inject bean="HASingletonPojoExample_4"/></property>
<property name="targetStartMethod">startSingleton</property>
<property name="targetStopMethod">stopSingleton</property>
- </bean>
+ </bean>
+
+ <!-- 5th HASingleton, PreferredMaster set to localhost:0. Election policy is to choose the oldest node as master -->
+ <bean class="org.jboss.ha.singleton.examples.HASingletonPojoExample"
+ name="HASingletonPojoExample_5">
+ <constructor><parameter>test/cluster/hasingleton/simplepojo/5</parameter></constructor>
+ </bean>
+ <bean class="org.jboss.ha.singleton.HASingletonController"
+ name="HASingletonControllerForBean_5">
+
+ <property name="clusterPartition"><inject bean="ElectionPolicyTestPartition"/></property>
+ <property name="electionPolicy"><inject bean="PreferredMasterElectionPolicy_1"/></property>
+ <property name="target"><inject bean="HASingletonPojoExample_5"/></property>
+ <property name="targetStartMethod">startSingleton</property>
+ <property name="targetStopMethod">stopSingleton</property>
+ </bean>
+
+
<!-- 6th HASingleton, Election policy is to choose the youngest node as master -->
<bean class="org.jboss.ha.singleton.examples.HASingletonPojoExample"
name="HASingletonPojoExample_6">
@@ -222,7 +240,7 @@
name="HASingletonControllerForBean_6">
<property name="clusterPartition"><inject bean="ElectionPolicyTestPartition"/></property>
- <property name="electionPolicy"><inject bean="HASingletonElectionPolicySimple_6"/></property>
+ <property name="electionPolicy"><inject bean="PreferredMasterElectionPolicy_2"/></property>
<property name="target"><inject bean="HASingletonPojoExample_6"/></property>
<property name="targetStartMethod">startSingleton</property>
<property name="targetStopMethod">stopSingleton</property>
More information about the jboss-cvs-commits
mailing list