[jboss-cvs] JBossAS SVN: r102687 - in projects/cluster/ha-server-cache-jbc/trunk/src/test/java/org/jboss: web/tomcat/service and 2 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Sun Mar 21 14:17:52 EDT 2010


Author: bstansberry at jboss.com
Date: 2010-03-21 14:17:52 -0400 (Sun, 21 Mar 2010)
New Revision: 102687

Added:
   projects/cluster/ha-server-cache-jbc/trunk/src/test/java/org/jboss/web/tomcat/service/sso/
   projects/cluster/ha-server-cache-jbc/trunk/src/test/java/org/jboss/web/tomcat/service/sso/jbc/
   projects/cluster/ha-server-cache-jbc/trunk/src/test/java/org/jboss/web/tomcat/service/sso/jbc/DelegatingMockCache.java
   projects/cluster/ha-server-cache-jbc/trunk/src/test/java/org/jboss/web/tomcat/service/sso/jbc/JBossCacheSSOClusterManagerUnitTestCase.java
Modified:
   projects/cluster/ha-server-cache-jbc/trunk/src/test/java/org/jboss/ha/cachemanager/CacheManagerUnitTestCase.java
Log:
[JBCLUSTER-252] Move test of JBossCacheSSOClusterManager to ha-server-cache-jbc

Modified: projects/cluster/ha-server-cache-jbc/trunk/src/test/java/org/jboss/ha/cachemanager/CacheManagerUnitTestCase.java
===================================================================
--- projects/cluster/ha-server-cache-jbc/trunk/src/test/java/org/jboss/ha/cachemanager/CacheManagerUnitTestCase.java	2010-03-21 15:45:02 UTC (rev 102686)
+++ projects/cluster/ha-server-cache-jbc/trunk/src/test/java/org/jboss/ha/cachemanager/CacheManagerUnitTestCase.java	2010-03-21 18:17:52 UTC (rev 102687)
@@ -20,6 +20,8 @@
 import org.jboss.cache.config.Configuration;
 import org.jboss.cache.config.ConfigurationRegistry;
 import org.jboss.cache.pojo.PojoCache;
