[jboss-cvs] JBossAS SVN: r111290 - in branches/JBPAPP_5_1_0_Final_JBPAPP-5820: testsuite/src/main/org/jboss/test/invokers/test and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon May 2 19:34:08 EDT 2011


Author: bmaxwell
Date: 2011-05-02 19:34:08 -0400 (Mon, 02 May 2011)
New Revision: 111290

Added:
   branches/JBPAPP_5_1_0_Final_JBPAPP-5820/testsuite/src/main/org/jboss/test/invokers/test/JBPAPP6428TestCase.java
Modified:
   branches/JBPAPP_5_1_0_Final_JBPAPP-5820/server/src/main/org/jboss/invocation/InvokerInterceptor.java
Log:
[JBPAPP-5820] port JBPAPP-6433 - EJB2 InvokerInterceptor isLocal returns true when it should return false

Modified: branches/JBPAPP_5_1_0_Final_JBPAPP-5820/server/src/main/org/jboss/invocation/InvokerInterceptor.java
===================================================================
--- branches/JBPAPP_5_1_0_Final_JBPAPP-5820/server/src/main/org/jboss/invocation/InvokerInterceptor.java	2011-05-02 23:26:14 UTC (rev 111289)
+++ branches/JBPAPP_5_1_0_Final_JBPAPP-5820/server/src/main/org/jboss/invocation/InvokerInterceptor.java	2011-05-02 23:34:08 UTC (rev 111290)
@@ -25,6 +25,7 @@
 import java.io.IOException;
 import java.io.ObjectInput;
 import java.io.ObjectOutput;
+import java.lang.reflect.Method;
 import java.lang.reflect.UndeclaredThrowableException;
 import java.math.BigDecimal;
 import java.math.BigInteger;
@@ -68,6 +69,12 @@
 
    /** The InvokerProxyHA class */
    protected static Class invokerProxyHA;
+   
+   // JBPAPP-6428 when determining isLocal, if this is true take into account the cluster partition name
+   private static final boolean isLocalCheckPartitionName = Boolean.parseBoolean( System.getProperty("org.jboss.invocation.use.partition.name", "false") );
+   // JBPAPP-6428 - these are static variables to cache the reflection methods needed for JBPAPP-6428  
+   private static Method getFamilyClusterInfo;
+   private static Method getFamilyName;
 
    static
    {
@@ -145,10 +152,54 @@
             return false;
       }
 
+      // JBPAPP-6428 - EJB2 InvokerInterceptor isLocal returns true when it should return false
+      // Only check the cluster names if it is clustered
+      if (isLocalCheckPartitionName == true)
+      {
+         if (isClustered(invocation) == true)
+         {
+        	 try
+        	 {
+	           String containerPartitionName = System.getProperty("jboss.partition.name");
+	           
+	           Object invokerProxyHA = invocation.getInvocationContext().getInvoker();
+	           
+	           // reflection to org.jboss.invocation.InvokerProxyHA.getFamilyClusterInfo().getFamilyName()
+	           String destinationPartitionName = getFamilyName(invokerProxyHA);
+	           
+	           if (containerPartitionName != null)
+	           {
+	             if (! destinationPartitionName.startsWith(containerPartitionName + "/"))
+	               return false;
+	           }
+        	 }
+           // Catch any reflection exception - which should not occur since isClustered == true
+        	 catch ( Exception e )
+        	 {
+        		 e.printStackTrace();
+        	 }
+         }
+      }
+      // end JBPAPP-6428
+      
       // See whether we have a local target
       return hasLocalTarget(invocation);
    }
 
