[jboss-cvs] JBossAS SVN: r111868 - in branches/JBPAPP_5_1_1_GA_JBPAPP-6914/testsuite: src/main/org/jboss/test/cluster/defaultcfg and 1 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Jul 27 17:32:00 EDT 2011


Author: bmaxwell
Date: 2011-07-27 17:32:00 -0400 (Wed, 27 Jul 2011)
New Revision: 111868

Added:
   branches/JBPAPP_5_1_1_GA_JBPAPP-6914/testsuite/src/main/org/jboss/test/cluster/defaultcfg/JBPAPP6869UnitTestCase.java
   branches/JBPAPP_5_1_1_GA_JBPAPP-6914/testsuite/src/main/org/jboss/test/cluster/testutil/MockDistributedReplicantManager.java
Modified:
   branches/JBPAPP_5_1_1_GA_JBPAPP-6914/testsuite/build.xml
Log:
[JBPAPP-6914] adding test case for setting default load balance policy

Modified: branches/JBPAPP_5_1_1_GA_JBPAPP-6914/testsuite/build.xml
===================================================================
--- branches/JBPAPP_5_1_1_GA_JBPAPP-6914/testsuite/build.xml	2011-07-27 19:52:26 UTC (rev 111867)
+++ branches/JBPAPP_5_1_1_GA_JBPAPP-6914/testsuite/build.xml	2011-07-27 21:32:00 UTC (rev 111868)
@@ -220,6 +220,8 @@
       <path refid="jboss.server.manager.classpath"/>
       <path refid="jboss.jbossts.classpath"/>
 
+      <!-- Needed for JBPAPP-6869 test case -->
+      <path refid="jboss.jboss.ejb3.proxy.clustered.classpath"/>
    </path>
 
    <property name="jboss.dist.client" value="${jboss.dist}/client" />
@@ -456,6 +458,9 @@
       <pathelement path="${jboss.dist.common.lib}/jbossts-common.jar" />
       <pathelement path="${jboss.dist}/docs/examples/transactions/jbossts-tools.sar" />
       <pathelement path="${jboss.dist}/docs/examples/transactions/jbossxts.sar" />
+
+      <!-- Needed for JBPAPP-6869 test case -->
+      <pathelement path="${jboss.dist.common.lib}/jboss-ejb3-proxy-clustered.jar" />
    </path>
 
    <!-- ======= -->

