[jboss-cvs] JBossAS SVN: r61669 - in branches/Branch_4_2/ejb3/src: resources/test/clusteredsession/islocal and 4 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Sun Mar 25 11:01:10 EDT 2007


Author: bstansberry at jboss.com
Date: 2007-03-25 11:01:10 -0400 (Sun, 25 Mar 2007)
New Revision: 61669

Added:
   branches/Branch_4_2/ejb3/src/resources/test/clusteredsession/islocal/
   branches/Branch_4_2/ejb3/src/resources/test/clusteredsession/islocal/META-INF/
   branches/Branch_4_2/ejb3/src/resources/test/clusteredsession/islocal/META-INF/ejb-jar.xml
   branches/Branch_4_2/ejb3/src/resources/test/clusteredsession/islocal/META-INF/jboss.xml
   branches/Branch_4_2/ejb3/src/resources/test/clusteredsession/islocal/foreign/
   branches/Branch_4_2/ejb3/src/resources/test/clusteredsession/islocal/foreign/testlocal-service.xml
   branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/VMTester.java
   branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/VMTesterBase.java
   branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/VMTesterStatefulBean.java
   branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/VMTesterStatelessBean.java
   branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/unit/ForeignPartitionLocalInterceptorUnitTestCase.java
   branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/unit/InvokeLocalTestBase.java
   branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/unit/SimpleIsLocalInterceptorUnitTestCase.java
Log:
[EJBTHREE-881] Test proper local/remote routing of calls

Added: branches/Branch_4_2/ejb3/src/resources/test/clusteredsession/islocal/META-INF/ejb-jar.xml
===================================================================
--- branches/Branch_4_2/ejb3/src/resources/test/clusteredsession/islocal/META-INF/ejb-jar.xml	                        (rev 0)
+++ branches/Branch_4_2/ejb3/src/resources/test/clusteredsession/islocal/META-INF/ejb-jar.xml	2007-03-25 15:01:10 UTC (rev 61669)
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ejb-jar
+        xmlns="http://java.sun.com/xml/ns/javaee"
+        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+        xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
+                            http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd"
+        version="3.0">
+   <enterprise-beans>
+      <session>
+         <ejb-name>NonClusteredStateless</ejb-name>
+         <remote>org.jboss.ejb3.test.clusteredsession.VMTester</remote>
+         <ejb-class>org.jboss.ejb3.test.clusteredsession.VMTesterStatelessBean</ejb-class>
+         <session-type>Stateless</session-type>
+         <transaction-type>Container</transaction-type>
+      </session>
+      <session>
+         <ejb-name>ClusteredStateless</ejb-name>
+         <remote>org.jboss.ejb3.test.clusteredsession.VMTester</remote>
+         <ejb-class>org.jboss.ejb3.test.clusteredsession.VMTesterStatelessBean</ejb-class>
+         <session-type>Stateless</session-type>
+         <transaction-type>Container</transaction-type>
+      </session>
+      <session>
+         <ejb-name>NonClusteredStateful</ejb-name>
+         <remote>org.jboss.ejb3.test.clusteredsession.VMTester</remote>
+         <ejb-class>org.jboss.ejb3.test.clusteredsession.VMTesterStatefulBean</ejb-class>
+         <session-type>Stateful</session-type>
+         <transaction-type>Container</transaction-type>
+      </session>
+      <session>
+         <ejb-name>ClusteredStateful</ejb-name>
+         <remote>org.jboss.ejb3.test.clusteredsession.VMTester</remote>
+         <ejb-class>org.jboss.ejb3.test.clusteredsession.VMTesterStatefulBean</ejb-class>
+         <session-type>Stateful</session-type>
+         <transaction-type>Container</transaction-type>
+      </session>
+   </enterprise-beans>
+</ejb-jar>

