[jboss-cvs] JBossAS SVN: r107822 - in projects/cluster/ha-server-cache-ispn/trunk: src/main/java/org/jboss/web/tomcat/service/session/distributedcache/ispn and 1 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu Aug 26 21:43:40 EDT 2010
Author: pferraro
Date: 2010-08-26 21:43:38 -0400 (Thu, 26 Aug 2010)
New Revision: 107822
Added:
projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/ispn/DefaultLockManagerSource.java
Modified:
projects/cluster/ha-server-cache-ispn/trunk/pom.xml
projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/ispn/DefaultCacheSource.java
projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/ispn/DistributedCacheManager.java
projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/ispn/DistributedCacheManagerFactory.java
projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/ispn/LockManagerSource.java
projects/cluster/ha-server-cache-ispn/trunk/src/test/java/org/jboss/web/tomcat/service/session/distributedcache/ispn/DefaultCacheSourceTest.java
projects/cluster/ha-server-cache-ispn/trunk/src/test/java/org/jboss/web/tomcat/service/session/distributedcache/ispn/DistributedCacheManagerFactoryTest.java
Log:
Disable session ownership support if cache mode is local.
Refactor LockManagerSource into separate impl class - no longer anything to gain by sharing impl class with CacheSource.
Key lock manager on cluster name, instead of container name.
Reinterpret ReplicationConfig.getCacheName() to refer to container name, or container+cache if qualified.
Change qualifier from ":" to "/", since legacy cache name use JMX object name which already contain colons.
Modified: projects/cluster/ha-server-cache-ispn/trunk/pom.xml
===================================================================
--- projects/cluster/ha-server-cache-ispn/trunk/pom.xml 2010-08-26 23:47:34 UTC (rev 107821)
+++ projects/cluster/ha-server-cache-ispn/trunk/pom.xml 2010-08-27 01:43:38 UTC (rev 107822)
@@ -32,7 +32,7 @@
<properties>
<version.jboss.ha.server.cache.spi>3.0.0.Alpha4</version.jboss.ha.server.cache.spi>
<version.jboss.ha.server.core>1.0.0.Alpha5</version.jboss.ha.server.core>
- <version.jboss.ha.server.ispn>1.0.0.Alpha7</version.jboss.ha.server.ispn>
+ <version.jboss.ha.server.ispn>1.0.0.Alpha8</version.jboss.ha.server.ispn>
<version.junit>4.8.1</version.junit>
<version.easymock>3.0</version.easymock>
</properties>
Modified: projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/ispn/DefaultCacheSource.java
===================================================================
--- projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/ispn/DefaultCacheSource.java 2010-08-26 23:47:34 UTC (rev 107821)
+++ projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/ispn/DefaultCacheSource.java 2010-08-27 01:43:38 UTC (rev 107822)
@@ -21,132 +21,62 @@
*/
package org.jboss.web.tomcat.service.session.distributedcache.ispn;
-import java.util.HashMap;
-import java.util.Map;
-
import org.infinispan.Cache;
import org.infinispan.config.Configuration;
import org.infinispan.config.Configuration.CacheMode;
import org.infinispan.manager.EmbeddedCacheManager;
-import org.infinispan.remoting.transport.jgroups.JGroupsTransport;
-import org.jboss.ha.core.framework.server.CoreGroupCommunicationService;
-import org.jboss.ha.framework.server.lock.SharedLocalYieldingClusterLockManager;
import org.jboss.ha.ispn.CacheContainerRegistry;
import org.jboss.metadata.web.jboss.ReplicationConfig;
import org.jboss.metadata.web.jboss.ReplicationMode;
import org.jboss.web.tomcat.service.session.distributedcache.spi.LocalDistributableSessionManager;
-import org.jgroups.Channel;
/**
* @author Paul Ferraro
*
*/
-public class DefaultCacheSource implements CacheSource, LockManagerSource
+public class DefaultCacheSource implements CacheSource
{
- /** The scope assigned to our group communication service */
- public static final Short SCOPE_ID = Short.valueOf((short) 222);
- /** The service name of the group communication service */
- public static final String SERVICE_NAME = "HTTPSESSIONOWNER";
-
- public static final String DEFAULT_CACHE_CONTAINER = "session";
-
private final CacheContainerRegistry registry;
- private String defaultContainerName = DEFAULT_CACHE_CONTAINER;
-
- private final Map<String,SharedLocalYieldingClusterLockManager> lockManagers = new HashMap<String, SharedLocalYieldingClusterLockManager>();
-
public DefaultCacheSource(CacheContainerRegistry registry)
{
this.registry = registry;
}
@Override
- public SharedLocalYieldingClusterLockManager getLockManager(LocalDistributableSessionManager manager)
- {
- String containerName = getContainerName(manager.getReplicationConfig());
-
- synchronized (lockManagers)
- {
- SharedLocalYieldingClusterLockManager lockManager = lockManagers.get(containerName);
-
- if (lockManager == null)
- {
- EmbeddedCacheManager container = this.registry.getCacheContainer(containerName);
- String cacheName = getCacheName(manager);
- Cache<Object, Object> cache = container.getCache(cacheName);
- JGroupsTransport transport = (JGroupsTransport) cache.getAdvancedCache().getRpcManager().getTransport();
- Channel channel = transport.getChannel();
-
- CoreGroupCommunicationService gcs = new CoreGroupCommunicationService();
- gcs.setChannel(channel);
- gcs.setScopeId(SCOPE_ID);
-
- try
- {
- gcs.start();
- }
- catch (Exception e)
- {
- throw new IllegalStateException("Unexpected exception while starting group communication service for " + containerName);
- }
-
- lockManager = new SharedLocalYieldingClusterLockManager(SERVICE_NAME, gcs, gcs);
-
- try
- {
- lockManager.start();
-
- this.lockManagers.put(containerName, lockManager);
- }
- catch (Exception e)
- {
- gcs.stop();
- throw new IllegalStateException("Unexpected exception while starting lock manager for " + containerName);
- }
- }
-
- return lockManager;
- }
- }
-
-
- @Override
public <K, V> Cache<K, V> getCache(LocalDistributableSessionManager manager)
{
- ReplicationConfig replConfig = manager.getReplicationConfig();
- String containerName = getContainerName(replConfig);
+ ReplicationConfig config = manager.getReplicationConfig();
+ String containerName = config.getCacheName();
+ String templateCacheName = null;
- EmbeddedCacheManager container = this.registry.getCacheContainer(containerName);
- String cacheName = getCacheName(manager);
-
- Cache<?, ?> templateCache = container.getCache();
- Configuration configuration = templateCache.getConfiguration().clone();
- CacheMode mode = getCacheMode(replConfig, configuration);
- configuration.setCacheMode(mode);
- container.defineConfiguration(cacheName, configuration);
- return container.getCache(cacheName);
- }
-
- private String getContainerName(ReplicationConfig replConfig)
- {
- String templateCacheName = replConfig.getCacheName();
- String containerName = this.defaultContainerName;
-
- if (templateCacheName != null)
+ if ((containerName != null) && !containerName.isEmpty())
{
- String[] parts = templateCacheName.split(":");
+ String[] parts = containerName.split("/");
if (parts.length == 2)
{
containerName = parts[0];
+ templateCacheName = parts[1];
}
}
- return containerName;
+ String hostName = manager.getHostName();
+ String host = (hostName == null) || hostName.isEmpty() ? "localhost" : hostName;
+
+ String context = manager.getContextName();
+ String path = context.isEmpty() || context.equals("/") ? "ROOT" : context.startsWith("/") ? context.substring(1) : context;
+
+ String cacheName = host + "/" + path;
+
+ EmbeddedCacheManager container = this.registry.getCacheContainer(containerName);
+
+ this.applyOverrides(container.defineConfiguration(cacheName, templateCacheName, new Configuration()), config);
+
+ return container.getCache(cacheName);
}
- private CacheMode getCacheMode(ReplicationConfig replConfig, Configuration configuration)
+ private void applyOverrides(Configuration configuration, ReplicationConfig replConfig)
{
Integer backups = replConfig.getBackups();
ReplicationMode replMode = replConfig.getReplicationMode();
@@ -193,22 +123,7 @@
}
}
}
- return mode;
- }
-
- private String getCacheName(LocalDistributableSessionManager manager)
- {
- String hostName = manager.getHostName();
- String host = (hostName == null) || hostName.isEmpty() ? "localhost" : hostName;
- String context = manager.getContextName();
- String path = context.isEmpty() || context.equals("/") ? "ROOT" : context.startsWith("/") ? context.substring(1) : context;
-
- return host + "/" + path;
- }
-
- public void setDefaultContainerName(String defaultContainerName)
- {
- this.defaultContainerName = defaultContainerName;
+ configuration.setCacheMode(mode);
}
}
Added: projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/ispn/DefaultLockManagerSource.java
===================================================================
--- projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/ispn/DefaultLockManagerSource.java (rev 0)
+++ projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/ispn/DefaultLockManagerSource.java 2010-08-27 01:43:38 UTC (rev 107822)
@@ -0,0 +1,99 @@
+/*
+ * 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.web.tomcat.service.session.distributedcache.ispn;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.infinispan.Cache;
+import org.infinispan.manager.EmbeddedCacheManager;
+import org.infinispan.remoting.transport.jgroups.JGroupsTransport;
+import org.jboss.ha.core.framework.server.CoreGroupCommunicationService;
+import org.jboss.ha.framework.server.lock.SharedLocalYieldingClusterLockManager;
+import org.jgroups.Channel;
+
+/**
+ * @author Vladimir Blagojevic
+ * @author Paul Ferraro
+ */
+public class DefaultLockManagerSource implements LockManagerSource
+{
+ /** The scope assigned to our group communication service */
+ public static final Short SCOPE_ID = Short.valueOf((short) 222);
+ /** The service name of the group communication service */
+ public static final String SERVICE_NAME = "HTTPSESSIONOWNER";
+
+ private final Map<String, SharedLocalYieldingClusterLockManager> lockManagers = new HashMap<String, SharedLocalYieldingClusterLockManager>();
+
+ /**
+ * {@inheritDoc}
+ * @see org.jboss.web.tomcat.service.session.distributedcache.ispn.LockManagerSource#getLockManager(org.infinispan.Cache)
+ */
+ @Override
+ public SharedLocalYieldingClusterLockManager getLockManager(Cache<?, ?> cache)
+ {
+ if (!cache.getConfiguration().getCacheMode().isDistributed()) return null;
+
+ EmbeddedCacheManager container = (EmbeddedCacheManager) cache.getCacheManager();
+ String clusterName = container.getGlobalConfiguration().getClusterName();
+
+ synchronized (this.lockManagers)
+ {
+ SharedLocalYieldingClusterLockManager lockManager = this.lockManagers.get(clusterName);
+
+ if (lockManager == null)
+ {
+ JGroupsTransport transport = (JGroupsTransport) cache.getAdvancedCache().getRpcManager().getTransport();
+ Channel channel = transport.getChannel();
+
+ CoreGroupCommunicationService gcs = new CoreGroupCommunicationService();
+ gcs.setChannel(channel);
+ gcs.setScopeId(SCOPE_ID);
+
+ try
+ {
+ gcs.start();
+ }
+ catch (Exception e)
+ {
+ throw new IllegalStateException("Unexpected exception while starting group communication service for " + clusterName);
+ }
+
+ lockManager = new SharedLocalYieldingClusterLockManager(SERVICE_NAME, gcs, gcs);
+
+ try
+ {
+ lockManager.start();
+ }
+ catch (Exception e)
+ {
+ gcs.stop();
+ throw new IllegalStateException("Unexpected exception while starting lock manager for " + clusterName);
+ }
+
+ this.lockManagers.put(clusterName, lockManager);
+ }
+
+ return lockManager;
+ }
+ }
+}
Modified: projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/ispn/DistributedCacheManager.java
===================================================================
--- projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/ispn/DistributedCacheManager.java 2010-08-26 23:47:34 UTC (rev 107821)
+++ projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/ispn/DistributedCacheManager.java 2010-08-27 01:43:38 UTC (rev 107822)
@@ -403,7 +403,7 @@
@Override
public SessionOwnershipSupport getSessionOwnershipSupport()
{
- return this;
+ return (this.lockManager != null) ? this : null;
}
@Override
Modified: projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/ispn/DistributedCacheManagerFactory.java
===================================================================
--- projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/ispn/DistributedCacheManagerFactory.java 2010-08-26 23:47:34 UTC (rev 107821)
+++ projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/ispn/DistributedCacheManagerFactory.java 2010-08-27 01:43:38 UTC (rev 107822)
@@ -46,25 +46,18 @@
*/
public class DistributedCacheManagerFactory implements org.jboss.web.tomcat.service.session.distributedcache.spi.DistributedCacheManagerFactory
{
- private CacheSource source;
- private LockManagerSource lmSource;
+ private CacheSource cacheSource = new DefaultCacheSource(DefaultCacheContainerRegistry.getInstance());
+ private LockManagerSource lockManagerSource = new DefaultLockManagerSource();
private SessionAttributeStorageFactory storageFactory = new SessionAttributeStorageFactoryImpl();
private SessionAttributeMarshallerFactory marshallerFactory = new SessionAttributeMarshallerFactoryImpl();
private CacheInvoker invoker = new RetryingCacheInvoker(10, 100);
private AtomicMapFactory atomicMapFactory = new DefaultAtomicMapFactory();
-
- public DistributedCacheManagerFactory()
- {
- DefaultCacheSource dcmSource = new DefaultCacheSource(DefaultCacheContainerRegistry.getInstance());
- this.source = dcmSource;
- this.lmSource = dcmSource;
- }
@Override
public <T extends OutgoingDistributableSessionData> org.jboss.web.tomcat.service.session.distributedcache.spi.DistributedCacheManager<T> getDistributedCacheManager(LocalDistributableSessionManager manager)
{
- Cache<String, AtomicMap<Object, Object>> cache = this.source.getCache(manager);
- SharedLocalYieldingClusterLockManager lockManager = this.lmSource.getLockManager(manager);
+ Cache<String, AtomicMap<Object, Object>> cache = this.cacheSource.getCache(manager);
+ SharedLocalYieldingClusterLockManager lockManager = this.lockManagerSource.getLockManager(cache);
TransactionManager tm = cache.getAdvancedCache().getTransactionManager();
if (!(tm instanceof BatchModeTransactionManager))
@@ -81,12 +74,12 @@
public void setCacheSource(CacheSource source)
{
- this.source = source;
+ this.cacheSource = source;
}
- public void setLockManagerSource(LockManagerSource lmSource)
+ public void setLockManagerSource(LockManagerSource source)
{
- this.lmSource = lmSource;
+ this.lockManagerSource = source;
}
public void setSessionAttributeStorageFactory(SessionAttributeStorageFactory storageFactory)
Modified: projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/ispn/LockManagerSource.java
===================================================================
--- projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/ispn/LockManagerSource.java 2010-08-26 23:47:34 UTC (rev 107821)
+++ projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/ispn/LockManagerSource.java 2010-08-27 01:43:38 UTC (rev 107822)
@@ -21,14 +21,13 @@
*/
package org.jboss.web.tomcat.service.session.distributedcache.ispn;
+import org.infinispan.Cache;
import org.jboss.ha.framework.server.lock.SharedLocalYieldingClusterLockManager;
-import org.jboss.web.tomcat.service.session.distributedcache.spi.LocalDistributableSessionManager;
/**
* @author Vladimir Blagojevic
- *
*/
public interface LockManagerSource
{
- SharedLocalYieldingClusterLockManager getLockManager(LocalDistributableSessionManager manager);
+ SharedLocalYieldingClusterLockManager getLockManager(Cache<?, ?> cache);
}
Modified: projects/cluster/ha-server-cache-ispn/trunk/src/test/java/org/jboss/web/tomcat/service/session/distributedcache/ispn/DefaultCacheSourceTest.java
===================================================================
--- projects/cluster/ha-server-cache-ispn/trunk/src/test/java/org/jboss/web/tomcat/service/session/distributedcache/ispn/DefaultCacheSourceTest.java 2010-08-26 23:47:34 UTC (rev 107821)
+++ projects/cluster/ha-server-cache-ispn/trunk/src/test/java/org/jboss/web/tomcat/service/session/distributedcache/ispn/DefaultCacheSourceTest.java 2010-08-27 01:43:38 UTC (rev 107822)
@@ -21,7 +21,6 @@
*/
package org.jboss.web.tomcat.service.session.distributedcache.ispn;
-import org.easymock.Capture;
import org.easymock.EasyMock;
import org.infinispan.Cache;
import org.infinispan.config.Configuration;
@@ -41,68 +40,71 @@
public class DefaultCacheSourceTest
{
@Test
- public void test()
+ public void getCache()
{
Configuration configuration = new Configuration();
configuration.setCacheMode(CacheMode.REPL_ASYNC);
ReplicationConfig config = new ReplicationConfig();
- config.setCacheName("session-cache");
+ config.setCacheName("standard-session-cache");
config.setReplicationMode(null);
config.setBackups(null);
// Validate host contribution to cache name
- this.start("session", "session-cache", null, "", "localhost/ROOT", config, configuration, CacheMode.REPL_ASYNC);
- this.start("session", "session-cache", "", "", "localhost/ROOT", config, configuration, CacheMode.REPL_ASYNC);
- this.start("session", "session-cache", "host1", "", "host1/ROOT", config, configuration, CacheMode.REPL_ASYNC);
+ this.getCache("standard-session-cache", null, null, "", "localhost/ROOT", config, configuration, CacheMode.REPL_ASYNC);
+ this.getCache("standard-session-cache", null, "", "", "localhost/ROOT", config, configuration, CacheMode.REPL_ASYNC);
+ this.getCache("standard-session-cache", null, "host1", "", "host1/ROOT", config, configuration, CacheMode.REPL_ASYNC);
// Validate context path contribution to cache name
- this.start("session", "session-cache", null, "/", "localhost/ROOT", config, configuration, CacheMode.REPL_ASYNC);
- this.start("session", "session-cache", null, "/context1", "localhost/context1", config, configuration, CacheMode.REPL_ASYNC);
- this.start("session", "session-cache", null, "/path/context1", "localhost/path/context1", config, configuration, CacheMode.REPL_ASYNC);
+ this.getCache("standard-session-cache", null, null, "/", "localhost/ROOT", config, configuration, CacheMode.REPL_ASYNC);
+ this.getCache("standard-session-cache", null, null, "/context1", "localhost/context1", config, configuration, CacheMode.REPL_ASYNC);
+ this.getCache("standard-session-cache", null, null, "/path/context1", "localhost/path/context1", config, configuration, CacheMode.REPL_ASYNC);
// Validate cache container qualified cache name
- config.setCacheName("default:session-cache");
- this.start("default", "session-cache", null, "", "localhost/ROOT", config, configuration, CacheMode.REPL_ASYNC);
+ config.setCacheName("default/session-cache");
+ this.getCache("default", "session-cache", null, "", "localhost/ROOT", config, configuration, CacheMode.REPL_ASYNC);
- config.setCacheName("session-cache");
+ config.setCacheName(null);
+ this.getCache(null, null, null, "", "localhost/ROOT", config, configuration, CacheMode.REPL_ASYNC);
+
+ config.setCacheName("standard-session-cache");
config.setReplicationMode(ReplicationMode.SYNCHRONOUS);
- this.start("session", "session-cache", null, "", "localhost/ROOT", config, configuration, CacheMode.REPL_SYNC);
+ this.getCache("standard-session-cache", null, null, "", "localhost/ROOT", config, configuration, CacheMode.REPL_SYNC);
config.setReplicationMode(ReplicationMode.ASYNCHRONOUS);
- this.start("session", "session-cache", null, "", "localhost/ROOT", config, configuration, CacheMode.REPL_ASYNC);
+ this.getCache("standard-session-cache", null, null, "", "localhost/ROOT", config, configuration, CacheMode.REPL_ASYNC);
config.setBackups(Integer.valueOf(-1));
config.setReplicationMode(null);
- this.start("session", "session-cache", null, "", "localhost/ROOT", config, configuration, CacheMode.REPL_ASYNC);
+ this.getCache("standard-session-cache", null, null, "", "localhost/ROOT", config, configuration, CacheMode.REPL_ASYNC);
config.setReplicationMode(ReplicationMode.SYNCHRONOUS);
- this.start("session", "session-cache", null, "", "localhost/ROOT", config, configuration, CacheMode.REPL_SYNC);
+ this.getCache("standard-session-cache", null, null, "", "localhost/ROOT", config, configuration, CacheMode.REPL_SYNC);
config.setReplicationMode(ReplicationMode.ASYNCHRONOUS);
- this.start("session", "session-cache", null, "", "localhost/ROOT", config, configuration, CacheMode.REPL_ASYNC);
+ this.getCache("standard-session-cache", null, null, "", "localhost/ROOT", config, configuration, CacheMode.REPL_ASYNC);
config.setBackups(Integer.valueOf(0));
config.setReplicationMode(null);
- this.start("session", "session-cache", null, "", "localhost/ROOT", config, configuration, CacheMode.LOCAL);
+ this.getCache("standard-session-cache", null, null, "", "localhost/ROOT", config, configuration, CacheMode.LOCAL);
config.setReplicationMode(ReplicationMode.SYNCHRONOUS);
- this.start("session", "session-cache", null, "", "localhost/ROOT", config, configuration, CacheMode.LOCAL);
+ this.getCache("standard-session-cache", null, null, "", "localhost/ROOT", config, configuration, CacheMode.LOCAL);
config.setReplicationMode(ReplicationMode.ASYNCHRONOUS);
- this.start("session", "session-cache", null, "", "localhost/ROOT", config, configuration, CacheMode.LOCAL);
+ this.getCache("standard-session-cache", null, null, "", "localhost/ROOT", config, configuration, CacheMode.LOCAL);
config.setBackups(Integer.valueOf(1));
config.setReplicationMode(null);
- this.start("session", "session-cache", null, "", "localhost/ROOT", config, configuration, CacheMode.DIST_ASYNC);
+ this.getCache("standard-session-cache", null, null, "", "localhost/ROOT", config, configuration, CacheMode.DIST_ASYNC);
config.setReplicationMode(ReplicationMode.SYNCHRONOUS);
- this.start("session", "session-cache", null, "", "localhost/ROOT", config, configuration, CacheMode.DIST_SYNC);
+ this.getCache("standard-session-cache", null, null, "", "localhost/ROOT", config, configuration, CacheMode.DIST_SYNC);
config.setReplicationMode(ReplicationMode.ASYNCHRONOUS);
- this.start("session", "session-cache", null, "", "localhost/ROOT", config, configuration, CacheMode.DIST_ASYNC);
+ this.getCache("standard-session-cache", null, null, "", "localhost/ROOT", config, configuration, CacheMode.DIST_ASYNC);
}
- private void start(String containerName, String templateCacheName, String hostName, String contextName, String cacheName, ReplicationConfig config, Configuration configuration, CacheMode mode)
+ private void getCache(String containerName, String templateCacheName, String hostName, String contextName, String cacheName, ReplicationConfig config, Configuration configuration, CacheMode mode)
{
CacheContainerRegistry registry = EasyMock.createStrictMock(CacheContainerRegistry.class);
@SuppressWarnings("unchecked")
@@ -111,7 +113,7 @@
Cache<Object, Object> templateCache = EasyMock.createStrictMock(Cache.class);
EmbeddedCacheManager container = EasyMock.createStrictMock(EmbeddedCacheManager.class);
LocalDistributableSessionManager manager = EasyMock.createStrictMock(LocalDistributableSessionManager.class);
- Capture<Configuration> capturedConfiguration = new Capture<Configuration>();
+ Configuration cacheConfiguration = configuration.clone();
DefaultCacheSource source = new DefaultCacheSource(registry);
@@ -120,9 +122,7 @@
EasyMock.expect(registry.getCacheContainer(containerName)).andReturn(container);
EasyMock.expect(manager.getHostName()).andReturn(hostName);
EasyMock.expect(manager.getContextName()).andReturn(contextName);
- EasyMock.expect(container.getCache()).andReturn(templateCache);
- EasyMock.expect(templateCache.getConfiguration()).andReturn(configuration);
- EasyMock.expect(container.defineConfiguration(EasyMock.eq(cacheName), EasyMock.capture(capturedConfiguration))).andReturn(new Configuration());
+ EasyMock.expect(container.defineConfiguration(cacheName, templateCacheName, new Configuration())).andReturn(cacheConfiguration);
EasyMock.expect(container.getCache(cacheName)).andReturn(cache);
EasyMock.replay(registry, manager, container, cache, templateCache);
@@ -133,7 +133,6 @@
Assert.assertSame(cache, result);
- Configuration cacheConfiguration = capturedConfiguration.getValue();
Assert.assertSame(mode, cacheConfiguration.getCacheMode());
Assert.assertEquals((config.getBackups() != null) ? config.getBackups().intValue() : 2, cacheConfiguration.getNumOwners());
}
Modified: projects/cluster/ha-server-cache-ispn/trunk/src/test/java/org/jboss/web/tomcat/service/session/distributedcache/ispn/DistributedCacheManagerFactoryTest.java
===================================================================
--- projects/cluster/ha-server-cache-ispn/trunk/src/test/java/org/jboss/web/tomcat/service/session/distributedcache/ispn/DistributedCacheManagerFactoryTest.java 2010-08-26 23:47:34 UTC (rev 107821)
+++ projects/cluster/ha-server-cache-ispn/trunk/src/test/java/org/jboss/web/tomcat/service/session/distributedcache/ispn/DistributedCacheManagerFactoryTest.java 2010-08-27 01:43:38 UTC (rev 107822)
@@ -50,8 +50,8 @@
*/
public class DistributedCacheManagerFactoryTest
{
- private final CacheSource source = EasyMock.createStrictMock(CacheSource.class);
- private final LockManagerSource lmsource = EasyMock.createStrictMock(LockManagerSource.class);
+ private final CacheSource cacheSource = EasyMock.createStrictMock(CacheSource.class);
+ private final LockManagerSource lockManagerSource = EasyMock.createStrictMock(LockManagerSource.class);
private final SessionAttributeStorageFactory storageFactory = EasyMock.createStrictMock(SessionAttributeStorageFactory.class);
private final SessionAttributeMarshallerFactory marshallerFactory = EasyMock.createStrictMock(SessionAttributeMarshallerFactory.class);
private final CacheInvoker invoker = EasyMock.createStrictMock(CacheInvoker.class);
@@ -73,14 +73,15 @@
factory.setSessionAttributeMarshallerFactory(this.marshallerFactory);
factory.setCacheInvoker(this.invoker);
factory.setAtomicMapFactory(this.atomicMapFactory);
- factory.setCacheSource(this.source);
- factory.setLockManagerSource(this.lmsource);
+ factory.setCacheSource(this.cacheSource);
+ factory.setLockManagerSource(this.lockManagerSource);
ReplicationConfig config = new ReplicationConfig();
ReplicationGranularity granularity = ReplicationGranularity.SESSION;
config.setReplicationGranularity(granularity);
- EasyMock.expect(this.source.<String, AtomicMap<Object, Object>>getCache(this.manager)).andReturn(this.cache);
+ EasyMock.expect(this.cacheSource.<String, AtomicMap<Object, Object>>getCache(this.manager)).andReturn(this.cache);
+ EasyMock.expect(this.lockManagerSource.getLockManager(EasyMock.same(cache))).andReturn(null);
EasyMock.expect(this.cache.getAdvancedCache()).andReturn(this.cache);
EasyMock.expect(this.cache.getTransactionManager()).andReturn(new BatchModeTransactionManager());
EasyMock.expect(this.cache.getConfiguration()).andReturn(new Configuration());
@@ -89,16 +90,16 @@
EasyMock.expect(this.manager.getReplicationConfig()).andReturn(config);
EasyMock.expect(this.storageFactory.createStorage(granularity, this.marshaller)).andReturn(this.storage);
- EasyMock.replay(this.storageFactory, this.marshallerFactory, this.invoker, this.manager, this.storage, this.marshaller, this.atomicMapFactory, this.source, this.cache);
+ EasyMock.replay(this.storageFactory, this.marshallerFactory, this.invoker, this.manager, this.storage, this.marshaller, this.atomicMapFactory, this.cacheSource, this.cache, this.lockManagerSource);
org.jboss.web.tomcat.service.session.distributedcache.spi.DistributedCacheManager<?> result = factory.getDistributedCacheManager(this.manager);
- EasyMock.verify(this.storageFactory, this.marshallerFactory, this.invoker, this.manager, this.storage, this.marshaller, this.atomicMapFactory, this.source, this.cache);
+ EasyMock.verify(this.storageFactory, this.marshallerFactory, this.invoker, this.manager, this.storage, this.marshaller, this.atomicMapFactory, this.cacheSource, this.cache, this.lockManagerSource);
Assert.assertNotNull(result);
Assert.assertTrue(result instanceof DistributedCacheManager);
- EasyMock.reset(this.storageFactory, this.marshallerFactory, this.invoker, this.manager, this.storage, this.marshaller, this.atomicMapFactory, this.source, this.cache);
+ EasyMock.reset(this.storageFactory, this.marshallerFactory, this.invoker, this.manager, this.storage, this.marshaller, this.atomicMapFactory, this.cacheSource, this.cache, this.lockManagerSource);
}
@Test
More information about the jboss-cvs-commits
mailing list