[jboss-cvs] JBossAS SVN: r109181 - in projects/cluster/ha-server-cache-ispn/trunk/src: test/java/org/jboss/web/tomcat/service/session/distributedcache/ispn and 1 other directory.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Fri Nov 5 15:16:12 EDT 2010
Author: pferraro
Date: 2010-11-05 15:16:12 -0400 (Fri, 05 Nov 2010)
New Revision: 109181
Added:
projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/ispn/JvmRouteCacheSource.java
projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/ispn/SessionCacheSource.java
projects/cluster/ha-server-cache-ispn/trunk/src/test/java/org/jboss/web/tomcat/service/session/distributedcache/ispn/JvmRouteCacheSourceTest.java
projects/cluster/ha-server-cache-ispn/trunk/src/test/java/org/jboss/web/tomcat/service/session/distributedcache/ispn/SessionCacheSourceTest.java
Removed:
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/test/java/org/jboss/web/tomcat/service/session/distributedcache/ispn/DefaultCacheSourceTest.java
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/DistributedCacheManagerFactory.java
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/DistributedCacheManagerTest.java
Log:
Use cache source abstraction for jvm route cache.
Default impl will use default cache container (ha-partition).
Deleted: 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-11-05 17:28:33 UTC (rev 109180)
+++ projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/ispn/DefaultCacheSource.java 2010-11-05 19:16:12 UTC (rev 109181)
@@ -1,129 +0,0 @@
-/*
- * 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 org.infinispan.Cache;
-import org.infinispan.config.Configuration;
-import org.infinispan.config.Configuration.CacheMode;
-import org.infinispan.manager.EmbeddedCacheManager;
-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;
-
-/**
- * @author Paul Ferraro
- *
- */
-public class DefaultCacheSource implements CacheSource
-{
- private static final String DELIMITER = "/";
-
- private final CacheContainerRegistry registry;
-
- public DefaultCacheSource(CacheContainerRegistry registry)
- {
- this.registry = registry;
- }
-
- @Override
- public <K, V> Cache<K, V> getCache(LocalDistributableSessionManager manager)
- {
- ReplicationConfig config = manager.getReplicationConfig();
- String containerName = config.getCacheName();
- String templateCacheName = null;
-
- if ((containerName != null) && !containerName.isEmpty())
- {
- String[] parts = containerName.split(DELIMITER);
-
- if (parts.length == 2)
- {
- containerName = parts[0];
- templateCacheName = parts[1];
- }
- }
-
- String cacheName = manager.getName();
-
- EmbeddedCacheManager container = this.registry.getCacheContainer(containerName);
-
- this.applyOverrides(container.defineConfiguration(cacheName, templateCacheName, new Configuration()), config);
-
- return container.<K, V>getCache(cacheName);
- }
-
- private Configuration applyOverrides(Configuration configuration, ReplicationConfig replConfig)
- {
- Integer backups = replConfig.getBackups();
- ReplicationMode replMode = replConfig.getReplicationMode();
-
- CacheMode mode = configuration.getCacheMode();
-
- if (backups != null)
- {
- int value = backups.intValue();
-
- configuration.setNumOwners(value + 1);
-
- if (value == 0)
- {
- mode = CacheMode.LOCAL;
- }
- else
- {
- boolean dist = (value > 0);
- boolean synchronous = mode.isSynchronous();
- if (dist)
- {
- mode = synchronous ? CacheMode.DIST_SYNC : CacheMode.DIST_ASYNC;
- }
- else // Negative backups means total replication
- {
- mode = synchronous ? CacheMode.REPL_SYNC : CacheMode.REPL_ASYNC;
- }
- configuration.setFetchInMemoryState(!dist);
- }
- }
-
- if (replMode != null)
- {
- switch (replMode)
- {
- case SYNCHRONOUS:
- {
- mode = mode.toSync();
- break;
- }
- case ASYNCHRONOUS:
- {
- mode = mode.toAsync();
- break;
- }
- }
- }
-
- configuration.setCacheMode(mode);
-
- return configuration;
- }
-}
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-11-05 17:28:33 UTC (rev 109180)
+++ projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/ispn/DistributedCacheManager.java 2010-11-05 19:16:12 UTC (rev 109181)
@@ -33,7 +33,6 @@
import org.infinispan.config.Configuration;
import org.infinispan.context.Flag;
import org.infinispan.distribution.DistributionManager;
-import org.infinispan.manager.CacheContainer;
import org.infinispan.manager.EmbeddedCacheManager;
import org.infinispan.notifications.Listener;
import org.infinispan.notifications.cachelistener.annotation.CacheEntryActivated;
@@ -101,10 +100,10 @@
private final CacheInvoker invoker;
private final BatchingManager batchingManager;
private final boolean passivationEnabled;
- private final Object viewChangeListener;
+ private final JvmRouteHandler jvmRouteHandler;
public DistributedCacheManager(LocalDistributableSessionManager manager,
- Cache<String, Map<Object, Object>> sessionCache, Cache<Address, String> jvmRouteCache,
+ Cache<String, Map<Object, Object>> sessionCache, CacheSource jvmRouteCacheSource,
SharedLocalYieldingClusterLockManager lockManager, SessionAttributeStorage<T> attributeStorage,
BatchingManager batchingManager, CacheInvoker invoker)
{
@@ -120,7 +119,7 @@
this.passivationEnabled = (loaderManagerConfig != null) ? loaderManagerConfig.isPassivation().booleanValue() && !loaderManagerConfig.isShared().booleanValue() : false;
- this.viewChangeListener = configuration.getCacheMode().isDistributed() ? new ViewChangeListener(this.manager) : null;
+ this.jvmRouteHandler = configuration.getCacheMode().isDistributed() ? new JvmRouteHandler(jvmRouteCacheSource, this.manager) : null;
}
/**
@@ -137,28 +136,21 @@
this.sessionCache.addListener(this);
- if (this.viewChangeListener != null)
+ if (this.jvmRouteHandler != null)
{
- Cache<Address, String> jvmRouteCache = getJvmRouteCache(this.sessionCache.getCacheManager(), this.manager);
+ EmbeddedCacheManager container = (EmbeddedCacheManager) this.sessionCache.getCacheManager();
- EmbeddedCacheManager container = (EmbeddedCacheManager) jvmRouteCache.getCacheManager();
+ container.addListener(this.jvmRouteHandler);
- container.addListener(this.viewChangeListener);
-
String jvmRoute = this.manager.getJvmRoute();
if (jvmRoute != null)
{
- jvmRouteCache.putIfAbsent(container.getAddress(), jvmRoute);
+ this.jvmRouteHandler.getCache().putIfAbsent(container.getAddress(), jvmRoute);
}
}
}
- static Cache<Address, String> getJvmRouteCache(CacheContainer container, LocalDistributableSessionManager manager)
- {
- return container.getCache(manager.getEngineName());
- }
-
/**
* {@inheritDoc}
* @see org.jboss.web.tomcat.service.session.distributedcache.spi.DistributedCacheManager#stop()
@@ -166,11 +158,10 @@
@Override
public void stop()
{
- if (this.viewChangeListener != null)
+ if (this.jvmRouteHandler != null)
{
EmbeddedCacheManager container = (EmbeddedCacheManager) this.sessionCache.getCacheManager();
-
- container.removeListener(this.viewChangeListener);
+ container.removeListener(this.jvmRouteHandler);
}
this.sessionCache.removeListener(this);
@@ -495,8 +486,7 @@
if ((manager != null) && !manager.isRehashInProgress())
{
- EmbeddedCacheManager container = (EmbeddedCacheManager) cache.getCacheManager();
- Cache<Address, String> jvmRouteCache = getJvmRouteCache(container, this.manager);
+ Cache<Address, String> jvmRouteCache = this.jvmRouteHandler.getCache();
for (Address address: manager.locate(sessionId))
{
@@ -557,21 +547,26 @@
this.manager.sessionActivated();
}
- @Listener(sync = false)
- public static class ViewChangeListener
+ @Listener
+ public static class JvmRouteHandler
{
private final LocalDistributableSessionManager manager;
+ private final Cache<Address, String> cache;
- ViewChangeListener(LocalDistributableSessionManager manager)
+ JvmRouteHandler(CacheSource cacheSource, LocalDistributableSessionManager manager)
{
+ this.cache = cacheSource.getCache(manager);
this.manager = manager;
}
+ public Cache<Address, String> getCache()
+ {
+ return this.cache;
+ }
+
@ViewChanged
public void viewChanged(ViewChangedEvent event)
{
- Cache<Address, String> cache = getJvmRouteCache(event.getCacheManager(), this.manager);
-
Collection<Address> oldMembers = event.getOldMembers();
Collection<Address> newMembers = event.getNewMembers();
@@ -580,7 +575,7 @@
{
if (!newMembers.contains(member))
{
- if (cache.remove(member) != null)
+ if (this.cache.remove(member) != null)
{
log.info("Removed stale jvm route entry from web session cache on behalf of member " + member);
}
@@ -594,7 +589,7 @@
Address localAddress = event.getLocalAddress();
if (!oldMembers.contains(localAddress) && newMembers.contains(localAddress))
{
- String oldJvmRoute = cache.put(localAddress, jvmRoute);
+ String oldJvmRoute = this.cache.put(localAddress, jvmRoute);
if (oldJvmRoute == null)
{
log.info("Adding missing jvm route entry to web session cache");
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-11-05 17:28:33 UTC (rev 109180)
+++ projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/ispn/DistributedCacheManagerFactory.java 2010-11-05 19:16:12 UTC (rev 109181)
@@ -46,7 +46,8 @@
*/
public class DistributedCacheManagerFactory implements org.jboss.web.tomcat.service.session.distributedcache.spi.DistributedCacheManagerFactory
{
- private CacheSource cacheSource = new DefaultCacheSource(DefaultCacheContainerRegistry.getInstance());
+ private CacheSource sessionCacheSource = new SessionCacheSource(DefaultCacheContainerRegistry.getInstance());
+ private CacheSource jvmRouteCacheSource = new JvmRouteCacheSource(DefaultCacheContainerRegistry.getInstance());
private LockManagerSource lockManagerSource = new DefaultLockManagerSource();
private SessionAttributeStorageFactory storageFactory = new SessionAttributeStorageFactoryImpl();
private SessionAttributeMarshallerFactory marshallerFactory = new SessionAttributeMarshallerFactoryImpl();
@@ -55,7 +56,7 @@
@Override
public <T extends OutgoingDistributableSessionData> org.jboss.web.tomcat.service.session.distributedcache.spi.DistributedCacheManager<T> getDistributedCacheManager(LocalDistributableSessionManager manager)
{
- Cache<String, Map<Object, Object>> sessionCache = this.cacheSource.getCache(manager);
+ Cache<String, Map<Object, Object>> sessionCache = this.sessionCacheSource.getCache(manager);
SharedLocalYieldingClusterLockManager lockManager = this.lockManagerSource.getLockManager(sessionCache);
TransactionManager tm = sessionCache.getAdvancedCache().getTransactionManager();
@@ -68,16 +69,19 @@
SessionAttributeMarshaller marshaller = this.marshallerFactory.createMarshaller(manager);
SessionAttributeStorage<T> storage = this.storageFactory.createStorage(manager.getReplicationConfig().getReplicationGranularity(), marshaller);
- sessionCache = new AtomicMapCache<String, Object, Object>(sessionCache);
-
- return new DistributedCacheManager<T>(manager, sessionCache, null, lockManager, storage, batchingManager, this.invoker);
+ return new DistributedCacheManager<T>(manager, new AtomicMapCache<String, Object, Object>(sessionCache), this.jvmRouteCacheSource, lockManager, storage, batchingManager, this.invoker);
}
- public void setCacheSource(CacheSource source)
+ public void setSessionCacheSource(CacheSource source)
{
- this.cacheSource = source;
+ this.sessionCacheSource = source;
}
+ public void setJvmRouteCacheSource(CacheSource source)
+ {
+ this.jvmRouteCacheSource = source;
+ }
+
public void setLockManagerSource(LockManagerSource source)
{
this.lockManagerSource = source;
Added: projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/ispn/JvmRouteCacheSource.java
===================================================================
--- projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/ispn/JvmRouteCacheSource.java (rev 0)
+++ projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/ispn/JvmRouteCacheSource.java 2010-11-05 19:16:12 UTC (rev 109181)
@@ -0,0 +1,50 @@
+/*
+ * 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 org.infinispan.Cache;
+import org.jboss.ha.ispn.CacheContainerRegistry;
+import org.jboss.web.tomcat.service.session.distributedcache.spi.LocalDistributableSessionManager;
+
+/**
+ * @author Paul Ferraro
+ *
+ */
+public class JvmRouteCacheSource implements CacheSource
+{
+ private final CacheContainerRegistry registry;
+
+ public JvmRouteCacheSource(CacheContainerRegistry registry)
+ {
+ this.registry = registry;
+ }
+
+ /**
+ * {@inheritDoc}
+ * @see org.jboss.web.tomcat.service.session.distributedcache.ispn.CacheSource#getCache(org.jboss.web.tomcat.service.session.distributedcache.spi.LocalDistributableSessionManager)
+ */
+ @Override
+ public <K, V> Cache<K, V> getCache(LocalDistributableSessionManager manager)
+ {
+ return this.registry.getCacheContainer().getCache(manager.getEngineName());
+ }
+}
Copied: projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/ispn/SessionCacheSource.java (from rev 109101, 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/SessionCacheSource.java (rev 0)
+++ projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/web/tomcat/service/session/distributedcache/ispn/SessionCacheSource.java 2010-11-05 19:16:12 UTC (rev 109181)
@@ -0,0 +1,129 @@
+/*
+ * 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 org.infinispan.Cache;
+import org.infinispan.config.Configuration;
+import org.infinispan.config.Configuration.CacheMode;
+import org.infinispan.manager.EmbeddedCacheManager;
+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;
+
+/**
+ * @author Paul Ferraro
+ *
+ */
+public class SessionCacheSource implements CacheSource
+{
+ private static final String DELIMITER = "/";
+
+ private final CacheContainerRegistry registry;
+
+ public SessionCacheSource(CacheContainerRegistry registry)
+ {
+ this.registry = registry;
+ }
+
+ @Override
+ public <K, V> Cache<K, V> getCache(LocalDistributableSessionManager manager)
+ {
+ ReplicationConfig config = manager.getReplicationConfig();
+ String containerName = config.getCacheName();
+ String templateCacheName = null;
+
+ if ((containerName != null) && !containerName.isEmpty())
+ {
+ String[] parts = containerName.split(DELIMITER);
+
+ if (parts.length == 2)
+ {
+ containerName = parts[0];
+ templateCacheName = parts[1];
+ }
+ }
+
+ String cacheName = manager.getName();
+
+ EmbeddedCacheManager container = this.registry.getCacheContainer(containerName);
+
+ this.applyOverrides(container.defineConfiguration(cacheName, templateCacheName, new Configuration()), config);
+
+ return container.<K, V>getCache(cacheName);
+ }
+
+ private Configuration applyOverrides(Configuration configuration, ReplicationConfig replConfig)
+ {
+ Integer backups = replConfig.getBackups();
+ ReplicationMode replMode = replConfig.getReplicationMode();
+
+ CacheMode mode = configuration.getCacheMode();
+
+ if (backups != null)
+ {
+ int value = backups.intValue();
+
+ configuration.setNumOwners(value + 1);
+
+ if (value == 0)
+ {
+ mode = CacheMode.LOCAL;
+ }
+ else
+ {
+ boolean dist = (value > 0);
+ boolean synchronous = mode.isSynchronous();
+ if (dist)
+ {
+ mode = synchronous ? CacheMode.DIST_SYNC : CacheMode.DIST_ASYNC;
+ }
+ else // Negative backups means total replication
+ {
+ mode = synchronous ? CacheMode.REPL_SYNC : CacheMode.REPL_ASYNC;
+ }
+ configuration.setFetchInMemoryState(!dist);
+ }
+ }
+
+ if (replMode != null)
+ {
+ switch (replMode)
+ {
+ case SYNCHRONOUS:
+ {
+ mode = mode.toSync();
+ break;
+ }
+ case ASYNCHRONOUS:
+ {
+ mode = mode.toAsync();
+ break;
+ }
+ }
+ }
+
+ configuration.setCacheMode(mode);
+
+ return configuration;
+ }
+}
Deleted: 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-11-05 17:28:33 UTC (rev 109180)
+++ projects/cluster/ha-server-cache-ispn/trunk/src/test/java/org/jboss/web/tomcat/service/session/distributedcache/ispn/DefaultCacheSourceTest.java 2010-11-05 19:16:12 UTC (rev 109181)
@@ -1,147 +0,0 @@
-/*
- * 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 org.easymock.EasyMock;
-import org.easymock.IMocksControl;
-import org.infinispan.Cache;
-import org.infinispan.config.Configuration;
-import org.infinispan.config.Configuration.CacheMode;
-import org.infinispan.manager.EmbeddedCacheManager;
-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.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-
-/**
- * @author Paul Ferraro
- *
- */
-public class DefaultCacheSourceTest
-{
- private IMocksControl control;
- private CacheContainerRegistry registry;
- private DefaultCacheSource source;
-
- @Before
- public void before()
- {
- this.control = EasyMock.createControl();
- this.registry = this.control.createMock(CacheContainerRegistry.class);
-
- this.source = new DefaultCacheSource(this.registry);
- }
-
- @Test
- public void getCache()
- {
- Configuration configuration = new Configuration();
- configuration.setCacheMode(CacheMode.REPL_ASYNC);
- ReplicationConfig config = new ReplicationConfig();
- config.setCacheName("standard-session-cache");
- config.setReplicationMode(null);
- config.setBackups(null);
-
- this.getCache("standard-session-cache", null, "//host/context1", config, configuration, CacheMode.REPL_ASYNC, null);
- this.getCache("standard-session-cache", null, "//host/context2", config, configuration, CacheMode.REPL_ASYNC, null);
-
- // Validate cache container qualified cache name
- config.setCacheName("default/session-cache");
- this.getCache("default", "session-cache", "//host/context", config, configuration, CacheMode.REPL_ASYNC, null);
-
- config.setCacheName(null);
- this.getCache(null, null, "//host/context", config, configuration, CacheMode.REPL_ASYNC, null);
-
- config.setCacheName("standard-session-cache");
- config.setReplicationMode(ReplicationMode.SYNCHRONOUS);
- this.getCache("standard-session-cache", null, "//host/context", config, configuration, CacheMode.REPL_SYNC, null);
-
- config.setReplicationMode(ReplicationMode.ASYNCHRONOUS);
- this.getCache("standard-session-cache", null, "//host/context", config, configuration, CacheMode.REPL_ASYNC, null);
-
- config.setBackups(Integer.valueOf(-1));
- config.setReplicationMode(null);
- this.getCache("standard-session-cache", null, "//host/context", config, configuration, CacheMode.REPL_ASYNC, true);
-
- config.setReplicationMode(ReplicationMode.SYNCHRONOUS);
- this.getCache("standard-session-cache", null, "//host/context", config, configuration, CacheMode.REPL_SYNC, true);
-
- config.setReplicationMode(ReplicationMode.ASYNCHRONOUS);
- this.getCache("standard-session-cache", null, "//host/context", config, configuration, CacheMode.REPL_ASYNC, true);
-
- config.setBackups(Integer.valueOf(0));
- config.setReplicationMode(null);
- this.getCache("standard-session-cache", null, "//host/context", config, configuration, CacheMode.LOCAL, null);
-
- config.setReplicationMode(ReplicationMode.SYNCHRONOUS);
- this.getCache("standard-session-cache", null, "//host/context", config, configuration, CacheMode.LOCAL, null);
-
- config.setReplicationMode(ReplicationMode.ASYNCHRONOUS);
- this.getCache("standard-session-cache", null, "//host/context", config, configuration, CacheMode.LOCAL, null);
-
- config.setBackups(Integer.valueOf(1));
- config.setReplicationMode(null);
- this.getCache("standard-session-cache", null, "//host/context", config, configuration, CacheMode.DIST_ASYNC, false);
-
- config.setReplicationMode(ReplicationMode.SYNCHRONOUS);
- this.getCache("standard-session-cache", null, "//host/context", config, configuration, CacheMode.DIST_SYNC, false);
-
- config.setReplicationMode(ReplicationMode.ASYNCHRONOUS);
- this.getCache("standard-session-cache", null, "//host/context", config, configuration, CacheMode.DIST_ASYNC, false);
- }
-
- private void getCache(String containerName, String templateCacheName, String cacheName, ReplicationConfig config, Configuration configuration, CacheMode mode, Boolean fetchInMemoryState)
- {
- @SuppressWarnings("unchecked")
- Cache<Object, Object> cache = this.control.createMock(Cache.class);
- EmbeddedCacheManager container = this.control.createMock(EmbeddedCacheManager.class);
- LocalDistributableSessionManager manager = this.control.createMock(LocalDistributableSessionManager.class);
- Configuration cacheConfiguration = configuration.clone();
-
- EasyMock.expect(manager.getReplicationConfig()).andReturn(config);
-
- EasyMock.expect(this.registry.getCacheContainer(containerName)).andReturn(container);
- EasyMock.expect(manager.getName()).andReturn(cacheName);
- EasyMock.expect(container.defineConfiguration(cacheName, templateCacheName, new Configuration())).andReturn(cacheConfiguration);
- EasyMock.expect(container.getCache(cacheName)).andReturn(cache);
-
- this.control.replay();
-
- Cache<Object, Object> result = source.getCache(manager);
-
- this.control.verify();
-
- Assert.assertSame(cache, result);
-
- Assert.assertSame(mode, cacheConfiguration.getCacheMode());
- Assert.assertEquals((config.getBackups() != null) ? config.getBackups().intValue() + 1 : 2, cacheConfiguration.getNumOwners());
- if (fetchInMemoryState != null)
- {
- Assert.assertEquals(fetchInMemoryState, cacheConfiguration.isFetchInMemoryState());
- }
-
- this.control.reset();
- }
-}
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-11-05 17:28:33 UTC (rev 109180)
+++ projects/cluster/ha-server-cache-ispn/trunk/src/test/java/org/jboss/web/tomcat/service/session/distributedcache/ispn/DistributedCacheManagerFactoryTest.java 2010-11-05 19:16:12 UTC (rev 109181)
@@ -47,7 +47,8 @@
public class DistributedCacheManagerFactoryTest
{
private IMocksControl control;
- private CacheSource cacheSource;
+ private CacheSource sessionCacheSource;
+ private CacheSource jvmRouteCacheSource;
private LockManagerSource lockManagerSource;
private SessionAttributeStorageFactory storageFactory;
private SessionAttributeMarshallerFactory marshallerFactory;
@@ -63,7 +64,8 @@
public void before()
{
this.control = EasyMock.createControl();
- this.cacheSource = this.control.createMock(CacheSource.class);
+ this.sessionCacheSource = this.control.createMock(CacheSource.class);
+ this.jvmRouteCacheSource = this.control.createMock(CacheSource.class);
this.lockManagerSource = this.control.createMock(LockManagerSource.class);
this.storageFactory = this.control.createMock(SessionAttributeStorageFactory.class);
this.marshallerFactory = this.control.createMock(SessionAttributeMarshallerFactory.class);
@@ -77,7 +79,8 @@
this.factory.setSessionAttributeStorageFactory(this.storageFactory);
this.factory.setSessionAttributeMarshallerFactory(this.marshallerFactory);
this.factory.setCacheInvoker(this.invoker);
- this.factory.setCacheSource(this.cacheSource);
+ this.factory.setSessionCacheSource(this.sessionCacheSource);
+ this.factory.setJvmRouteCacheSource(this.jvmRouteCacheSource);
this.factory.setLockManagerSource(this.lockManagerSource);
}
@@ -88,7 +91,7 @@
ReplicationGranularity granularity = ReplicationGranularity.SESSION;
config.setReplicationGranularity(granularity);
- EasyMock.expect(this.cacheSource.getCache(this.manager)).andReturn(this.cache);
+ EasyMock.expect(this.sessionCacheSource.getCache(this.manager)).andReturn(this.cache);
EasyMock.expect(this.lockManagerSource.getLockManager(EasyMock.same(this.cache))).andReturn(null);
EasyMock.expect(this.cache.getAdvancedCache()).andReturn(this.cache);
EasyMock.expect(this.cache.getTransactionManager()).andReturn(new BatchModeTransactionManager());
Modified: projects/cluster/ha-server-cache-ispn/trunk/src/test/java/org/jboss/web/tomcat/service/session/distributedcache/ispn/DistributedCacheManagerTest.java
===================================================================
--- projects/cluster/ha-server-cache-ispn/trunk/src/test/java/org/jboss/web/tomcat/service/session/distributedcache/ispn/DistributedCacheManagerTest.java 2010-11-05 17:28:33 UTC (rev 109180)
+++ projects/cluster/ha-server-cache-ispn/trunk/src/test/java/org/jboss/web/tomcat/service/session/distributedcache/ispn/DistributedCacheManagerTest.java 2010-11-05 19:16:12 UTC (rev 109181)
@@ -35,11 +35,11 @@
import org.infinispan.context.Flag;
import org.infinispan.distribution.DistributionManager;
import org.infinispan.lifecycle.ComponentStatus;
-import org.infinispan.manager.CacheContainer;
import org.infinispan.manager.EmbeddedCacheManager;
import org.infinispan.notifications.cachelistener.event.CacheEntryActivatedEvent;
import org.infinispan.notifications.cachelistener.event.CacheEntryModifiedEvent;
import org.infinispan.notifications.cachelistener.event.CacheEntryRemovedEvent;
+import org.infinispan.notifications.cachemanagerlistener.event.ViewChangedEvent;
import org.infinispan.remoting.transport.Address;
import org.jboss.ha.framework.server.lock.SharedLocalYieldingClusterLockManager;
import org.jboss.ha.ispn.invoker.CacheInvoker;
@@ -63,6 +63,7 @@
private LocalDistributableSessionManager sessionManager;
private SessionAttributeStorage<OutgoingDistributableSessionData> storage;
private AdvancedCache<String, Map<Object, Object>> sessionCache;
+ private Cache<Address, String> jvmRouteCache;
private SharedLocalYieldingClusterLockManager lockManager;
private BatchingManager batchingManager;
private CacheInvoker invoker;
@@ -76,18 +77,21 @@
this.sessionManager = this.control.createMock(LocalDistributableSessionManager.class);
this.storage = this.control.createMock(SessionAttributeStorage.class);
this.sessionCache = this.control.createMock(AdvancedCache.class);
+ this.jvmRouteCache = this.control.createMock(Cache.class);
this.lockManager = this.control.createMock(SharedLocalYieldingClusterLockManager.class);
this.batchingManager = this.control.createMock(BatchingManager.class);
this.invoker = this.control.createMock(CacheInvoker.class);
+ CacheSource cacheSource = this.control.createMock(CacheSource.class);
Configuration configuration = new Configuration();
configuration.setCacheMode(CacheMode.DIST_SYNC);
EasyMock.expect(this.sessionCache.getConfiguration()).andReturn(configuration);
+ EasyMock.expect(cacheSource.<Address, String>getCache(this.sessionManager)).andReturn(this.jvmRouteCache);
this.control.replay();
- this.manager = new DistributedCacheManager<OutgoingDistributableSessionData>(this.sessionManager, this.sessionCache, null, this.lockManager, this.storage, this.batchingManager, this.invoker);
+ this.manager = new DistributedCacheManager<OutgoingDistributableSessionData>(this.sessionManager, this.sessionCache, cacheSource, this.lockManager, this.storage, this.batchingManager, this.invoker);
this.control.verify();
this.control.reset();
@@ -104,13 +108,11 @@
this.start(ComponentStatus.TERMINATED, true);
}
- private void start(ComponentStatus status, boolean startCache)
+ private DistributedCacheManager.JvmRouteHandler start(ComponentStatus status, boolean startCache)
{
- CacheContainer container = this.control.createMock(CacheContainer.class);
- EmbeddedCacheManager manager = this.control.createMock(EmbeddedCacheManager.class);
- @SuppressWarnings("unchecked")
- Cache<Address, String> cache = this.control.createMock(Cache.class);
+ EmbeddedCacheManager container = this.control.createMock(EmbeddedCacheManager.class);
Address address = this.control.createMock(Address.class);
+ Capture<DistributedCacheManager.JvmRouteHandler> capturedJvmRouteHandler = new Capture<DistributedCacheManager.JvmRouteHandler>();
String jvmRoute = "node0";
EasyMock.expect(this.sessionCache.getStatus()).andReturn(status);
@@ -123,16 +125,12 @@
this.sessionCache.addListener(EasyMock.same(this.manager));
EasyMock.expect(this.sessionCache.getCacheManager()).andReturn(container);
- EasyMock.expect(container.<Address, String>getCache("engine")).andReturn(cache);
- EasyMock.expect(cache.getCacheManager()).andReturn(manager);
-// container.addListener(EasyMock.same(this.manager));
- manager.addListener(EasyMock.anyObject());
+ container.addListener(EasyMock.capture(capturedJvmRouteHandler));
- EasyMock.expect(manager.getAddress()).andReturn(address);
EasyMock.expect(this.sessionManager.getJvmRoute()).andReturn(jvmRoute);
- EasyMock.expect(this.sessionManager.getEngineName()).andReturn("engine");
- EasyMock.expect(cache.putIfAbsent(EasyMock.same(address), EasyMock.same(jvmRoute))).andReturn(null);
+ EasyMock.expect(container.getAddress()).andReturn(address);
+ EasyMock.expect(this.jvmRouteCache.putIfAbsent(EasyMock.same(address), EasyMock.same(jvmRoute))).andReturn(null);
this.control.replay();
@@ -140,6 +138,8 @@
this.control.verify();
this.control.reset();
+
+ return capturedJvmRouteHandler.getValue();
}
@Test
@@ -149,7 +149,7 @@
EasyMock.expect(this.sessionCache.getCacheManager()).andReturn(container);
- container.removeListener(EasyMock.anyObject());
+ container.removeListener(EasyMock.isA(DistributedCacheManager.JvmRouteHandler.class));
this.sessionCache.removeListener(EasyMock.same(this.manager));
this.sessionCache.stop();
@@ -724,37 +724,33 @@
this.control.verify();
}
-/*
+
@Test
public void viewChanged()
{
ViewChangedEvent event = this.control.createMock(ViewChangedEvent.class);
- EmbeddedCacheManager container = this.control.createMock(EmbeddedCacheManager.class);
- @SuppressWarnings("unchecked")
- Cache<Address, String> cache = this.control.createMock(Cache.class);
Address newMember = EasyMock.createMock(Address.class);
Address member = EasyMock.createMock(Address.class);
Address oldMember = EasyMock.createMock(Address.class);
String jvmRoute = "node1";
+
+ DistributedCacheManager.JvmRouteHandler handler = this.start(ComponentStatus.RUNNING, false);
- EasyMock.expect(event.getCacheManager()).andReturn(container);
- EasyMock.expect(this.sessionManager.getEngineName()).andReturn("engine");
- EasyMock.expect(container.<Address, String>getCache("engine")).andReturn(cache);
EasyMock.expect(event.getOldMembers()).andReturn(Arrays.asList(member, oldMember));
EasyMock.expect(event.getNewMembers()).andReturn(Arrays.asList(member, newMember));
- EasyMock.expect(cache.remove(EasyMock.same(oldMember))).andReturn(null);
+ EasyMock.expect(this.jvmRouteCache.remove(EasyMock.same(oldMember))).andReturn(null);
EasyMock.expect(event.getLocalAddress()).andReturn(newMember);
EasyMock.expect(this.sessionManager.getJvmRoute()).andReturn(jvmRoute);
- EasyMock.expect(cache.put(EasyMock.same(newMember), EasyMock.same(jvmRoute))).andReturn(null);
+ EasyMock.expect(this.jvmRouteCache.put(EasyMock.same(newMember), EasyMock.same(jvmRoute))).andReturn(null);
this.control.replay();
- this.manager.viewChanged(event);
+ handler.viewChanged(event);
this.control.verify();
}
-*/
+
@Test
public void isLocal()
{
@@ -827,9 +823,6 @@
this.control.reset();
- EmbeddedCacheManager container = this.control.createMock(EmbeddedCacheManager.class);
- @SuppressWarnings("unchecked")
- Cache<Address, String> cache = this.control.createMock(Cache.class);
Address address1 = this.control.createMock(Address.class);
Address address2 = this.control.createMock(Address.class);
Address address3 = this.control.createMock(Address.class);
@@ -837,12 +830,9 @@
EasyMock.expect(this.sessionCache.getAdvancedCache()).andReturn(this.sessionCache);
EasyMock.expect(this.sessionCache.getDistributionManager()).andReturn(distManager);
EasyMock.expect(distManager.isRehashInProgress()).andReturn(false);
- EasyMock.expect(this.sessionCache.getCacheManager()).andReturn(container);
- EasyMock.expect(this.sessionManager.getEngineName()).andReturn("engine");
- EasyMock.expect(container.<Address, String>getCache("engine")).andReturn(cache);
EasyMock.expect(distManager.locate(EasyMock.same(sessionId))).andReturn(Arrays.asList(address1, address2, address3));
- EasyMock.expect(cache.get(EasyMock.same(address1))).andReturn(null);
- EasyMock.expect(cache.get(EasyMock.same(address2))).andReturn(expected);
+ EasyMock.expect(this.jvmRouteCache.get(EasyMock.same(address1))).andReturn(null);
+ EasyMock.expect(this.jvmRouteCache.get(EasyMock.same(address2))).andReturn(expected);
EasyMock.expect(this.sessionCache.withFlags(Flag.FORCE_SYNCHRONOUS)).andReturn(this.sessionCache);
this.control.replay();
Added: projects/cluster/ha-server-cache-ispn/trunk/src/test/java/org/jboss/web/tomcat/service/session/distributedcache/ispn/JvmRouteCacheSourceTest.java
===================================================================
--- projects/cluster/ha-server-cache-ispn/trunk/src/test/java/org/jboss/web/tomcat/service/session/distributedcache/ispn/JvmRouteCacheSourceTest.java (rev 0)
+++ projects/cluster/ha-server-cache-ispn/trunk/src/test/java/org/jboss/web/tomcat/service/session/distributedcache/ispn/JvmRouteCacheSourceTest.java 2010-11-05 19:16:12 UTC (rev 109181)
@@ -0,0 +1,64 @@
+/*
+ * 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 org.easymock.EasyMock;
+import org.easymock.IMocksControl;
+import org.infinispan.Cache;
+import org.infinispan.manager.EmbeddedCacheManager;
+import org.jboss.ha.ispn.CacheContainerRegistry;
+import org.jboss.web.tomcat.service.session.distributedcache.spi.LocalDistributableSessionManager;
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * @author Paul Ferraro
+ *
+ */
+public class JvmRouteCacheSourceTest
+{
+ @Test
+ public void getCache()
+ {
+ IMocksControl control = EasyMock.createStrictControl();
+ CacheContainerRegistry registry = control.createMock(CacheContainerRegistry.class);
+ LocalDistributableSessionManager manager = control.createMock(LocalDistributableSessionManager.class);
+ EmbeddedCacheManager container = control.createMock(EmbeddedCacheManager.class);
+ @SuppressWarnings("unchecked")
+ Cache<Object, Object> expected = control.createMock(Cache.class);
+ String engine = "engine";
+
+ CacheSource source = new JvmRouteCacheSource(registry);
+
+ EasyMock.expect(registry.getCacheContainer()).andReturn(container);
+ EasyMock.expect(manager.getEngineName()).andReturn(engine);
+ EasyMock.expect(container.getCache(EasyMock.same(engine))).andReturn(expected);
+
+ control.replay();
+
+ Cache<Object, Object> result = source.getCache(manager);
+
+ control.verify();
+
+ Assert.assertSame(expected, result);
+ }
+}
Copied: projects/cluster/ha-server-cache-ispn/trunk/src/test/java/org/jboss/web/tomcat/service/session/distributedcache/ispn/SessionCacheSourceTest.java (from rev 109101, 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/SessionCacheSourceTest.java (rev 0)
+++ projects/cluster/ha-server-cache-ispn/trunk/src/test/java/org/jboss/web/tomcat/service/session/distributedcache/ispn/SessionCacheSourceTest.java 2010-11-05 19:16:12 UTC (rev 109181)
@@ -0,0 +1,147 @@
+/*
+ * 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 org.easymock.EasyMock;
+import org.easymock.IMocksControl;
+import org.infinispan.Cache;
+import org.infinispan.config.Configuration;
+import org.infinispan.config.Configuration.CacheMode;
+import org.infinispan.manager.EmbeddedCacheManager;
+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.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * @author Paul Ferraro
+ *
+ */
+public class SessionCacheSourceTest
+{
+ private IMocksControl control;
+ private CacheContainerRegistry registry;
+ private SessionCacheSource source;
+
+ @Before
+ public void before()
+ {
+ this.control = EasyMock.createControl();
+ this.registry = this.control.createMock(CacheContainerRegistry.class);
+
+ this.source = new SessionCacheSource(this.registry);
+ }
+
+ @Test
+ public void getCache()
+ {
+ Configuration configuration = new Configuration();
+ configuration.setCacheMode(CacheMode.REPL_ASYNC);
+ ReplicationConfig config = new ReplicationConfig();
+ config.setCacheName("standard-session-cache");
+ config.setReplicationMode(null);
+ config.setBackups(null);
+
+ this.getCache("standard-session-cache", null, "//host/context1", config, configuration, CacheMode.REPL_ASYNC, null);
+ this.getCache("standard-session-cache", null, "//host/context2", config, configuration, CacheMode.REPL_ASYNC, null);
+
+ // Validate cache container qualified cache name
+ config.setCacheName("default/session-cache");
+ this.getCache("default", "session-cache", "//host/context", config, configuration, CacheMode.REPL_ASYNC, null);
+
+ config.setCacheName(null);
+ this.getCache(null, null, "//host/context", config, configuration, CacheMode.REPL_ASYNC, null);
+
+ config.setCacheName("standard-session-cache");
+ config.setReplicationMode(ReplicationMode.SYNCHRONOUS);
+ this.getCache("standard-session-cache", null, "//host/context", config, configuration, CacheMode.REPL_SYNC, null);
+
+ config.setReplicationMode(ReplicationMode.ASYNCHRONOUS);
+ this.getCache("standard-session-cache", null, "//host/context", config, configuration, CacheMode.REPL_ASYNC, null);
+
+ config.setBackups(Integer.valueOf(-1));
+ config.setReplicationMode(null);
+ this.getCache("standard-session-cache", null, "//host/context", config, configuration, CacheMode.REPL_ASYNC, true);
+
+ config.setReplicationMode(ReplicationMode.SYNCHRONOUS);
+ this.getCache("standard-session-cache", null, "//host/context", config, configuration, CacheMode.REPL_SYNC, true);
+
+ config.setReplicationMode(ReplicationMode.ASYNCHRONOUS);
+ this.getCache("standard-session-cache", null, "//host/context", config, configuration, CacheMode.REPL_ASYNC, true);
+
+ config.setBackups(Integer.valueOf(0));
+ config.setReplicationMode(null);
+ this.getCache("standard-session-cache", null, "//host/context", config, configuration, CacheMode.LOCAL, null);
+
+ config.setReplicationMode(ReplicationMode.SYNCHRONOUS);
+ this.getCache("standard-session-cache", null, "//host/context", config, configuration, CacheMode.LOCAL, null);
+
+ config.setReplicationMode(ReplicationMode.ASYNCHRONOUS);
+ this.getCache("standard-session-cache", null, "//host/context", config, configuration, CacheMode.LOCAL, null);
+
+ config.setBackups(Integer.valueOf(1));
+ config.setReplicationMode(null);
+ this.getCache("standard-session-cache", null, "//host/context", config, configuration, CacheMode.DIST_ASYNC, false);
+
+ config.setReplicationMode(ReplicationMode.SYNCHRONOUS);
+ this.getCache("standard-session-cache", null, "//host/context", config, configuration, CacheMode.DIST_SYNC, false);
+
+ config.setReplicationMode(ReplicationMode.ASYNCHRONOUS);
+ this.getCache("standard-session-cache", null, "//host/context", config, configuration, CacheMode.DIST_ASYNC, false);
+ }
+
+ private void getCache(String containerName, String templateCacheName, String cacheName, ReplicationConfig config, Configuration configuration, CacheMode mode, Boolean fetchInMemoryState)
+ {
+ @SuppressWarnings("unchecked")
+ Cache<Object, Object> cache = this.control.createMock(Cache.class);
+ EmbeddedCacheManager container = this.control.createMock(EmbeddedCacheManager.class);
+ LocalDistributableSessionManager manager = this.control.createMock(LocalDistributableSessionManager.class);
+ Configuration cacheConfiguration = configuration.clone();
+
+ EasyMock.expect(manager.getReplicationConfig()).andReturn(config);
+
+ EasyMock.expect(this.registry.getCacheContainer(containerName)).andReturn(container);
+ EasyMock.expect(manager.getName()).andReturn(cacheName);
+ EasyMock.expect(container.defineConfiguration(cacheName, templateCacheName, new Configuration())).andReturn(cacheConfiguration);
+ EasyMock.expect(container.getCache(cacheName)).andReturn(cache);
+
+ this.control.replay();
+
+ Cache<Object, Object> result = source.getCache(manager);
+
+ this.control.verify();
+
+ Assert.assertSame(cache, result);
+
+ Assert.assertSame(mode, cacheConfiguration.getCacheMode());
+ Assert.assertEquals((config.getBackups() != null) ? config.getBackups().intValue() + 1 : 2, cacheConfiguration.getNumOwners());
+ if (fetchInMemoryState != null)
+ {
+ Assert.assertEquals(fetchInMemoryState, cacheConfiguration.isFetchInMemoryState());
+ }
+
+ this.control.reset();
+ }
+}
More information about the jboss-cvs-commits
mailing list