[jboss-cvs] JBossAS SVN: r66340 - 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 Oct 22 17:00:27 EDT 2007
Author: galder.zamarreno at jboss.com
Date: 2007-10-22 17:00:27 -0400 (Mon, 22 Oct 2007)
New Revision: 66340
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-4180] Second set of HA singleton election tests added which are Pojo bean based rather than MBean based.
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 2007-10-22 20:50:39 UTC (rev 66339)
+++ trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/test/HASingletonElectionPolicyTestCase.java 2007-10-22 21:00:27 UTC (rev 66340)
@@ -21,11 +21,17 @@
*/
package org.jboss.test.cluster.defaultcfg.test;
+import java.util.Properties;
+
import javax.management.MBeanServerConnection;
import javax.management.ObjectName;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
import junit.framework.Test;
+import org.jboss.ha.singleton.examples.HASingletonPojoExample;
import org.jboss.test.JBossClusteredTestCase;
/**
@@ -39,9 +45,12 @@
*/
public class HASingletonElectionPolicyTestCase extends JBossClusteredTestCase
{
+ private final Properties env = new Properties();
+
public HASingletonElectionPolicyTestCase(String name)
{
super(name);
+ env.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
}
public static Test suite() throws Exception
@@ -50,7 +59,7 @@
return getDeploySetup(HASingletonElectionPolicyTestCase.class, "ha-electionpolicy-beans.xml");
}
- public void testElectionPolicy() throws Exception
+ public void testMBeanElectionPolicy() throws Exception
{
// Get MBeanServerConnections
MBeanServerConnection[] adaptors = this.getAdaptors();
@@ -103,4 +112,53 @@
return;
}
+
+ public void testPojoElectionPolicy() throws Exception
+ {
+ String[] namingUrls = getNamingURLs();
+ int size = namingUrls.length;
+ assertTrue(size == 2); // cluster size must be 2 for 3rd policy test
+
+ // First policy is to elect the oldest node (position = 0)
+ int exampleNumber = 1;
+ shouldHaveHaSingletonDeployed(namingUrls[0], exampleNumber);
+ shouldNotHaveHaSingletonDeployed(namingUrls[size - 1], exampleNumber);
+
+ // Second policy is the youngest (position = -1)
+ exampleNumber = 2;
+ shouldNotHaveHaSingletonDeployed(namingUrls[0], exampleNumber);
+ shouldHaveHaSingletonDeployed(namingUrls[size - 1], exampleNumber);
+
+ // 3rd policy is the 2nd oldest (position = 1)
+ exampleNumber = 3;
+ shouldNotHaveHaSingletonDeployed(namingUrls[0], exampleNumber);
+ shouldHaveHaSingletonDeployed(namingUrls[1], exampleNumber);
+
+ // 4th policy is not set, default is oldest
+ exampleNumber = 4;
+ shouldHaveHaSingletonDeployed(namingUrls[0], exampleNumber);
+ shouldNotHaveHaSingletonDeployed(namingUrls[size - 1], exampleNumber);
+ }
+
+ private void shouldHaveHaSingletonDeployed(String namingUrl, int exampleNumber) throws Exception
+ {
+ env.setProperty(Context.PROVIDER_URL, namingUrl);
+ Context ctx = new InitialContext(env);
+ HASingletonPojoExample pojo = (HASingletonPojoExample)ctx.lookup("test/cluster/hasingleton/simplepojo/" + exampleNumber);
+ assertTrue("Pojo in " + namingUrl + " should be deployed as HA singleton", pojo.isMasterNode());
+ }
+
+ private void shouldNotHaveHaSingletonDeployed(String namingUrl, int exampleNumber) throws Exception
+ {
+ env.setProperty(Context.PROVIDER_URL, namingUrl);
+ Context ctx = new InitialContext(env);
+ try
+ {
+ HASingletonPojoExample pojo = (HASingletonPojoExample)ctx.lookup("test/cluster/hasingleton/simplepojo/" + exampleNumber);
+ fail("Should have thrown a NamingException indicating 'test not bound'");
+ }
+ catch(NamingException ne)
+ {
+ }
+ }
}
Modified: trunk/testsuite/src/resources/cluster/hasingleton/electionpolicy/ha-electionpolicy-beans.xml
===================================================================
--- trunk/testsuite/src/resources/cluster/hasingleton/electionpolicy/ha-electionpolicy-beans.xml 2007-10-22 20:50:39 UTC (rev 66339)
+++ trunk/testsuite/src/resources/cluster/hasingleton/electionpolicy/ha-electionpolicy-beans.xml 2007-10-22 21:00:27 UTC (rev 66340)
@@ -1,13 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<deployment xmlns="urn:jboss:bean-deployer:2.0">
+
+ <!-- ==================================================================== -->
+ <!-- MBean style HA singleton election definition -->
+ <!-- ==================================================================== -->
<!-- First HASingleton, Election policy is to choose the oldest node as master -->
<bean class="org.jboss.ha.singleton.examples.HASingletonMBeanExample"
name="HASingletonMBeanExample_1">
<annotation>@org.jboss.aop.microcontainer.aspects.jmx.JMX(name="jboss.examples:service=HASingletonMBeanExample_1", exposedInterface=org.jboss.ha.singleton.examples.HASingletonMBeanExampleMBean.class, registerDirectly=true)</annotation>
</bean>
-
+
<bean class="org.jboss.ha.singleton.HASingletonElectionPolicySimple"
name="HASingletonElectionPolicySimple_1">
<property name="position">0</property>
@@ -24,14 +28,14 @@
<property name="targetStartMethod">startSingleton</property>
<property name="targetStopMethod">stopSingleton</property>
<property name="targetStopMethodArgument">true</property>
- </bean>
-
+ </bean>
+
<!-- Second HASingleton, Election policy is to choose the youngest node as master -->
<bean class="org.jboss.ha.singleton.examples.HASingletonMBeanExample"
name="HASingletonMBeanExample_2">
<annotation>@org.jboss.aop.microcontainer.aspects.jmx.JMX(name="jboss.examples:service=HASingletonMBeanExample_2", exposedInterface=org.jboss.ha.singleton.examples.HASingletonMBeanExampleMBean.class, registerDirectly=true)</annotation>
</bean>
-
+
<bean class="org.jboss.ha.singleton.HASingletonElectionPolicySimple"
name="HASingletonElectionPolicySimple_2">
<property name="position">-1</property>
@@ -48,14 +52,14 @@
<property name="targetStartMethod">startSingleton</property>
<property name="targetStopMethod">stopSingleton</property>
<property name="targetStopMethodArgument">true</property>
- </bean>
-
+ </bean>
+
<!-- Third HASingleton, Election policy is to choose the 2nd oldest node as master -->
<bean class="org.jboss.ha.singleton.examples.HASingletonMBeanExample"
name="HASingletonMBeanExample_3">
<annotation>@org.jboss.aop.microcontainer.aspects.jmx.JMX(name="jboss.examples:service=HASingletonMBeanExample_3", exposedInterface=org.jboss.ha.singleton.examples.HASingletonMBeanExampleMBean.class, registerDirectly=true)</annotation>
- </bean>
-
+ </bean>
+
<bean class="org.jboss.ha.singleton.HASingletonElectionPolicySimple"
name="HASingletonElectionPolicySimple_3">
<property name="position">1</property>
@@ -72,14 +76,14 @@
<property name="targetStartMethod">startSingleton</property>
<property name="targetStopMethod">stopSingleton</property>
<property name="targetStopMethodArgument">true</property>
- </bean>
-
+ </bean>
+
<!-- Fourth HASingleton, No election policy defined. By default, the oldest node is selected -->
<bean class="org.jboss.ha.singleton.examples.HASingletonMBeanExample"
name="HASingletonMBeanExample_4">
<annotation>@org.jboss.aop.microcontainer.aspects.jmx.JMX(name="jboss.examples:service=HASingletonMBeanExample_4", exposedInterface=org.jboss.ha.singleton.examples.HASingletonMBeanExampleMBean.class, registerDirectly=true)</annotation>
- </bean>
-
+ </bean>
+
<bean class="org.jboss.ha.singleton.HASingletonController"
name="HASingletonController_4">
@@ -91,7 +95,73 @@
<property name="targetStopMethod">stopSingleton</property>
<property name="targetStopMethodArgument">true</property>
</bean>
-
+
+ <!-- ==================================================================== -->
+ <!-- Pojo style HA singleton election definition -->
+ <!-- ==================================================================== -->
+
+ <!-- First HASingleton, Election policy is to choose the oldest node as master -->
+ <bean class="org.jboss.ha.singleton.examples.HASingletonPojoExample"
+ name="HASingletonPojoExample_1">
+ <constructor><parameter>test/cluster/hasingleton/simplepojo/1</parameter></constructor>
+ </bean>
+
+ <bean class="org.jboss.ha.singleton.HASingletonController"
+ name="HASingletonControllerForBean_1">
+
+ <property name="clusterPartition"><inject bean="ElectionPolicyTestPartition"/></property>
+ <property name="electionPolicy"><inject bean="HASingletonElectionPolicySimple_1"/></property>
+ <property name="target"><inject bean="HASingletonPojoExample_1"/></property>
+ <property name="targetStartMethod">startSingleton</property>
+ <property name="targetStopMethod">stopSingleton</property>
+ </bean>
+
+ <!-- Second HASingleton, Election policy is to choose the youngest node as master -->
+ <bean class="org.jboss.ha.singleton.examples.HASingletonPojoExample"
+ name="HASingletonPojoExample_2">
+ <constructor><parameter>test/cluster/hasingleton/simplepojo/2</parameter></constructor>
+ </bean>
+
+ <bean class="org.jboss.ha.singleton.HASingletonController"
+ name="HASingletonControllerForBean_2">
+
+ <property name="clusterPartition"><inject bean="ElectionPolicyTestPartition"/></property>
+ <property name="electionPolicy"><inject bean="HASingletonElectionPolicySimple_2"/></property>
+ <property name="target"><inject bean="HASingletonPojoExample_2"/></property>
+ <property name="targetStartMethod">startSingleton</property>
+ <property name="targetStopMethod">stopSingleton</property>
+ </bean>
+
+ <!-- Third HASingleton, Election policy is to choose the 2nd oldest node as master -->
+ <bean class="org.jboss.ha.singleton.examples.HASingletonPojoExample"
+ name="HASingletonPojoExample_3">
+ <constructor><parameter>test/cluster/hasingleton/simplepojo/3</parameter></constructor>
+ </bean>
+
+ <bean class="org.jboss.ha.singleton.HASingletonController"
+ name="HASingletonControllerForBean_3">
+
+ <property name="clusterPartition"><inject bean="ElectionPolicyTestPartition"/></property>
+ <property name="electionPolicy"><inject bean="HASingletonElectionPolicySimple_3"/></property>
+ <property name="target"><inject bean="HASingletonPojoExample_3"/></property>
+ <property name="targetStartMethod">startSingleton</property>
+ <property name="targetStopMethod">stopSingleton</property>
+ </bean>
+
+ <!-- Fourth HASingleton, No election policy defined. By default, the oldest node is selected -->
+ <bean class="org.jboss.ha.singleton.examples.HASingletonPojoExample"
+ name="HASingletonPojoExample_4">
+ <constructor><parameter>test/cluster/hasingleton/simplepojo/4</parameter></constructor>
+ </bean>
+
+ <bean class="org.jboss.ha.singleton.HASingletonController"
+ name="HASingletonControllerForBean_4">
+
+ <property name="clusterPartition"><inject bean="ElectionPolicyTestPartition"/></property>
+ <property name="target"><inject bean="HASingletonPojoExample_4"/></property>
+ <property name="targetStartMethod">startSingleton</property>
+ <property name="targetStopMethod">stopSingleton</property>
+ </bean>
<bean name="ElectionPolicyTestCacheConfig"
class="org.jboss.cache.config.Configuration">
More information about the jboss-cvs-commits
mailing list