Added: branches/JBPAPP_5_1_1_GA_JBPAPP-6914/testsuite/src/main/org/jboss/test/cluster/defaultcfg/JBPAPP6869UnitTestCase.java
===================================================================
--- branches/JBPAPP_5_1_1_GA_JBPAPP-6914/testsuite/src/main/org/jboss/test/cluster/defaultcfg/JBPAPP6869UnitTestCase.java	                        (rev 0)
+++ branches/JBPAPP_5_1_1_GA_JBPAPP-6914/testsuite/src/main/org/jboss/test/cluster/defaultcfg/JBPAPP6869UnitTestCase.java	2011-07-27 21:32:00 UTC (rev 111868)
@@ -0,0 +1,153 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2011, 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 org.jboss.ejb3.proxy.clustered.registry.ProxyClusteringInfo;
+import org.jboss.ejb3.proxy.clustered.registry.ProxyClusteringRegistry;
+import org.jboss.ha.framework.server.HAPartitionLocator;
+import org.jboss.logging.Logger;
+import org.jboss.metadata.ejb.jboss.ClusterConfigMetaData;
+import org.jboss.metadata.ejb.jboss.JBossSessionBeanMetaData;
+import org.jboss.metadata.ejb.spec.SessionType;
+import org.jboss.remoting.InvokerLocator;
+import org.jboss.test.JBossTestCase;
+import org.jboss.test.cluster.testutil.MockDistributedReplicantManager;
+import org.jboss.test.cluster.testutil.MockHAPartition;
+
+/**
+ * Test case for testing setting the default load balance policy
+ * https://issues.jboss.org/browse/JBPAPP-6869
+ * 
+ * @author bmaxwell
+ * 
+ */
+public class JBPAPP6869UnitTestCase extends JBossTestCase
+{
+   private static final String DEFAULT_STATELESS = "org.jboss.ha.client.loadbalance.RoundRobin";      
+   private static final String DEFAULT_STATEFUL = "org.jboss.ha.client.loadbalance.aop.FirstAvailable";
+
+   private Logger log = Logger.getLogger(this.getClass().getName());
+   
+   public JBPAPP6869UnitTestCase(String name)
+   {
+      super(name);
+   }
+   
+   public void testDefault()
+   {
+      ProxyClusteringRegistry pcr = new ProxyClusteringRegistry();
+      
+      // default LBP for Stateless
+      log.info("Testing the default for stateless");
+      Class clazz = getMockProxyClusteringInfo(pcr, null).getLoadBalancePolicy();
+      if( ! clazz.getName().equals(DEFAULT_STATELESS) )
+         fail("Default LoadBalancePolicy for Stateless Bean should be " + DEFAULT_STATELESS + " not " + clazz.getName());
+      
+      // default LBP/Sticky for Stateful
+      log.info("Testing the default for stateful");
+      clazz = getMockProxyClusteringInfo(pcr, SessionType.Stateful).getLoadBalancePolicy();
+      if( ! clazz.getName().equals(DEFAULT_STATEFUL) )
+         fail("Default LoadBalancePolicy for Stateless Bean should be " + DEFAULT_STATEFUL + " not " + clazz.getName());               
+   }
+   
+   public void testSetDefaultLoadBalancePolicyForStateless()
+   {      
+      ProxyClusteringRegistry pcr = new ProxyClusteringRegistry();
+
+      // test setting default LBP
+      log.info("Testing ability to set default Load Balance Policy for stateless");
+      pcr.setDefaultLoadBalancePolicy("FirstAvailable");     
+      String expected = "org.jboss.ha.client.loadbalance.FirstAvailable";
+      Class clazz = getMockProxyClusteringInfo(pcr, null).getLoadBalancePolicy();      
+      
+      if(! clazz.getName().equals(expected))
+         fail("Default LoadBalancePolicy for Stateless Bean should be " + expected + " not " + clazz.getName());
+         
+      // test fully qualified classname      
+      log.info("Testing ability to set default fully qualified Load Balance Policy for stateless");
+      pcr.setDefaultLoadBalancePolicy("org.jboss.ha.client.loadbalance.FirstAvailable");     
+      expected = "org.jboss.ha.client.loadbalance.FirstAvailable";
+      clazz = getMockProxyClusteringInfo(pcr, null).getLoadBalancePolicy();      
+      
+      if(! clazz.getName().equals(expected))
+         fail("Default LoadBalancePolicy for Stateless Bean should be " + expected + " not " + clazz.getName());
+   }
+   
+   public void testSetDefaultLoadBalancePolicyForStateful()
+   {
+      ProxyClusteringRegistry pcr = new ProxyClusteringRegistry();
+
+      // test setting default LBP
+      log.info("Testing ability to set default Load Balance Policy for Stateful");
+      pcr.setDefaultLoadBalancePolicy("RoundRobin");     
+      String expected = "org.jboss.ha.client.loadbalance.RoundRobin";
+      Class clazz = getMockProxyClusteringInfo(pcr, null).getLoadBalancePolicy();      
+      
+      if(! clazz.getName().equals(expected))
+         fail("Default LoadBalancePolicy for Stateful Bean should be " + expected + " not " + clazz.getName());
+         
+      // test fully qualified classname      
+      log.info("Testing ability to set default fully qualified Load Balance Policy for stateless");
+      pcr.setDefaultLoadBalancePolicy("org.jboss.ha.client.loadbalance.RoundRobin");     
+      expected = "org.jboss.ha.client.loadbalance.RoundRobin";
+      clazz = getMockProxyClusteringInfo(pcr, null).getLoadBalancePolicy();      
+      
+      if(! clazz.getName().equals(expected))
+         fail("Default LoadBalancePolicy for Stateful Bean should be " + expected + " not " + clazz.getName());
+   }
+    
+   private ProxyClusteringInfo getMockProxyClusteringInfo(ProxyClusteringRegistry pcr, SessionType sessionType)
+   {
+      try
+      {         
+         String partitionName = "MockPartition"; // this is hardcoded in MocHAPartition        
+         MockHAPartition partition = new MockHAPartition();         
+
+         partition.registerRPCHandler("testHandler", new MockDistributedReplicantManager());
+         
+         HAPartitionLocator.getHAPartitionLocator().registerHAPartition(partition);
+   
+         String containerName = "testcaseJBPAPP6869";
+         String proxyFactoryName = "testcaseJBPAPP6869ProxyFactoryName";
+         
+         JBossSessionBeanMetaData metadata = new JBossSessionBeanMetaData();
+         
+         if(sessionType != null)
+            metadata.setSessionType(sessionType);
+            
+         ClusterConfigMetaData clusterConfig = new ClusterConfigMetaData();
+         clusterConfig.setPartitionName(partitionName);
+         metadata.setClusterConfig(clusterConfig);
+         
+         InvokerLocator locator = new InvokerLocator("http://localhost/testcase/jbpapp6869");
+         
+         return pcr.registerClusteredBean(containerName, proxyFactoryName, metadata, locator);                       
+      }
+      catch(Exception e)
+      {
+         e.printStackTrace();
+         fail(e.getMessage());
+      }
+      return null;
+   }
+   
+}