+import org.jboss.ha.framework.server.CacheManagerLocator;
+import org.jboss.ha.framework.server.PojoCacheManagerLocator;
 import org.jgroups.JChannelFactory;
 
 /**
@@ -50,6 +52,9 @@
          }
       }
       caches.clear();
+      
+      CacheManagerLocator.getCacheManagerLocator().deregisterCacheManager();
+      PojoCacheManagerLocator.getCacheManagerLocator().deregisterCacheManager();
    }
 
    /**

Added: projects/cluster/ha-server-cache-jbc/trunk/src/test/java/org/jboss/web/tomcat/service/sso/jbc/DelegatingMockCache.java
===================================================================
--- projects/cluster/ha-server-cache-jbc/trunk/src/test/java/org/jboss/web/tomcat/service/sso/jbc/DelegatingMockCache.java	                        (rev 0)
+++ projects/cluster/ha-server-cache-jbc/trunk/src/test/java/org/jboss/web/tomcat/service/sso/jbc/DelegatingMockCache.java	2010-03-21 18:17:52 UTC (rev 102687)
@@ -0,0 +1,502 @@
+/*
+ * 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.web.tomcat.service.sso.jbc;
+
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.jboss.cache.Cache;
+import org.jboss.cache.CacheException;
+import org.jboss.cache.CacheStatus;
+import org.jboss.cache.Fqn;
+import org.jboss.cache.InvocationContext;
+import org.jboss.cache.Node;
+import org.jboss.cache.NodeNotExistsException;
+import org.jboss.cache.Region;
+import org.jboss.cache.config.Configuration;
+import org.jboss.cache.interceptors.base.CommandInterceptor;
+import org.jgroups.Address;
+
+/**
+ * Cache impl that delegates all calls to a passed in object.
+ * Meant to provide a base for overriding methods.
+ * 
+ * @author <a href="brian.stansberry at jboss.com">Brian Stansberry</a>
+ * @version $Revision: 86279 $
+ */
+public class DelegatingMockCache<K, V> implements Cache<K, V>
+{
+
+   private final Cache<K, V> delegate;
+   
+   public DelegatingMockCache(Cache<K, V> delegate) 
+   {
+      super();
+      this.delegate = delegate;
+   }
+   
+   public void addInterceptor(CommandInterceptor arg0, Class arg1)
+   {
+      delegate.addInterceptor(arg0, arg1);      
+   }
+
+   public void addInterceptor(CommandInterceptor arg0, int arg1)
+   {
+      delegate.addInterceptor(arg0, arg1);      
+   }
+
+   public void removeInterceptor(int arg0)
+   {
+      delegate.removeInterceptor(arg0);      
+   }
+
+   public void startBatch()
+   {
+      delegate.startBatch();    
+   }
+
+   public void endBatch(boolean arg0)
+   {
+      delegate.endBatch(arg0);      
+   }
+
+   public void removeInterceptor(Class arg0)
+   {
+      // TODO Auto-generated method stub
+      
+   }
+   
+//   public void addInterceptor(Interceptor arg0, int arg1)
+//   {
+//      delegate.addInterceptor(arg0, arg1);
+//   }
+//
+//   public void addInterceptor(Interceptor arg0, Class arg1)
+//   {
+//      delegate.addInterceptor(arg0, arg1);
+//   }
+//
+//   public boolean exists(Fqn arg0)
+//   {
+//      return delegate.exists(arg0);
+//   }
+//
+//   public boolean exists(String arg0)
+//   {
+//      return delegate.exists(arg0);
+//   }
+
+//   public void fetchPartialState(List arg0, Fqn arg1) throws Exception
+//   {
+//      delegate.fetchPartialState(arg0, arg1);
+//   }
+//
+//   public void fetchPartialState(List arg0, Fqn arg1, Fqn arg2) throws Exception
+//   {
+//      delegate.fetchPartialState(arg0, arg1, arg2);
+//   }
+
+//   public BuddyManager getBuddyManager()
+//   {
+//      return delegate.getBuddyManager();
+//   }
+//
+//   public CacheLoaderManager getCacheLoaderManager()
+//   {
+//      return delegate.getCacheLoaderManager();
+//   }
+//
+//   public Set getChildrenNames(Fqn arg0)
+//   {
+//      return delegate.getChildrenNames(arg0);
+//   }
+//
+//   public Set getChildrenNames(String arg0)
+//   {
+//      return delegate.getChildrenNames(arg0);
+//   }
+//
+//   public String getClusterName()
+//   {
+//      return delegate.getClusterName();
+//   }
+//
+//   public GlobalTransaction getCurrentTransaction()
+//   {
+//      return delegate.getCurrentTransaction();
+//   }
+//
+//   public GlobalTransaction getCurrentTransaction(Transaction arg0, boolean arg1)
+//   {
+//      return delegate.getCurrentTransaction(arg0, arg1);
+//   }
+//
+//   public List getInterceptorChain()
+//   {
+//      return delegate.getInterceptorChain();
+//   }
+//
+//   public Set getInternalFqns()
+//   {
+//      return delegate.getInternalFqns();
+//   }
+
+//   public Map getLockTable()
+//   {
+//      return delegate.getLockTable();
+//   }
+
+//   public Marshaller getMarshaller()
+//   {
+//      return delegate.getMarshaller();
+//   }
+//
+//   public Notifier getNotifier()
+//   {
+//      return delegate.getNotifier();
+//   }
+//
+//   public int getNumberOfAttributes()
+//   {
+//      return delegate.getNumberOfAttributes();
+//   }
+//
+//   public int getNumberOfLocksHeld()
+//   {
+//      return delegate.getNumberOfLocksHeld();
+//   }
+//
+//   public int getNumberOfNodes()
+//   {
+//      return delegate.getNumberOfNodes();
+//   }
+//
+//   public RPCManager getRPCManager()
+//   {
+//      return delegate.getRPCManager();
+//   }
+//
+//   public RegionManager getRegionManager()
+//   {
+//      return delegate.getRegionManager();
+//   }
+//
+//   public NodeSPI getRoot()
+//   {
+//      return delegate.getRoot();
+//   }
+//
+//   public StateTransferManager getStateTransferManager()
+//   {
+//      return delegate.getStateTransferManager();
+//   }
+//
+//   public TransactionManager getTransactionManager()
+//   {
+//      return delegate.getTransactionManager();
+//   }
+//
+//   public TransactionTable getTransactionTable()
+//   {
+//      return delegate.getTransactionTable();
+//   }
+//
+//   public GravitateResult gravitateData(Fqn arg0, boolean arg1)
+//   {
+//      return delegate.gravitateData(arg0, arg1);
+//   }
+//
+//   public NodeSPI peek(Fqn arg0, boolean arg1)
+//   {
+//      return delegate.peek(arg0, arg1);
+//   }
+//
+//   public NodeSPI peek(Fqn arg0, boolean arg1, boolean arg2)
+//   {
+//      return delegate.peek(arg0, arg1, arg2);
+//   }
+//
+//   public void removeInterceptor(int arg0)
+//   {
+//      delegate.removeInterceptor(arg0);
+//   }
+//
+//   public void removeInterceptor(Class arg0)
+//   {
+//      delegate.removeInterceptor(arg0);
+//   }
+
+   public Node getNode(Fqn arg0)
+   {
+      return delegate.getNode(arg0);
+   }
+
+   public Node getNode(String arg0)
+   {
+      return delegate.getNode(arg0);
+   }
+
+   public Node getRoot()
+   {
+      return delegate.getRoot();
+   }
+
+   public void addCacheListener(Object arg0)
+   {
+      delegate.addCacheListener(arg0);
+   }
+
+   public void addCacheListener(Fqn arg0, Object arg1)
+   {
+      //delegate.addCacheListener(arg0, arg1);
+   }
+
+   public void clearData(String arg0)
+   {
+      delegate.clearData(arg0);
+   }
+
+   public void clearData(Fqn arg0)
+   {
+      delegate.clearData(arg0);
+   }
+
+   public void create() throws CacheException
+   {
+      delegate.create();
+   }
+
+   public void destroy()
+   {
+      delegate.destroy();
+   }
+
+   public void evict(Fqn arg0)
+   {
+      delegate.evict(arg0);
+   }
+
+   public void evict(Fqn arg0, boolean arg1)
+   {
+      delegate.evict(arg0, arg1);
+   }
+
+   public V get(Fqn arg0, K arg1)
+   {
+      return delegate.get(arg0, arg1);
+   }
+
+   public V get(String arg0, K arg1)
+   {
+      return delegate.get(arg0, arg1);
+   }
+
+   public Set getCacheListeners()
+   {
+      return delegate.getCacheListeners();
+   }
+
+   public Set getCacheListeners(Fqn arg0)
+   {
+      return new HashSet<Object>();
+   }
+
+   public CacheStatus getCacheStatus()
+   {
+      return delegate.getCacheStatus();
+   }
+
+   public Configuration getConfiguration()
+   {
+      return delegate.getConfiguration();
+   }
+
+   public Map getData(Fqn arg0)
+   {
+      return delegate.getData(arg0);
+   }
+
+   public InvocationContext getInvocationContext()
+   {
+      return delegate.getInvocationContext();
+   }
+
+   public Set getKeys(String arg0)
+   {
+      return delegate.getKeys(arg0);
+   }
+
+   public Set getKeys(Fqn arg0)
+   {
+      return delegate.getKeys(arg0);
+   }
+
+   public Address getLocalAddress()
+   {
+      return delegate.getLocalAddress();
+   }
+
+   public List getMembers()
+   {
+      return delegate.getMembers();
+   }
+
+//   public NodeSPI getNode(Fqn arg0)
+//   {
+//      return delegate.getNode(arg0);
+//   }
+//
+//   public NodeSPI getNode(String arg0)
+//   {
+//      return delegate.getNode(arg0);
+//   }
+
+   public Region getRegion(Fqn arg0, boolean arg1)
+   {
+      return delegate.getRegion(arg0, arg1);
+   }
+
+   public String getVersion()
+   {
+      return delegate.getVersion();
+   }
+
+   public void move(Fqn arg0, Fqn arg1) throws NodeNotExistsException
+   {
+      delegate.move(arg0, arg1);
+   }
+
+   public void move(String arg0, String arg1) throws NodeNotExistsException
+   {
+      delegate.move(arg0, arg1);
+   }
+
+   public void put(Fqn arg0, Map arg1)
+   {
+      delegate.put(arg0, arg1);
+   }
+
+   public void put(String arg0, Map arg1)
+   {
+      delegate.put(arg0, arg1);
+   }
+
+   public V put(Fqn arg0, K arg1, V arg2)
+   {
+      return delegate.put(arg0, arg1, arg2);
+   }
+
+   public V put(String arg0, K arg1, V arg2)
+   {
+      return delegate.put(arg0, arg1, arg2);
+   }
+
+   public void putForExternalRead(Fqn arg0, K arg1, V arg2)
+   {
+      delegate.putForExternalRead(arg0, arg1, arg2);
+   }
+
+   public V remove(Fqn arg0, K arg1)
+   {
+      return delegate.remove(arg0, arg1);
+   }
+
+   public V remove(String arg0, K arg1)
+   {
+      return delegate.remove(arg0, arg1);
+   }
+
+   public void removeCacheListener(Object arg0)
+   {
+      delegate.removeCacheListener(arg0);
+   }
+
+   public void removeCacheListener(Fqn arg0, Object arg1)
+   {
+      //delegate.removeCacheListener(arg0, arg1);
+   }
+
+   public boolean removeNode(Fqn arg0)
+   {
+      return delegate.removeNode(arg0);
+   }
+
+   public boolean removeNode(String arg0)
+   {
+      return delegate.removeNode(arg0);
+   }
+
+   public boolean removeRegion(Fqn arg0)
+   {
+      return delegate.removeRegion(arg0);
+   }
+
+   public void setInvocationContext(InvocationContext arg0)
+   {
+      delegate.setInvocationContext(arg0);
+   }
+
+   public void start() throws CacheException
+   {
+      delegate.start();
+   }
+
+   public void stop()
+   {
+      delegate.stop();
+   }
+
+   public Set<Object> getChildrenNames(Fqn arg0)
+   {
+      // FIXME just delegate once we use JBC 3.1
+      Node n = delegate.getRoot().getChild(arg0);
+      return n == null ? Collections.emptySet() : n.getChildrenNames();
+   }
+
+   public Set<String> getChildrenNames(String arg0)
+   {
+      // FIXME just delegate once we use JBC 3.1
+      Set<Object> names = getChildrenNames(Fqn.fromString(arg0));
+      Set<String> result = new HashSet<String>();
+      for (Object name : names)
+      {
+         result.add(name.toString());
+      }
+      return result;
+   }
+
+   public boolean isLeaf(Fqn arg0)
+   {
+      // FIXME just delegate once we use JBC 3.1
+      return getChildrenNames(arg0).size() == 0;
+   }
+
+   public boolean isLeaf(String arg0)
+   {
+      // FIXME just delegate once we use JBC 3.1
+      return isLeaf(Fqn.fromString(arg0));
+   }
+
+}