Added: branches/Branch_4_2/ejb3/src/resources/test/clusteredsession/islocal/META-INF/jboss.xml
===================================================================
--- branches/Branch_4_2/ejb3/src/resources/test/clusteredsession/islocal/META-INF/jboss.xml	                        (rev 0)
+++ branches/Branch_4_2/ejb3/src/resources/test/clusteredsession/islocal/META-INF/jboss.xml	2007-03-25 15:01:10 UTC (rev 61669)
@@ -0,0 +1,34 @@
+<?xml version="1.0"?>
+<jboss
+        xmlns="http://java.sun.com/xml/ns/javaee"
+        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+        xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
+                            http://www.jboss.org/j2ee/schema/jboss_5_0.xsd"
+        version="3.0">
+      <enterprise-beans>
+         <session>
+            <ejb-name>NonClusteredStateful</ejb-name>
+            <jndi-name>NonClusteredStatefulRemote</jndi-name>
+         </session>
+         <session>
+            <ejb-name>NonClusteredStateless</ejb-name>
+            <jndi-name>NonClusteredStatelessRemote</jndi-name>
+         </session>
+         <session>
+            <ejb-name>ClusteredStateful</ejb-name>
+            <jndi-name>ClusteredStatefulRemote</jndi-name>
+            <clustered>true</clustered>
+            <cluster-config>
+               <partition-name>${clusteredsession.islocal.partition:DefaultPartition}</partition-name>
+            </cluster-config>
+         </session>
+         <session>
+            <ejb-name>ClusteredStateless</ejb-name>
+            <jndi-name>ClusteredStatelessRemote</jndi-name>
+            <clustered>true</clustered>
+            <cluster-config>
+               <partition-name>${clusteredsession.islocal.partition:DefaultPartition}</partition-name>
+            </cluster-config>
+         </session>
+      </enterprise-beans>
+   </jboss>
\ No newline at end of file

Added: branches/Branch_4_2/ejb3/src/resources/test/clusteredsession/islocal/foreign/testlocal-service.xml
===================================================================
--- branches/Branch_4_2/ejb3/src/resources/test/clusteredsession/islocal/foreign/testlocal-service.xml	                        (rev 0)
+++ branches/Branch_4_2/ejb3/src/resources/test/clusteredsession/islocal/foreign/testlocal-service.xml	2007-03-25 15:01:10 UTC (rev 61669)
@@ -0,0 +1,84 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!-- ===================================================================== -->
+<!--                                                                       -->
+<!--  Sample Clustering Service Configuration                              -->
+<!--                                                                       -->
+<!-- ===================================================================== -->
+
+<server>
+
+   <!-- ==================================================================== -->
+   <!-- Cluster Partition: defines cluster                                   -->
+   <!-- ==================================================================== -->
+
+   <mbean code="org.jboss.ha.framework.server.ClusterPartition"
+      name="jboss:service=Ejb3IsLocalTestPartition">
+
+      <!-- Name of the partition being built -->
+      <attribute name="PartitionName">Ejb3IsLocalTestPartition</attribute>
+
+      <!-- The address used to determine the node name -->
+      <attribute name="NodeAddress">${jboss.bind.address}</attribute>
+
+      <!-- Determine if deadlock detection is enabled -->
+      <attribute name="DeadlockDetection">False</attribute>
+
+      <!-- Max time (in ms) to wait for state transfer to complete. Increase for large states -->
+      <attribute name="StateTransferTimeout">30000</attribute>
+
+      <!-- The JGroups protocol configuration -->
+      <attribute name="PartitionConfig">
+         <!--
+         The default UDP stack:
+         - If you have a multihomed machine, set the UDP protocol's bind_addr attribute to the
+         appropriate NIC IP address, e.g bind_addr="192.168.0.2".
+         - On Windows machines, because of the media sense feature being broken with multicast
+         (even after disabling media sense) set the UDP protocol's loopback attribute to true
+         -->
+         <Config>
+            <UDP mcast_addr="${jboss.partition.udpGroup:228.3.3.3}" 
+                 mcast_port="${jboss.hapartition.mcast_port:44444}"
+                 tos="8"
+                 ucast_recv_buf_size="20000000"
+                 ucast_send_buf_size="640000"
+                 mcast_recv_buf_size="25000000"
+                 mcast_send_buf_size="640000"
+                 loopback="false"
+                 discard_incompatible_packets="true"
+                 max_bundle_size="64000"
+                 max_bundle_timeout="30"
+                 use_incoming_packet_handler="true"
+                 use_outgoing_packet_handler="false"
+                 ip_ttl="${jgroups.udp.ip_ttl:2}"
+                 down_thread="false" up_thread="false"
+                 enable_bundling="false"/>
+            <PING timeout="2000"
+                  down_thread="false" up_thread="false" num_initial_members="3"/>
+            <MERGE2 max_interval="100000"
+                    down_thread="false" up_thread="false" min_interval="20000"/>
+            <FD_SOCK down_thread="false" up_thread="false"/>
+            <FD timeout="10000" max_tries="5" down_thread="false" up_thread="false" shun="true"/>
+            <VERIFY_SUSPECT timeout="1500" down_thread="false" up_thread="false"/>
+            <pbcast.NAKACK max_xmit_size="60000"
+                    use_mcast_xmit="false" gc_lag="0"
+                    retransmit_timeout="300,600,1200,2400,4800"
+                    down_thread="false" up_thread="false"
+                    discard_delivered_msgs="true"/>
+            <UNICAST timeout="300,600,1200,2400,3600"
+                    down_thread="false" up_thread="false"/>
+            <pbcast.STABLE stability_delay="1000" desired_avg_gossip="50000"
+                    down_thread="false" up_thread="false"
+                    max_bytes="400000"/>
+            <pbcast.GMS print_local_addr="true" join_timeout="3000"
+                    down_thread="false" up_thread="false"
+                    join_retry_timeout="2000" shun="true"
+                    view_bundling="true"/>
+            <FRAG2 frag_size="60000" down_thread="false" up_thread="false"/>
+            <pbcast.STATE_TRANSFER down_thread="false" up_thread="false" use_flush="false"/>
+         </Config>
+      </attribute>
+      <depends>jboss:service=Naming</depends>
+   </mbean>
+
+</server>

