[jboss-cvs] JBossAS SVN: r107358 - in projects/cluster/ha-server-cache-ispn/trunk/src: test/java/org/jboss/web/tomcat/service/session/sso/ispn and 1 other directory.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Aug 3 12:36:31 EDT 2010
Author: smarlow at redhat.com
Date: 2010-08-03 12:36:30 -0400 (Tue, 03 Aug 2010)
New Revision: 107358
Modified:
projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/web/tomcat/service/session/sso/ispn/SSOClusterManager.java
projects/cluster/ha-server-cache-ispn/trunk/src/test/java/org/jboss/web/tomcat/service/session/sso/ispn/SSOClusterManagerTest.java
Log:
testing
Modified: projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/web/tomcat/service/session/sso/ispn/SSOClusterManager.java
===================================================================
--- projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/web/tomcat/service/session/sso/ispn/SSOClusterManager.java 2010-08-03 16:29:25 UTC (rev 107357)
+++ projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/web/tomcat/service/session/sso/ispn/SSOClusterManager.java 2010-08-03 16:36:30 UTC (rev 107358)
@@ -23,7 +23,6 @@
package org.jboss.web.tomcat.service.session.sso.ispn;
import org.infinispan.atomic.AtomicMap;
-import org.infinispan.atomic.AtomicMapLookup;
import org.infinispan.config.Configuration;
import org.infinispan.notifications.cachelistener.annotation.CacheEntryModified;
import org.infinispan.notifications.cachelistener.annotation.CacheEntryRemoved;
@@ -34,6 +33,8 @@
import org.infinispan.Cache;
import org.infinispan.remoting.transport.Address;
import org.jboss.ha.framework.server.ispn.InfinispanHAPartitionCacheHandler;
+import org.jboss.ha.ispn.atomic.AtomicMapFactory;
+import org.jboss.ha.ispn.atomic.DefaultAtomicMapFactory;
import org.jboss.logging.Logger;
import org.jboss.util.threadpool.ThreadPool;
import org.jboss.web.tomcat.service.sso.spi.FullyQualifiedSessionId;
@@ -145,6 +146,8 @@
private volatile InfinispanHAPartitionCacheHandler<CacheKey, Object> cacheHandler;
+ private final AtomicMapFactory atomicMapFactory;
+
// ------------------------------------------------------------ Properties
public InfinispanHAPartitionCacheHandler getCacheHandler()
@@ -167,6 +170,22 @@
return threadPool != null;
}
+ // ----------------------------------------------------- Constructor
+
+ public SSOClusterManager()
+ {
+ this.atomicMapFactory = new DefaultAtomicMapFactory();
+ }
+
+ /**
+ * This constructor is for unit testing
+ * @param atomicMapFactory
+ */
+ public SSOClusterManager(AtomicMapFactory atomicMapFactory)
+ {
+ this.atomicMapFactory = atomicMapFactory;
+ }
+
// ----------------------------------------------------- SSOClusterManager
/**
@@ -782,7 +801,7 @@
private Set<FullyQualifiedSessionId> getSSOSessions(String ssoId) throws Exception
{
CacheKey key = new CacheKey(ssoId,CacheKey.Type.SESSION);
- AtomicMap m = AtomicMapLookup.getAtomicMap(cache, key, true);
+ AtomicMap m = this.atomicMapFactory.getAtomicMap( (Cache<CacheKey, AtomicMap<Object, Object>>)(Cache)cache, key, true);
return m!=null ? m.keySet() : Collections.EMPTY_SET;
}
@@ -883,7 +902,7 @@
private void putSessionInCache(String ssoId, FullyQualifiedSessionId fullyQualifiedSessionId) throws Exception
{
CacheKey key = new CacheKey(ssoId,CacheKey.Type.SESSION);
- AtomicMap m = AtomicMapLookup.getAtomicMap(cache, key, true);
+ AtomicMap m = this.atomicMapFactory.getAtomicMap( (Cache<CacheKey, AtomicMap<Object, Object>>)(Cache)cache, key, true);
m.put(fullyQualifiedSessionId, null);
}
@@ -954,7 +973,7 @@
private void removeSessionFromCache(String ssoId, FullyQualifiedSessionId fullyQualifiedSessionId) throws Exception
{
CacheKey key = new CacheKey(ssoId,CacheKey.Type.SESSION);
- AtomicMap m = AtomicMapLookup.getAtomicMap(cache, key, false);
+ AtomicMap m = this.atomicMapFactory.getAtomicMap( (Cache<CacheKey, AtomicMap<Object, Object>>)(Cache)cache, key, false);
if (m != null)
{
m.remove(fullyQualifiedSessionId);
Modified: projects/cluster/ha-server-cache-ispn/trunk/src/test/java/org/jboss/web/tomcat/service/session/sso/ispn/SSOClusterManagerTest.java
===================================================================
--- projects/cluster/ha-server-cache-ispn/trunk/src/test/java/org/jboss/web/tomcat/service/session/sso/ispn/SSOClusterManagerTest.java 2010-08-03 16:29:25 UTC (rev 107357)
+++ projects/cluster/ha-server-cache-ispn/trunk/src/test/java/org/jboss/web/tomcat/service/session/sso/ispn/SSOClusterManagerTest.java 2010-08-03 16:36:30 UTC (rev 107358)
@@ -5,6 +5,7 @@
import org.infinispan.Cache;
import org.infinispan.atomic.AtomicMap;
import org.jboss.ha.framework.server.ispn.InfinispanHAPartitionCacheHandler;
+import org.jboss.ha.ispn.atomic.AtomicMapFactory;
import org.jboss.web.tomcat.service.session.sso.ispn.SSOClusterManager;
import org.jboss.web.tomcat.service.sso.spi.FullyQualifiedSessionId;
import org.junit.Assert;
@@ -12,19 +13,37 @@
import org.junit.Before;
import javax.transaction.Transaction;
import javax.transaction.TransactionManager;
+import java.util.HashSet;
public class SSOClusterManagerTest
{
SSOClusterManager ssoManager;
- Cache<Object, Object> cache;
+ Cache<Object, AtomicMap<Object, Object>>cache;
+
String ssoId;
+ FullyQualifiedSessionId fqs;
- @Before
- public void setup() throws Exception
+
+ @Test
+ public void addSession() throws Exception
{
- ssoManager = new SSOClusterManager();
+ // Prepare for the test (TODO: consider refactoring initialization into @Before step)
+ ssoId = "sso session 1";
+ fqs = new FullyQualifiedSessionId(ssoId, "context", "Boston");
+
+ AtomicMapFactory atomicMapFactory = EasyMock.createNiceMock(AtomicMapFactory.class);
+ AtomicMap atomicMap = EasyMock.createMock(AtomicMap.class);
+
+ ssoManager = new SSOClusterManager(atomicMapFactory);
cache = EasyMock.createMock(Cache.class);
+
+ CacheKey key = new CacheKey(ssoId, CacheKey.Type.SESSION);
+ EasyMock.expect(atomicMapFactory.getAtomicMap( cache, key, true)).andReturn(atomicMap);
+ EasyMock.expectLastCall().anyTimes();
+ EasyMock.expect(atomicMapFactory.getAtomicMap( cache, key, false)).andReturn(atomicMap);
+ EasyMock.expectLastCall().anyTimes();
+
InfinispanHAPartitionCacheHandler cacheHandler = EasyMock.createMock(InfinispanHAPartitionCacheHandler.class);
EasyMock.expect(cacheHandler.getCache()).andReturn(cache);
EasyMock.expectLastCall().anyTimes();
@@ -51,21 +70,23 @@
EasyMock.expectLastCall().anyTimes();
ssoManager.setCacheHandler(cacheHandler);
- ssoId = "sso session 1";
- AtomicMap atomicMap = EasyMock.createMock(AtomicMap.class);
+
EasyMock.expect(cache.get(EasyMock.anyObject())).andReturn(atomicMap);
EasyMock.expectLastCall().anyTimes();
- EasyMock.replay(cache, cacheHandler, advancedCache, tm, transaction, atomicMap);
- }
- @Test
- public void addSession() throws Exception
- {
+ EasyMock.expect(atomicMap.put(fqs, null)).andReturn(null);
+ EasyMock.expectLastCall().anyTimes();
+ HashSet result = new HashSet();
+ result.add(fqs);
+ EasyMock.expect(atomicMap.keySet()).andReturn(result);
+
+ EasyMock.replay(cache, cacheHandler, advancedCache, tm, transaction, atomicMap, atomicMapFactory);
+
+ // Start testing
ssoManager.start();
- FullyQualifiedSessionId fqs = new FullyQualifiedSessionId(ssoId, "context", "Boston");
ssoManager.addSession(ssoId, fqs);
-
+ Assert.assertEquals("should have 1 session.",1,ssoManager.getSessionCount(ssoId));
}
More information about the jboss-cvs-commits
mailing list