Added: projects/cluster/ha-server-cache-jbc/trunk/src/test/java/org/jboss/web/tomcat/service/sso/jbc/JBossCacheSSOClusterManagerUnitTestCase.java
===================================================================
--- projects/cluster/ha-server-cache-jbc/trunk/src/test/java/org/jboss/web/tomcat/service/sso/jbc/JBossCacheSSOClusterManagerUnitTestCase.java	                        (rev 0)
+++ projects/cluster/ha-server-cache-jbc/trunk/src/test/java/org/jboss/web/tomcat/service/sso/jbc/JBossCacheSSOClusterManagerUnitTestCase.java	2010-03-21 18:17:52 UTC (rev 102687)
@@ -0,0 +1,553 @@
+/*
+* JBoss, a division of Red Hat
+* Copyright 2006, Red Hat Middleware, LLC, 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.web.tomcat.service.sso.jbc;
+
+import java.util.Vector;
+
+import javax.management.MBeanServer;
+import javax.management.MBeanServerFactory;
+import javax.management.ObjectName;
+import javax.transaction.TransactionManager;
+
+import junit.framework.TestCase;
+
+import org.jboss.cache.Cache;
+import org.jboss.cache.DefaultCacheFactory;
+import org.jboss.cache.config.Configuration;
+import org.jboss.cache.config.ConfigurationRegistry;
+import org.jboss.cache.config.Configuration.CacheMode;
+import org.jboss.cache.jmx.CacheJmxWrapper;
+import org.jboss.cache.notifications.event.EventImpl;
+import org.jboss.cache.notifications.event.Event.Type;
+import org.jboss.cache.pojo.PojoCache;
+import org.jboss.cache.pojo.PojoCacheFactory;
+import org.jboss.cache.pojo.jmx.PojoCacheJmxWrapper;
+import org.jboss.cache.transaction.BatchModeTransactionManager;
+import org.jboss.cache.transaction.TransactionManagerLookup;
+import org.jboss.ha.cachemanager.CacheManager;
+import org.jboss.ha.cachemanager.DependencyInjectedConfigurationRegistry;
+import org.jboss.ha.framework.server.CacheManagerLocator;
+import org.jboss.ha.framework.server.PojoCacheManagerLocator;
+import org.jboss.logging.Logger;
+import org.jboss.util.threadpool.BasicThreadPool;
+import org.jboss.web.tomcat.service.sso.jbc.JBossCacheSSOClusterManager;
+import org.jboss.web.tomcat.service.sso.spi.FullyQualifiedSessionId;
+import org.jboss.web.tomcat.service.sso.spi.SSOClusterManager;
+import org.jboss.web.tomcat.service.sso.spi.SSOCredentials;
+import org.jboss.web.tomcat.service.sso.spi.SSOLocalManager;
+import org.jgroups.Address;
+import org.jgroups.JChannelFactory;
+import org.jgroups.View;
+import org.jgroups.ViewId;
+import org.jgroups.stack.IpAddress;
+
+/**
+ * Test of the JBossCacheSSOClusterManager class.
+ * 
+ * @author Brian Stansberry
+ */
+public class JBossCacheSSOClusterManagerUnitTestCase extends TestCase
+{
+   /**
+    * Default global value for the cacheName property
+    */
+   private static final String CACHE_OBJECT_NAME = "jboss.cache:service=ClusteredSSOCache";
+   private static final String DEFAULT_CACHE_NAME = "clustered-sso";
+   
+   private static final Logger log = Logger.getLogger(JBossCacheSSOClusterManagerUnitTestCase.class);
+   
+   private static IpAddress LOCAL_ADDRESS;
+   private static IpAddress REMOTE_ADDRESS;
+   
+   private String bindAddress;
+   private MBeanServer mbeanServer;
+   private CacheManager cacheManager;
+   
+   public JBossCacheSSOClusterManagerUnitTestCase(String name)
+   {
+      super(name);
+   }
+   
+   @Override
+   protected void setUp() throws Exception
+   {
+      super.setUp();
+      
+      bindAddress = System.getProperty("jgroups.bind.address");
+      System.setProperty("jgroups.bind.address", "127.0.0.1");
+      
+      LOCAL_ADDRESS  = new IpAddress("127.0.0.1", 11111);
+      REMOTE_ADDRESS = new IpAddress("192.168.0.1", 11111);
+   }
+   
+   @Override
+   protected void tearDown() throws Exception
+   {
+      super.tearDown();
+      
+      if (bindAddress == null)
+         System.clearProperty("jgroups.bind.address");
+      else
+         System.setProperty("jgroups.bind.address", bindAddress);
+      
+      if (cacheManager != null)
+      {
+         cacheManager.stop();
+         cacheManager = null;
+         CacheManagerLocator.getCacheManagerLocator().deregisterCacheManager();
+         PojoCacheManagerLocator.getCacheManagerLocator().deregisterCacheManager();
+      }
+      
+      if (mbeanServer != null)
+      {
+         MBeanServerFactory.releaseMBeanServer(mbeanServer);
+         mbeanServer = null;
+      }
+   }
+
+   public void testCacheJmxIntegration() throws Exception
+   {
+      log.debug("+++ testCacheJmxIntegration()");
+      
+      mbeanServer = MBeanServerFactory.createMBeanServer("cacheJmxTest");
+      CacheJmxWrapper wrapper = null;
+      try 
+      {
+         // Register a cache
+         wrapper = new CacheJmxWrapper();
+         // JBAS-4097 -- don't use a TransactionManagerLookup that will
+         // bind DummyTransactionManager into JNDI, as that will screw
+         // up other tests
+         wrapper.setTransactionManagerLookupClass(MockTransactionManagerLookup.class.getName());
+         wrapper.setCacheMode("REPL_SYNC");
+         mbeanServer.registerMBean(wrapper, new ObjectName(CACHE_OBJECT_NAME));
+         wrapper.create();
+         wrapper.start();
+         
+         // Build up an SSO infrastructure based on LOCAL_ADDRESS         
+         JBossCacheSSOClusterManager localSSOManager = new JBossCacheSSOClusterManager();
+         
+         MockSSOValve localValve = new MockSSOValve(mbeanServer, localSSOManager, CACHE_OBJECT_NAME);
+         localSSOManager.setSSOLocalManager(localValve);
+         localSSOManager.start();
+         
+         // Create an SSO that will have two sessions from local valve
+         localSSOManager.register("1", "FORM", "Brian", "password");
+         
+         localSSOManager.addSession("1", getFullyQualifiedSessionId("A", "1"));
+         
+         localSSOManager.addSession("1", getFullyQualifiedSessionId("B", "2"));
+         
+         // Confirm that data is cached properly
+         assertEquals("SSO 1 has correct number of sessions", 2, localSSOManager.getSessionCount("1"));   
+      }
+      finally
+      {
+         try
+         {
+            if (wrapper != null)
+            {
+               wrapper.stop();
+               wrapper.destroy();
+            }
+         }
+         catch (Exception ignored)
+         {            
+         }
+      }      
+   }
+
+   public void testPojoCacheJmxIntegration() throws Exception
+   {
+      log.debug("+++ testPojoCacheJmxIntegration()");
+      
+      mbeanServer = MBeanServerFactory.createMBeanServer("pojoCacheTest");
+      PojoCacheJmxWrapper wrapper = null;
+      try 
+      {
+         // Register a cache
+         wrapper = new PojoCacheJmxWrapper();
+         // JBAS-4097 -- don't use a TransactionManagerLookup that will
+         // bind DummyTransactionManager into JNDI, as that will screw
+         // up other tests
+         wrapper.setTransactionManagerLookupClass(MockTransactionManagerLookup.class.getName());
+         wrapper.setCacheMode("REPL_SYNC");
+         mbeanServer.registerMBean(wrapper, new ObjectName(CACHE_OBJECT_NAME));
+         wrapper.create();
+         wrapper.start();
+         
+         // Build up an SSO infrastructure based on LOCAL_ADDRESS         
+         JBossCacheSSOClusterManager localSSOManager = new JBossCacheSSOClusterManager();
+         
+         MockSSOValve localValve = new MockSSOValve(mbeanServer, localSSOManager, CACHE_OBJECT_NAME);
+         localSSOManager.setSSOLocalManager(localValve);
+         localSSOManager.start();
+         
+         // Create an SSO that will have two sessions from local valve
+         localSSOManager.register("1", "FORM", "Brian", "password");
+         
+         localSSOManager.addSession("1", getFullyQualifiedSessionId("A", "1"));
+         
+         localSSOManager.addSession("1", getFullyQualifiedSessionId("B", "2"));
+         
+         // Confirm that data is cached properly
+         assertEquals("SSO 1 has correct number of sessions", 2, localSSOManager.getSessionCount("1"));   
+      }
+      finally
+      {
+         try
+         {
+            if (wrapper != null)
+            {
+               wrapper.stop();
+               wrapper.destroy();
+            }
+         }
+         catch (Exception ignored)
+         {            
+         }
+      }
+   }
+
+   public void testPojoCacheIntegration() throws Exception
+   {
+      log.debug("+++ testPojoCacheIntegration()");
+      
+      CacheManager cacheManager = getCacheManager();
+
+      // Register a cache
+      Configuration config = new Configuration();
+      // JBAS-4097 -- don't use a TransactionManagerLookup that will
+      // bind DummyTransactionManager into JNDI, as that will screw
+      // up other tests
+      config.setTransactionManagerLookupClass(MockTransactionManagerLookup.class.getName());
+      config.setCacheMode("REPL_SYNC");
+      PojoCache pc = PojoCacheFactory.createCache(config, false);
+      
+      cacheManager.registerPojoCache(pc, DEFAULT_CACHE_NAME);
+      
+      // Build up an SSO infrastructure based on LOCAL_ADDRESS         
+      JBossCacheSSOClusterManager localSSOManager = new JBossCacheSSOClusterManager();
+      
+      MockSSOValve localValve = new MockSSOValve(mbeanServer, localSSOManager);
+      localSSOManager.setSSOLocalManager(localValve);
+      localSSOManager.start();
+      
+      // Create an SSO that will have two sessions from local valve
+      localSSOManager.register("1", "FORM", "Brian", "password");
+      
+      localSSOManager.addSession("1", getFullyQualifiedSessionId("A", "1"));
+      
+      localSSOManager.addSession("1", getFullyQualifiedSessionId("B", "2"));
+      
+      // Confirm that data is cached properly
+      assertEquals("SSO 1 has correct number of sessions", 2, localSSOManager.getSessionCount("1"));
+   }
+   
+   public void testDeadMemberCleanupWithPool() throws Exception
+   {
+      log.debug("+++ testDeadMemberCleanupWithPool()");
+      deadMemberCleanupTest(true);
+   }
+   
+   public void testDeadMemberCleanupWithoutPool() throws Exception
+   {
+      log.debug("+++ testDeadMemberCleanupWithoutPool()");
+      deadMemberCleanupTest(false);
+   }
+   
+   private void deadMemberCleanupTest(boolean usePool) throws Exception
+   {       
+      mbeanServer = usePool ? MBeanServerFactory.createMBeanServer("deadMemberTest")
+                                        : null;
+
+      CacheManager cacheManager = getCacheManager();
+      // Register a cache
+      Cache<Object, Object> delegate = new DefaultCacheFactory<Object, Object>().createCache(false);
+      MockTreeCache cache = new MockTreeCache(delegate);
+      // JBAS-4097 -- don't use a TransactionManagerLookup that will
+      // bind DummyTransactionManager into JNDI, as that will screw
+      // up other tests
+      cache.getConfiguration().getRuntimeConfig().setTransactionManager(new BatchModeTransactionManager());
+      
+      cacheManager.registerCache(cache, DEFAULT_CACHE_NAME);
+      
+      if (usePool)
+      {
+         BasicThreadPool pool = new BasicThreadPool();
+         mbeanServer.registerMBean(pool, new ObjectName(JBossCacheSSOClusterManager.DEFAULT_THREAD_POOL_NAME));
+      }
+      
+      // Build up an SSO infrastructure based on LOCAL_ADDRESS  
+      JBossCacheSSOClusterManager localSSOManager = new JBossCacheSSOClusterManager();
+      
+      MockSSOValve localValve = new MockSSOValve(mbeanServer, localSSOManager);
+      localSSOManager.setSSOLocalManager(localValve);
+      localSSOManager.start();
+      
+      assertEquals("Thread pool usage as expected", usePool, localSSOManager.isUsingThreadPool());
+      
+      //  Build up a second SSO infrastructure based on LOCAL_ADDRESS
+      // It uses the same mock cache, but we change the cache address
+      // so it thinks it's a different address when it starts
+      cache.setOurAddress(REMOTE_ADDRESS);
+      
+      JBossCacheSSOClusterManager remoteSSOManager = new JBossCacheSSOClusterManager();
+      
+      MockSSOValve remoteValve = new MockSSOValve(mbeanServer, remoteSSOManager);
+      remoteSSOManager.setSSOLocalManager(localValve);
+      remoteSSOManager.start();
+      
+      
+      // Create an SSO that will have sessions from both valves
+      localSSOManager.register("1", "FORM", "Brian", "password");
+      
+      localSSOManager.addSession("1", getFullyQualifiedSessionId("A", "1"));
+      
+      remoteSSOManager.addSession("1", getFullyQualifiedSessionId("B", "2"));
+      
+      
+      // Create another SSO with sessions only from remote
+      remoteSSOManager.register("2", "FORM", "Brian", "password");
+      
+      remoteSSOManager.addSession("2", getFullyQualifiedSessionId("C", "3"));
+      
+      remoteSSOManager.addSession("2", getFullyQualifiedSessionId("D", "4"));
+      
+      
+      // Create a third SSO that will have sessions from both valves
+      // with the same session id
+      localSSOManager.register("3", "FORM", "Brian", "password");
+      
+      localSSOManager.addSession("3", getFullyQualifiedSessionId("E", "5"));
+      
+      remoteSSOManager.addSession("3", getFullyQualifiedSessionId("E", "5"));
+      
+      
+      // Create a fourth SSO that will have two sessions from local valve
+      localSSOManager.register("4", "FORM", "Brian", "password");
+      
+      localSSOManager.addSession("4", getFullyQualifiedSessionId("F", "7"));
+      
+      localSSOManager.addSession("4", getFullyQualifiedSessionId("G", "8"));
+      
+      
+      // Create a fifth SSO with sessions only from remote, same session id
+      // but different managers
+      remoteSSOManager.register("5", "FORM", "Brian", "password");
+      
+      remoteSSOManager.addSession("5", getFullyQualifiedSessionId("H", "9"));
+      
+      remoteSSOManager.addSession("5", getFullyQualifiedSessionId("I", "9"));
+      
+      // Confirm that data is cached properly
+      assertEquals("SSO 1 has correct number of sessions", 2, localSSOManager.getSessionCount("1"));
+      assertEquals("SSO 1 has correct number of sessions", 2, remoteSSOManager.getSessionCount("1"));
+      assertEquals("SSO 2 has correct number of sessions", 2, localSSOManager.getSessionCount("2"));
+      assertEquals("SSO 2 has correct number of sessions", 2, remoteSSOManager.getSessionCount("2"));
+      assertEquals("SSO 3 has correct number of sessions", 2, localSSOManager.getSessionCount("3"));
+      assertEquals("SSO 3 has correct number of sessions", 2, remoteSSOManager.getSessionCount("3"));
+      assertEquals("SSO 4 has correct number of sessions", 2, localSSOManager.getSessionCount("4"));
+      assertEquals("SSO 4 has correct number of sessions", 2, remoteSSOManager.getSessionCount("4"));
+      assertEquals("SSO 5 has correct number of sessions", 2, localSSOManager.getSessionCount("5"));
+      assertEquals("SSO 5 has correct number of sessions", 2, remoteSSOManager.getSessionCount("5"));
+      
+      // Put in a new view with REMOTE_ADDRESS dead
+      ViewId viewId = new ViewId(LOCAL_ADDRESS, 1);
+      Vector v = new Vector();
+      v.add(LOCAL_ADDRESS);
+      EventImpl event = new EventImpl();
+      event.setNewView(new View(viewId, v));
+      event.setType(Type.VIEW_CHANGED);
+      event.setPre(false);
+      
+      localSSOManager.viewChange(event);
+      
+      // Give the cleanup thread time to finish
+      Thread.sleep(2000);
+      
+      // Confirm that cached data is properly cleaned up
+      assertEquals("SSO 1 has correct number of sessions", 1, localSSOManager.getSessionCount("1"));
+      assertEquals("SSO 2 has correct number of sessions", 0, localSSOManager.getSessionCount("2"));
+      assertEquals("SSO 3 has correct number of sessions", 1, localSSOManager.getSessionCount("3"));
+      assertEquals("SSO 4 has correct number of sessions", 2, localSSOManager.getSessionCount("4"));
+      assertEquals("SSO 5 has correct number of sessions", 0, localSSOManager.getSessionCount("5"));
+   }
+   
+   /**
+    * Test for JBAS-5609 -- confirm that if sessions from different managers
+    * but with the same session id are registered, the removal of one leaves
+    * the SSO in the proper state.
+    */
+   public void testSameSessionId() throws Exception
+   {
+      CacheManager cacheManager = getCacheManager();
+      // Register a cache
+      Cache<Object, Object> delegate = new DefaultCacheFactory<Object, Object>().createCache(false);
+      MockTreeCache cache = new MockTreeCache(delegate);
+      // JBAS-4097 -- don't use a TransactionManagerLookup that will
+      // bind DummyTransactionManager into JNDI, as that will screw
+      // up other tests
+      cache.getConfiguration().getRuntimeConfig().setTransactionManager(new BatchModeTransactionManager());
+      
+      cacheManager.registerCache(cache, DEFAULT_CACHE_NAME);
+      
+      // Build up an SSO infrastructure based on LOCAL_ADDRESS  
+      JBossCacheSSOClusterManager localSSOManager = new JBossCacheSSOClusterManager();
+      
+      MockSSOValve localValve = new MockSSOValve(mbeanServer, localSSOManager);
+      localSSOManager.setSSOLocalManager(localValve);
+      localSSOManager.start();
+      
+      
+      // Create an SSO that will have sessions from both valves
+      localSSOManager.register("1", "FORM", "Brian", "password");
+      
+      localSSOManager.addSession("1", getFullyQualifiedSessionId("A", "1"));
+      
+      localSSOManager.addSession("1", getFullyQualifiedSessionId("B", "1"));
+      
+      assertEquals(2, localSSOManager.getSessionCount("1"));
+      
+      localSSOManager.removeSession("1", getFullyQualifiedSessionId("B", "1"));
+      
+      assertEquals(1, localSSOManager.getSessionCount("1"));
+   }
+   
+   private CacheManager getCacheManager() throws Exception
+   {
+      if (cacheManager == null)
+      {
+         JChannelFactory channelFactory = new JChannelFactory();
+         ConfigurationRegistry registry = new DependencyInjectedConfigurationRegistry();
+         cacheManager = new CacheManager(registry, channelFactory);
+         cacheManager.start();
+      }
+      return cacheManager;
+   }
+   
+   private FullyQualifiedSessionId getFullyQualifiedSessionId(String contextName, String sessionId)
+   {
+      return new FullyQualifiedSessionId(sessionId, contextName, "localhost");
+   }
+   
+   
+   static class MockTreeCache extends DelegatingMockCache
+   {
+      private IpAddress ourAddress = LOCAL_ADDRESS;
+      
+      public MockTreeCache(Cache delegate) throws Exception
+      {
+         super(delegate);
+         getConfiguration().setCacheMode(CacheMode.LOCAL);
+      }
+
+      @Override
+      public Address getLocalAddress()
+      {
+         return ourAddress;
+      }
+      
+      void setOurAddress(IpAddress address)
+      {
+         ourAddress = address;
+      }
+
+      @Override
+      public Vector getMembers()
+      {
+         Vector v = new Vector();
+         v.add(LOCAL_ADDRESS);
+         v.add(REMOTE_ADDRESS);
+         return v;
+      }      
+      
+   }
+   
+   /**
+    * Override ClusteredSingleSignOn to suppress the empty SSO callbacks
+    */
+   static class MockSSOValve implements SSOLocalManager
+   {
+      private final MBeanServer mbeanServer;
+      private final String cacheConfig;
+      private final SSOClusterManager clusterManager;
+      
+      MockSSOValve(MBeanServer server, SSOClusterManager clusterManager)
+      {
+         this(server, clusterManager, DEFAULT_CACHE_NAME);
+      }
+      
+      MockSSOValve(MBeanServer server, SSOClusterManager clusterManager, String cacheConfig)
+      {
+         this.mbeanServer = server; 
+         this.clusterManager = clusterManager;
+         this.cacheConfig = cacheConfig;
+      }
+      
+      public MBeanServer getMBeanServer()
+      {
+         return mbeanServer;
+      }
+      
+      public void notifySSOEmpty(String ssoId)
+      {
+         // no-op
+      }
+
+      public void notifySSONotEmpty(String ssoId)
+      {
+         // no-op
+      }
+
+      public void deregister(String ssoId)
+      {
+         throw new UnsupportedOperationException("deregister");
+      }
+
+      public String getCacheConfig()
+      {
+         return cacheConfig;
+      }
+
+      public String getThreadPoolName()
+      {
+         return "jboss.system:service=ThreadPool";
+      }
+
+      public void remoteUpdate(String ssoId, SSOCredentials credentials)
+      {
+         throw new UnsupportedOperationException("remoteUpdate");
+      }      
+   }
+   
+   public static class MockTransactionManagerLookup implements TransactionManagerLookup
+   {
+
+      public TransactionManager getTransactionManager() throws Exception
+      {
+         return new BatchModeTransactionManager();
+      }
+
+   }
+
+}




More information about the jboss-cvs-commits mailing list