Added: branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/VMTester.java
===================================================================
--- branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/VMTester.java	                        (rev 0)
+++ branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/VMTester.java	2007-03-25 15:01:10 UTC (rev 61669)
@@ -0,0 +1,45 @@
+/*
+ * 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.ejb3.test.clusteredsession;
+
+import java.rmi.dgc.VMID;
+
+import javax.naming.NamingException;
+
+/**
+ * Provides access to a static VMID field and ability to
+ * download a remote proxy and check the VMID of its bean.
+ * 
+ * @author <a href="brian.stansberry at jboss.com">Brian Stansberry</a>
+ * @version $Revision$
+ */
+public interface VMTester
+{
+   public static final VMID VMID = new VMID();
+   
+   VMID getVMID();
+   
+   VMID getVMIDFromRemote(VMTester remote) throws NamingException;
+   
+   VMID getVMIDFromRemoteLookup(String jndiURL, String name) throws NamingException;
+}

Added: branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/VMTesterBase.java
===================================================================
--- branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/VMTesterBase.java	                        (rev 0)
+++ branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/VMTesterBase.java	2007-03-25 15:01:10 UTC (rev 61669)
@@ -0,0 +1,65 @@
+/*
+ * 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.ejb3.test.clusteredsession;
+
+import java.rmi.dgc.VMID;
+import java.util.Properties;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+
+import org.jboss.logging.Logger;
+
+/**
+ * @author Brian Stansberry
+ */
+public class VMTesterBase
+{
+   private static final Logger log = Logger.getLogger(VMTesterBase.class);
+   
+   public VMID getVMID()
+   {
+      log.debug("Ignore; just a stack trace", new Exception("Ignore; just a stack trace"));
+      return VMTester.VMID;
+   }
+
+   public VMID getVMIDFromRemoteLookup(String jndiURL, String name)
+   throws NamingException
+   {
+      log.info("Looking up " + jndiURL + "/" + name);
+      Properties env = new Properties();
+      env.setProperty(Context.PROVIDER_URL, jndiURL);
+      env.setProperty("jnp.disableDiscovery", "true");
+      InitialContext ctx = new InitialContext(env);
+      VMTester tester = (VMTester) ctx.lookup(name);
+      return tester.getVMID();
+   }
+   
+   public VMID getVMIDFromRemote(VMTester remote)
+   {
+      return remote.getVMID();
+   }
+
+   
+}

Added: branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/VMTesterStatefulBean.java
===================================================================
--- branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/VMTesterStatefulBean.java	                        (rev 0)
+++ branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/VMTesterStatefulBean.java	2007-03-25 15:01:10 UTC (rev 61669)
@@ -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.ejb3.test.clusteredsession;
+
+import javax.ejb.Remote;
+import javax.ejb.Stateful;
+
+/**
+ * @author Brian Stansberry
+ */
+ at Stateful
+ at Remote(VMTester.class)
+public class VMTesterStatefulBean extends VMTesterBase implements VMTester
+{
+}

Added: branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/VMTesterStatelessBean.java
===================================================================
--- branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/VMTesterStatelessBean.java	                        (rev 0)
+++ branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/VMTesterStatelessBean.java	2007-03-25 15:01:10 UTC (rev 61669)
@@ -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.ejb3.test.clusteredsession;
+
+import javax.ejb.Remote;
+import javax.ejb.Stateless;
+
+/**
+ * @author Brian Stansberry
+ */
+ at Stateless
+ at Remote(VMTester.class)
+public class VMTesterStatelessBean extends VMTesterBase implements VMTester
+{
+}

