[jboss-cvs] JBossAS SVN: r87436 - in branches/Branch_5_x/testsuite: src/main/org/jboss/test/cluster and 5 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Apr 16 11:13:26 EDT 2009


Author: galder.zamarreno at jboss.com
Date: 2009-04-16 11:13:26 -0400 (Thu, 16 Apr 2009)
New Revision: 87436

Added:
   branches/Branch_5_x/testsuite/src/main/org/jboss/test/cluster/defaultcfg/test/LookupSucceededFilterUnitTestCase.java
   branches/Branch_5_x/testsuite/src/main/org/jboss/test/cluster/defaultcfg/test/TruthfulResponseFilterUnitTestCase.java
   branches/Branch_5_x/testsuite/src/main/org/jboss/test/cluster/rspfilter/
   branches/Branch_5_x/testsuite/src/main/org/jboss/test/cluster/rspfilter/Echo.java
   branches/Branch_5_x/testsuite/src/main/org/jboss/test/cluster/rspfilter/EchoMBean.java
   branches/Branch_5_x/testsuite/src/main/org/jboss/test/cluster/rspfilter/TruthfulResponseFilter.java
   branches/Branch_5_x/testsuite/src/resources/cluster/rspfilter/
   branches/Branch_5_x/testsuite/src/resources/cluster/rspfilter/META-INF/
   branches/Branch_5_x/testsuite/src/resources/cluster/rspfilter/META-INF/jboss-service.xml
Modified:
   branches/Branch_5_x/testsuite/imports/sections/cluster.xml
Log:
[JBAS-5703] Added standalone lookup response filter unit test and in server, call on cluster with response filter test.

Modified: branches/Branch_5_x/testsuite/imports/sections/cluster.xml
===================================================================
--- branches/Branch_5_x/testsuite/imports/sections/cluster.xml	2009-04-16 15:11:46 UTC (rev 87435)
+++ branches/Branch_5_x/testsuite/imports/sections/cluster.xml	2009-04-16 15:13:26 UTC (rev 87436)
@@ -807,6 +807,13 @@
             <include name="org/jboss/test/cluster/ejb2/ustxsticky/*"/>
          </fileset>
       </zip>    
+
+      <zip destfile="${build.lib}/rspfilter.sar">
+         <zipfileset dir="${build.resources}/cluster/rspfilter"/>
+         <fileset dir="${build.classes}">
+            <include name="org/jboss/test/cluster/rspfilter/*"/>
+         </fileset>
+      </zip>    
       
    </target>  
 </project>

Added: branches/Branch_5_x/testsuite/src/main/org/jboss/test/cluster/defaultcfg/test/LookupSucceededFilterUnitTestCase.java
===================================================================
--- branches/Branch_5_x/testsuite/src/main/org/jboss/test/cluster/defaultcfg/test/LookupSucceededFilterUnitTestCase.java	                        (rev 0)
+++ branches/Branch_5_x/testsuite/src/main/org/jboss/test/cluster/defaultcfg/test/LookupSucceededFilterUnitTestCase.java	2009-04-16 15:13:26 UTC (rev 87436)
@@ -0,0 +1,87 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, 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.test.cluster.defaultcfg.test;
+
+import junit.framework.TestCase;
+
+import org.jboss.ha.framework.interfaces.ClusterNode;
+import org.jboss.ha.framework.interfaces.ResponseFilter;
+import org.jboss.ha.framework.server.ClusterNodeImpl;
+import org.jboss.ha.framework.server.ClusterPartition;
+import org.jboss.ha.framework.server.RspFilterAdapter;
+import org.jboss.ha.jndi.LookupSucceededFilter;
+import org.jgroups.Address;
+import org.jgroups.blocks.RspFilter;
+import org.jgroups.stack.IpAddress;
+
+/**
+ * LookupSucceededFilterUnitTestCase.
+ * 
+ * @author Galder Zamarreño
+ */
+public class LookupSucceededFilterUnitTestCase extends TestCase
+{
+   public void testFilterLogic()
+   {
+      ResponseFilter filter = new LookupSucceededFilter();
+      ClusterNode sender = new ClusterNodeImpl(new IpAddress(12345));
+      exerciseFilterLogic(filter, sender);
+   }
+
+   public void testFilterLogicViaAdapter()
+   {
+      ResponseFilter filter = new LookupSucceededFilter();
+      Address sender = new IpAddress(12345);
+      RspFilterAdapter adapter = new RspFilterAdapter(filter);
+      exerciseFilterLogic(adapter, sender);
+  }
+   
+   private void exerciseFilterLogic(ResponseFilter filter, ClusterNode sender)
+   {
+      filter.isAcceptable(null, sender);
+      assertTrue(filter.needMoreResponses());
+      
+      filter.isAcceptable(new Exception(), sender);
+      assertTrue(filter.needMoreResponses());
+      
+      filter.isAcceptable(new ClusterPartition.NoHandlerForRPC(), sender);
+      assertTrue(filter.needMoreResponses());
+
+      filter.isAcceptable(new String(), sender);
+      assertFalse(filter.needMoreResponses());
+   }
+   
+   private void exerciseFilterLogic(RspFilter filter, Address sender)
+   {
+      filter.isAcceptable(null, sender);
+      assertTrue(filter.needMoreResponses());
+      
+      filter.isAcceptable(new Exception(), sender);
+      assertTrue(filter.needMoreResponses());
+      
+      filter.isAcceptable(new ClusterPartition.NoHandlerForRPC(), sender);
+      assertTrue(filter.needMoreResponses());
+
+      filter.isAcceptable(new String(), sender);
+      assertFalse(filter.needMoreResponses());
+   }
+}

