[jboss-cvs] JBossAS SVN: r67744 - in branches/JBoss_4_0_0_CP/testsuite/src/main/org/jboss/test/cluster: drm and 1 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Sun Dec 2 17:27:15 EST 2007


Author: jiwils
Date: 2007-12-02 17:27:15 -0500 (Sun, 02 Dec 2007)
New Revision: 67744

Added:
   branches/JBoss_4_0_0_CP/testsuite/src/main/org/jboss/test/cluster/drm/
   branches/JBoss_4_0_0_CP/testsuite/src/main/org/jboss/test/cluster/drm/MockHAPartition.java
   branches/JBoss_4_0_0_CP/testsuite/src/main/org/jboss/test/cluster/test/DRMTestCase.java
Log:
Fix for [ASPATCH-322]; added test DRMTestCase.testReplicantOrder to test the backport of [JBAS-2677].

Copied: branches/JBoss_4_0_0_CP/testsuite/src/main/org/jboss/test/cluster/drm/MockHAPartition.java (from rev 67645, branches/JBoss_4_0_1_SP1_JBAS-2700/testsuite/src/main/org/jboss/test/cluster/drm/MockHAPartition.java)
===================================================================
--- branches/JBoss_4_0_0_CP/testsuite/src/main/org/jboss/test/cluster/drm/MockHAPartition.java	                        (rev 0)
+++ branches/JBoss_4_0_0_CP/testsuite/src/main/org/jboss/test/cluster/drm/MockHAPartition.java	2007-12-02 22:27:15 UTC (rev 67744)
@@ -0,0 +1,217 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, 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.drm;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Vector;
+
+import org.jboss.ha.framework.interfaces.ClusterNode;
+import org.jboss.ha.framework.interfaces.DistributedReplicantManager;
+import org.jboss.ha.framework.interfaces.DistributedState;
+import org.jboss.ha.framework.interfaces.HAPartition;
+import org.jgroups.stack.IpAddress;
+
+/**
+ * Mock implementation of HAPartition intended to support unit testing
+ * of DistributedReplicantManagerImpl without the need for an underlying
+ * JChannel.
+ * 
+ * @author <a href="brian.stansberry at jboss.com">Brian Stansberry</a>
+ * @version $Id$
+ */
+public class MockHAPartition implements HAPartition
+{   
+   public static final String PARTITION_NAME = "MockPartition";
+   
+   private DistributedReplicantManager drm;
+   private Vector currentNodes;
+   private ClusterNode localAddress;
+   private ArrayList remoteReplicants;
+   
+   public MockHAPartition(ClusterNode localAddress)
+   {
+      this.localAddress = localAddress;
+   }
+   // ------------------------------------------------------------  HAPartition
+   
+   public String getNodeName()
+   {
+      return localAddress.getName();
+   }
+
+   public String getPartitionName()
+   {
+      return PARTITION_NAME;
+   }
+
+   public DistributedReplicantManager getDistributedReplicantManager()
+   {
+      return drm;
+   }
+
+   public DistributedState getDistributedStateService()
+   {
+
+      throw new UnsupportedOperationException("not implemented");
+   }
+
+   public void registerRPCHandler(String serviceName, Object handler)
+   {
+      if (handler instanceof DistributedReplicantManager)
+         drm = (DistributedReplicantManager) handler;
+      else
+         throw new UnsupportedOperationException("not implemented");
+   }
+
+   public void unregisterRPCHandler(String serviceName, Object subscriber)
+   {
+      if (subscriber == drm)
+         drm = null;
+      else    
+         throw new UnsupportedOperationException("not implemented");
+   }
+
+   public ArrayList callMethodOnCluster(String serviceName, String methodName, Object[] args, Class[] types,
+         boolean excludeSelf) throws Exception
+   {
+      if (excludeSelf)
+      {
+         if ("_add".equals(methodName)) 
+         {
+            // no-op -- there is no cluster
+            return null;
+         }
+         else if ("lookupLocalReplicants".equals(methodName) && args.length == 0)
+         {
+            return remoteReplicants;
+         }
+      }
+      // TODO Implement lookupLocalReplicants for DRM SERVICE_NAME
+
+      throw new UnsupportedOperationException("not implemented");
+   }
+
+   public ArrayList callMethodOnCluster(String serviceName, String methodName, Object[] args, boolean excludeSelf)
+         throws Exception
+   {
+
+      throw new UnsupportedOperationException("not implemented");
+   }
+
+   public void callAsynchMethodOnCluster(String serviceName, String methodName, Object[] args, Class[] types,
+         boolean excludeSelf) throws Exception
+   {
+      if (excludeSelf && "_remove".equals(methodName))
+      {
+         // no-op -- there is no cluster
+         return;
+      }
+
+      throw new UnsupportedOperationException("not implemented");
+   }
+
+   public void callAsynchMethodOnCluster(String serviceName, String methodName, Object[] args, boolean excludeSelf)
+         throws Exception
+   {
+      throw new UnsupportedOperationException("not implemented");
+   }
+
+   public ArrayList callMethodOnCoordinatorNode(String serviceName, String methodName, Object[] args, Class[] types,
+         boolean excludeSelf) throws Exception
+   {
+      throw new UnsupportedOperationException("not implemented");
+   }
+
+   public void subscribeToStateTransferEvents(String serviceName, HAPartitionStateTransfer subscriber)
+   {
+      // no-op. at this point the test fixture directly passes state
+      // to the target DRM
+   }
+
+   public void unsubscribeFromStateTransferEvents(String serviceName, HAPartitionStateTransfer subscriber)
+   {
+      // no-op. at this point the test fixture directly passes state
+      // to the target DRM
+   }
+
+   public void registerMembershipListener(HAMembershipListener listener)
+   {
+      // no-op. at this point the test fixture directly passes membership
+      // changes to the target DRM
+   }
+
+   public void unregisterMembershipListener(HAMembershipListener listener)
+   {
+      // no-op. at this point the test fixture directly passes membership
+      // changes to the target DRM
+   }
+   
+   public boolean getAllowSynchronousMembershipNotifications()
+   {
+      return false;
+   }
+   
+   public void setAllowSynchronousMembershipNotifications(boolean allowSync)
+   {
+      // no-op      
+   }
+
+   public long getCurrentViewId()
+   {
+
+      throw new UnsupportedOperationException("not implemented");
+   }
+
+   public Vector getCurrentView()
+   {
+      Vector result = new Vector();
+      for (int i = 0; i < currentNodes.size(); i++)
+         result.add(((ClusterNode) currentNodes.elementAt(i)).getName());
+         
+      return result;
+   }
+
+   public ClusterNode[] getClusterNodes()
+   {
+      ClusterNode[] result = new ClusterNode[currentNodes.size()];
+      return (ClusterNode[]) currentNodes.toArray(result);
+   }
+
+   public ClusterNode getClusterNode()
+   {
+      return localAddress;
+   }
+   
+   // ---------------------------------------------------------  Public Methods
+   
+   public void setCurrentViewClusterNodes(Vector nodes)
+   {
+      this.currentNodes = nodes;
+   }
+   
+   public void setRemoteReplicants(ArrayList remoteReplicants)
+   {
+      this.remoteReplicants = remoteReplicants;
+   }
+
+}