Added: branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/unit/ForeignPartitionLocalInterceptorUnitTestCase.java
===================================================================
--- branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/unit/ForeignPartitionLocalInterceptorUnitTestCase.java	                        (rev 0)
+++ branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/unit/ForeignPartitionLocalInterceptorUnitTestCase.java	2007-03-25 15:01:10 UTC (rev 61669)
@@ -0,0 +1,130 @@
+/*
+ * 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.ejb3.test.clusteredsession.unit;
+
+import javax.management.ObjectName;
+
+import org.jboss.jmx.adaptor.rmi.RMIAdaptor;
+
+import junit.framework.Test;
+
+/**
+ * @author Brian Stansberry
+ */
+public class ForeignPartitionLocalInterceptorUnitTestCase extends InvokeLocalTestBase
+{
+   private static final String PARTITION_NAME_VALUE = "Ejb3IsLocalTestPartition";
+   
+   private static boolean deployed0 = false;
+   private static boolean deployed1 = false;
+   
+   /**
+    * @param name
+    */
+   public ForeignPartitionLocalInterceptorUnitTestCase(String name)
+   {
+      super(name);
+   }
+
+   public static Test suite() throws Exception
+   {
+      return getDeploySetup(ForeignPartitionLocalInterceptorUnitTestCase.class,
+                           "testlocal-service.xml");
+   }
+
+   @Override
+   protected void setUp() throws Exception
+   {
+      super.setUp();
+      
+      cleanDeployments();
+      
+      deployJars();
+   }
+
+   @Override
+   protected void tearDown() throws Exception
+   {
+      super.tearDown();
+      
+      cleanDeployments();      
+   }
+   
+   @Override
+   protected String getPartitionName()
+   {
+      return PARTITION_NAME_VALUE;
+   }
+   
+   public void testClusteredStatefulGoesRemote() throws Exception
+   {
+      stayLocalTest("ClusteredStatefulRemote", false);
+   }
+   
+   public void testClusteredStatelessGoesRemote() throws Exception
+   {
+      stayLocalTest("ClusteredStatelessRemote", false);      
+   }
+   
+   public void testNonClusteredStatefulGoesRemote() throws Exception
+   {
+      stayLocalTest("NonClusteredStatefulRemote", false);      
+   }
+   
+   public void testNonClusteredStatelessGoesRemote() throws Exception
+   {
+      stayLocalTest("NonClusteredStatelessRemote", false);    
+   }
+
+   private void cleanDeployments() throws Exception
+   {
+      RMIAdaptor[] adaptors = getAdaptors();
+      
+      if (deployed0)
+      {
+         undeploy(adaptors[0], "clusteredsession-local.jar");
+         deployed0 = false;
+      }
+      
+      if (deployed1)
+      {
+         undeploy(adaptors[1], "clusteredsession-local.jar");
+         deployed1 = false;
+      }
+   }
+   
+   private void deployJars() throws Exception
+   {
+      RMIAdaptor[] adaptors = getAdaptors();
+      
+      deploy(adaptors[0], "clusteredsession-local.jar");
+      deployed0 = true;
+      
+      
+      deploy(adaptors[1], "clusteredsession-local.jar");
+      deployed1 = true;      
+   }
+   
+   
+
+}