Added: branches/Branch_5_x/testsuite/src/main/org/jboss/test/cluster/defaultcfg/test/TruthfulResponseFilterUnitTestCase.java
===================================================================
--- branches/Branch_5_x/testsuite/src/main/org/jboss/test/cluster/defaultcfg/test/TruthfulResponseFilterUnitTestCase.java	                        (rev 0)
+++ branches/Branch_5_x/testsuite/src/main/org/jboss/test/cluster/defaultcfg/test/TruthfulResponseFilterUnitTestCase.java	2009-04-16 15:13:26 UTC (rev 87436)
@@ -0,0 +1,86 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, 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.test.cluster.defaultcfg.test;
+
+import java.util.List;
+
+import javax.management.MBeanServerConnection;
+import javax.management.ObjectName;
+
+import junit.framework.Test;
+
+import org.jboss.ha.framework.interfaces.ResponseFilter;
+import org.jboss.test.JBossClusteredTestCase;
+import org.jboss.test.cluster.rspfilter.TruthfulResponseFilter;
+
+/**
+ * TruthfulResponseFilterUnitTestCase.
+ * 
+ * @author Galder Zamarreño
+ */
+public class TruthfulResponseFilterUnitTestCase extends JBossClusteredTestCase
+{
+   public TruthfulResponseFilterUnitTestCase(String name)
+   {
+      super(name);
+   }
+
+   public static Test suite() throws Exception
+   {
+      return getDeploySetup(TruthfulResponseFilterUnitTestCase.class, "rspfilter.sar");
+   }
+   
+   public void testTrueEcho() throws Exception
+   {
+      MBeanServerConnection[] adaptors = this.getAdaptors();
+      ObjectName on = new ObjectName("cluster.rspfilter:service=Echo");
+      ResponseFilter filter = new TruthfulResponseFilter();
+      Object[] args = new Object[] {true, false, filter};
+      String[] signature = new String[] {boolean.class.getName(), boolean.class.getName(),ResponseFilter.class.getName()};
+      List resps = (List) adaptors[0].invoke(on, "callEchoOnCluster", args, signature);
+      log.debug("Response list: " + resps);
+      assertEquals(1, resps.size());
+      
+      if (resps.get(0) instanceof Exception) 
+      {
+         throw (Exception)resps.get(0);
+      }
+      
+      assertTrue(((Boolean)resps.get(0)).booleanValue());
+   }
+
+//   Commented from the time being since it results of call timing out since there'd be no responses
+//   and this will force 1 minute wait. testTrueEcho() is enough to give us an indication of 
+//   response filter being in action.
+//   
+//   public void testFalseEcho() throws Exception
+//   {
+//      MBeanServerConnection[] adaptors = this.getAdaptors();
+//      ObjectName on = new ObjectName("cluster.rspfilter:service=Echo");
+//      ResponseFilter filter = new TruthfulResponseFilter();
+//      Object[] args = new Object[] {false, false, filter};
+//      String[] signature = new String[] {boolean.class.getName(), boolean.class.getName(),ResponseFilter.class.getName()};
+//      List resps = (List) adaptors[0].invoke(on, "callEchoOnCluster", args, signature);
+//      log.debug("Response list: " + resps);
+//      assertEquals(0, resps.size());
+//   }
+}

Added: branches/Branch_5_x/testsuite/src/main/org/jboss/test/cluster/rspfilter/Echo.java
===================================================================
--- branches/Branch_5_x/testsuite/src/main/org/jboss/test/cluster/rspfilter/Echo.java	                        (rev 0)
+++ branches/Branch_5_x/testsuite/src/main/org/jboss/test/cluster/rspfilter/Echo.java	2009-04-16 15:13:26 UTC (rev 87436)
@@ -0,0 +1,76 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, 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.test.cluster.rspfilter;
+
+import java.util.List;
+
+import org.jboss.ha.framework.interfaces.ClusterNode;
+import org.jboss.ha.framework.interfaces.HAPartition;
+import org.jboss.ha.framework.interfaces.ResponseFilter;
+import org.jboss.logging.Logger;
+
+/**
+ * Echo.
+ * 
+ * @author Galder Zamarreño
+ */
+public class Echo implements EchoMBean
+{
+   private static final Logger log = Logger.getLogger(Echo.class);
+   private static final String NAME = "cluster.rspfilter:service=Echo";
+   private HAPartition partition;
+   
+   public boolean echo(boolean echo, ClusterNode sender)
+   {
+      // Only reply echo if I'm *not* the node that send it.
+      if (!sender.equals(partition.getClusterNode()))
+      {
+         return echo;
+      }
+      return false;
+   }
+
+   public void setHAPartition(HAPartition partition)
+   {
+      log.debug("Set partition: " + partition);
+      this.partition = partition;
+   }
+
+   public List callEchoOnCluster(boolean echo, boolean excludeSelf, ResponseFilter filter) throws Exception
+   {
+      log.debug("callEchoOnCluster(" + echo+ ", " + excludeSelf + ", " + filter+ ")");
+      return partition.callMethodOnCluster(NAME, "echo", new Object[] {echo, partition.getClusterNode()}, 
+            new Class[] {boolean.class, ClusterNode.class}, excludeSelf, filter);
+   }
+   
+   public void start() throws Exception
+   {
+      log.debug("Register rpc handler " + this + " with " + NAME);
+      partition.registerRPCHandler(NAME, this);
+   }
+   
+   public void stop() throws Exception
+   {
+      log.debug("Unregister rpc handler " + this + " with " + NAME);
+      partition.unregisterRPCHandler(NAME, this);
+   }
+}

