[jboss-cvs] JBossAS SVN: r107002 - in projects/cluster/ha-server-cache-ispn/trunk/src: test/java/org/jboss/ha/web/tomcat/service/session/distributedcache/impl and 1 other directory.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Jul 21 16:08:16 EDT 2010
Author: pferraro
Date: 2010-07-21 16:08:16 -0400 (Wed, 21 Jul 2010)
New Revision: 107002
Added:
projects/cluster/ha-server-cache-ispn/trunk/src/test/java/org/jboss/ha/web/tomcat/service/session/distributedcache/impl/DistributedCacheManagerTest.java
Modified:
projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/web/tomcat/service/session/distributedcache/impl/DistributedCacheManagerImpl.java
Log:
Unit test for DistributedCacheManager - almost complete
Modified: projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/web/tomcat/service/session/distributedcache/impl/DistributedCacheManagerImpl.java
===================================================================
--- projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/web/tomcat/service/session/distributedcache/impl/DistributedCacheManagerImpl.java 2010-07-21 19:39:03 UTC (rev 107001)
+++ projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/web/tomcat/service/session/distributedcache/impl/DistributedCacheManagerImpl.java 2010-07-21 20:08:16 UTC (rev 107002)
@@ -170,14 +170,12 @@
this.attributeStorage.store(data, sessionData);
- CacheInvoker.Operation<Void> operation = new CacheInvoker.Operation<Void>()
+ CacheInvoker.Operation<AtomicMap<Object, Object>> operation = new CacheInvoker.Operation<AtomicMap<Object, Object>>()
{
@Override
- public Void invoke(Cache<String, AtomicMap<Object, Object>> cache)
+ public AtomicMap<Object, Object> invoke(Cache<String, AtomicMap<Object, Object>> cache)
{
- cache.put(sessionId, data);
-
- return null;
+ return cache.put(sessionId, data);
}
};
@@ -193,7 +191,7 @@
@Override
public IncomingDistributableSessionData getSessionData(final String sessionId, String dataOwner, boolean includeAttributes)
{
- return (dataOwner != null) ? this.getData(sessionId, includeAttributes) : null;
+ return (dataOwner == null) ? this.getData(sessionId, includeAttributes) : null;
}
private IncomingDistributableSessionData getData(final String sessionId, boolean includeAttributes)
@@ -253,17 +251,7 @@
@Override
public void removeSession(final String sessionId)
{
- CacheInvoker.Operation<Void> operation = new CacheInvoker.Operation<Void>()
- {
- @Override
- public Void invoke(Cache<String, AtomicMap<Object, Object>> cache)
- {
- cache.remove(sessionId);
- return null;
- }
- };
-
- this.invoker.invoke(this.cache, operation);
+ this.removeSession(sessionId, false);
}
/**
@@ -273,19 +261,28 @@
@Override
public void removeSessionLocal(final String sessionId)
{
- CacheInvoker.Operation<Void> operation = new CacheInvoker.Operation<Void>()
+ this.removeSession(sessionId, true);
+ }
+
+ private void removeSession(final String sessionId, final boolean local)
+ {
+ CacheInvoker.Operation<AtomicMap<Object, Object>> operation = new CacheInvoker.Operation<AtomicMap<Object, Object>>()
{
@Override
- public Void invoke(Cache<String, AtomicMap<Object, Object>> cache)
+ public AtomicMap<Object, Object> invoke(Cache<String, AtomicMap<Object, Object>> cache)
{
- cache.getAdvancedCache().withFlags(Flag.CACHE_MODE_LOCAL).remove(sessionId);
- return null;
+ if (local)
+ {
+ cache.getAdvancedCache().withFlags(Flag.CACHE_MODE_LOCAL);
+ }
+
+ return cache.remove(sessionId);
}
};
this.invoker.invoke(this.cache, operation);
}
-
+
/**
* {@inheritDoc}
* @see org.jboss.web.tomcat.service.session.distributedcache.spi.DistributedCacheManager#removeSessionLocal(java.lang.String, java.lang.String)
@@ -295,7 +292,7 @@
{
if (dataOwner == null)
{
- this.removeSessionLocal(sessionId);
+ this.removeSession(sessionId, true);
}
}
Added: projects/cluster/ha-server-cache-ispn/trunk/src/test/java/org/jboss/ha/web/tomcat/service/session/distributedcache/impl/DistributedCacheManagerTest.java
===================================================================
--- projects/cluster/ha-server-cache-ispn/trunk/src/test/java/org/jboss/ha/web/tomcat/service/session/distributedcache/impl/DistributedCacheManagerTest.java (rev 0)
+++ projects/cluster/ha-server-cache-ispn/trunk/src/test/java/org/jboss/ha/web/tomcat/service/session/distributedcache/impl/DistributedCacheManagerTest.java 2010-07-21 20:08:16 UTC (rev 107002)
@@ -0,0 +1,684 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, 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.ha.web.tomcat.service.session.distributedcache.impl;
+
+import java.util.Collections;
+import java.util.Map;
+
+import junit.framework.Assert;
+
+import org.easymock.Capture;
+import org.easymock.EasyMock;
+import org.infinispan.AdvancedCache;
+import org.infinispan.Cache;
+import org.infinispan.atomic.AtomicMap;
+import org.infinispan.config.Configuration;
+import org.infinispan.context.Flag;
+import org.infinispan.lifecycle.ComponentStatus;
+import org.infinispan.manager.CacheContainer;
+import org.infinispan.manager.EmbeddedCacheManager;
+import org.infinispan.notifications.cachelistener.event.CacheEntryRemovedEvent;
+import org.infinispan.transaction.tm.BatchModeTransactionManager;
+import org.jboss.metadata.web.jboss.ReplicationConfig;
+import org.jboss.web.tomcat.service.session.distributedcache.spi.DistributableSessionMetadata;
+import org.jboss.web.tomcat.service.session.distributedcache.spi.DistributedCacheManager;
+import org.jboss.web.tomcat.service.session.distributedcache.spi.IncomingDistributableSessionData;
+import org.jboss.web.tomcat.service.session.distributedcache.spi.LocalDistributableSessionManager;
+import org.jboss.web.tomcat.service.session.distributedcache.spi.OutgoingDistributableSessionData;
+import org.jboss.web.tomcat.service.session.distributedcache.spi.SessionOwnershipSupport;
+import org.junit.Test;
+
+/**
+ * @author Paul Ferraro
+ *
+ */
+public class DistributedCacheManagerTest
+{
+ private LocalDistributableSessionManager manager = EasyMock.createStrictMock(LocalDistributableSessionManager.class);
+ private CacheContainer container = EasyMock.createStrictMock(CacheContainer.class);
+ @SuppressWarnings("unchecked")
+ private SessionAttributeStorage<OutgoingDistributableSessionData> storage = EasyMock.createStrictMock(SessionAttributeStorage.class);
+ @SuppressWarnings("unchecked")
+ private AdvancedCache<String, AtomicMap<Object, Object>> cache = EasyMock.createStrictMock(AdvancedCache.class);
+ private CacheInvoker invoker = EasyMock.createStrictMock(CacheInvoker.class);
+
+ @Test
+ public void start()
+ {
+ ReplicationConfig config = new ReplicationConfig();
+ config.setCacheName("session-cache");
+
+ // Validate host contribution to cache name
+ this.start(null, "", "localhost/ROOT", config, ComponentStatus.INSTANTIATED, true, new Configuration());
+ this.start("", "", "localhost/ROOT", config, ComponentStatus.INSTANTIATED, true, new Configuration());
+ this.start("host1", "", "host1/ROOT", config, ComponentStatus.INSTANTIATED, true, new Configuration());
+
+ // Validate context path contribution to cache name
+ this.start(null, "/", "localhost/ROOT", config, ComponentStatus.INSTANTIATED, true, new Configuration());
+ this.start(null, "/context1", "localhost/context1", config, ComponentStatus.INSTANTIATED, true, new Configuration());
+ this.start(null, "/path/context1", "localhost/path/context1", config, ComponentStatus.INSTANTIATED, true, new Configuration());
+
+ // Validate starting of cache per cache status
+ this.start(null, "", "localhost/ROOT", config, ComponentStatus.FAILED, true, new Configuration());
+ this.start(null, "", "localhost/ROOT", config, ComponentStatus.INITIALIZING, true, new Configuration());
+ this.start(null, "", "localhost/ROOT", config, ComponentStatus.RUNNING, false, new Configuration());
+ this.start(null, "", "localhost/ROOT", config, ComponentStatus.STOPPING, true, new Configuration());
+ this.start(null, "", "localhost/ROOT", config, ComponentStatus.TERMINATED, true, new Configuration());
+ }
+
+ private DistributedCacheManagerImpl<OutgoingDistributableSessionData> start(String hostName, String contextName, String cacheName, ReplicationConfig config, ComponentStatus cacheStatus, boolean startCache, Configuration configuration)
+ {
+ DistributedCacheManagerImpl<OutgoingDistributableSessionData> manager = new DistributedCacheManagerImpl<OutgoingDistributableSessionData>(this.manager, this.container, this.storage, this.invoker);
+
+ @SuppressWarnings("unchecked")
+ Cache<Object, Object> cache = EasyMock.createStrictMock(Cache.class);
+ EmbeddedCacheManager cacheManager = EasyMock.createStrictMock(EmbeddedCacheManager.class);
+ String templateCacheName = config.getCacheName();
+
+ EasyMock.expect(this.manager.getHostName()).andReturn(hostName);
+ EasyMock.expect(this.manager.getContextName()).andReturn(contextName);
+ EasyMock.expect(this.manager.getReplicationConfig()).andReturn(config);
+ EasyMock.expect(this.container.getCache()).andReturn(cache);
+ EasyMock.expect(cache.getCacheManager()).andReturn(cacheManager);
+ EasyMock.expect(cacheManager.defineConfiguration(cacheName, templateCacheName, new Configuration())).andReturn(configuration);
+ EasyMock.expect(cacheManager.<String, AtomicMap<Object, Object>>getCache(cacheName)).andReturn(this.cache);
+
+ EasyMock.expect(this.cache.getStatus()).andReturn(cacheStatus);
+ if (startCache)
+ {
+ this.cache.start();
+ }
+ EasyMock.expect(this.cache.getAdvancedCache()).andReturn(this.cache);
+ EasyMock.expect(this.cache.getTransactionManager()).andReturn(new BatchModeTransactionManager());
+ this.cache.addListener(manager);
+
+ EasyMock.expect(this.cache.getConfiguration()).andReturn(configuration);
+
+ EasyMock.replay(this.manager, this.container, this.storage, this.cache, this.invoker, cache, cacheManager);
+
+ manager.start();
+
+ EasyMock.verify(this.manager, this.container, this.storage, this.cache, this.invoker, cache, cacheManager);
+
+ Assert.assertNotNull(manager.getBatchingManager());
+
+ EasyMock.reset(this.manager, this.container, this.storage, this.cache, this.invoker, cache, cacheManager);
+
+ return manager;
+ }
+
+ private DistributedCacheManagerImpl<OutgoingDistributableSessionData> startDistributedCacheManager()
+ {
+ ReplicationConfig config = new ReplicationConfig();
+ config.setCacheName("session-cache");
+
+ return this.start(null, "", "localhost/ROOT", config, ComponentStatus.INSTANTIATED, true, new Configuration());
+ }
+
+ @Test
+ public void stop()
+ {
+ DistributedCacheManager<OutgoingDistributableSessionData> manager = this.startDistributedCacheManager();
+
+ this.cache.removeListener(manager);
+ this.cache.stop();
+
+ EasyMock.replay(this.manager, this.container, this.storage, this.cache, this.invoker);
+
+ manager.stop();
+
+ EasyMock.verify(this.manager, this.container, this.storage, this.cache, this.invoker);
+ EasyMock.reset(this.manager, this.container, this.storage, this.cache, this.invoker);
+ }
+
+ @Test
+ public void sessionCreated()
+ {
+ DistributedCacheManager<OutgoingDistributableSessionData> manager = this.startDistributedCacheManager();
+
+ EasyMock.replay(this.manager, this.container, this.storage, this.cache, this.invoker);
+
+ manager.sessionCreated("abc");
+
+ EasyMock.verify(this.manager, this.container, this.storage, this.cache, this.invoker);
+ EasyMock.reset(this.manager, this.container, this.storage, this.cache, this.invoker);
+ }
+
+ @Test
+ public void storeSessionData()
+ {
+ OutgoingDistributableSessionData data = EasyMock.createNiceMock(OutgoingDistributableSessionData.class);
+
+ DistributedCacheManager<OutgoingDistributableSessionData> manager = this.startDistributedCacheManager();
+ Capture<AtomicMap<Object, Object>> capturedMap = new Capture<AtomicMap<Object, Object>>();
+ Capture<CacheInvoker.Operation<AtomicMap<Object, Object>>> capturedOperation = new Capture<CacheInvoker.Operation<AtomicMap<Object, Object>>>();
+
+ String sessionId = "abc";
+ int version = 10;
+ long timestamp = System.currentTimeMillis();
+ DistributableSessionMetadata metadata = new DistributableSessionMetadata();
+
+ EasyMock.expect(data.getRealId()).andReturn(sessionId);
+ EasyMock.expect(data.getVersion()).andReturn(version);
+ EasyMock.expect(data.getTimestamp()).andReturn(timestamp);
+ EasyMock.expect(data.getMetadata()).andReturn(metadata);
+
+ this.storage.store(EasyMock.capture(capturedMap), EasyMock.same(data));
+
+ EasyMock.expect(this.invoker.invoke(EasyMock.same(this.cache), EasyMock.capture(capturedOperation))).andReturn(null);
+
+ EasyMock.replay(this.manager, this.container, this.storage, this.cache, this.invoker, data);
+
+ manager.storeSessionData(data);
+
+ EasyMock.verify(this.manager, this.container, this.storage, this.cache, this.invoker, data);
+
+ AtomicMap<Object, Object> map = capturedMap.getValue();
+
+ Assert.assertEquals(3, map.size());
+ Assert.assertEquals(version, map.get(Byte.valueOf((byte) AtomicMapEntry.VERSION.ordinal())));
+ Assert.assertEquals(timestamp, map.get(Byte.valueOf((byte) AtomicMapEntry.TIMESTAMP.ordinal())));
+ Assert.assertSame(metadata, map.get(Byte.valueOf((byte) AtomicMapEntry.METADATA.ordinal())));
+
+ EasyMock.reset(this.manager, this.container, this.storage, this.cache, this.invoker, data);
+
+
+ CacheInvoker.Operation<AtomicMap<Object, Object>> operation = capturedOperation.getValue();
+ @SuppressWarnings("unchecked")
+ AtomicMap<Object, Object> oldMap = EasyMock.createMock(AtomicMap.class);
+
+ EasyMock.expect(this.cache.put(EasyMock.same(sessionId), EasyMock.same(map))).andReturn(oldMap);
+
+ EasyMock.replay(this.manager, this.container, this.storage, this.cache, this.invoker, data);
+
+ AtomicMap<Object, Object> result = operation.invoke(this.cache);
+
+ EasyMock.verify(this.manager, this.container, this.storage, this.cache, this.invoker, data);
+
+ Assert.assertSame(oldMap, result);
+
+ EasyMock.reset(this.manager, this.container, this.storage, this.cache, this.invoker, data);
+ }
+
+ @Test
+ public void getSessionDataNoOwner() throws Exception
+ {
+ this.getSessionDataNoOwner(true);
+
+ this.getSessionDataNoOwner(false);
+ }
+
+ private void getSessionDataNoOwner(boolean includeAttributes) throws Exception
+ {
+ String sessionId = "abc";
+ @SuppressWarnings("unchecked")
+ AtomicMap<Object, Object> map = EasyMock.createNiceMock(AtomicMap.class);
+ Map<String, Object> attributes = Collections.emptyMap();
+
+ Capture<CacheInvoker.Operation<AtomicMap<Object, Object>>> capturedOperation = new Capture<CacheInvoker.Operation<AtomicMap<Object, Object>>>();
+
+ Integer version = Integer.valueOf(10);
+ Long timestamp = Long.valueOf(System.currentTimeMillis());
+ DistributableSessionMetadata metadata = new DistributableSessionMetadata();
+
+ DistributedCacheManager<OutgoingDistributableSessionData> manager = this.startDistributedCacheManager();
+
+ EasyMock.expect(this.invoker.invoke(EasyMock.same(this.cache), EasyMock.capture(capturedOperation))).andReturn(map);
+
+ EasyMock.expect(map.get(Byte.valueOf((byte) AtomicMapEntry.VERSION.ordinal()))).andReturn(version);
+ EasyMock.expect(map.get(Byte.valueOf((byte) AtomicMapEntry.TIMESTAMP.ordinal()))).andReturn(timestamp);
+ EasyMock.expect(map.get(Byte.valueOf((byte) AtomicMapEntry.METADATA.ordinal()))).andReturn(metadata);
+
+ if (includeAttributes)
+ {
+ EasyMock.expect(this.storage.load(map)).andReturn(attributes);
+ }
+
+ EasyMock.replay(this.manager, this.container, this.storage, this.cache, this.invoker, map);
+
+ IncomingDistributableSessionData result = manager.getSessionData(sessionId, null, includeAttributes);
+
+ EasyMock.verify(this.manager, this.container, this.storage, this.cache, this.invoker, map);
+
+ Assert.assertNotNull(result);
+ Assert.assertEquals(version.intValue(), result.getVersion());
+ Assert.assertEquals(timestamp.longValue(), result.getTimestamp());
+ Assert.assertSame(metadata, result.getMetadata());
+
+ if (includeAttributes)
+ {
+ Assert.assertSame(attributes, result.getSessionAttributes());
+ }
+ else
+ {
+ IllegalStateException exception = null;
+ Map<String, Object> sessionAttributes = null;
+
+ try
+ {
+ sessionAttributes = result.getSessionAttributes();
+ }
+ catch (IllegalStateException e)
+ {
+ exception = e;
+ }
+
+ Assert.assertNull(sessionAttributes);
+ Assert.assertNotNull(exception);
+ }
+
+ EasyMock.reset(this.manager, this.container, this.storage, this.cache, this.invoker, map);
+
+
+ CacheInvoker.Operation<AtomicMap<Object, Object>> operation = capturedOperation.getValue();
+ @SuppressWarnings("unchecked")
+ AtomicMap<Object, Object> expectedMap = EasyMock.createMock(AtomicMap.class);
+
+ EasyMock.expect(this.cache.get(EasyMock.same(sessionId))).andReturn(expectedMap);
+
+ EasyMock.replay(this.manager, this.container, this.storage, this.cache, this.invoker, expectedMap);
+
+ AtomicMap<Object, Object> resultMap = operation.invoke(this.cache);
+
+ EasyMock.verify(this.manager, this.container, this.storage, this.cache, this.invoker, expectedMap);
+
+ Assert.assertSame(expectedMap, resultMap);
+
+ EasyMock.reset(this.manager, this.container, this.storage, this.cache, this.invoker, expectedMap);
+ }
+
+ @Test
+ public void getMissingSessionDataNoOwner()
+ {
+ this.getMissingSessionDataNoOwner(true);
+
+ this.getMissingSessionDataNoOwner(false);
+ }
+
+ private void getMissingSessionDataNoOwner(boolean includeAttributes)
+ {
+ Capture<CacheInvoker.Operation<AtomicMap<Object, Object>>> capturedOperation = new Capture<CacheInvoker.Operation<AtomicMap<Object, Object>>>();
+
+ DistributedCacheManager<OutgoingDistributableSessionData> manager = this.startDistributedCacheManager();
+
+ EasyMock.expect(this.invoker.invoke(EasyMock.same(this.cache), EasyMock.capture(capturedOperation))).andReturn(null);
+
+ EasyMock.replay(this.manager, this.container, this.storage, this.cache, this.invoker);
+
+ IncomingDistributableSessionData result = manager.getSessionData("abc", null, includeAttributes);
+
+ EasyMock.verify(this.manager, this.container, this.storage, this.cache, this.invoker);
+
+ Assert.assertNull(result);
+
+ EasyMock.reset(this.manager, this.container, this.storage, this.cache, this.invoker);
+
+
+ CacheInvoker.Operation<AtomicMap<Object, Object>> operation = capturedOperation.getValue();
+ @SuppressWarnings("unchecked")
+ AtomicMap<Object, Object> expectedMap = EasyMock.createMock(AtomicMap.class);
+
+ EasyMock.expect(this.cache.get("abc")).andReturn(expectedMap);
+
+ EasyMock.replay(this.manager, this.container, this.storage, this.cache, this.invoker);
+
+ AtomicMap<Object, Object> resultMap = operation.invoke(this.cache);
+
+ EasyMock.verify(this.manager, this.container, this.storage, this.cache, this.invoker);
+
+ Assert.assertSame(expectedMap, resultMap);
+
+ EasyMock.reset(this.manager, this.container, this.storage, this.cache, this.invoker);
+ }
+
+ @Test
+ public void getSessionDataWithOwner()
+ {
+ this.getSessionDataWithOwner(true);
+
+ this.getSessionDataWithOwner(false);
+ }
+
+ private void getSessionDataWithOwner(boolean includeAttributes)
+ {
+ DistributedCacheManager<OutgoingDistributableSessionData> manager = this.startDistributedCacheManager();
+
+ EasyMock.replay(this.manager, this.container, this.storage, this.cache, this.invoker);
+
+ IncomingDistributableSessionData result = manager.getSessionData("abc", "owner1", includeAttributes);
+
+ EasyMock.verify(this.manager, this.container, this.storage, this.cache, this.invoker);
+
+ Assert.assertNull(result);
+
+ EasyMock.reset(this.manager, this.container, this.storage, this.cache, this.invoker);
+ }
+
+ @Test
+ public void removeSession()
+ {
+ String sessionId = "abc";
+
+ Capture<CacheInvoker.Operation<AtomicMap<Object, Object>>> capturedOperation = new Capture<CacheInvoker.Operation<AtomicMap<Object, Object>>>();
+
+ DistributedCacheManager<OutgoingDistributableSessionData> manager = this.startDistributedCacheManager();
+
+ EasyMock.expect(this.invoker.invoke(EasyMock.same(this.cache), EasyMock.capture(capturedOperation))).andReturn(null);
+
+ EasyMock.replay(this.manager, this.container, this.storage, this.cache, this.invoker);
+
+ manager.removeSession(sessionId);
+
+ EasyMock.verify(this.manager, this.container, this.storage, this.cache, this.invoker);
+ EasyMock.reset(this.manager, this.container, this.storage, this.cache, this.invoker);
+
+
+ CacheInvoker.Operation<AtomicMap<Object, Object>> operation = capturedOperation.getValue();
+ @SuppressWarnings("unchecked")
+ AtomicMap<Object, Object> expectedMap = EasyMock.createMock(AtomicMap.class);
+
+ EasyMock.expect(this.cache.remove(sessionId)).andReturn(expectedMap);
+
+ EasyMock.replay(this.manager, this.container, this.storage, this.cache, this.invoker);
+
+ AtomicMap<Object, Object> resultMap = operation.invoke(this.cache);
+
+ EasyMock.verify(this.manager, this.container, this.storage, this.cache, this.invoker);
+
+ Assert.assertSame(expectedMap, resultMap);
+
+ EasyMock.reset(this.manager, this.container, this.storage, this.cache, this.invoker);
+ }
+
+ @Test
+ public void removeSessionLocal()
+ {
+ String sessionId = "abc";
+
+ Capture<CacheInvoker.Operation<AtomicMap<Object, Object>>> capturedOperation = new Capture<CacheInvoker.Operation<AtomicMap<Object, Object>>>();
+
+ DistributedCacheManager<OutgoingDistributableSessionData> manager = this.startDistributedCacheManager();
+
+ EasyMock.expect(this.invoker.invoke(EasyMock.same(this.cache), EasyMock.capture(capturedOperation))).andReturn(null);
+
+ EasyMock.replay(this.manager, this.container, this.storage, this.cache, this.invoker);
+
+ manager.removeSessionLocal(sessionId);
+
+ EasyMock.verify(this.manager, this.container, this.storage, this.cache, this.invoker);
+ EasyMock.reset(this.manager, this.container, this.storage, this.cache, this.invoker);
+
+
+ CacheInvoker.Operation<AtomicMap<Object, Object>> operation = capturedOperation.getValue();
+ @SuppressWarnings("unchecked")
+ AtomicMap<Object, Object> expectedMap = EasyMock.createMock(AtomicMap.class);
+
+ EasyMock.expect(this.cache.getAdvancedCache()).andReturn(this.cache);
+ EasyMock.expect(this.cache.withFlags(Flag.CACHE_MODE_LOCAL)).andReturn(this.cache);
+ EasyMock.expect(this.cache.remove(sessionId)).andReturn(expectedMap);
+
+ EasyMock.replay(this.manager, this.container, this.storage, this.cache, this.invoker);
+
+ AtomicMap<Object, Object> resultMap = operation.invoke(this.cache);
+
+ EasyMock.verify(this.manager, this.container, this.storage, this.cache, this.invoker);
+
+ Assert.assertSame(expectedMap, resultMap);
+
+ EasyMock.reset(this.manager, this.container, this.storage, this.cache, this.invoker);
+ }
+
+ @Test
+ public void removeSessionLocalNoOwner()
+ {
+ String sessionId = "abc";
+
+ Capture<CacheInvoker.Operation<AtomicMap<Object, Object>>> capturedOperation = new Capture<CacheInvoker.Operation<AtomicMap<Object, Object>>>();
+
+ DistributedCacheManager<OutgoingDistributableSessionData> manager = this.startDistributedCacheManager();
+
+ EasyMock.expect(this.invoker.invoke(EasyMock.same(this.cache), EasyMock.capture(capturedOperation))).andReturn(null);
+
+ EasyMock.replay(this.manager, this.container, this.storage, this.cache, this.invoker);
+
+ manager.removeSessionLocal(sessionId, null);
+
+ EasyMock.verify(this.manager, this.container, this.storage, this.cache, this.invoker);
+ EasyMock.reset(this.manager, this.container, this.storage, this.cache, this.invoker);
+
+
+ CacheInvoker.Operation<AtomicMap<Object, Object>> operation = capturedOperation.getValue();
+ @SuppressWarnings("unchecked")
+ AtomicMap<Object, Object> expectedMap = EasyMock.createMock(AtomicMap.class);
+
+ EasyMock.expect(this.cache.getAdvancedCache()).andReturn(this.cache);
+ EasyMock.expect(this.cache.withFlags(Flag.CACHE_MODE_LOCAL)).andReturn(this.cache);
+ EasyMock.expect(this.cache.remove(sessionId)).andReturn(expectedMap);
+
+ EasyMock.replay(this.manager, this.container, this.storage, this.cache, this.invoker);
+
+ AtomicMap<Object, Object> resultMap = operation.invoke(this.cache);
+
+ EasyMock.verify(this.manager, this.container, this.storage, this.cache, this.invoker);
+
+ Assert.assertSame(expectedMap, resultMap);
+
+ EasyMock.reset(this.manager, this.container, this.storage, this.cache, this.invoker);
+ }
+
+ @Test
+ public void removeSessionLocalWithOwner()
+ {
+ DistributedCacheManager<OutgoingDistributableSessionData> manager = this.startDistributedCacheManager();
+
+ EasyMock.replay(this.manager, this.container, this.storage, this.cache, this.invoker);
+
+ manager.removeSessionLocal("abc", "owner1");
+
+ EasyMock.verify(this.manager, this.container, this.storage, this.cache, this.invoker);
+ EasyMock.reset(this.manager, this.container, this.storage, this.cache, this.invoker);
+ }
+
+ @Test
+ public void evictSession()
+ {
+ String sessionId = "abc";
+
+ Capture<CacheInvoker.Operation<Void>> capturedOperation = new Capture<CacheInvoker.Operation<Void>>();
+
+ DistributedCacheManager<OutgoingDistributableSessionData> manager = this.startDistributedCacheManager();
+
+ EasyMock.expect(this.invoker.invoke(EasyMock.same(this.cache), EasyMock.capture(capturedOperation))).andReturn(null);
+
+ EasyMock.replay(this.manager, this.container, this.storage, this.cache, this.invoker);
+
+ manager.evictSession(sessionId);
+
+ EasyMock.verify(this.manager, this.container, this.storage, this.cache, this.invoker);
+ EasyMock.reset(this.manager, this.container, this.storage, this.cache, this.invoker);
+
+
+ CacheInvoker.Operation<Void> operation = capturedOperation.getValue();
+
+ this.cache.evict(sessionId);
+
+ EasyMock.replay(this.manager, this.container, this.storage, this.cache, this.invoker);
+
+ Void result = operation.invoke(this.cache);
+
+ EasyMock.verify(this.manager, this.container, this.storage, this.cache, this.invoker);
+
+ Assert.assertNull(result);
+
+ EasyMock.reset(this.manager, this.container, this.storage, this.cache, this.invoker);
+ }
+
+ @Test
+ public void evictSessionNoOwner()
+ {
+ String sessionId = "abc";
+
+ Capture<CacheInvoker.Operation<Void>> capturedOperation = new Capture<CacheInvoker.Operation<Void>>();
+
+ DistributedCacheManager<OutgoingDistributableSessionData> manager = this.startDistributedCacheManager();
+
+ EasyMock.expect(this.invoker.invoke(EasyMock.same(this.cache), EasyMock.capture(capturedOperation))).andReturn(null);
+
+ EasyMock.replay(this.manager, this.container, this.storage, this.cache, this.invoker);
+
+ manager.evictSession(sessionId, null);
+
+ EasyMock.verify(this.manager, this.container, this.storage, this.cache, this.invoker);
+ EasyMock.reset(this.manager, this.container, this.storage, this.cache, this.invoker);
+
+
+ CacheInvoker.Operation<Void> operation = capturedOperation.getValue();
+
+ this.cache.evict(sessionId);
+
+ EasyMock.replay(this.manager, this.container, this.storage, this.cache, this.invoker);
+
+ Void result = operation.invoke(this.cache);
+
+ EasyMock.verify(this.manager, this.container, this.storage, this.cache, this.invoker);
+
+ Assert.assertNull(result);
+
+ EasyMock.reset(this.manager, this.container, this.storage, this.cache, this.invoker);
+ }
+
+ @Test
+ public void evictSessionLocalWithOwner()
+ {
+ DistributedCacheManager<OutgoingDistributableSessionData> manager = this.startDistributedCacheManager();
+
+ EasyMock.replay(this.manager, this.container, this.storage, this.cache, this.invoker);
+
+ manager.evictSession("abc", "owner1");
+
+ EasyMock.verify(this.manager, this.container, this.storage, this.cache, this.invoker);
+ EasyMock.reset(this.manager, this.container, this.storage, this.cache, this.invoker);
+ }
+
+ @Test
+ public void getSessionIds()
+ {
+ DistributedCacheManager<OutgoingDistributableSessionData> manager = this.startDistributedCacheManager();
+
+ EasyMock.expect(this.cache.keySet()).andReturn(Collections.singleton("abc"));
+
+ EasyMock.replay(this.manager, this.container, this.storage, this.cache, this.invoker);
+
+ Map<String, String> result = manager.getSessionIds();
+
+ EasyMock.verify(this.manager, this.container, this.storage, this.cache, this.invoker);
+
+ Assert.assertNotNull(result);
+ Assert.assertEquals(1, result.size());
+ Assert.assertTrue(result.containsKey("abc"));
+ Assert.assertNull(result.get("abc"));
+
+ EasyMock.reset(this.manager, this.container, this.storage, this.cache, this.invoker);
+ }
+
+ @Test
+ public void setForceSynchronous()
+ {
+ this.setForceSynchronous(true);
+ this.setForceSynchronous(false);
+ }
+
+ private void setForceSynchronous(boolean forceSynchronous)
+ {
+ DistributedCacheManager<OutgoingDistributableSessionData> manager = this.startDistributedCacheManager();
+
+ this.invoker.setForceSynchronous(forceSynchronous);
+
+ EasyMock.replay(this.manager, this.container, this.storage, this.cache, this.invoker);
+
+ manager.setForceSynchronous(forceSynchronous);
+
+ EasyMock.verify(this.manager, this.container, this.storage, this.cache, this.invoker);
+ EasyMock.reset(this.manager, this.container, this.storage, this.cache, this.invoker);
+ }
+
+ @Test
+ public void getSessionOwnershipSupport()
+ {
+ DistributedCacheManager<OutgoingDistributableSessionData> manager = this.startDistributedCacheManager();
+
+ EasyMock.replay(this.manager, this.container, this.storage, this.cache, this.invoker);
+
+ SessionOwnershipSupport support = manager.getSessionOwnershipSupport();
+
+ EasyMock.verify(this.manager, this.container, this.storage, this.cache, this.invoker);
+
+// TODO when session ownership support is added, replace these assertions
+ Assert.assertNull(support);
+// Assert.assertSame(manager, support);
+
+ EasyMock.reset(this.manager, this.container, this.storage, this.cache, this.invoker);
+ }
+
+ @Test
+ public void removed()
+ {
+ CacheEntryRemovedEvent event = EasyMock.createNiceMock(CacheEntryRemovedEvent.class);
+
+ DistributedCacheManagerImpl<OutgoingDistributableSessionData> manager = this.startDistributedCacheManager();
+
+
+ EasyMock.expect(event.isPre()).andReturn(true);
+
+ EasyMock.replay(this.manager, this.container, this.storage, this.cache, this.invoker, event);
+
+ manager.removed(event);
+
+ EasyMock.verify(this.manager, this.container, this.storage, this.cache, this.invoker, event);
+ EasyMock.reset(this.manager, this.container, this.storage, this.cache, this.invoker, event);
+
+
+ EasyMock.expect(event.isPre()).andReturn(false);
+ EasyMock.expect(event.isOriginLocal()).andReturn(true);
+
+ EasyMock.replay(this.manager, this.container, this.storage, this.cache, this.invoker, event);
+
+ manager.removed(event);
+
+ EasyMock.verify(this.manager, this.container, this.storage, this.cache, this.invoker, event);
+ EasyMock.reset(this.manager, this.container, this.storage, this.cache, this.invoker, event);
+
+
+ EasyMock.expect(event.isPre()).andReturn(false);
+ EasyMock.expect(event.isOriginLocal()).andReturn(false);
+ EasyMock.expect(event.getKey()).andReturn("abc");
+
+ this.manager.notifyRemoteInvalidation("abc");
+
+ EasyMock.replay(this.manager, this.container, this.storage, this.cache, this.invoker, event);
+
+ manager.removed(event);
+
+ EasyMock.verify(this.manager, this.container, this.storage, this.cache, this.invoker, event);
+ EasyMock.reset(this.manager, this.container, this.storage, this.cache, this.invoker, event);
+ }
+}
More information about the jboss-cvs-commits
mailing list