[jboss-cvs] JBossAS SVN: r60778 - in trunk/testsuite: imports/sections and 5 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Feb 21 16:59:07 EST 2007
Author: jerrygauth
Date: 2007-02-21 16:59:07 -0500 (Wed, 21 Feb 2007)
New Revision: 60778
Added:
trunk/testsuite/src/main/org/jboss/test/cluster/rpc/
trunk/testsuite/src/main/org/jboss/test/cluster/rpc/Person.java
trunk/testsuite/src/main/org/jboss/test/cluster/rpc/PersonQuery.java
trunk/testsuite/src/main/org/jboss/test/cluster/rpc/RPCUser.java
trunk/testsuite/src/main/org/jboss/test/cluster/rpc/RPCUserMBean.java
trunk/testsuite/src/main/org/jboss/test/cluster/test/RPCTestCase.java
trunk/testsuite/src/resources/cluster/rpc/
trunk/testsuite/src/resources/cluster/rpc/jboss-service.xml
Modified:
trunk/testsuite/build.xml
trunk/testsuite/imports/sections/cluster.xml
Log:
JBAS-4006, add deserialization test to cluster
Modified: trunk/testsuite/build.xml
===================================================================
--- trunk/testsuite/build.xml 2007-02-21 19:59:40 UTC (rev 60777)
+++ trunk/testsuite/build.xml 2007-02-21 21:59:07 UTC (rev 60778)
@@ -596,6 +596,7 @@
<include name="org/jboss/test/cluster/test/CrossServerCallsUnitTestCase.class"/>
<include name="org/jboss/test/cluster/test/DistributedStateTestCase.class"/>
<include name="org/jboss/test/cluster/test/DRMTestCase.class"/>
+ <include name="org/jboss/test/cluster/test/RPCTestCase.class"/>
<include name="org/jboss/test/cluster/test/FamilyClusterInfoUnitTestCase.class"/>
<include name="org/jboss/test/cluster/test/HAJndiTestCase.class"/>
<include name="org/jboss/test/cluster/partition/test/*TestCase.class"/>
Modified: trunk/testsuite/imports/sections/cluster.xml
===================================================================
--- trunk/testsuite/imports/sections/cluster.xml 2007-02-21 19:59:40 UTC (rev 60777)
+++ trunk/testsuite/imports/sections/cluster.xml 2007-02-21 21:59:07 UTC (rev 60778)
@@ -28,6 +28,15 @@
<include name="org/jboss/test/cluster/test/*_Stub.class"/>
</fileset>
</jar>
+
+ <jar destfile="${build.lib}/rpc-tests.sar">
+ <metainf dir="${build.resources}/cluster/rpc">
+ <include name="jboss-service.xml"/>
+ </metainf>
+ <fileset dir="${build.classes}">
+ <include name="org/jboss/test/cluster/rpc/*"/>
+ </fileset>
+ </jar>
<jar destfile="${build.lib}/partitionstatetransfer.sar">
<metainf dir="${build.resources}/cluster/partition">
Added: trunk/testsuite/src/main/org/jboss/test/cluster/rpc/Person.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/cluster/rpc/Person.java (rev 0)
+++ trunk/testsuite/src/main/org/jboss/test/cluster/rpc/Person.java 2007-02-21 21:59:07 UTC (rev 60778)
@@ -0,0 +1,108 @@
+/*
+ * JBoss, the OpenSource J2EE webOS
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package org.jboss.test.cluster.rpc;
+
+import java.io.Serializable;
+import java.util.Calendar;
+
+public class Person implements Serializable
+{
+
+ private Calendar dob;
+ private String name;
+ private String address;
+ private String city;
+ private String state;
+ private String postal;
+ private String employer;
+
+ private Person() {}
+
+ public Person(String name)
+ {
+ this.name = name;
+ }
+
+ public void setAddress(String address, String city, String state, String postal)
+ {
+ this.address = address;
+ this.city = city;
+ this.state = state;
+ this.postal = postal;
+ }
+
+ public void setDob(Calendar dob)
+ {
+ this.dob = dob;
+ }
+
+ public Calendar getDob()
+ {
+ return dob;
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+
+ public String getAddress()
+ {
+ return address;
+ }
+
+ public String getCity()
+ {
+ return city;
+ }
+
+ public String getState()
+ {
+ return state;
+ }
+
+ public String getPostal()
+ {
+ return postal;
+ }
+
+ public void setEmployer(String employer)
+ {
+ this.employer = employer;
+ }
+
+ public String getEmployer()
+ {
+ return employer;
+ }
+
+ public int getAge()
+ {
+ Calendar today = Calendar.getInstance();
+ int age = today.get(Calendar.YEAR) - dob.get(Calendar.YEAR);
+ dob.add(Calendar.YEAR, age);
+ if (today.before(dob))
+ {
+ age--;
+ }
+ return age;
+ }
+
+ public String toString()
+ {
+ StringBuffer sb = new StringBuffer();
+ sb.append("name: " + name);
+ if (dob != null)
+ {
+ sb.append("; dob: " + dob.getTime());
+ }
+ sb.append("; address: " + address + ", " + city + ", " + state + " " + postal);
+ sb.append("; employer: " + employer);
+
+ return sb.toString();
+ }
+}
\ No newline at end of file
Added: trunk/testsuite/src/main/org/jboss/test/cluster/rpc/PersonQuery.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/cluster/rpc/PersonQuery.java (rev 0)
+++ trunk/testsuite/src/main/org/jboss/test/cluster/rpc/PersonQuery.java 2007-02-21 21:59:07 UTC (rev 60778)
@@ -0,0 +1,64 @@
+/*
+ * JBoss, the OpenSource J2EE webOS
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package org.jboss.test.cluster.rpc;
+
+import java.io.Serializable;
+
+/*
+ * trivial custom class to be used as parameter
+ */
+public class PersonQuery implements Serializable
+{
+ private String city = null;
+ private String state = null;
+ private String employer = null;
+
+ public PersonQuery() {}
+
+ public void setCity(String city)
+ {
+ this.city = city;
+ }
+
+ public String getCity()
+ {
+ return city;
+ }
+
+ public void setState(String state)
+ {
+ this.state = state;
+ }
+
+ public String getState()
+ {
+ return state;
+ }
+
+ public void setEmployer(String employer)
+ {
+ this.employer = employer;
+ }
+
+ public String getEmployer()
+ {
+ return employer;
+ }
+
+ public boolean isMatch(Person person)
+ {
+ if (city != null && !city.equalsIgnoreCase(person.getCity()))
+ return false;
+ if (state != null && !state.equalsIgnoreCase(person.getState()))
+ return false;
+ if (employer != null && !employer.equalsIgnoreCase(person.getEmployer()))
+ return false;
+
+ return true;
+ }
+
+}
Added: trunk/testsuite/src/main/org/jboss/test/cluster/rpc/RPCUser.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/cluster/rpc/RPCUser.java (rev 0)
+++ trunk/testsuite/src/main/org/jboss/test/cluster/rpc/RPCUser.java 2007-02-21 21:59:07 UTC (rev 60778)
@@ -0,0 +1,119 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2007, 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.rpc;
+
+import javax.naming.InitialContext;
+import java.util.ArrayList;
+import java.util.GregorianCalendar;
+
+import org.jboss.ha.framework.interfaces.ClusterNode;
+import org.jboss.ha.framework.interfaces.HAPartition;
+import org.jboss.logging.Logger;
+import org.jboss.system.ServiceMBeanSupport;
+
+/** Tests of clustered RPC calls
+*
+* @author Jerry Gauthier
+* @version $Revision: $
+*/
+public class RPCUser extends ServiceMBeanSupport implements RPCUserMBean
+{
+ 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";
+
+ protected String partitionName;
+ protected HAPartition partition = null;
+ private Person myPerson = null;
+
+ public String getPartitionName()
+ {
+ return partitionName;
+ }
+
+ public void setPartitionName(String partitionName)
+ {
+ this.partitionName = partitionName;
+ }
+
+ public void startService() throws Exception
+ {
+ // Lookup the partition
+ InitialContext ctx = new InitialContext();
+ String jndiName = JNDI_PARTITION + partitionName;
+ partition = (HAPartition) ctx.lookup(jndiName);
+ log.debug("Obtained partition from partition="+partitionName);
+ if (partition == null)
+ throw new Exception("RPCUser partition is null, JNDI lookup failed");
+
+ partition.registerRPCHandler(SERVICE_NAME, 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))
+ {
+ p = new Person("John White");
+ p.setAddress("Main Street", "Boston", "MA", "02101");
+ p.setDob(new GregorianCalendar(1965, GregorianCalendar.MARCH, 30));
+ p.setEmployer("Novell");
+ }
+ else
+ {
+ p = new Person("Jane Brown");
+ p.setAddress("High Street", "Sacramento", "CA", "94203");
+ p.setDob(new GregorianCalendar(1970, GregorianCalendar.JULY, 15));
+ p.setEmployer("Acme");
+ }
+ myPerson = p;
+
+ }
+
+ public ArrayList runRetrieveAll() throws Exception
+ {
+ return partition.callMethodOnCluster(SERVICE_NAME, 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);
+ }
+
+ public Person getPerson()
+ {
+ return myPerson;
+ }
+
+ public Person getPersonMatch(PersonQuery query)
+ {
+ if (query.isMatch(myPerson))
+ return myPerson;
+ else
+ return null;
+ }
+
+}
Added: trunk/testsuite/src/main/org/jboss/test/cluster/rpc/RPCUserMBean.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/cluster/rpc/RPCUserMBean.java (rev 0)
+++ trunk/testsuite/src/main/org/jboss/test/cluster/rpc/RPCUserMBean.java 2007-02-21 21:59:07 UTC (rev 60778)
@@ -0,0 +1,21 @@
+/*
+ * JBoss, the OpenSource J2EE webOS
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package org.jboss.test.cluster.rpc;
+
+import java.util.ArrayList;
+
+import org.jboss.system.ServiceMBean;
+
+public interface RPCUserMBean extends ServiceMBean {
+
+ public ArrayList runRetrieveAll() throws Exception;
+ public ArrayList runRetrieveQuery(PersonQuery query) throws Exception;
+ public void setPartitionName(String name);
+ public String getPartitionName();
+
+}
+
Added: trunk/testsuite/src/main/org/jboss/test/cluster/test/RPCTestCase.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/cluster/test/RPCTestCase.java (rev 0)
+++ trunk/testsuite/src/main/org/jboss/test/cluster/test/RPCTestCase.java 2007-02-21 21:59:07 UTC (rev 60778)
@@ -0,0 +1,147 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2007, 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 java.util.ArrayList;
+import javax.management.ObjectName;
+
+import junit.framework.Test;
+
+import org.jboss.jmx.adaptor.rmi.RMIAdaptor;
+import org.jboss.jmx.adaptor.rmi.RMIAdaptorExt;
+import org.jboss.test.JBossClusteredTestCase;
+import org.jboss.test.cluster.rpc.Person;
+import org.jboss.test.cluster.rpc.PersonQuery;
+
+/** Tests of clustered RPC calls
+ *
+ * @author Jerry Gauthier
+ * @version $Revision: $
+ */
+public class RPCTestCase extends JBossClusteredTestCase
+{
+ // must match service name in rpc-tests.sar
+ private static final String RPC_SERVICE = "jboss.test:service=RPCTestCase";
+
+ public static Test suite() throws Exception
+ {
+ Test t1 = getDeploySetup(RPCTestCase.class, "rpc-tests.sar");
+ return t1;
+ }
+
+ public RPCTestCase(String name)
+ {
+ super(name);
+ }
+
+ public void testMethodOnCluster() throws Exception
+ {
+ log.debug("+++ testMethodOnCluster");
+
+ RMIAdaptor[] adaptors = getAdaptors();
+ RMIAdaptorExt server0 = (RMIAdaptorExt) adaptors[0];
+ ObjectName rpcService = new ObjectName(RPC_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()));
+
+ }
+
+ public void testParmMethodOnCluster() throws Exception
+ {
+ log.debug("+++ testParmMethodOnCluster");
+
+ RMIAdaptor[] adaptors = getAdaptors();
+ RMIAdaptorExt server1 = (RMIAdaptorExt) adaptors[1];
+ ObjectName rpcService = new ObjectName(RPC_SERVICE);
+
+ // try using a custom class as parameter
+ String employer = "Novell";
+ 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 testAsynchMethodOnCluster() throws Exception
+ {
+ log.debug("+++ testAsynchMethodOnCluster");
+
+ RMIAdaptor[] adaptors = getAdaptors();
+ RMIAdaptorExt server0 = (RMIAdaptorExt) adaptors[0];
+ RMIAdaptorExt server1 = (RMIAdaptorExt) adaptors[1];
+ log.info("server0: " + server0 + "; server1: " + server1);
+ ObjectName rpcService = new ObjectName(RPC_SERVICE);
+
+ }
+
+ public void testMethodOnCoordinatorNode() throws Exception
+ {
+ log.debug("+++ testMethodOnCoordinatorNode");
+
+ RMIAdaptor[] adaptors = getAdaptors();
+ RMIAdaptorExt server0 = (RMIAdaptorExt) adaptors[0];
+ RMIAdaptorExt server1 = (RMIAdaptorExt) adaptors[1];
+ log.info("server0: " + server0 + "; server1: " + server1);
+ ObjectName rpcService = new ObjectName(RPC_SERVICE);
+
+ }
+
+}
Added: trunk/testsuite/src/resources/cluster/rpc/jboss-service.xml
===================================================================
--- trunk/testsuite/src/resources/cluster/rpc/jboss-service.xml (rev 0)
+++ trunk/testsuite/src/resources/cluster/rpc/jboss-service.xml 2007-02-21 21:59:07 UTC (rev 60778)
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<server>
+ <mbean code="org.jboss.test.cluster.rpc.RPCUser"
+ name="jboss.test:service=RPCTestCase">
+ <depends>HAPartition</depends>
+ <attribute name="PartitionName">DefaultPartition</attribute>
+ </mbean>
+</server>
More information about the jboss-cvs-commits
mailing list