Added: branches/JBPAPP_5_1_1_GA_JBPAPP-6914/testsuite/src/main/org/jboss/test/cluster/testutil/MockDistributedReplicantManager.java
===================================================================
--- branches/JBPAPP_5_1_1_GA_JBPAPP-6914/testsuite/src/main/org/jboss/test/cluster/testutil/MockDistributedReplicantManager.java	                        (rev 0)
+++ branches/JBPAPP_5_1_1_GA_JBPAPP-6914/testsuite/src/main/org/jboss/test/cluster/testutil/MockDistributedReplicantManager.java	2011-07-27 21:32:00 UTC (rev 111868)
@@ -0,0 +1,116 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2011, 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.testutil;
+
+import java.io.Serializable;
+import java.util.Collection;
+import java.util.List;
+
+import org.jboss.ha.framework.interfaces.ClusterNode;
+import org.jboss.ha.framework.interfaces.DistributedReplicantManager;
+
+/**
+ * This is a mock object for using in test cases, note it is not implemented, it was just needed to testing JBPAPP-6869
+ * 
+ * @author bmaxwell
+ */
+public class MockDistributedReplicantManager implements DistributedReplicantManager
+{
+
+   @Override
+   public void registerListener(String key, ReplicantListener subscriber)
+   {
+      // TODO Auto-generated method stub
+      
+   }
+
+   @Override
+   public void unregisterListener(String key, ReplicantListener subscriber)
+   {
+      // TODO Auto-generated method stub
+      
+   }
+
+   @Override
+   public void add(String key, Serializable replicant) throws Exception
+   {
+      // TODO Auto-generated method stub
+      
+   }
+
+   @Override
+   public void remove(String key) throws Exception
+   {
+      // TODO Auto-generated method stub
+      
+   }
+
+   @Override
+   public Serializable lookupLocalReplicant(String key)
+   {
+      // TODO Auto-generated method stub
+      return null;
+   }
+
+   @Override
+   public List lookupReplicants(String key)
+   {
+      // TODO Auto-generated method stub
+      return null;
+   }
+
+   @Override
+   public List lookupReplicantsNodeNames(String key)
+   {
+      // TODO Auto-generated method stub
+      return null;
+   }
+
+   @Override
+   public List<ClusterNode> lookupReplicantsNodes(String key)
+   {
+      // TODO Auto-generated method stub
+      return null;
+   }
+
+   @Override
+   public Collection getAllServices()
+   {
+      // TODO Auto-generated method stub
+      return null;
+   }
+
+   @Override
+   public int getReplicantsViewId(String key)
+   {
+      // TODO Auto-generated method stub
+      return 0;
+   }
+
+   @Override
+   public boolean isMasterReplica(String key)
+   {
+      // TODO Auto-generated method stub
+      return false;
+   }
+
+}



More information about the jboss-cvs-commits mailing list