Copied: branches/JBoss_4_0_0_CP/testsuite/src/main/org/jboss/test/cluster/test/DRMTestCase.java (from rev 67645, branches/JBoss_4_0_1_SP1_JBAS-2700/testsuite/src/main/org/jboss/test/cluster/test/DRMTestCase.java)
===================================================================
--- branches/JBoss_4_0_0_CP/testsuite/src/main/org/jboss/test/cluster/test/DRMTestCase.java	                        (rev 0)
+++ branches/JBoss_4_0_0_CP/testsuite/src/main/org/jboss/test/cluster/test/DRMTestCase.java	2007-12-02 22:27:15 UTC (rev 67744)
@@ -0,0 +1,257 @@
+/*
+* JBoss, the OpenSource J2EE webOS
+*
+* Distributable under LGPL license.
+* See terms of license at gnu.org.
+*/
+package org.jboss.test.cluster.test;
+
+import java.rmi.RemoteException;
+import java.rmi.server.UnicastRemoteObject;
+import java.security.SecureRandom;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.Vector;
+import java.util.List;
+import java.util.HashSet;
+
+import javax.management.MBeanServer;
+import javax.management.MBeanServerFactory;
+import javax.management.MBeanServerInvocationHandler;
+import javax.management.ObjectName;
+import javax.management.Notification;
+
+import junit.framework.Test;
+
+import org.jboss.test.JBossClusteredTestCase;
+
+/* Added per movement to 401sp1, not part of ASPATCH-322
+import org.jboss.test.cluster.drm.IReplicants;
+*/
+
+import org.jboss.test.cluster.drm.MockHAPartition;
+import org.jboss.ha.framework.interfaces.ClusterNode;
+import org.jboss.ha.framework.interfaces.DistributedReplicantManager.ReplicantListener;
+import org.jboss.ha.framework.server.DistributedReplicantManagerImpl;
+import org.jboss.jmx.adaptor.rmi.RMIAdaptor;
+import org.jboss.jmx.adaptor.rmi.RMIAdaptorExt;
+import org.jboss.jmx.adaptor.rmi.RMINotificationListener;
+import org.jgroups.stack.IpAddress;
+import org.apache.log4j.Logger;
+
+/** Tests of http session replication
+ *
+ * @author  Scott.Stark at jboss.org
+ * @version $Revision$
+ */
+public class DRMTestCase extends JBossClusteredTestCase
+{
+   static class TestListener extends UnicastRemoteObject
+      implements RMINotificationListener
+   {
+      private Logger log;
+      TestListener(Logger log) throws RemoteException
+      {
+         this.log = log;
+      }
+      public void handleNotification(Notification notification, Object handback)
+         throws RemoteException
+      {
+         log.info(notification);
+      }
+   }
+
+   /** ReplicantListener that caches the list of replicants */
+   static class CachingListener implements ReplicantListener
+   {
+      List replicants = null;
+      boolean clean = true;
+
+      public void replicantsChanged(String key, List newReplicants,
+                                    int newReplicantsViewId)
+      {
+         this.replicants = newReplicants;
+         if (clean && newReplicants != null)
+         {
+            int last = Integer.MIN_VALUE;
+            for (Iterator iter = newReplicants.iterator(); iter.hasNext(); )
+            {
+               int cur = ((Integer) iter.next()).intValue();
+               if (last >= cur)
+               {
+                  clean = false;
+                  break;
+               }
+
+               last = cur;
+            }
+         }
+      }
+
+   }
+
+   public static Test suite() throws Exception
+   {
+      Test t1 = getDeploySetup(DRMTestCase.class, "drm-tests.sar");
+      return t1;
+   }
+
+   public DRMTestCase(String name)
+   {
+      super(name);
+   }
+
+/* Test added per movment to 401sp1, not related to ASPATCH-322
+   public void testStateReplication()
+      throws Exception
+   {
+      log.debug("+++ testStateReplication");
+
+      RMIAdaptor[] adaptors = getAdaptors();
+      String[] servers = super.getServers();
+      RMIAdaptorExt server0 = (RMIAdaptorExt) adaptors[0];
+      log.info("server0: "+server0);
+      ObjectName clusterService = new ObjectName("jboss:service=DefaultPartition");
+      Vector view0 = (Vector) server0.getAttribute(clusterService, "CurrentView");
+      log.info("server0: CurrentView, "+view0);
+      ObjectName drmService = new ObjectName("jboss.test:service=DRMTestCase");
+      IReplicants drm0 = (IReplicants)
+         MBeanServerInvocationHandler.newProxyInstance(server0, drmService,
+         IReplicants.class, true);
+      TestListener listener = new TestListener(log);
+      server0.addNotificationListener(drmService, listener, null, null);
+      String address = (String) drm0.lookupLocalReplicant();
+      log.info("server0: lookupLocalReplicant: "+address);
+      assertTrue("server0: address("+address+") == server0("+servers[0]+")",
+         address.equals(servers[0]));
+
+      RMIAdaptorExt server1 = (RMIAdaptorExt) adaptors[1];
+      log.info("server1: "+server1);
+      Vector view1 = (Vector) server1.getAttribute(clusterService, "CurrentView");
+      log.info("server1: CurrentView, "+view1);
+      IReplicants drm1 = (IReplicants)
+         MBeanServerInvocationHandler.newProxyInstance(server1, drmService,
+         IReplicants.class, true);
+      server1.addNotificationListener(drmService, listener, null, null);
+      address = (String) drm1.lookupLocalReplicant();
+      log.info("server1: lookupLocalReplicant: "+address);
+      assertTrue("server1: address("+address+") == server1("+servers[1]+")",
+         address.equals(servers[1]));
+
+      List replicants0 = drm0.lookupLocalReplicants();
+      List replicants1 = drm1.lookupLocalReplicants();
+      assertTrue("size of replicants0 == replicants1)",
+         replicants0.size() == replicants1.size());
+      HashSet testSet = new HashSet(replicants0);
+      for(int n = 0; n < replicants0.size(); n ++)
+      {
+         Object entry = replicants1.get(n);
+         assertTrue("replicants0 contains:"+entry, testSet.contains(entry));
+      }
+   } */
+
+   public void testReplicantOrder() throws Exception
+   {
+      MBeanServer mbeanServer =
+         MBeanServerFactory.createMBeanServer("mockPartitionA");
+      try {
+
+         //  Create a fake view for the MockHAPartition
+         ClusterNode[] nodes = new ClusterNode[5];
+         String[] names = new String[nodes.length];
+         Integer[] replicants = new Integer[nodes.length];
+         Vector allNodes = new Vector();
+         for (int i = 0; i < nodes.length; i++)
+         {
+            nodes[i] = new ClusterNode(new IpAddress("127.0.0.1", 12340 + i));
+            allNodes.add(nodes[i]);
+            names[i] = nodes[i].getName();
+            replicants[i] = new Integer(i);
+         }
+
+         MockHAPartition partition = new MockHAPartition(nodes[2]);
+         partition.setCurrentViewClusterNodes(allNodes);
+
+         DistributedReplicantManagerImpl drm =
+               new DistributedReplicantManagerImpl(partition, mbeanServer);
+         drm.init();
+         drm.start();
+
+         CachingListener listener = new CachingListener();
+         drm.registerListener("TEST", listener);
+
+         SecureRandom random = new SecureRandom();
+         boolean[] added = new boolean[nodes.length];
+         List lookup = null;
+         for (int i = 0; i < 10; i++)
+         {
+            int node = random.nextInt(nodes.length);
+            if (added[node])
+            {
+               if (node == 2)
+                  drm.remove("TEST");
+               else
+                  drm._remove("TEST", nodes[node].getName());
+               added[node] = false;
+            }
+            else
+            {
+               if (node == 2)
+                  drm.add("TEST", replicants[node]);
+               else
+                  drm._add("TEST", nodes[node].getName(), replicants[node]);
+               added[node] = true;
+            }
+
+            // Confirm the proper order of the replicant node names
+            lookup = maskListClass(drm.lookupReplicantsNodeNames("TEST"));
+            confirmReplicantList(lookup, names, added);
+
+            // Confirm the proper order of the replicants via lookupReplicants
+            lookup = maskListClass(drm.lookupReplicants("TEST"));
+            confirmReplicantList(lookup, replicants, added);
+
+            // Confirm the listener got the same list
+//            assertEquals("Listener received a correct list", lookup,
+//                         maskListClass(listener.replicants));
+         }
+
+         // Let the asynchronous notification thread catch up
+         sleep(25);
+
+         // Confirm all lists presented to the listener were properly ordered
+         assertTrue("Listener saw no misordered lists", listener.clean);
+
+      }
+      finally {
+         MBeanServerFactory.releaseMBeanServer(mbeanServer);
+      }
+   }
+
+   private void confirmReplicantList(List current, Object[] all, boolean[] added)
+   {
+      Iterator iter = current.iterator();
+      for (int i = 0; i < added.length; i++)
+      {
+         if (added[i])
+         {
+            assertTrue("List has more replicants", iter.hasNext());
+            assertEquals("Replicant for node " + i + " is next",
+                         all[i], iter.next());
+         }
+      }
+      assertFalse("List has no extra replicants", iter.hasNext());
+   }
+
+   /** Converts the given list to an ArrayList, if it isn't already */
+   private List maskListClass(List toMask)
+   {
+      if (toMask instanceof ArrayList)
+         return toMask;
+      else if (toMask == null)
+         return new ArrayList();
+      else
+         return new ArrayList(toMask);
+   }
+
+}




More information about the jboss-cvs-commits mailing list