Added: branches/Branch_5_x/testsuite/src/main/org/jboss/test/cluster/rspfilter/EchoMBean.java
===================================================================
--- branches/Branch_5_x/testsuite/src/main/org/jboss/test/cluster/rspfilter/EchoMBean.java	                        (rev 0)
+++ branches/Branch_5_x/testsuite/src/main/org/jboss/test/cluster/rspfilter/EchoMBean.java	2009-04-16 15:13:26 UTC (rev 87436)
@@ -0,0 +1,42 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, 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.test.cluster.rspfilter;
+
+import java.util.List;
+
+import org.jboss.ha.framework.interfaces.ClusterNode;
+import org.jboss.ha.framework.interfaces.HAPartition;
+import org.jboss.ha.framework.interfaces.ResponseFilter;
+
+/**
+ * EchoMBean.
+ * 
+ * @author Galder Zamarreño
+ */
+public interface EchoMBean 
+{
+   boolean echo(boolean echo, ClusterNode sender);
+   void start() throws Exception;
+   void stop() throws Exception;
+   void setHAPartition(HAPartition clusterPartition);
+   List callEchoOnCluster(boolean echo, boolean excludeSelf, ResponseFilter filter) throws Exception;
+}

Added: branches/Branch_5_x/testsuite/src/main/org/jboss/test/cluster/rspfilter/TruthfulResponseFilter.java
===================================================================
--- branches/Branch_5_x/testsuite/src/main/org/jboss/test/cluster/rspfilter/TruthfulResponseFilter.java	                        (rev 0)
+++ branches/Branch_5_x/testsuite/src/main/org/jboss/test/cluster/rspfilter/TruthfulResponseFilter.java	2009-04-16 15:13:26 UTC (rev 87436)
@@ -0,0 +1,65 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, 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.test.cluster.rspfilter;
+
+import java.io.Serializable;
+
+import org.jboss.ha.framework.interfaces.ClusterNode;
+import org.jboss.ha.framework.interfaces.ResponseFilter;
+import org.jboss.ha.framework.server.ClusterPartition.NoHandlerForRPC;
+import org.jboss.logging.Logger;
+
+/**
+ * TruthfulResponseFilter.
+ * 
+ * @author Galder Zamarreño
+ */
+public class TruthfulResponseFilter implements ResponseFilter, Serializable
+{
+   private static final long serialVersionUID = 2223820538160300865L;
+   private static final Logger log = Logger.getLogger(TruthfulResponseFilter.class);
+   private boolean lookupSucceeded;
+
+   public boolean isAcceptable(Object response, ClusterNode sender)
+   {
+      log.debug("isAcceptable (" + response + ") from " + sender);
+      
+      if (response != null && !(response instanceof Exception) && !(response instanceof NoHandlerForRPC)) 
+      {
+         lookupSucceeded = (Boolean)response; 
+      }
+      
+      if (lookupSucceeded)
+      {
+         log.debug("Lookup succeded from " + sender);
+      }
+      
+      return lookupSucceeded;
+   }
+
+   public boolean needMoreResponses()
+   {
+      log.debug("needMoreResponses? " + !(lookupSucceeded));
+      return !(lookupSucceeded);
+   }
+
+}

Added: branches/Branch_5_x/testsuite/src/resources/cluster/rspfilter/META-INF/jboss-service.xml
===================================================================
--- branches/Branch_5_x/testsuite/src/resources/cluster/rspfilter/META-INF/jboss-service.xml	                        (rev 0)
+++ branches/Branch_5_x/testsuite/src/resources/cluster/rspfilter/META-INF/jboss-service.xml	2009-04-16 15:13:26 UTC (rev 87436)
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<server>
+  <mbean code="org.jboss.test.cluster.rspfilter.Echo" name="cluster.rspfilter:service=Echo">
+    <attribute name="HAPartition"><inject bean="HAPartition"/></attribute>
+  </mbean>
+</server>




More information about the jboss-cvs-commits mailing list