[jboss-cvs] JBossAS SVN: r61871 - in trunk/testsuite/src: main/org/jboss/test/cluster/test and 1 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu Mar 29 20:13:05 EDT 2007
Author: jerrygauth
Date: 2007-03-29 20:13:05 -0400 (Thu, 29 Mar 2007)
New Revision: 61871
Modified:
trunk/testsuite/src/main/org/jboss/test/cluster/rpc/RPCUser.java
trunk/testsuite/src/main/org/jboss/test/cluster/test/RPCTestCase.java
trunk/testsuite/src/resources/cluster/rpc/jboss-service.xml
Log:
JBAS-4106, added unit tests for ClusterPartition RPC scoped classloader support
Modified: trunk/testsuite/src/main/org/jboss/test/cluster/rpc/RPCUser.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/cluster/rpc/RPCUser.java 2007-03-29 23:00:25 UTC (rev 61870)
+++ trunk/testsuite/src/main/org/jboss/test/cluster/rpc/RPCUser.java 2007-03-30 00:13:05 UTC (rev 61871)
@@ -39,11 +39,11 @@
{
protected static Logger log = Logger.getLogger(RPCUser.class);
private static final String JNDI_PARTITION = "/HAPartition/";
- private static final String SERVICE_NAME = "RPCTestCase";
private static final String METHOD_GET_PERSON = "getPerson";
private static final String METHOD_GET_PERSON_MATCH = "getPersonMatch";
private static final String METHOD_NOTIFY_PERSON = "notifyPerson";
+ protected String rpcServiceName;
protected String partitionName;
protected HAPartition partition = null;
private Person myPerson = null;
@@ -60,6 +60,8 @@
public void startService() throws Exception
{
+ rpcServiceName = this.serviceName.toString();
+ log.debug("RPCTestCase.startService() - " + rpcServiceName);
// Lookup the partition
InitialContext ctx = new InitialContext();
String jndiName = JNDI_PARTITION + partitionName;
@@ -68,13 +70,24 @@
if (partition == null)
throw new Exception("RPCUser partition is null, JNDI lookup failed");
- partition.registerRPCHandler(SERVICE_NAME, this);
+ ClusterNode me = partition.getClusterNode();
+ ClusterNode[] nodes = partition.getClusterNodes();
+ boolean isFirstNode = (nodes != null && nodes[0].equals(me));
+ // register the service with the partition
+ // note that "OneNode" services are only registered on the first node
+ if (rpcServiceName.indexOf("OneNode") < 0 || isFirstNode)
+ {
+ // ClassLoader services register with a classloader reference
+ if (rpcServiceName.indexOf("ClassLoader") >= 0)
+ partition.registerRPCHandler(rpcServiceName, this, Thread.currentThread().getContextClassLoader());
+ else
+ partition.registerRPCHandler(rpcServiceName, this);
+ }
+
// add a different person to each of the two nodes
- ClusterNode me = partition.getClusterNode();
- ClusterNode[] nodes = partition.getClusterNodes();
Person p;
- if (nodes != null && nodes[0].equals(me))
+ if (isFirstNode)
{
p = new Person("John White");
p.setAddress("Main Street", "Boston", "MA", "02101");
@@ -84,7 +97,7 @@
else
{
p = new Person("Jane Brown");
- p.setAddress("High Street", "Sacramento", "CA", "94203");
+ p.setAddress("High Street", "Cambridge", "MA", "02141");
p.setDob(new GregorianCalendar(1970, GregorianCalendar.JULY, 15));
p.setEmployer("AcmeLtd");
}
@@ -94,26 +107,26 @@
public ArrayList runRetrieveAll() throws Exception
{
- return partition.callMethodOnCluster(SERVICE_NAME, METHOD_GET_PERSON, null, null, false);
+ return partition.callMethodOnCluster(rpcServiceName, METHOD_GET_PERSON, null, null, false);
}
public ArrayList runRetrieveQuery(PersonQuery query) throws Exception
{
Object[] parms = new Object[]{query};
Class[] types = new Class[]{PersonQuery.class};
- return partition.callMethodOnCluster(SERVICE_NAME, METHOD_GET_PERSON_MATCH, parms, types, false);
+ return partition.callMethodOnCluster(rpcServiceName, METHOD_GET_PERSON_MATCH, parms, types, false);
}
public ArrayList runRetrieveFromCoordinator() throws Exception
{
- return partition.callMethodOnCoordinatorNode(SERVICE_NAME, METHOD_GET_PERSON, null, null, false);
+ return partition.callMethodOnCoordinatorNode(rpcServiceName, METHOD_GET_PERSON, null, null, false);
}
public void runNotifyAllAsynch() throws Exception
{
Object[] parms = new Object[]{Boolean.TRUE};
Class[] types = new Class[]{Boolean.class};
- partition.callAsynchMethodOnCluster(SERVICE_NAME, METHOD_NOTIFY_PERSON, parms, types, false);
+ partition.callAsynchMethodOnCluster(rpcServiceName, METHOD_NOTIFY_PERSON, parms, types, false);
}
public Person getPerson()
Modified: trunk/testsuite/src/main/org/jboss/test/cluster/test/RPCTestCase.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/cluster/test/RPCTestCase.java 2007-03-29 23:00:25 UTC (rev 61870)
+++ trunk/testsuite/src/main/org/jboss/test/cluster/test/RPCTestCase.java 2007-03-30 00:13:05 UTC (rev 61871)
@@ -39,8 +39,11 @@
*/
public class RPCTestCase extends JBossClusteredTestCase
{
- // must match service name in rpc-tests.sar
+ // must match service names in rpc-tests.sar
private static final String RPC_SERVICE = "jboss.test:service=RPCTestCase";
+ private static final String RPC_ONENODE_SERVICE = "jboss.test:service=RPCOneNodeTestCase";
+ private static final String RPC_CLASSLOADER_SERVICE = "jboss.test:service=RPCClassLoaderTestCase";
+ private static final String RPC_ONENODE_CLASSLOADER_SERVICE = "jboss.test:service=RPCOneNodeClassLoaderTestCase";
public static Test suite() throws Exception
{
@@ -179,5 +182,135 @@
assertTrue("expected " + employer + " as selected response value, got " + respEmpl,
(employer.equalsIgnoreCase(respEmpl)));
}
+
+ public void testMethodOnOneNode() throws Exception
+ {
+ log.debug("+++ testMethodOnOneNode");
+
+ RMIAdaptor[] adaptors = getAdaptors();
+ RMIAdaptorExt server0 = (RMIAdaptorExt) adaptors[0];
+ ObjectName rpcService = new ObjectName(RPC_ONENODE_SERVICE);
+ Object obj0 = server0.invoke(rpcService, "runRetrieveAll", null, null);
+ assertNotNull("expected ArrayList as result type, got null", obj0);
+ assertTrue( "expected ArrayList as result type, got " +obj0.getClass().getName(), obj0 instanceof ArrayList);
+ ArrayList responses = (ArrayList)obj0;
+
+ // there should be one response as the service is only registered on one node
+ assertEquals("Result should contain one response; ", 1, responses.size());
+ for (int i = 0; i < responses.size(); i++)
+ {
+ Object response = responses.get(i);
+ if (response instanceof Exception)
+ fail("received exception response: " + ((Exception)response).toString());
+ assertTrue("expected Person as response type, got " +response.getClass().getName(), response instanceof Person);
+ }
+
+ }
+
+ public void testClassLoaderParmMethodOnOneNode() throws Exception
+ {
+ log.debug("+++ testClassLoaderParmMethodOnOneNode");
+
+ RMIAdaptor[] adaptors = getAdaptors();
+ RMIAdaptorExt server1 = (RMIAdaptorExt) adaptors[1];
+ ObjectName rpcService = new ObjectName(RPC_ONENODE_CLASSLOADER_SERVICE);
+
+ // try using a custom class as parameter
+ String employer = "WidgetsRUs";
+ PersonQuery query = new PersonQuery();
+ query.setEmployer(employer);
+ Object[] parms = new Object[]{query};
+ String[] types = new String[]{"org.jboss.test.cluster.rpc.PersonQuery"};
+
+ Object obj1 = server1.invoke(rpcService, "runRetrieveQuery", parms, types);
+ assertNotNull("expected ArrayList as result type, got null", obj1);
+ assertTrue( "expected ArrayList as result type, got " +obj1.getClass().getName(), obj1 instanceof ArrayList);
+ ArrayList responses = (ArrayList)obj1;
+
+ // there should be one response as the service is only registered on one node
+ assertEquals("Result should contain one response; ", 1, responses.size());
+ for (int i = 0; i < responses.size(); i++)
+ {
+ Object response = responses.get(i);
+ if (response instanceof Exception)
+ fail("received exception response: " + ((Exception)response).toString());
+ if (response != null)
+ {
+ assertTrue("expected Person as response type, got " +response.getClass().getName(), response instanceof Person);
+ String respEmpl = ((Person)response).getEmployer();
+ assertTrue("expected " + employer + " as selected response value, got " + respEmpl,
+ (employer.equalsIgnoreCase(respEmpl)));
+ }
+ }
+
+ }
+
+ public void testClassLoaderParmMethodOnCluster() throws Exception
+ {
+ log.debug("+++ testClassLoaderParmMethodOnCluster");
+
+ RMIAdaptor[] adaptors = getAdaptors();
+ RMIAdaptorExt server1 = (RMIAdaptorExt) adaptors[1];
+ ObjectName rpcService = new ObjectName(RPC_CLASSLOADER_SERVICE);
+
+ // try using a custom class as parameter
+ String employer = "WidgetsRUs";
+ PersonQuery query = new PersonQuery();
+ query.setEmployer(employer);
+ Object[] parms = new Object[]{query};
+ String[] types = new String[]{"org.jboss.test.cluster.rpc.PersonQuery"};
+
+ Object obj1 = server1.invoke(rpcService, "runRetrieveQuery", parms, types);
+ assertNotNull("expected ArrayList as result type, got null", obj1);
+ assertTrue( "expected ArrayList as result type, got " +obj1.getClass().getName(), obj1 instanceof ArrayList);
+ ArrayList responses = (ArrayList)obj1;
+
+ // there should be two responses, a Person and a null value
+ assertEquals("Result should contain two responses; ", 2, responses.size());
+ for (int i = 0; i < responses.size(); i++)
+ {
+ Object response = responses.get(i);
+ if (response instanceof Exception)
+ fail("received exception response: " + ((Exception)response).toString());
+ if (response != null)
+ {
+ assertTrue("expected Person as response type, got " +response.getClass().getName(), response instanceof Person);
+ String respEmpl = ((Person)response).getEmployer();
+ assertTrue("expected " + employer + " as selected response value, got " + respEmpl,
+ (employer.equalsIgnoreCase(respEmpl)));
+ }
+ }
+
+ }
+
+ public void testClassLoaderMethodOnCluster() throws Exception
+ {
+ log.debug("+++ testClassLoaderMethodOnCluster");
+
+ RMIAdaptor[] adaptors = getAdaptors();
+ RMIAdaptorExt server0 = (RMIAdaptorExt) adaptors[0];
+ ObjectName rpcService = new ObjectName(RPC_CLASSLOADER_SERVICE);
+
+ Object obj0 = server0.invoke(rpcService, "runRetrieveAll", null, null);
+ assertNotNull("expected ArrayList as result type, got null", obj0);
+ assertTrue( "expected ArrayList as result type, got " +obj0.getClass().getName(), obj0 instanceof ArrayList);
+ ArrayList responses = (ArrayList)obj0;
+
+ // there should be two Person responses, the attributes should differ
+ assertEquals("Result should contain two responses; ", 2, responses.size());
+ for (int i = 0; i < responses.size(); i++)
+ {
+ Object response = responses.get(i);
+ if (response instanceof Exception)
+ fail("received exception response: " + ((Exception)response).toString());
+ assertTrue("expected Person as response type, got " +response.getClass().getName(), response instanceof Person);
+ }
+ Person person0 = (Person)responses.get(0);
+ Person person1 = (Person)responses.get(1);
+ assertFalse("expected different person names, got " + person0.getName(),
+ person0.getName().equals(person1.getName()));
+
+ }
+
}
Modified: trunk/testsuite/src/resources/cluster/rpc/jboss-service.xml
===================================================================
--- trunk/testsuite/src/resources/cluster/rpc/jboss-service.xml 2007-03-29 23:00:25 UTC (rev 61870)
+++ trunk/testsuite/src/resources/cluster/rpc/jboss-service.xml 2007-03-30 00:13:05 UTC (rev 61871)
@@ -1,9 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
+<server>
-<server>
- <mbean code="org.jboss.test.cluster.rpc.RPCUser"
- name="jboss.test:service=RPCTestCase">
- <depends>HAPartition</depends>
- <attribute name="PartitionName">DefaultPartition</attribute>
- </mbean>
+ <mbean code="org.jboss.test.cluster.rpc.RPCUser" name="jboss.test:service=RPCTestCase">
+ <depends>HAPartition</depends>
+ <attribute name="PartitionName">DefaultPartition</attribute>
+ </mbean>
+
+ <mbean code="org.jboss.test.cluster.rpc.RPCUser" name="jboss.test:service=RPCClassLoaderTestCase">
+ <depends>HAPartition</depends>
+ <attribute name="PartitionName">DefaultPartition</attribute>
+ </mbean>
+
+ <mbean code="org.jboss.test.cluster.rpc.RPCUser" name="jboss.test:service=RPCOneNodeTestCase">
+ <depends>HAPartition</depends>
+ <attribute name="PartitionName">DefaultPartition</attribute>
+ </mbean>
+
+ <mbean code="org.jboss.test.cluster.rpc.RPCUser" name="jboss.test:service=RPCOneNodeClassLoaderTestCase">
+ <depends>HAPartition</depends>
+ <attribute name="PartitionName">DefaultPartition</attribute>
+ </mbean>
+
</server>
More information about the jboss-cvs-commits
mailing list