+   private String getFamilyName(Object invokerProxyHA) throws Exception
+   {
+      if(getFamilyClusterInfo == null)
+         getFamilyClusterInfo = invokerProxyHA.getClass().getMethod("getFamilyClusterInfo", new Class[0]);
+      
+      Object familyClusterInfo = getFamilyClusterInfo.invoke(invokerProxyHA, new Object[0]);
+      
+      if(getFamilyName == null)
+         getFamilyName = familyClusterInfo.getClass().getMethod("getFamilyName", new Class[0]);
+               
+      return (String) getFamilyName.invoke(familyClusterInfo, new Object[0]);      
+   }
+   
+   
    /**
     * Whether we are in a clustered environment<p>
     *

Added: branches/JBPAPP_5_1_0_Final_JBPAPP-5820/testsuite/src/main/org/jboss/test/invokers/test/JBPAPP6428TestCase.java
===================================================================
--- branches/JBPAPP_5_1_0_Final_JBPAPP-5820/testsuite/src/main/org/jboss/test/invokers/test/JBPAPP6428TestCase.java	                        (rev 0)
+++ branches/JBPAPP_5_1_0_Final_JBPAPP-5820/testsuite/src/main/org/jboss/test/invokers/test/JBPAPP6428TestCase.java	2011-05-02 23:34:08 UTC (rev 111290)
@@ -0,0 +1,102 @@
+package org.jboss.test.invokers.test;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.jboss.ha.framework.interfaces.LoadBalancePolicy;
+import org.jboss.ha.framework.interfaces.RoundRobin;
+import org.jboss.invocation.InvokerInterceptor;
+import org.jboss.invocation.unified.interfaces.UnifiedInvokerHAProxy;
+import org.jboss.invocation.Invocation;
+import org.jboss.invocation.InvocationContext;
+import org.jboss.invocation.Invoker;
+import org.jboss.remoting.InvokerLocator;
+import org.jboss.system.Registry;
+import org.jboss.test.JBossTestCase;
+
+
+public class JBPAPP6428TestCase extends JBossTestCase
+{
+   private static String CHECK_PARTITION_PROPERTY = "org.jboss.invocation.use.partition.name";
+
+   private static String PARTITION_NAME = "jboss.partition.name";
+
+   public JBPAPP6428TestCase(String name)
+   {
+      super(name);
+   }
+
+   private Invoker dummyInvoker = new Invoker()
+   {
+      @Override
+      public String getServerHostName() throws Exception
+      {
+         return null;
+      }
+      
+      @Override
+      public Object invoke(Invocation invocation) throws Exception
+      {
+         return null;
+      }
+   };
+
+   private InvokerInterceptor getDummyInvoker()
+   {
+      InvokerInterceptor invokerInterceptor = new InvokerInterceptor();
+
+      // this needs to be set to get back the first if
+      invokerInterceptor.setLocal(dummyInvoker);
+
+      return invokerInterceptor;
+   }
+
+   public Invocation getDummyInvocation(String destinationCluster)
+   {
+      Invocation invocation = new Invocation();
+      try
+      {
+         // Setup context to have name in org.jboss.invocation.InvokerProxyHA.getFamilyClusterInfo().getFamilyName()
+         InvokerLocator locator = new InvokerLocator("http://localhost:8080/dummyInvokerPath");
+         List targets = new ArrayList();
+         LoadBalancePolicy loadBalancePolicy = new RoundRobin();
+         String clusterFamilyName = destinationCluster;
+         UnifiedInvokerHAProxy invokerProxy = new UnifiedInvokerHAProxy(locator, false, targets, loadBalancePolicy, clusterFamilyName, 0L);
+                  
+         InvocationContext invocationContext = new InvocationContext();
+         invocationContext.setInvoker(invokerProxy);      
+         invocation.setInvocationContext(invocationContext);
+         
+         invocation.setObjectName("JBPAPP6428Test-dummy-"+destinationCluster);
+         
+         Registry.bind(invocation.getObjectName(), invocation);
+      } 
+      catch ( Exception e)
+      {
+         e.printStackTrace();
+      }
+      return invocation;
+   }
+
+   public void testCheckPartitionTrue()
+   {
+      System.setProperty(CHECK_PARTITION_PROPERTY, "true");
+
+      // This is the cluster that the server is set to -g cluster1
+      System.setProperty(PARTITION_NAME, "cluster1");
+
+      // Test when invocation should go to cluster1 - isLocal should return true
+      String destinationCluster = "cluster1/";
+      InvokerInterceptor invokerInterceptor = getDummyInvoker();
+      Invocation invocation = getDummyInvocation(destinationCluster);
+      assertTrue("Test destination == server cluster", invokerInterceptor.isLocal(invocation));
+      Registry.unbind(invocation.getObjectName());
+         
+      // Test when invocation should go to cluster2 - isLocal should return false      
+      destinationCluster = "cluster2/";
+      invokerInterceptor = getDummyInvoker();
+      invocation = getDummyInvocation(destinationCluster);            
+      assertFalse("Test destination != server cluster", invokerInterceptor.isLocal(invocation));
+      Registry.unbind(invocation.getObjectName());
+   }
+}



More information about the jboss-cvs-commits mailing list