Added: branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/unit/InvokeLocalTestBase.java
===================================================================
--- branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/unit/InvokeLocalTestBase.java	                        (rev 0)
+++ branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/unit/InvokeLocalTestBase.java	2007-03-25 15:01:10 UTC (rev 61669)
@@ -0,0 +1,128 @@
+/*
+ * 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.ejb3.test.clusteredsession.unit;
+
+import java.rmi.dgc.VMID;
+import java.util.Properties;
+
+import javax.management.ObjectName;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+
+import org.jboss.ejb3.test.clusteredsession.VMTester;
+import org.jboss.jmx.adaptor.rmi.RMIAdaptor;
+import org.jboss.test.JBossClusteredTestCase;
+
+/**
+ * @author Brian Stansberry
+ */
+public abstract class InvokeLocalTestBase extends JBossClusteredTestCase
+{
+   public static final String TESTER_JNDI_NAME = "NonClusteredStatelessRemote";
+   private static final String PROPERTIES_SERVICE = "jboss:type=Service,name=SystemProperties";
+   private static final String PARTITION_NAME_PROPERTY = "clusteredsession.islocal.partition";
+   
+   
+   public InvokeLocalTestBase(String name)
+   {
+      super(name);
+   }
+
+   
+   @Override
+   protected void setUp() throws Exception
+   {
+      super.setUp();
+      
+      RMIAdaptor[] adaptors = getAdaptors();
+      setPartitionName(adaptors[1]);
+   }
+
+
+   @Override
+   protected void tearDown() throws Exception
+   {
+      super.tearDown();
+      
+      RMIAdaptor[] adaptors = getAdaptors();
+      clearPartitionName(adaptors[1]);
+   }
+
+
+   protected void stayLocalTest(String jndiName, boolean expectLocal)
+      throws Exception
+   {
+      String[] jndiURLs = getNamingURLs();
+      
+      Properties env = new Properties();
+      env.setProperty(Context.PROVIDER_URL, jndiURLs[0]);
+      env.setProperty("jnp.disableDiscovery", "true");
+      InitialContext ctx = new InitialContext(env);
+      VMTester tester = (VMTester) ctx.lookup(TESTER_JNDI_NAME);
+      
+      VMID local = tester.getVMID();
+      assertNotNull("Got the local VMID", local);
+      
+      Properties env1 = new Properties();
+      env1.setProperty(Context.PROVIDER_URL, jndiURLs[1]);
+      env1.setProperty("jnp.disableDiscovery", "true");
+      ctx = new InitialContext(env1);
+      VMTester remote = (VMTester) ctx.lookup(jndiName);
+      
+      // This call instantiates the SFSB if needed
+      VMID remoteID = remote.getVMID();
+      assertNotNull("Got the remote VMID", remoteID);
+      
+      VMID passThroughID = tester.getVMIDFromRemote(remote);
+      assertNotNull("Got the remote VMID", passThroughID);
+      
+      if (expectLocal)
+         assertEquals("Call stayed local", local, passThroughID);
+      else
+         assertFalse("Call went remote", local.equals(passThroughID));
+      
+//      passThroughID = tester.getVMIDFromRemoteLookup(jndiURLs[1], jndiName);
+//      assertNotNull("Got the remote VMID", passThroughID);
+//      
+//      if (expectLocal)
+//         assertEquals("Call stayed local", local, passThroughID);
+//      else
+//         assertFalse("Call went remote", local.equals(passThroughID));
+   }
+   
+   protected abstract String getPartitionName();
+   
+   private void setPartitionName(RMIAdaptor adaptor) throws Exception
+   {
+      Object[] args = { PARTITION_NAME_PROPERTY, getPartitionName() };
+      String[] sig = { String.class.getName(), String.class.getName() };
+      adaptor.invoke(new ObjectName(PROPERTIES_SERVICE), "set", args, sig);
+   }
+   
+   private void clearPartitionName(RMIAdaptor adaptor) throws Exception
+   {
+      Object[] args = { PARTITION_NAME_PROPERTY };
+      String[] sig = { String.class.getName() };
+      adaptor.invoke(new ObjectName(PROPERTIES_SERVICE), "remove", args, sig);
+   }
+}

Added: branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/unit/SimpleIsLocalInterceptorUnitTestCase.java
===================================================================
--- branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/unit/SimpleIsLocalInterceptorUnitTestCase.java	                        (rev 0)
+++ branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredsession/unit/SimpleIsLocalInterceptorUnitTestCase.java	2007-03-25 15:01:10 UTC (rev 61669)
@@ -0,0 +1,80 @@
+/*
+ * 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.ejb3.test.clusteredsession.unit;
+
+import java.rmi.dgc.VMID;
+import java.util.Properties;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+
+import junit.framework.Test;
+
+import org.jboss.ejb3.test.clusteredsession.VMTester;
+import org.jboss.test.JBossClusteredTestCase;
+
+/**
+ * @author Brian Stansberry *
+ */
+public class SimpleIsLocalInterceptorUnitTestCase 
+extends InvokeLocalTestBase
+{
+
+   public SimpleIsLocalInterceptorUnitTestCase(String name)
+   {
+      super(name);
+   }
+
+   public static Test suite() throws Exception
+   {
+      return getDeploySetup(SimpleIsLocalInterceptorUnitTestCase.class,
+                           "clusteredsession-local.jar");
+   }
+   
+   @Override
+   protected String getPartitionName()
+   {
+      return "DefaultPartition";
+   }
+
+   public void testClusteredStatefulStaysLocal() throws Exception
+   {
+      stayLocalTest("ClusteredStatefulRemote" ,true);
+   }
+   
+   public void testClusteredStatelessStaysLocal() throws Exception
+   {
+      stayLocalTest("ClusteredStatelessRemote" ,true);      
+   }
+   
+   public void testNonClusteredStatefulGoesRemote() throws Exception
+   {
+      stayLocalTest("NonClusteredStatefulRemote", false);      
+   }
+   
+   public void testNonClusteredStatelessGoesRemote() throws Exception
+   {
+      stayLocalTest("NonClusteredStatelessRemote", false);    
+   }
+
+}




More information about the jboss-cvs-commits mailing list