[jboss-cvs] JBossAS SVN: r107942 - in branches/infinispan-int/testsuite/src/main/org/jboss/test/cluster: testutil and 1 other directory.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Sep 1 16:36:16 EDT 2010
Author: pferraro
Date: 2010-09-01 16:36:15 -0400 (Wed, 01 Sep 2010)
New Revision: 107942
Modified:
branches/infinispan-int/testsuite/src/main/org/jboss/test/cluster/defaultcfg/simpleweb/test/AttributeBasedMaxUnreplicatedIntervalTestCase.java
branches/infinispan-int/testsuite/src/main/org/jboss/test/cluster/defaultcfg/simpleweb/test/BuddyReplicationFailoverUnitTestCase.java
branches/infinispan-int/testsuite/src/main/org/jboss/test/cluster/defaultcfg/simpleweb/test/BuddyReplicationToPassivatedSessionUnitTestCase.java
branches/infinispan-int/testsuite/src/main/org/jboss/test/cluster/defaultcfg/simpleweb/test/ClusteredSessionMemoryLeakTestCase.java
branches/infinispan-int/testsuite/src/main/org/jboss/test/cluster/defaultcfg/simpleweb/test/ClusteredSessionNotificationPolicyTestCase.java
branches/infinispan-int/testsuite/src/main/org/jboss/test/cluster/defaultcfg/simpleweb/test/ClusteredSessionUnitTestCase.java
branches/infinispan-int/testsuite/src/main/org/jboss/test/cluster/defaultcfg/simpleweb/test/ConcurrentFailoverRequestsTestCase.java
branches/infinispan-int/testsuite/src/main/org/jboss/test/cluster/defaultcfg/simpleweb/test/FailedExpirationTestCase.java
branches/infinispan-int/testsuite/src/main/org/jboss/test/cluster/defaultcfg/simpleweb/test/JBossCacheManagerConfigurationUnitTestCase.java
branches/infinispan-int/testsuite/src/main/org/jboss/test/cluster/defaultcfg/simpleweb/test/MultipleWarSingleRedeployTestCase.java
branches/infinispan-int/testsuite/src/main/org/jboss/test/cluster/defaultcfg/simpleweb/test/ReplicationToPassivatedSessionUnitTestCase.java
branches/infinispan-int/testsuite/src/main/org/jboss/test/cluster/defaultcfg/simpleweb/test/SessionBasedMaxUnreplicatedIntervalTestCase.java
branches/infinispan-int/testsuite/src/main/org/jboss/test/cluster/defaultcfg/simpleweb/test/SessionCountUnitTestCase.java
branches/infinispan-int/testsuite/src/main/org/jboss/test/cluster/defaultcfg/simpleweb/test/SessionExpirationUnitTestCase.java
branches/infinispan-int/testsuite/src/main/org/jboss/test/cluster/defaultcfg/simpleweb/test/StoppedManagerUnitTestCase.java
branches/infinispan-int/testsuite/src/main/org/jboss/test/cluster/testutil/CacheConfigTestSetup.java
branches/infinispan-int/testsuite/src/main/org/jboss/test/cluster/testutil/SessionTestUtil.java
Log:
Replace TestDistributedCacheManagerFactory usage with CacheContainer.
Modified: branches/infinispan-int/testsuite/src/main/org/jboss/test/cluster/defaultcfg/simpleweb/test/AttributeBasedMaxUnreplicatedIntervalTestCase.java
===================================================================
--- branches/infinispan-int/testsuite/src/main/org/jboss/test/cluster/defaultcfg/simpleweb/test/AttributeBasedMaxUnreplicatedIntervalTestCase.java 2010-09-01 20:34:46 UTC (rev 107941)
+++ branches/infinispan-int/testsuite/src/main/org/jboss/test/cluster/defaultcfg/simpleweb/test/AttributeBasedMaxUnreplicatedIntervalTestCase.java 2010-09-01 20:36:15 UTC (rev 107942)
@@ -29,7 +29,6 @@
import org.jboss.test.cluster.testutil.SessionTestUtil;
import org.jboss.test.cluster.web.mocks.BasicRequestHandler;
import org.jboss.test.cluster.web.mocks.SetAttributesRequestHandler;
-import org.jboss.web.tomcat.service.session.JBossCacheManager;
/**
* Tests of handling of ClusteredSession.maxUnreplicatedInterval. This version
@@ -48,7 +47,7 @@
public static Test suite() throws Exception
{
- return CacheConfigTestSetup.getTestSetup(AttributeBasedMaxUnreplicatedIntervalTestCase.class, dcmFactories, false, null, !useBuddyRepl, false);
+ return CacheConfigTestSetup.getTestSetup(AttributeBasedMaxUnreplicatedIntervalTestCase.class, cacheContainers, false, null, !useBuddyRepl);
}
protected ReplicationGranularity getReplicationGranularity()
@@ -71,12 +70,10 @@
String warname = String.valueOf(++testId);
// A war with a maxInactive of 3 secs and a maxUnreplicated of 1
- JBossCacheManager[] mgrs = getCacheManagers(warname, 3, 1);
- JBossCacheManager jbcm0 = mgrs[0];
- JBossCacheManager jbcm1 = mgrs[1];
+ startManagers(warname, 3, 1);
SetAttributesRequestHandler setHandler = new SetAttributesRequestHandler(allAttributes, false);
- SessionTestUtil.invokeRequest(jbcm0, setHandler, null);
+ SessionTestUtil.invokeRequest(managers[0], setHandler, null);
validateNewSession(setHandler);
@@ -84,7 +81,7 @@
// Now make a request that will not trigger replication but keeps the jbcm0 session alive
BasicRequestHandler getHandler = new BasicRequestHandler(immutables.keySet(), false);
- SessionTestUtil.invokeRequest(jbcm0, getHandler, setHandler.getSessionId());
+ SessionTestUtil.invokeRequest(managers[0], getHandler, setHandler.getSessionId());
validateExpectedAttributes(immutables, getHandler);
@@ -94,17 +91,17 @@
// jbcm1 considers the session unmodified for > 3 sec maxInactiveInterval.
// Try to drive the session out of the jbcm1 cache
- jbcm1.backgroundProcess();
+ managers[1].backgroundProcess();
// Replicate just one attribute; see if the other is still in jbcm1
SetAttributesRequestHandler modifyHandler = new SetAttributesRequestHandler(mutables, false);
- SessionTestUtil.invokeRequest(jbcm0, modifyHandler, setHandler.getSessionId());
+ SessionTestUtil.invokeRequest(managers[0], modifyHandler, setHandler.getSessionId());
// Fail over and confirm all is well. If the session was removed,
// the last replication of just one attribute won't restore all
// attributes and we'll have a failure
getHandler = new BasicRequestHandler(allAttributes.keySet(), false);
- SessionTestUtil.invokeRequest(jbcm1, getHandler, setHandler.getSessionId());
+ SessionTestUtil.invokeRequest(managers[1], getHandler, setHandler.getSessionId());
validateExpectedAttributes(allAttributes, getHandler);
}
@@ -116,25 +113,23 @@
String warname = String.valueOf(++testId);
// A war with a maxInactive of 2 secs and a maxUnreplicated of -1
- JBossCacheManager[] mgrs = getCacheManagers(warname, 2, -1);
- JBossCacheManager jbcm0 = mgrs[0];
- JBossCacheManager jbcm1 = mgrs[1];
+ startManagers(warname, 2, -1);
SetAttributesRequestHandler setHandler = new SetAttributesRequestHandler(allAttributes, false);
- SessionTestUtil.invokeRequest(jbcm0, setHandler, null);
+ SessionTestUtil.invokeRequest(managers[0], setHandler, null);
validateNewSession(setHandler);
Thread.sleep(250);
SetAttributesRequestHandler modifyHandler = new SetAttributesRequestHandler(mutables, false);
- SessionTestUtil.invokeRequest(jbcm0, modifyHandler, setHandler.getSessionId());
+ SessionTestUtil.invokeRequest(managers[0], modifyHandler, setHandler.getSessionId());
Thread.sleep(1760);
// Fail over and confirm all is well
BasicRequestHandler getHandler = new BasicRequestHandler(allAttributes.keySet(), false);
- SessionTestUtil.invokeRequest(jbcm1, getHandler, setHandler.getSessionId());
+ SessionTestUtil.invokeRequest(managers[1], getHandler, setHandler.getSessionId());
validateExpectedAttributes(allAttributes, getHandler);
Modified: branches/infinispan-int/testsuite/src/main/org/jboss/test/cluster/defaultcfg/simpleweb/test/BuddyReplicationFailoverUnitTestCase.java
===================================================================
--- branches/infinispan-int/testsuite/src/main/org/jboss/test/cluster/defaultcfg/simpleweb/test/BuddyReplicationFailoverUnitTestCase.java 2010-09-01 20:34:46 UTC (rev 107941)
+++ branches/infinispan-int/testsuite/src/main/org/jboss/test/cluster/defaultcfg/simpleweb/test/BuddyReplicationFailoverUnitTestCase.java 2010-09-01 20:36:15 UTC (rev 107942)
@@ -31,22 +31,19 @@
import java.io.File;
import java.util.Collections;
-import java.util.HashSet;
-import java.util.Set;
import junit.framework.Test;
import junit.framework.TestCase;
+import org.infinispan.manager.CacheContainer;
import org.jboss.logging.Logger;
import org.jboss.metadata.web.jboss.JBossWebMetaData;
import org.jboss.metadata.web.jboss.ReplicationGranularity;
import org.jboss.metadata.web.jboss.ReplicationTrigger;
import org.jboss.test.cluster.testutil.CacheConfigTestSetup;
-import org.jboss.test.cluster.testutil.SessionTestUtil;
import org.jboss.test.cluster.web.mocks.InvalidateSessionRequestHandler;
import org.jboss.test.cluster.web.mocks.SetAttributesRequestHandler;
import org.jboss.web.tomcat.service.session.JBossCacheManager;
-import org.jboss.web.tomcat.service.session.distributedcache.spi.TestDistributedCacheManagerFactory;
/**
* Unit tests of failover with buddy replication
@@ -55,13 +52,13 @@
*/
public class BuddyReplicationFailoverUnitTestCase extends TestCase
{
- protected static TestDistributedCacheManagerFactory[] dcmFactories = new TestDistributedCacheManagerFactory[4];
+ protected static CacheContainer[] cacheContainers = new CacheContainer[4];
protected static long testId = System.currentTimeMillis();
protected Logger log = Logger.getLogger(getClass());
- protected Set<JBossCacheManager> managers = new HashSet<JBossCacheManager>();
+ protected JBossCacheManager<?>[] managers = new JBossCacheManager[cacheContainers.length];
public BuddyReplicationFailoverUnitTestCase(String name)
{
@@ -72,7 +69,7 @@
{
File tmpDir = new File(System.getProperty("java.io.tmpdir"));
File root = new File(tmpDir, BuddyReplicationFailoverUnitTestCase.class.getSimpleName());
- return CacheConfigTestSetup.getTestSetup(BuddyReplicationFailoverUnitTestCase.class, dcmFactories, false, root.getAbsolutePath(), false, false);
+ return CacheConfigTestSetup.getTestSetup(BuddyReplicationFailoverUnitTestCase.class, cacheContainers, false, root.getAbsolutePath(), false);
}
@Override
@@ -83,11 +80,14 @@
super.tearDown();
}
finally
- {
- for (JBossCacheManager manager : managers)
- manager.stop();
-
- managers.clear();
+ {
+ for (JBossCacheManager<?> manager : managers)
+ {
+ if (manager != null)
+ {
+ manager.stop();
+ }
+ }
}
}
@@ -108,39 +108,39 @@
String warname = String.valueOf(++testId);
// A war with a maxInactive of 30 mins and a maxIdle of 1
- JBossCacheManager[] mgrs = getCacheManagers(warname, 1800000, 1, -1);
+ this.startManagers(warname, 1800000, 1, -1);
SetAttributesRequestHandler setHandler = new SetAttributesRequestHandler(Collections.singletonMap("count", getAttributeValue(0)), false);
- invokeRequest(mgrs[3], setHandler, null);
+ invokeRequest(managers[3], setHandler, null);
String id = setHandler.getSessionId();
setHandler = new SetAttributesRequestHandler(Collections.singletonMap("count", getAttributeValue(1)), false);
- invokeRequest(mgrs[3], setHandler, id);
+ invokeRequest(managers[3], setHandler, id);
assertEquals(getAttributeValue(0), setHandler.getCheckedAttributes().get("count"));
sleepThread(1100);
- mgrs[0].backgroundProcess();
- mgrs[1].backgroundProcess();
- mgrs[2].backgroundProcess();
- mgrs[3].backgroundProcess();
+ managers[0].backgroundProcess();
+ managers[1].backgroundProcess();
+ managers[2].backgroundProcess();
+ managers[3].backgroundProcess();
setHandler = new SetAttributesRequestHandler(Collections.singletonMap("count", getAttributeValue(2)), false);
- invokeRequest(mgrs[3], setHandler, id);
+ invokeRequest(managers[3], setHandler, id);
assertEquals(getAttributeValue(1), setHandler.getCheckedAttributes().get("count"));
setHandler = new SetAttributesRequestHandler(Collections.singletonMap("count", getAttributeValue(3)), false);
- invokeRequest(mgrs[3], setHandler, id);
+ invokeRequest(managers[3], setHandler, id);
assertEquals(getAttributeValue(2), setHandler.getCheckedAttributes().get("count"));
// Invalidate on the failover request
InvalidateSessionRequestHandler invalidationHandler = new InvalidateSessionRequestHandler(Collections.singleton("count"), false);
- invokeRequest(mgrs[0], invalidationHandler, id);
+ invokeRequest(managers[0], invalidationHandler, id);
assertEquals(getAttributeValue(3), invalidationHandler.getCheckedAttributes().get("count"));
setHandler = new SetAttributesRequestHandler(Collections.singletonMap("count", getAttributeValue(0)), false);
- invokeRequest(mgrs[0], invalidationHandler, id);
+ invokeRequest(managers[0], invalidationHandler, id);
assertNull(setHandler.getCheckedAttributes().get("count"));
}
@@ -151,67 +151,61 @@
String warname = String.valueOf(++testId);
// A war with a maxInactive of 30 mins and no maxIdle
- JBossCacheManager[] mgrs = getCacheManagers(warname, 1800000, -1, -1);
+ this.startManagers(warname, 1800000, -1, -1);
log.info("managers created");
log.info("creating session");
SetAttributesRequestHandler setHandler = new SetAttributesRequestHandler(Collections.singletonMap("count", getAttributeValue(0)), false);
- invokeRequest(mgrs[0], setHandler, null);
+ invokeRequest(managers[0], setHandler, null);
String id = setHandler.getSessionId();
// Modify
log.info("modifying session");
setHandler = new SetAttributesRequestHandler(Collections.singletonMap("count", getAttributeValue(1)), false);
- invokeRequest(mgrs[0], setHandler, id);
+ invokeRequest(managers[0], setHandler, id);
assertEquals(getAttributeValue(0), setHandler.getCheckedAttributes().get("count"));
// Failover and modify
log.info("failing over");
setHandler = new SetAttributesRequestHandler(Collections.singletonMap("count", getAttributeValue(2)), false);
- invokeRequest(mgrs[3], setHandler, id);
+ invokeRequest(managers[3], setHandler, id);
assertEquals(getAttributeValue(1), setHandler.getCheckedAttributes().get("count"));
// Modify
log.info("modifying session");
setHandler = new SetAttributesRequestHandler(Collections.singletonMap("count", getAttributeValue(3)), false);
- invokeRequest(mgrs[3], setHandler, id);
+ invokeRequest(managers[3], setHandler, id);
assertEquals(getAttributeValue(2), setHandler.getCheckedAttributes().get("count"));
// Failback and modify
log.info("failing back");
setHandler = new SetAttributesRequestHandler(Collections.singletonMap("count", getAttributeValue(4)), false);
- invokeRequest(mgrs[0], setHandler, id);
+ invokeRequest(managers[0], setHandler, id);
assertEquals(getAttributeValue(3), setHandler.getCheckedAttributes().get("count"));
// Invalidate
log.info("invalidating");
InvalidateSessionRequestHandler invalidationHandler = new InvalidateSessionRequestHandler(Collections.singleton("count"), false);
- invokeRequest(mgrs[0], invalidationHandler, id);
+ invokeRequest(managers[0], invalidationHandler, id);
assertEquals(getAttributeValue(4), invalidationHandler.getCheckedAttributes().get("count"));
// Reestablish
log.info("re-establishing");
setHandler = new SetAttributesRequestHandler(Collections.singletonMap("count", getAttributeValue(0)), false);
- invokeRequest(mgrs[0], invalidationHandler, id);
+ invokeRequest(managers[0], invalidationHandler, id);
assertNull(setHandler.getCheckedAttributes().get("count"));
}
- protected JBossCacheManager[] getCacheManagers(String warname, int maxInactive, int maxIdle, int maxUnreplicated)
- throws Exception
+ protected void startManagers(String warname, int maxInactive, int maxIdle, int maxUnreplicated) throws Exception
{
- JBossCacheManager[] result = new JBossCacheManager[dcmFactories.length];
- for (int i = 0; i < dcmFactories.length; i++)
+ JBossWebMetaData metadata = createWebMetaData(getReplicationGranularity(), getReplicationTrigger(), -1, true, maxIdle, -1, true, maxUnreplicated);
+ for (int i = 0; i < cacheContainers.length; i++)
{
- JBossCacheManager jbcm = createManager(warname, maxInactive, dcmFactories[i], null);
- JBossWebMetaData metadata = createWebMetaData(getReplicationGranularity(), getReplicationTrigger(), -1, true, maxIdle, -1, true, maxUnreplicated);
- jbcm.init(warname, metadata);
- this.managers.add(jbcm);
- jbcm.start();
- result[i] = jbcm;
+ managers[i] = createManager(warname, maxInactive, cacheContainers[i], null);
+ managers[i].init(warname, metadata);
+ managers[i].start();
}
-
- return result;
}
}
Modified: branches/infinispan-int/testsuite/src/main/org/jboss/test/cluster/defaultcfg/simpleweb/test/BuddyReplicationToPassivatedSessionUnitTestCase.java
===================================================================
--- branches/infinispan-int/testsuite/src/main/org/jboss/test/cluster/defaultcfg/simpleweb/test/BuddyReplicationToPassivatedSessionUnitTestCase.java 2010-09-01 20:34:46 UTC (rev 107941)
+++ branches/infinispan-int/testsuite/src/main/org/jboss/test/cluster/defaultcfg/simpleweb/test/BuddyReplicationToPassivatedSessionUnitTestCase.java 2010-09-01 20:36:15 UTC (rev 107942)
@@ -36,7 +36,6 @@
*/
public class BuddyReplicationToPassivatedSessionUnitTestCase extends ReplicationToPassivatedSessionUnitTestCase
{
-
/**
* Create a new BuddyReplicationToPassivatedSessionUnitTestCase.
*
@@ -51,7 +50,6 @@
{
File tmpDir = new File(System.getProperty("java.io.tmpdir"));
File root = new File(tmpDir, BuddyReplicationToPassivatedSessionUnitTestCase.class.getSimpleName());
- return CacheConfigTestSetup.getTestSetup(BuddyReplicationToPassivatedSessionUnitTestCase.class, dcmFactories, false, root.getAbsolutePath(), false, false);
+ return CacheConfigTestSetup.getTestSetup(BuddyReplicationToPassivatedSessionUnitTestCase.class, cacheContainers, false, root.getAbsolutePath(), false);
}
-
}
Modified: branches/infinispan-int/testsuite/src/main/org/jboss/test/cluster/defaultcfg/simpleweb/test/ClusteredSessionMemoryLeakTestCase.java
===================================================================
--- branches/infinispan-int/testsuite/src/main/org/jboss/test/cluster/defaultcfg/simpleweb/test/ClusteredSessionMemoryLeakTestCase.java 2010-09-01 20:34:46 UTC (rev 107941)
+++ branches/infinispan-int/testsuite/src/main/org/jboss/test/cluster/defaultcfg/simpleweb/test/ClusteredSessionMemoryLeakTestCase.java 2010-09-01 20:36:15 UTC (rev 107942)
@@ -35,6 +35,7 @@
import junit.framework.Test;
import org.apache.catalina.Session;
+import org.infinispan.manager.CacheContainer;
import org.jboss.logging.Logger;
import org.jboss.metadata.web.jboss.JBossWebMetaData;
import org.jboss.metadata.web.jboss.ReplicationGranularity;
@@ -48,7 +49,6 @@
import org.jboss.test.cluster.web.mocks.SetAttributesRequestHandler;
import org.jboss.test.cluster.web.notification.SessionSpecListenerAttribute;
import org.jboss.web.tomcat.service.session.JBossCacheManager;
-import org.jboss.web.tomcat.service.session.distributedcache.spi.TestDistributedCacheManagerFactory;
/**
* Tests that references to cached sessions and attributes are released.
@@ -57,7 +57,7 @@
*/
public class ClusteredSessionMemoryLeakTestCase extends JBossTestCase
{
- protected static TestDistributedCacheManagerFactory[] dcmFactories = new TestDistributedCacheManagerFactory[2];
+ protected static CacheContainer[] cacheContainers = new CacheContainer[2];
protected static long testId = System.currentTimeMillis();
@@ -70,7 +70,7 @@
protected Logger log = Logger.getLogger(getClass());
- protected Set<JBossCacheManager> managers = new HashSet<JBossCacheManager>();
+ protected JBossCacheManager<?>[] managers = new JBossCacheManager[cacheContainers.length];
public ClusteredSessionMemoryLeakTestCase(String name)
{
@@ -83,7 +83,7 @@
File root = new File(tmpDir, ClusteredSessionMemoryLeakTestCase.class.getSimpleName());
root.mkdirs();
root.deleteOnExit();
- return CacheConfigTestSetup.getTestSetup(ClusteredSessionMemoryLeakTestCase.class, dcmFactories, false, root.getAbsolutePath(), true, false);
+ return CacheConfigTestSetup.getTestSetup(ClusteredSessionMemoryLeakTestCase.class, cacheContainers, false, root.getAbsolutePath(), true);
}
@Override
@@ -91,18 +91,20 @@
{
super.tearDown();
- for (JBossCacheManager manager : managers)
+ for (JBossCacheManager<?> manager : managers)
{
- try
+ if (manager != null)
{
- manager.stop();
+ try
+ {
+ manager.stop();
+ }
+ catch (RuntimeException ignored)
+ {
+ log.debug("tearDown(): Caught exception cleaning up manager -- " + ignored.getLocalizedMessage());
+ }
}
- catch (RuntimeException ignored)
- {
- log.debug("tearDown(): Caught exception cleaning up manager -- " + ignored.getLocalizedMessage());
- }
}
- managers.clear();
SessionSpecListenerAttribute.invocations.clear();
@@ -126,26 +128,23 @@
String warname = String.valueOf(++testId);
// A war with a maxInactive of 30 mins maxUnreplicated of 0
- JBossCacheManager[] mgrs = getCacheManagers(warname, 1800, 1);
- JBossCacheManager jbcm0 = mgrs[0];
- JBossCacheManager jbcm1 = mgrs[1];
+ this.startManagers(warname, 1800, 1);
-
// Initial request
SetAttributesRequestHandler setHandler = new SetAttributesRequestHandler(getAttributeMap(), false);
log.info("initial request");
- SessionTestUtil.invokeRequest(jbcm0, setHandler, null);
+ SessionTestUtil.invokeRequest(managers[0], setHandler, null);
String sessionId = setHandler.getSessionId();
- WeakReference<Session> session0A = new WeakReference<Session>(jbcm0.findSession(sessionId));
- SessionTestUtil.cleanupPipeline(jbcm0);
+ WeakReference<Session> session0A = new WeakReference<Session>(managers[0].findSession(sessionId));
+ SessionTestUtil.cleanupPipeline(managers[0]);
assertNotNull(session0A.get());
// Modify attribute request
setHandler = new SetAttributesRequestHandler(getAttributeMap(), false);
log.info("Modify attribute request");
- SessionTestUtil.invokeRequest(jbcm0, setHandler, sessionId);
- SessionTestUtil.cleanupPipeline(jbcm0);
+ SessionTestUtil.invokeRequest(managers[0], setHandler, sessionId);
+ SessionTestUtil.cleanupPipeline(managers[0]);
System.gc();
System.runFinalization();
@@ -155,9 +154,9 @@
Thread.sleep(1100);
log.info("passivate node 0");
- jbcm0.backgroundProcess();
+ managers[0].backgroundProcess();
log.info("passivate node 1");
- jbcm1.backgroundProcess();
+ managers[1].backgroundProcess();
System.gc();
System.runFinalization();
@@ -167,10 +166,10 @@
// Remove attribute request
RemoveAttributesRequestHandler removeHandler = new RemoveAttributesRequestHandler(KEYS, false);
log.info("remove request");
- SessionTestUtil.invokeRequest(jbcm0, removeHandler, sessionId);
+ SessionTestUtil.invokeRequest(managers[0], removeHandler, sessionId);
- WeakReference<Session> session0B = new WeakReference<Session>(jbcm0.findSession(sessionId));
- SessionTestUtil.cleanupPipeline(jbcm0);
+ WeakReference<Session> session0B = new WeakReference<Session>(managers[0].findSession(sessionId));
+ SessionTestUtil.cleanupPipeline(managers[0]);
System.gc();
System.runFinalization();
assertEquals(0, Attribute.attributeCount());
@@ -179,10 +178,10 @@
// Failover request
setHandler = new SetAttributesRequestHandler(getAttributeMap(), false);
log.info("failover request");
- SessionTestUtil.invokeRequest(jbcm1, setHandler, sessionId);
+ SessionTestUtil.invokeRequest(managers[1], setHandler, sessionId);
- WeakReference<Session> session1A = new WeakReference<Session>(jbcm1.findSession(sessionId));
- SessionTestUtil.cleanupPipeline(jbcm1);
+ WeakReference<Session> session1A = new WeakReference<Session>(managers[1].findSession(sessionId));
+ SessionTestUtil.cleanupPipeline(managers[1]);
assertNotNull(session1A.get());
assertEquals(1, Attribute.attributeCount());
@@ -190,9 +189,9 @@
Thread.sleep(1100);
log.info("passivate node 0");
- jbcm0.backgroundProcess();
+ managers[0].backgroundProcess();
log.info("passivate node 1");
- jbcm1.backgroundProcess();
+ managers[1].backgroundProcess();
System.gc();
System.runFinalization();
@@ -203,28 +202,28 @@
// Reactivate
BasicRequestHandler getHandler = new BasicRequestHandler(KEYS, false);
log.info("activate node 1");
- SessionTestUtil.invokeRequest(jbcm1, getHandler, sessionId);
+ SessionTestUtil.invokeRequest(managers[1], getHandler, sessionId);
- WeakReference<Session> session1B = new WeakReference<Session>(jbcm1.findSession(sessionId));
- SessionTestUtil.cleanupPipeline(jbcm1);
+ WeakReference<Session> session1B = new WeakReference<Session>(managers[1].findSession(sessionId));
+ SessionTestUtil.cleanupPipeline(managers[1]);
assertNotNull(session1B.get());
assertEquals(1, Attribute.attributeCount());
// Fail back
getHandler = new BasicRequestHandler(KEYS, false);
log.info("fail back request");
- SessionTestUtil.invokeRequest(jbcm0, getHandler, sessionId);
+ SessionTestUtil.invokeRequest(managers[0], getHandler, sessionId);
- WeakReference<Session> session0C = new WeakReference<Session>(jbcm0.findSession(sessionId));
- SessionTestUtil.cleanupPipeline(jbcm0);
+ WeakReference<Session> session0C = new WeakReference<Session>(managers[0].findSession(sessionId));
+ SessionTestUtil.cleanupPipeline(managers[0]);
assertNotNull(session0C.get());
assertEquals(2, Attribute.attributeCount());
// Invalidate session
InvalidateSessionRequestHandler invalidateHandler = new InvalidateSessionRequestHandler(KEYS, false);
log.info("invalidate request");
- SessionTestUtil.invokeRequest(jbcm0, invalidateHandler, sessionId);
- SessionTestUtil.cleanupPipeline(jbcm0);
+ SessionTestUtil.invokeRequest(managers[0], invalidateHandler, sessionId);
+ SessionTestUtil.cleanupPipeline(managers[0]);
System.gc();
System.runFinalization();
@@ -239,31 +238,29 @@
String warname = String.valueOf(++testId);
// A war with a maxInactive of 2 secs and a maxIdle of 10 (don't passivate)
- JBossCacheManager[] mgrs = getCacheManagers(warname, 2, 10);
- JBossCacheManager jbcm0 = mgrs[0];
- JBossCacheManager jbcm1 = mgrs[1];
+ this.startManagers(warname, 2, 10);
// Initial request
SetAttributesRequestHandler setHandler = new SetAttributesRequestHandler(getAttributeMap(), false);
log.info("initial request");
- SessionTestUtil.invokeRequest(jbcm0, setHandler, null);
- assertEquals(1, Attribute.attributeCount());
+ SessionTestUtil.invokeRequest(managers[0], setHandler, null);
+ assertEquals(1, Attribute.attributeCount());
String sessionId = setHandler.getSessionId();
- WeakReference<Session> session0A = new WeakReference<Session>(jbcm0.findSession(sessionId));
- SessionTestUtil.cleanupPipeline(jbcm0);
+ WeakReference<Session> session0A = new WeakReference<Session>(managers[0].findSession(sessionId));
+ SessionTestUtil.cleanupPipeline(managers[0]);
assertNotNull(session0A.get());
- assertEquals(1, Attribute.attributeCount());
+ assertEquals(1, Attribute.attributeCount());
// Failover request
setHandler = new SetAttributesRequestHandler(getAttributeMap(), false);
log.info("fail over request");
- SessionTestUtil.invokeRequest(jbcm1, setHandler, sessionId);
+ SessionTestUtil.invokeRequest(managers[1], setHandler, sessionId);
assertNotNull(setHandler.getCheckedAttributes().get(KEY));
assertEquals(Attribute.COUNT -1, ((Attribute) setHandler.getCheckedAttributes().get(KEY)).getCount());
- WeakReference<Session> session1A = new WeakReference<Session>(jbcm1.findSession(sessionId));
- SessionTestUtil.cleanupPipeline(jbcm1);
+ WeakReference<Session> session1A = new WeakReference<Session>(managers[1].findSession(sessionId));
+ SessionTestUtil.cleanupPipeline(managers[1]);
System.gc();
System.runFinalization();
@@ -274,9 +271,9 @@
Thread.sleep(2100);
log.info("expire node 0");
- jbcm0.backgroundProcess();
+ managers[0].backgroundProcess();
log.info("expire node 1");
- jbcm1.backgroundProcess();
+ managers[1].backgroundProcess();
System.gc();
System.runFinalization();
@@ -291,22 +288,20 @@
String warname = String.valueOf(++testId);
// A war with a maxInactive of 30 mins and no maxIdle
- JBossCacheManager[] mgrs = getCacheManagers(warname, 1800, -1);
- JBossCacheManager jbcm0 = mgrs[0];
- JBossCacheManager jbcm1 = mgrs[1];
+ this.startManagers(warname, 1800, -1);
// Initial request
SetAttributesRequestHandler setHandler = new SetAttributesRequestHandler(getAttributeMap(), false);
- SessionTestUtil.invokeRequest(jbcm0, setHandler, null);
- assertEquals(1, Attribute.attributeCount());
+ SessionTestUtil.invokeRequest(managers[0], setHandler, null);
+ assertEquals(1, Attribute.attributeCount());
String sessionId = setHandler.getSessionId();
- WeakReference<Session> session0A = new WeakReference<Session>(jbcm0.findSession(sessionId));
- SessionTestUtil.cleanupPipeline(jbcm0);
+ WeakReference<Session> session0A = new WeakReference<Session>(managers[0].findSession(sessionId));
+ SessionTestUtil.cleanupPipeline(managers[0]);
assertNotNull(session0A.get());
- jbcm0.stop();
- jbcm1.stop();
+ managers[0].stop();
+ managers[1].stop();
System.gc();
System.runFinalization();
@@ -314,22 +309,15 @@
assertNull(session0A.get());
}
- protected JBossCacheManager[] getCacheManagers(String warname, int maxInactive, int maxIdle)
- throws Exception
+ protected void startManagers(String warname, int maxInactive, int maxIdle) throws Exception
{
- JBossCacheManager jbcm0 = SessionTestUtil.createManager(warname, maxInactive, dcmFactories[0], null);
- JBossWebMetaData metadata = SessionTestUtil.createWebMetaData(getReplicationGranularity(), getReplicationTrigger(), -1, maxIdle > 0, maxIdle, -1 ,false, 0);
- jbcm0.init(warname, metadata);
- this.managers.add(jbcm0);
- jbcm0.start();
-
- JBossCacheManager jbcm1 = SessionTestUtil.createManager(warname, maxInactive, dcmFactories[1], null);
- metadata = SessionTestUtil.createWebMetaData(getReplicationGranularity(), getReplicationTrigger(), -1, true, maxIdle, -1 ,false, 0);
- jbcm1.init(warname, metadata);
- this.managers.add(jbcm1);
- jbcm1.start();
-
- return new JBossCacheManager[]{jbcm0, jbcm1};
+ for (int i = 0; i < cacheContainers.length; ++i)
+ {
+ managers[i] = SessionTestUtil.createManager(warname, maxInactive, cacheContainers[i], null);
+ JBossWebMetaData metadata = SessionTestUtil.createWebMetaData(getReplicationGranularity(), getReplicationTrigger(), -1, (i == 0) ? (maxIdle > 0) : true, maxIdle, -1 ,false, 0);
+ managers[i].init(warname, metadata);
+ managers[i].start();
+ }
}
private static Map<String, Object> getAttributeMap()
Modified: branches/infinispan-int/testsuite/src/main/org/jboss/test/cluster/defaultcfg/simpleweb/test/ClusteredSessionNotificationPolicyTestCase.java
===================================================================
--- branches/infinispan-int/testsuite/src/main/org/jboss/test/cluster/defaultcfg/simpleweb/test/ClusteredSessionNotificationPolicyTestCase.java 2010-09-01 20:34:46 UTC (rev 107941)
+++ branches/infinispan-int/testsuite/src/main/org/jboss/test/cluster/defaultcfg/simpleweb/test/ClusteredSessionNotificationPolicyTestCase.java 2010-09-01 20:36:15 UTC (rev 107942)
@@ -25,14 +25,13 @@
import java.io.File;
import java.util.Collections;
import java.util.HashMap;
-import java.util.HashSet;
import java.util.List;
import java.util.Map;
-import java.util.Set;
import junit.framework.Test;
import org.apache.catalina.Context;
+import org.infinispan.manager.CacheContainer;
import org.jboss.logging.Logger;
import org.jboss.metadata.web.jboss.JBossWebMetaData;
import org.jboss.metadata.web.jboss.ReplicationGranularity;
@@ -49,7 +48,6 @@
import org.jboss.test.cluster.web.notification.MockHttpSessionListener;
import org.jboss.test.cluster.web.notification.SessionSpecListenerAttribute;
import org.jboss.web.tomcat.service.session.JBossCacheManager;
-import org.jboss.web.tomcat.service.session.distributedcache.spi.TestDistributedCacheManagerFactory;
/**
* Tests of handling of servlet spec notifications.
@@ -58,7 +56,7 @@
*/
public class ClusteredSessionNotificationPolicyTestCase extends JBossTestCase
{
- protected static TestDistributedCacheManagerFactory[] dcmFactories = new TestDistributedCacheManagerFactory[2];
+ protected static CacheContainer[] cacheContainers = new CacheContainer[2];
protected static long testId = System.currentTimeMillis();
@@ -66,7 +64,7 @@
protected Logger log = Logger.getLogger(getClass());
- protected Set<JBossCacheManager> managers = new HashSet<JBossCacheManager>();
+ protected JBossCacheManager<?>[] managers = new JBossCacheManager[cacheContainers.length];
protected Map<String, Object> allAttributes;
protected Map<String, Object> immutables;
@@ -87,7 +85,7 @@
{
File tmpDir = new File(System.getProperty("java.io.tmpdir"));
File root = new File(tmpDir, ClusteredSessionNotificationPolicyTestCase.class.getSimpleName());
- return CacheConfigTestSetup.getTestSetup(ClusteredSessionNotificationPolicyTestCase.class, dcmFactories, false, root.getAbsolutePath(), !useBuddyRepl, false);
+ return CacheConfigTestSetup.getTestSetup(ClusteredSessionNotificationPolicyTestCase.class, cacheContainers, false, root.getAbsolutePath(), !useBuddyRepl);
}
@@ -122,18 +120,20 @@
System.clearProperty("jboss.web.clustered.session.notification.policy");
}
- for (JBossCacheManager manager : managers)
+ for (JBossCacheManager<?> manager : managers)
{
- try
+ if (manager != null)
{
- manager.stop();
+ try
+ {
+ manager.stop();
+ }
+ catch (RuntimeException ignored)
+ {
+ log.debug("tearDown(): Caught exception cleaning up manager -- " + ignored.getLocalizedMessage());
+ }
}
- catch (RuntimeException ignored)
- {
- log.debug("tearDown(): Caught exception cleaning up manager -- " + ignored.getLocalizedMessage());
- }
}
- managers.clear();
SessionSpecListenerAttribute.invocations.clear();
}
@@ -165,35 +165,33 @@
String warname = String.valueOf(++testId);
// A war with a maxInactive of 30 mins maxUnreplicated of 0
- JBossCacheManager[] mgrs = getCacheManagers(warname, 1800, 1);
- JBossCacheManager jbcm0 = mgrs[0];
- JBossCacheManager jbcm1 = mgrs[1];
+ this.startManagers(warname, 1800, 1);
- assertTrue(jbcm0.getNotificationPolicy() instanceof MockClusteredSessionNotificationPolicy);
- MockClusteredSessionNotificationPolicy mcsnp0 = (MockClusteredSessionNotificationPolicy) jbcm0.getNotificationPolicy();
+ assertTrue(managers[0].getNotificationPolicy() instanceof MockClusteredSessionNotificationPolicy);
+ MockClusteredSessionNotificationPolicy mcsnp0 = (MockClusteredSessionNotificationPolicy) managers[0].getNotificationPolicy();
assertNotNull("capability set", mcsnp0.getClusteredSessionNotificationCapability());
mcsnp0.setResponse(notify);
- assertTrue(jbcm1.getNotificationPolicy() instanceof MockClusteredSessionNotificationPolicy);
- MockClusteredSessionNotificationPolicy mcsnp1 = (MockClusteredSessionNotificationPolicy) jbcm1.getNotificationPolicy();
+ assertTrue(managers[1].getNotificationPolicy() instanceof MockClusteredSessionNotificationPolicy);
+ MockClusteredSessionNotificationPolicy mcsnp1 = (MockClusteredSessionNotificationPolicy) managers[1].getNotificationPolicy();
assertNotNull("capability set", mcsnp1.getClusteredSessionNotificationCapability());
mcsnp1.setResponse(notify);
MockHttpSessionListener hsl0 = new MockHttpSessionListener();
MockHttpSessionAttributeListener hsal0 = new MockHttpSessionAttributeListener();
- Context ctx = (Context) jbcm0.getContainer();
+ Context ctx = (Context) managers[0].getContainer();
ctx.setApplicationSessionLifecycleListeners(new Object[]{ hsl0 });
ctx.setApplicationEventListeners(new Object[]{ hsal0 });
MockHttpSessionListener hsl1 = new MockHttpSessionListener();
MockHttpSessionAttributeListener hsal1 = new MockHttpSessionAttributeListener();
- ctx = (Context) jbcm1.getContainer();
+ ctx = (Context) managers[1].getContainer();
ctx.setApplicationSessionLifecycleListeners(new Object[]{ hsl1 });
ctx.setApplicationEventListeners(new Object[]{ hsal1 });
// Initial request
SetAttributesRequestHandler setHandler = new SetAttributesRequestHandler(attributes, false);
- SessionTestUtil.invokeRequest(jbcm0, setHandler, null);
+ SessionTestUtil.invokeRequest(managers[0], setHandler, null);
validateNewSession(setHandler);
String sessionId = setHandler.getSessionId();
@@ -218,7 +216,7 @@
// Modify attribute request
setHandler = new SetAttributesRequestHandler(newAttributes, false);
- SessionTestUtil.invokeRequest(jbcm0, setHandler, sessionId);
+ SessionTestUtil.invokeRequest(managers[0], setHandler, sessionId);
if (!notify)
{
@@ -241,8 +239,8 @@
// Passivate
Thread.sleep(1100);
- jbcm0.backgroundProcess();
- jbcm1.backgroundProcess();
+ managers[0].backgroundProcess();
+ managers[1].backgroundProcess();
if (!notify)
{
@@ -259,7 +257,7 @@
// Remove attribute request
RemoveAttributesRequestHandler removeHandler = new RemoveAttributesRequestHandler(newAttributes.keySet(), false);
- SessionTestUtil.invokeRequest(jbcm0, removeHandler, sessionId);
+ SessionTestUtil.invokeRequest(managers[0], removeHandler, sessionId);
if (!notify)
{
@@ -280,7 +278,7 @@
// Failover request
setHandler = new SetAttributesRequestHandler(attributes, false);
- SessionTestUtil.invokeRequest(jbcm1, setHandler, sessionId);
+ SessionTestUtil.invokeRequest(managers[1], setHandler, sessionId);
if (!notify)
{
@@ -303,8 +301,8 @@
// Passivate
Thread.sleep(1100);
- jbcm0.backgroundProcess();
- jbcm1.backgroundProcess();
+ managers[0].backgroundProcess();
+ managers[1].backgroundProcess();
if (!notify)
{
@@ -321,7 +319,7 @@
// Fail back and invalidate session after changing attribute
InvalidateSessionRequestHandler invalidateHandler = new InvalidateSessionRequestHandler(newAttributes.keySet(), false);
- SessionTestUtil.invokeRequest(jbcm0, invalidateHandler, sessionId);
+ SessionTestUtil.invokeRequest(managers[0], invalidateHandler, sessionId);
if (!notify)
{
@@ -360,35 +358,33 @@
String warname = String.valueOf(++testId);
// A war with a maxInactive of 2 secs and a maxIdle of 1
- JBossCacheManager[] mgrs = getCacheManagers(warname, 2, 1);
- JBossCacheManager jbcm0 = mgrs[0];
- JBossCacheManager jbcm1 = mgrs[1];
+ this.startManagers(warname, 2, 1);
- assertTrue(jbcm0.getNotificationPolicy() instanceof MockClusteredSessionNotificationPolicy);
- MockClusteredSessionNotificationPolicy mcsnp0 = (MockClusteredSessionNotificationPolicy) jbcm0.getNotificationPolicy();
+ assertTrue(managers[0].getNotificationPolicy() instanceof MockClusteredSessionNotificationPolicy);
+ MockClusteredSessionNotificationPolicy mcsnp0 = (MockClusteredSessionNotificationPolicy) managers[0].getNotificationPolicy();
assertNotNull("capability set", mcsnp0.getClusteredSessionNotificationCapability());
mcsnp0.setResponse(notify);
- assertTrue(jbcm1.getNotificationPolicy() instanceof MockClusteredSessionNotificationPolicy);
- MockClusteredSessionNotificationPolicy mcsnp1 = (MockClusteredSessionNotificationPolicy) jbcm1.getNotificationPolicy();
+ assertTrue(managers[1].getNotificationPolicy() instanceof MockClusteredSessionNotificationPolicy);
+ MockClusteredSessionNotificationPolicy mcsnp1 = (MockClusteredSessionNotificationPolicy) managers[1].getNotificationPolicy();
assertNotNull("capability set", mcsnp1.getClusteredSessionNotificationCapability());
mcsnp1.setResponse(notify);
MockHttpSessionListener hsl0 = new MockHttpSessionListener();
MockHttpSessionAttributeListener hsal0 = new MockHttpSessionAttributeListener();
- Context ctx = (Context) jbcm0.getContainer();
+ Context ctx = (Context) managers[0].getContainer();
ctx.setApplicationSessionLifecycleListeners(new Object[]{ hsl0 });
ctx.setApplicationEventListeners(new Object[]{ hsal0 });
MockHttpSessionListener hsl1 = new MockHttpSessionListener();
MockHttpSessionAttributeListener hsal1 = new MockHttpSessionAttributeListener();
- ctx = (Context) jbcm1.getContainer();
+ ctx = (Context) managers[1].getContainer();
ctx.setApplicationSessionLifecycleListeners(new Object[]{ hsl1 });
ctx.setApplicationEventListeners(new Object[]{ hsal1 });
// Initial request
SetAttributesRequestHandler setHandler = new SetAttributesRequestHandler(attributes, false);
- SessionTestUtil.invokeRequest(jbcm0, setHandler, null);
+ SessionTestUtil.invokeRequest(managers[0], setHandler, null);
validateNewSession(setHandler);
@@ -414,7 +410,7 @@
// Failover request
setHandler = new SetAttributesRequestHandler(newAttributes, false);
- SessionTestUtil.invokeRequest(jbcm1, setHandler, sessionId);
+ SessionTestUtil.invokeRequest(managers[1], setHandler, sessionId);
if (!notify)
{
@@ -439,8 +435,8 @@
// Passivate
Thread.sleep(1100);
- jbcm0.backgroundProcess();
- jbcm1.backgroundProcess();
+ managers[0].backgroundProcess();
+ managers[1].backgroundProcess();
if (!notify)
{
@@ -459,8 +455,8 @@
// Expire
Thread.sleep(1000);
- jbcm0.backgroundProcess();
- jbcm1.backgroundProcess();
+ managers[0].backgroundProcess();
+ managers[1].backgroundProcess();
if (!notify)
{
@@ -504,35 +500,33 @@
String warname = String.valueOf(++testId);
// A war with a maxInactive of 30 mins and no maxIdle
- JBossCacheManager[] mgrs = getCacheManagers(warname, 1800, -1);
- JBossCacheManager jbcm0 = mgrs[0];
- JBossCacheManager jbcm1 = mgrs[1];
+ this.startManagers(warname, 1800, -1);
- assertTrue(jbcm0.getNotificationPolicy() instanceof MockClusteredSessionNotificationPolicy);
- MockClusteredSessionNotificationPolicy mcsnp0 = (MockClusteredSessionNotificationPolicy) jbcm0.getNotificationPolicy();
+ assertTrue(managers[0].getNotificationPolicy() instanceof MockClusteredSessionNotificationPolicy);
+ MockClusteredSessionNotificationPolicy mcsnp0 = (MockClusteredSessionNotificationPolicy) managers[0].getNotificationPolicy();
assertNotNull("capability set", mcsnp0.getClusteredSessionNotificationCapability());
mcsnp0.setResponse(notify);
- assertTrue(jbcm1.getNotificationPolicy() instanceof MockClusteredSessionNotificationPolicy);
- MockClusteredSessionNotificationPolicy mcsnp1 = (MockClusteredSessionNotificationPolicy) jbcm1.getNotificationPolicy();
+ assertTrue(managers[1].getNotificationPolicy() instanceof MockClusteredSessionNotificationPolicy);
+ MockClusteredSessionNotificationPolicy mcsnp1 = (MockClusteredSessionNotificationPolicy) managers[1].getNotificationPolicy();
assertNotNull("capability set", mcsnp1.getClusteredSessionNotificationCapability());
mcsnp1.setResponse(notify);
MockHttpSessionListener hsl0 = new MockHttpSessionListener();
MockHttpSessionAttributeListener hsal0 = new MockHttpSessionAttributeListener();
- Context ctx = (Context) jbcm0.getContainer();
+ Context ctx = (Context) managers[0].getContainer();
ctx.setApplicationSessionLifecycleListeners(new Object[]{ hsl0 });
ctx.setApplicationEventListeners(new Object[]{ hsal0 });
MockHttpSessionListener hsl1 = new MockHttpSessionListener();
MockHttpSessionAttributeListener hsal1 = new MockHttpSessionAttributeListener();
- ctx = (Context) jbcm1.getContainer();
+ ctx = (Context) managers[1].getContainer();
ctx.setApplicationSessionLifecycleListeners(new Object[]{ hsl1 });
ctx.setApplicationEventListeners(new Object[]{ hsal1 });
// Initial request
SetAttributesRequestHandler setHandler = new SetAttributesRequestHandler(attributes, false);
- SessionTestUtil.invokeRequest(jbcm0, setHandler, null);
+ SessionTestUtil.invokeRequest(managers[0], setHandler, null);
validateNewSession(setHandler);
@@ -555,7 +549,7 @@
}
- jbcm0.stop();
+ managers[0].stop();
if (!notify)
{
@@ -576,7 +570,7 @@
}
- jbcm1.stop();
+ managers[0].stop();
if (!notify)
{
@@ -649,24 +643,15 @@
}
}
- protected JBossCacheManager[] getCacheManagers(String warname, int maxInactive, int maxIdle)
- throws Exception
+ protected void startManagers(String warname, int maxInactive, int maxIdle) throws Exception
{
- JBossCacheManager jbcm0 = SessionTestUtil.createManager(warname, maxInactive, dcmFactories[0], null);
- JBossWebMetaData metadata = SessionTestUtil.createWebMetaData(getReplicationGranularity(), getReplicationTrigger(), -1, maxIdle > 0, maxIdle, -1 ,false, 0);
- metadata.getReplicationConfig().setSessionNotificationPolicy(MockClusteredSessionNotificationPolicy.class.getName());
- jbcm0.init(warname, metadata);
- this.managers.add(jbcm0);
- jbcm0.start();
-
- JBossCacheManager jbcm1 = SessionTestUtil.createManager(warname, maxInactive, dcmFactories[1], null);
- metadata = SessionTestUtil.createWebMetaData(getReplicationGranularity(), getReplicationTrigger(), -1, true, maxIdle, -1 ,false, 0);
- metadata.getReplicationConfig().setSessionNotificationPolicy(MockClusteredSessionNotificationPolicy.class.getName());
- jbcm1.init(warname, metadata);
- this.managers.add(jbcm1);
- jbcm1.start();
-
- return new JBossCacheManager[]{jbcm0, jbcm1};
+ for (int i = 0; i < cacheContainers.length; ++i)
+ {
+ managers[i] = SessionTestUtil.createManager(warname, maxInactive, cacheContainers[i], null);
+ JBossWebMetaData metadata = SessionTestUtil.createWebMetaData(getReplicationGranularity(), getReplicationTrigger(), -1, (i == 0) ? (maxIdle > 0) : true, maxIdle, -1 ,false, 0);
+ managers[i].init(warname, metadata);
+ managers[i].start();
+ }
}
protected void validateExpectedAttributes(Map<String, Object> expected, BasicRequestHandler handler)
Modified: branches/infinispan-int/testsuite/src/main/org/jboss/test/cluster/defaultcfg/simpleweb/test/ClusteredSessionUnitTestCase.java
===================================================================
--- branches/infinispan-int/testsuite/src/main/org/jboss/test/cluster/defaultcfg/simpleweb/test/ClusteredSessionUnitTestCase.java 2010-09-01 20:34:46 UTC (rev 107941)
+++ branches/infinispan-int/testsuite/src/main/org/jboss/test/cluster/defaultcfg/simpleweb/test/ClusteredSessionUnitTestCase.java 2010-09-01 20:36:15 UTC (rev 107942)
@@ -25,11 +25,11 @@
import junit.framework.TestCase;
import org.jboss.metadata.web.jboss.ReplicationGranularity;
-import org.jboss.test.cluster.testutil.JGroupsSystemPropertySupport;
import org.jboss.test.cluster.testutil.SessionTestUtil;
import org.jboss.test.cluster.web.mocks.MockDistributedCacheManagerFactory;
import org.jboss.web.tomcat.service.session.ClusteredSession;
import org.jboss.web.tomcat.service.session.JBossCacheManager;
+import org.jboss.web.tomcat.service.session.distributedcache.spi.OutgoingDistributableSessionData;
/**
* Unit tests of {@link ClusteredSession}.
@@ -62,18 +62,18 @@
*/
public void testNewSessionIsOutdated() throws Exception
{
- JBossCacheManager mgr = new JBossCacheManager(new MockDistributedCacheManagerFactory());
+ JBossCacheManager<?> mgr = new JBossCacheManager<OutgoingDistributableSessionData>(new MockDistributedCacheManagerFactory());
SessionTestUtil.setupContainer("test", null, mgr);
mgr.start();
mgr.setReplicationGranularity(ReplicationGranularity.SESSION);
- ClusteredSession sess = (ClusteredSession) mgr.createEmptySession();
+ ClusteredSession<?> sess = (ClusteredSession<?>) mgr.createEmptySession();
assertTrue(sess.isOutdated());
sess.setCreationTime(System.currentTimeMillis());
assertFalse(sess.isOutdated());
mgr.setReplicationGranularity(ReplicationGranularity.ATTRIBUTE);
- sess = (ClusteredSession) mgr.createEmptySession();
+ sess = (ClusteredSession<?>) mgr.createEmptySession();
assertTrue(sess.isOutdated());
sess.setCreationTime(System.currentTimeMillis());
assertFalse(sess.isOutdated());
Modified: branches/infinispan-int/testsuite/src/main/org/jboss/test/cluster/defaultcfg/simpleweb/test/ConcurrentFailoverRequestsTestCase.java
===================================================================
--- branches/infinispan-int/testsuite/src/main/org/jboss/test/cluster/defaultcfg/simpleweb/test/ConcurrentFailoverRequestsTestCase.java 2010-09-01 20:34:46 UTC (rev 107941)
+++ branches/infinispan-int/testsuite/src/main/org/jboss/test/cluster/defaultcfg/simpleweb/test/ConcurrentFailoverRequestsTestCase.java 2010-09-01 20:36:15 UTC (rev 107942)
@@ -23,7 +23,6 @@
package org.jboss.test.cluster.defaultcfg.simpleweb.test;
import java.util.Collections;
-import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.CountDownLatch;
@@ -36,6 +35,8 @@
import org.apache.catalina.Manager;
import org.apache.catalina.Valve;
import org.apache.catalina.connector.Request;
+import org.infinispan.manager.CacheContainer;
+import org.infinispan.manager.EmbeddedCacheManager;
import org.jboss.logging.Logger;
import org.jboss.metadata.web.jboss.JBossWebMetaData;
import org.jboss.test.cluster.testutil.JGroupsSystemPropertySupport;
@@ -44,7 +45,6 @@
import org.jboss.test.cluster.web.mocks.ConcurrentRequestHandler;
import org.jboss.test.cluster.web.mocks.SetAttributesRequestHandler;
import org.jboss.web.tomcat.service.session.JBossCacheManager;
-import org.jboss.web.tomcat.service.session.distributedcache.spi.TestDistributedCacheManagerFactory;
/**
* JBAS-7379. Tests that multiple concurrent failover requests for
@@ -60,7 +60,8 @@
private static long testCount = System.currentTimeMillis();
private final JGroupsSystemPropertySupport jgSupport = new JGroupsSystemPropertySupport();
- private Set<TestDistributedCacheManagerFactory> dcmFactories = new HashSet<TestDistributedCacheManagerFactory>();
+ private final EmbeddedCacheManager[] cacheContainers = new EmbeddedCacheManager[2];
+ private final JBossCacheManager<?>[] managers = new JBossCacheManager[cacheContainers.length];
private ExecutorService threadPool;
@@ -97,21 +98,36 @@
{
threadPool.shutdownNow();
}
-
- for (TestDistributedCacheManagerFactory factory : dcmFactories)
- {
- try
+
+ for (JBossCacheManager<?> manager: managers)
+ {
+ if (manager != null)
{
- factory.cleanup(true);
+ try
+ {
+ manager.stop();
+ }
+ catch (Exception e)
+ {
+ log.error(e.getMessage(), e);
+ }
}
- catch (Exception e)
+ }
+
+ for (CacheContainer cacheContainer: cacheContainers)
+ {
+ if (cacheContainer != null)
{
- log.error(e.getMessage(), e);
+ try
+ {
+ cacheContainer.stop();
+ }
+ catch (Exception e)
+ {
+ log.error(e.getMessage(), e);
+ }
}
-
}
-
- dcmFactories.clear();
}
}
@@ -119,24 +135,24 @@
{
++testCount;
+ String warName = "test" + testCount;
JBossWebMetaData webMetaData = SessionTestUtil.createWebMetaData(100);
- String warName = "test" + testCount;
- JBossCacheManager jbcm0 = SessionTestUtil.createManager(warName, 30, false, null, false, false, null);
- jbcm0.init(warName, webMetaData);
- jbcm0.start();
+ for (int i = 0; i < cacheContainers.length; ++i)
+ {
+ cacheContainers[i] = SessionTestUtil.createCacheContainer(false, null, false, false);
+ cacheContainers[i].start();
+
+ managers[i] = SessionTestUtil.createManager(warName, 30, cacheContainers[i], null);
+ managers[i].init(warName, webMetaData);
+ managers[i].start();
+ }
- JBossCacheManager jbcm1 = SessionTestUtil.createManager(warName, 30, false, null, false, false, null);
- jbcm1.init(warName, webMetaData);
- jbcm1.start();
+ SessionTestUtil.blockUntilViewsReceived(cacheContainers, 10000);
- TestDistributedCacheManagerFactory[] array = new TestDistributedCacheManagerFactory[dcmFactories.size()];
- array = dcmFactories.toArray(array);
- SessionTestUtil.blockUntilViewsReceived(array, 10000);
-
Object value = "0";
Map<String, Object> attrs = Collections.unmodifiableMap(Collections.singletonMap("count", value));
SetAttributesRequestHandler setHandler = new SetAttributesRequestHandler(attrs, false);
- SessionTestUtil.invokeRequest(jbcm0, setHandler, null);
+ SessionTestUtil.invokeRequest(managers[0], setHandler, null);
String id1 = setHandler.getSessionId();
assertNotNull(id1);
@@ -144,7 +160,7 @@
// Add a second session that we can check for replication; this is a proxy
// for checking that first session has replicated
setHandler = new SetAttributesRequestHandler(attrs, false);
- SessionTestUtil.invokeRequest(jbcm0, setHandler, null);
+ SessionTestUtil.invokeRequest(managers[0], setHandler, null);
String id2 = setHandler.getSessionId();
assertNotNull(id1);
@@ -156,7 +172,7 @@
for (int i = 0; i < 10; i++)
{
BasicRequestHandler getHandler = new BasicRequestHandler(attrs.keySet(), false);
- SessionTestUtil.invokeRequest(jbcm1, getHandler, id2);
+ SessionTestUtil.invokeRequest(managers[1], getHandler, id2);
if (getHandler.getCheckedAttributes() != null && value.equals(getHandler.getCheckedAttributes().get("count")))
{
found = true;
@@ -166,7 +182,7 @@
}
assertTrue("sessions replicated", found);
- jbcm0.stop();
+ managers[0].stop();
int THREADS = 10;
threadPool = Executors.newFixedThreadPool(THREADS);
@@ -174,12 +190,12 @@
CountDownLatch startingGun = new CountDownLatch(THREADS + 1);
CountDownLatch finishedSignal = new CountDownLatch(THREADS);
ConcurrentRequestHandler concurrentHandler = new ConcurrentRequestHandler();
- Valve pipelineHead = SessionTestUtil.setupPipeline(jbcm1, concurrentHandler);
+ Valve pipelineHead = SessionTestUtil.setupPipeline(managers[1], concurrentHandler);
Loader[] loaders = new Loader[THREADS];
for (int i = 0; i < loaders.length; i++)
{
- loaders[i] = new Loader(pipelineHead, concurrentHandler, jbcm1, id1, attrs.keySet(), startingGun, finishedSignal);
+ loaders[i] = new Loader(pipelineHead, concurrentHandler, managers[1], id1, attrs.keySet(), startingGun, finishedSignal);
threadPool.execute(loaders[i]);
}
@@ -193,6 +209,8 @@
assertTrue("checked 'count' attribute for " + i, loaders[i].checkedAttributes.containsKey("count"));
assertEquals("correct value for " + i, value, loaders[i].checkedAttributes.get("count"));
}
+
+ managers[1].stop();
}
private static class Loader implements Runnable
Modified: branches/infinispan-int/testsuite/src/main/org/jboss/test/cluster/defaultcfg/simpleweb/test/FailedExpirationTestCase.java
===================================================================
--- branches/infinispan-int/testsuite/src/main/org/jboss/test/cluster/defaultcfg/simpleweb/test/FailedExpirationTestCase.java 2010-09-01 20:34:46 UTC (rev 107941)
+++ branches/infinispan-int/testsuite/src/main/org/jboss/test/cluster/defaultcfg/simpleweb/test/FailedExpirationTestCase.java 2010-09-01 20:36:15 UTC (rev 107942)
@@ -28,15 +28,14 @@
import java.io.IOException;
import java.io.Serializable;
import java.util.HashMap;
-import java.util.HashSet;
import java.util.Map;
-import java.util.Set;
import javax.servlet.http.HttpSessionBindingEvent;
import javax.servlet.http.HttpSessionBindingListener;
import junit.framework.TestCase;
+import org.infinispan.manager.CacheContainer;
import org.jboss.logging.Logger;
import org.jboss.metadata.web.jboss.JBossWebMetaData;
import org.jboss.test.cluster.testutil.JGroupsSystemPropertySupport;
@@ -44,7 +43,6 @@
import org.jboss.test.cluster.web.mocks.InvalidateSessionRequestHandler;
import org.jboss.test.cluster.web.mocks.SetAttributesRequestHandler;
import org.jboss.web.tomcat.service.session.JBossCacheManager;
-import org.jboss.web.tomcat.service.session.distributedcache.spi.TestDistributedCacheManagerFactory;
/**
* A FailedExpirationTestCase.
@@ -59,7 +57,8 @@
private static long testCount = System.currentTimeMillis();
private final JGroupsSystemPropertySupport jgSupport = new JGroupsSystemPropertySupport();
- private Set<TestDistributedCacheManagerFactory> dcmFactories = new HashSet<TestDistributedCacheManagerFactory>();
+ private CacheContainer cacheContainer;
+ private JBossCacheManager<?> manager;
private String tempDir;
/**
@@ -96,21 +95,30 @@
finally
{
jgSupport.restoreProperties();
-
- for (TestDistributedCacheManagerFactory factory : dcmFactories)
- {
+
+ if (manager != null)
+ {
try
{
- factory.cleanup(true);
+ manager.stop();
}
catch (Exception e)
{
log.error(e.getMessage(), e);
}
-
}
- dcmFactories.clear();
+ if (cacheContainer != null)
+ {
+ try
+ {
+ cacheContainer.stop();
+ }
+ catch (Exception e)
+ {
+ log.error(e.getMessage(), e);
+ }
+ }
SessionTestUtil.cleanFilesystem(tempDir);
}
@@ -120,15 +128,18 @@
{
++testCount;
+ cacheContainer = SessionTestUtil.createCacheContainer(true, null, false, false);
+ cacheContainer.start();
JBossWebMetaData webMetaData = SessionTestUtil.createWebMetaData(10, true, 1, -1);
webMetaData.getReplicationConfig().setMaxUnreplicatedInterval(0);
+
String warName = "test" + testCount;
- JBossCacheManager jbcm = SessionTestUtil.createManager(warName, 2, true, null, false, false, null);
- jbcm.init(warName, webMetaData);
- jbcm.start();
+ manager = SessionTestUtil.createManager(warName, 2, cacheContainer, null);
+ manager.init(warName, webMetaData);
+ manager.start();
- assertEquals(0, jbcm.getActiveSessionCount());
- assertEquals(0, jbcm.getPassivatedSessionCount());
+ assertEquals(0, manager.getActiveSessionCount());
+ assertEquals(0, manager.getPassivatedSessionCount());
Map<String, Object> attrs = new HashMap<String, Object>();
attrs.put("failInvalid", new FailInvalidationAttribute());
@@ -136,36 +147,38 @@
// Establish session.
SetAttributesRequestHandler setHandler = new SetAttributesRequestHandler(attrs, false);
- SessionTestUtil.invokeRequest(jbcm, setHandler, null);
+ SessionTestUtil.invokeRequest(manager, setHandler, null);
validateNewSession(setHandler);
String id = setHandler.getSessionId();
- assertEquals(1, jbcm.getActiveSessionCount());
- assertEquals(0, jbcm.getPassivatedSessionCount());
+ assertEquals(1, manager.getActiveSessionCount());
+ assertEquals(0, manager.getPassivatedSessionCount());
InvalidateSessionRequestHandler invalHandler = new InvalidateSessionRequestHandler(attrs.keySet(), false);
try
{
- SessionTestUtil.invokeRequest(jbcm, invalHandler, id);
+ SessionTestUtil.invokeRequest(manager, invalHandler, id);
fail("Invalidation not rejected");
}
catch (RejectedException ok) {}
- assertEquals(0, jbcm.getActiveSessionCount());
- assertEquals(0, jbcm.getPassivatedSessionCount());
+ assertEquals(0, manager.getActiveSessionCount());
+ assertEquals(0, manager.getPassivatedSessionCount());
}
public void testFailedExpiration() throws Exception
{
++testCount;
+ cacheContainer = SessionTestUtil.createCacheContainer(true, null, false, false);
+ cacheContainer.start();
JBossWebMetaData webMetaData = SessionTestUtil.createWebMetaData(10, true, 1, -1);
webMetaData.getReplicationConfig().setMaxUnreplicatedInterval(0);
String warName = "test" + testCount;
- JBossCacheManager jbcm = SessionTestUtil.createManager(warName, 2, true, null, false, false, null);
- jbcm.init(warName, webMetaData);
- jbcm.start();
+ manager = SessionTestUtil.createManager(warName, 2, cacheContainer, null);
+ manager.init(warName, webMetaData);
+ manager.start();
- assertEquals(0, jbcm.getActiveSessionCount());
- assertEquals(0, jbcm.getPassivatedSessionCount());
+ assertEquals(0, manager.getActiveSessionCount());
+ assertEquals(0, manager.getPassivatedSessionCount());
Map<String, Object> attrs = new HashMap<String, Object>();
attrs.put("failInvalid", new FailInvalidationAttribute());
@@ -173,16 +186,16 @@
// Establish session.
SetAttributesRequestHandler setHandler = new SetAttributesRequestHandler(attrs, false);
- SessionTestUtil.invokeRequest(jbcm, setHandler, null);
+ SessionTestUtil.invokeRequest(manager, setHandler, null);
validateNewSession(setHandler);
- String id = setHandler.getSessionId();
- assertEquals(1, jbcm.getActiveSessionCount());
- assertEquals(0, jbcm.getPassivatedSessionCount());
+
+ assertEquals(1, manager.getActiveSessionCount());
+ assertEquals(0, manager.getPassivatedSessionCount());
SessionTestUtil.sleepThread(2010);
- jbcm.backgroundProcess();
- assertEquals(0, jbcm.getActiveSessionCount());
- assertEquals(0, jbcm.getPassivatedSessionCount());
+ manager.backgroundProcess();
+ assertEquals(0, manager.getActiveSessionCount());
+ assertEquals(0, manager.getPassivatedSessionCount());
}
public void testFailedExpirationAfterPassivation() throws Exception
@@ -190,15 +203,17 @@
++testCount;
String passivationDir = SessionTestUtil.getPassivationDir(tempDir, testCount, 1);
+ cacheContainer = SessionTestUtil.createCacheContainer(true, passivationDir, false, false);
+ cacheContainer.start();
JBossWebMetaData webMetaData = SessionTestUtil.createWebMetaData(10, true, 1, -1);
webMetaData.getReplicationConfig().setMaxUnreplicatedInterval(0);
String warName = "test" + testCount;
- JBossCacheManager jbcm = SessionTestUtil.createManager(warName, 2, true, passivationDir, false, false, null);
- jbcm.init(warName, webMetaData);
- jbcm.start();
+ manager = SessionTestUtil.createManager(warName, 2, cacheContainer, null);
+ manager.init(warName, webMetaData);
+ manager.start();
- assertEquals(0, jbcm.getActiveSessionCount());
- assertEquals(0, jbcm.getPassivatedSessionCount());
+ assertEquals(0, manager.getActiveSessionCount());
+ assertEquals(0, manager.getPassivatedSessionCount());
Map<String, Object> attrs = new HashMap<String, Object>();
attrs.put("failInvalid", new FailInvalidationAttribute());
@@ -206,21 +221,21 @@
// Establish session.
SetAttributesRequestHandler setHandler = new SetAttributesRequestHandler(attrs, false);
- SessionTestUtil.invokeRequest(jbcm, setHandler, null);
+ SessionTestUtil.invokeRequest(manager, setHandler, null);
validateNewSession(setHandler);
- String id = setHandler.getSessionId();
- assertEquals(1, jbcm.getActiveSessionCount());
- assertEquals(0, jbcm.getPassivatedSessionCount());
+
+ assertEquals(1, manager.getActiveSessionCount());
+ assertEquals(0, manager.getPassivatedSessionCount());
SessionTestUtil.sleepThread(1010);
- jbcm.backgroundProcess();
- assertEquals(0, jbcm.getActiveSessionCount());
- assertEquals(1, jbcm.getPassivatedSessionCount());
+ manager.backgroundProcess();
+ assertEquals(0, manager.getActiveSessionCount());
+ assertEquals(1, manager.getPassivatedSessionCount());
SessionTestUtil.sleepThread(1010);
- jbcm.backgroundProcess();
- assertEquals(0, jbcm.getActiveSessionCount());
- assertEquals(0, jbcm.getPassivatedSessionCount());
+ manager.backgroundProcess();
+ assertEquals(0, manager.getActiveSessionCount());
+ assertEquals(0, manager.getPassivatedSessionCount());
}
public static class FailInvalidationAttribute extends FailDeserializationAttribute
Modified: branches/infinispan-int/testsuite/src/main/org/jboss/test/cluster/defaultcfg/simpleweb/test/JBossCacheManagerConfigurationUnitTestCase.java
===================================================================
--- branches/infinispan-int/testsuite/src/main/org/jboss/test/cluster/defaultcfg/simpleweb/test/JBossCacheManagerConfigurationUnitTestCase.java 2010-09-01 20:34:46 UTC (rev 107941)
+++ branches/infinispan-int/testsuite/src/main/org/jboss/test/cluster/defaultcfg/simpleweb/test/JBossCacheManagerConfigurationUnitTestCase.java 2010-09-01 20:36:15 UTC (rev 107942)
@@ -22,11 +22,9 @@
package org.jboss.test.cluster.defaultcfg.simpleweb.test;
-import java.util.HashSet;
-import java.util.Set;
-
import junit.framework.TestCase;
+import org.infinispan.manager.CacheContainer;
import org.jboss.logging.Logger;
import org.jboss.metadata.javaee.spec.EmptyMetaData;
import org.jboss.metadata.web.jboss.JBossWebMetaData;
@@ -37,8 +35,6 @@
import org.jboss.metadata.web.jboss.SnapshotMode;
import org.jboss.test.cluster.testutil.SessionTestUtil;
import org.jboss.web.tomcat.service.session.JBossCacheManager;
-import org.jboss.web.tomcat.service.session.distributedcache.spi.DistributedCacheManagerFactory;
-import org.jboss.web.tomcat.service.session.distributedcache.spi.TestDistributedCacheManagerFactory;
/**
* Unit tests of session count management.
@@ -52,7 +48,8 @@
private static long testCount = System.currentTimeMillis();
- private Set<TestDistributedCacheManagerFactory> dcmFactories = new HashSet<TestDistributedCacheManagerFactory>();
+ private CacheContainer cacheContainer;
+ private JBossCacheManager<?> manager;
private String tempDir;
/**
@@ -70,20 +67,29 @@
{
super.tearDown();
- for (TestDistributedCacheManagerFactory factory : dcmFactories)
- {
+ if (manager != null)
+ {
try
{
- factory.cleanup(true);
+ manager.stop();
}
catch (Exception e)
{
log.error(e.getMessage(), e);
}
-
}
- dcmFactories.clear();
+ if (cacheContainer != null)
+ {
+ try
+ {
+ cacheContainer.stop();
+ }
+ catch (Exception e)
+ {
+ log.error(e.getMessage(), e);
+ }
+ }
if (tempDir != null)
{
@@ -96,48 +102,45 @@
log.info("Enter testUseJK");
++testCount;
- DistributedCacheManagerFactory factory = SessionTestUtil.createDistributedCacheManagerFactory(true, null, false, false, false);
- JBossCacheManager jbcm = SessionTestUtil.createManager("test" + testCount, 5, factory, null);
+ cacheContainer = SessionTestUtil.createCacheContainer(true, null, false, false);
+ cacheContainer.start();
+
+ manager = SessionTestUtil.createManager("test" + testCount, 5, cacheContainer, null);
JBossWebMetaData webMetaData = createWebMetaData(null, null, null, null, null);
- jbcm.init("test.war", webMetaData);
- jbcm.start();
+ manager.init("test.war", webMetaData);
+ manager.start();
- assertFalse("With no config, not using JK", jbcm.getUseJK());
+ assertFalse("With no config, not using JK", manager.getUseJK());
- cleanupManager(jbcm, factory);
+ manager.stop();
- factory = SessionTestUtil.createDistributedCacheManagerFactory(true, null, false, false, false);
- jbcm = SessionTestUtil.createManager("test" + ++testCount, 5, factory, null);
+ manager = SessionTestUtil.createManager("test" + ++testCount, 5, cacheContainer, null);
webMetaData = createWebMetaData(null, null, null, null, Boolean.TRUE);
- jbcm.init("test.war", webMetaData);
- jbcm.start();
+ manager.init("test.war", webMetaData);
+ manager.start();
- assertTrue("With no jvmRoute but a config, using JK", jbcm.getUseJK());
+ assertTrue("With no jvmRoute but a config, using JK", manager.getUseJK());
- cleanupManager(jbcm, factory);
+ manager.stop();
- factory = SessionTestUtil.createDistributedCacheManagerFactory(true, null, false, false, false);
- jbcm = SessionTestUtil.createManager("test" + ++testCount, 5, factory, "test");
+ manager = SessionTestUtil.createManager("test" + ++testCount, 5, cacheContainer, "test");
webMetaData = createWebMetaData(null, null, null, null, null);
- jbcm.init("test.war", webMetaData);
- jbcm.start();
+ manager.init("test.war", webMetaData);
+ manager.start();
- assertTrue("With jvmRoute set, using JK", jbcm.getUseJK());
+ assertTrue("With jvmRoute set, using JK", manager.getUseJK());
- cleanupManager(jbcm, factory);
+ manager.stop();
- factory = SessionTestUtil.createDistributedCacheManagerFactory(true, null, false, false, false);
- jbcm = SessionTestUtil.createManager("test" + ++testCount, 5, factory, "test");
+ manager = SessionTestUtil.createManager("test" + ++testCount, 5, cacheContainer, "test");
webMetaData = createWebMetaData(null, null, null, null, Boolean.FALSE);
- jbcm.init("test.war", webMetaData);
- jbcm.start();
+ manager.init("test.war", webMetaData);
+ manager.start();
- assertFalse("With a jvmRoute but config=false, not using JK", jbcm.getUseJK());
-
- cleanupManager(jbcm, factory);
+ assertFalse("With a jvmRoute but config=false, not using JK", manager.getUseJK());
}
public void testSnapshot() throws Exception
@@ -146,39 +149,30 @@
++testCount;
- DistributedCacheManagerFactory factory = SessionTestUtil.createDistributedCacheManagerFactory(true, null, false, false, false);
- JBossCacheManager jbcm = SessionTestUtil.createManager("test" + testCount, 5, factory, null);
+ cacheContainer = SessionTestUtil.createCacheContainer(true, null, false, false);
+ cacheContainer.start();
+ manager = SessionTestUtil.createManager("test" + testCount, 5, cacheContainer, null);
JBossWebMetaData webMetaData = createWebMetaData(null, null, null, null, null);
- jbcm.init("test.war", webMetaData);
- jbcm.start();
+ manager.init("test.war", webMetaData);
+ manager.start();
- assertEquals("With no config, using instant", SnapshotMode.INSTANT, jbcm.getSnapshotMode());
+ assertEquals("With no config, using instant", SnapshotMode.INSTANT, manager.getSnapshotMode());
- cleanupManager(jbcm, factory);
+ manager.stop();
- factory = SessionTestUtil.createDistributedCacheManagerFactory(true, null, false, false, false);
- jbcm = SessionTestUtil.createManager("test" + ++testCount, 5, factory, null);
+ manager = SessionTestUtil.createManager("test" + ++testCount, 5, cacheContainer, null);
webMetaData = createWebMetaData(null, null, null, null, Boolean.TRUE);
webMetaData.getReplicationConfig().setSnapshotMode(SnapshotMode.INTERVAL);
webMetaData.getReplicationConfig().setSnapshotInterval(new Integer(2));
- jbcm.init("test.war", webMetaData);
- jbcm.start();
+ manager.init("test.war", webMetaData);
+ manager.start();
- assertEquals("With config, using interval", SnapshotMode.INTERVAL, jbcm.getSnapshotMode());
- assertEquals("With config, using 2 second interval", 2, jbcm.getSnapshotInterval());
-
- cleanupManager(jbcm, factory);
-
+ assertEquals("With config, using interval", SnapshotMode.INTERVAL, manager.getSnapshotMode());
+ assertEquals("With config, using 2 second interval", 2, manager.getSnapshotInterval());
}
- private void cleanupManager(JBossCacheManager mgr, DistributedCacheManagerFactory factory) throws Exception
- {
- mgr.stop();
- dcmFactories.remove(factory);
- }
-
private JBossWebMetaData createWebMetaData(Integer maxSessions,
Boolean passivation,
Integer maxIdle,
Modified: branches/infinispan-int/testsuite/src/main/org/jboss/test/cluster/defaultcfg/simpleweb/test/MultipleWarSingleRedeployTestCase.java
===================================================================
--- branches/infinispan-int/testsuite/src/main/org/jboss/test/cluster/defaultcfg/simpleweb/test/MultipleWarSingleRedeployTestCase.java 2010-09-01 20:34:46 UTC (rev 107941)
+++ branches/infinispan-int/testsuite/src/main/org/jboss/test/cluster/defaultcfg/simpleweb/test/MultipleWarSingleRedeployTestCase.java 2010-09-01 20:36:15 UTC (rev 107942)
@@ -24,12 +24,11 @@
import java.util.Collections;
import java.util.HashMap;
-import java.util.HashSet;
import java.util.Map;
-import java.util.Set;
import junit.framework.Test;
+import org.infinispan.manager.CacheContainer;
import org.jboss.logging.Logger;
import org.jboss.metadata.web.jboss.JBossWebMetaData;
import org.jboss.metadata.web.jboss.ReplicationGranularity;
@@ -40,7 +39,6 @@
import org.jboss.test.cluster.web.mocks.BasicRequestHandler;
import org.jboss.test.cluster.web.mocks.SetAttributesRequestHandler;
import org.jboss.web.tomcat.service.session.JBossCacheManager;
-import org.jboss.web.tomcat.service.session.distributedcache.spi.TestDistributedCacheManagerFactory;
/**
* Tests for JBAS-7205. Deploy two wars on each node, sharing a cache between
@@ -50,7 +48,7 @@
*/
public class MultipleWarSingleRedeployTestCase extends JBossTestCase
{
- protected static TestDistributedCacheManagerFactory[] dcmFactories = new TestDistributedCacheManagerFactory[2];
+ protected static CacheContainer[] cacheContainers = new CacheContainer[2];
protected static long testId = System.currentTimeMillis();
@@ -58,7 +56,8 @@
protected Logger log = Logger.getLogger(getClass());
- protected Set<JBossCacheManager> managers = new HashSet<JBossCacheManager>();
+ protected JBossCacheManager<?>[] managersA = new JBossCacheManager[cacheContainers.length];
+ protected JBossCacheManager<?>[] managersB = new JBossCacheManager[cacheContainers.length];
protected Map<String, Object> allAttributes;
@@ -69,7 +68,7 @@
public static Test suite() throws Exception
{
- return CacheConfigTestSetup.getTestSetup(MultipleWarSingleRedeployTestCase.class, dcmFactories, false, null, !useBuddyRepl, true);
+ return CacheConfigTestSetup.getTestSetup(MultipleWarSingleRedeployTestCase.class, cacheContainers, false, null, !useBuddyRepl);
}
@@ -90,10 +89,21 @@
{
super.tearDown();
- for (JBossCacheManager manager : managers)
- manager.stop();
+ for (JBossCacheManager<?> manager : managersA)
+ {
+ if (manager != null)
+ {
+ manager.stop();
+ }
+ }
- managers.clear();
+ for (JBossCacheManager<?> manager : managersB)
+ {
+ if (manager != null)
+ {
+ manager.stop();
+ }
+ }
}
protected ReplicationGranularity getReplicationGranularity()
@@ -108,44 +118,39 @@
public void testMultipleWarSingleRedeploy() throws Exception
{
- String warnameA = "A" + String.valueOf(++testId);
- JBossCacheManager[] mgrsA = getCacheManagers(warnameA);
- JBossCacheManager jbcmA0 = mgrsA[0];
- JBossCacheManager jbcmA1 = mgrsA[1];
+ String warnameA = "A" + String.valueOf(++testId);
+ this.startManagers(warnameA, managersA);
String warnameB = "B" + String.valueOf(testId);
- JBossCacheManager[] mgrsB = getCacheManagers(warnameB);
- JBossCacheManager jbcmB0 = mgrsB[0];
- JBossCacheManager jbcmB1 = mgrsB[1];
+ this.startManagers(warnameB, managersB);
// Establish session.
SetAttributesRequestHandler setHandler = new SetAttributesRequestHandler(allAttributes, false);
- SessionTestUtil.invokeRequest(jbcmA0, setHandler, null);
+ SessionTestUtil.invokeRequest(managersA[0], setHandler, null);
validateNewSession(setHandler);
String idA = setHandler.getSessionId();
setHandler = new SetAttributesRequestHandler(allAttributes, false);
- SessionTestUtil.invokeRequest(jbcmB0, setHandler, null);
+ SessionTestUtil.invokeRequest(managersB[0], setHandler, null);
validateNewSession(setHandler);
String idB = setHandler.getSessionId();
BasicRequestHandler getHandler = new BasicRequestHandler(allAttributes.keySet(), false);
- SessionTestUtil.invokeRequest(jbcmA1, getHandler, idA);
+ SessionTestUtil.invokeRequest(managersA[1], getHandler, idA);
validateExpectedAttributes(allAttributes, getHandler);
getHandler = new BasicRequestHandler(allAttributes.keySet(), false);
- SessionTestUtil.invokeRequest(jbcmB1, getHandler, idB);
+ SessionTestUtil.invokeRequest(managersB[1], getHandler, idB);
validateExpectedAttributes(allAttributes, getHandler);
// Undeploy one webapp on node 1
- jbcmB1.stop();
- managers.remove(jbcmB1);
+ managersB[1].stop();
log.info("jbcmB1 stopped");
// Deploy again
- jbcmB1 = getCacheManager(warnameB, dcmFactories[1]);
+ managersB[1] = this.startManager(warnameB, cacheContainers[1]);
log.info("jbcmB1 started");
@@ -153,37 +158,32 @@
// log.info(dcmFactories[1].getCache().getMembers());
getHandler = new BasicRequestHandler(allAttributes.keySet(), false);
- SessionTestUtil.invokeRequest(jbcmA1, getHandler, idA);
+ SessionTestUtil.invokeRequest(managersA[1], getHandler, idA);
validateExpectedAttributes(allAttributes, getHandler);
getHandler = new BasicRequestHandler(allAttributes.keySet(), false);
- SessionTestUtil.invokeRequest(jbcmB1, getHandler, idB);
+ SessionTestUtil.invokeRequest(managersB[1], getHandler, idB);
validateExpectedAttributes(allAttributes, getHandler);
}
- protected JBossCacheManager[] getCacheManagers(String warname)
- throws Exception
+ protected void startManagers(String warname, JBossCacheManager<?>[] managers) throws Exception
{
- JBossCacheManager[] result = new JBossCacheManager[dcmFactories.length];
- for (int i = 0; i < result.length; i++)
+ for (int i = 0; i < cacheContainers.length; i++)
{
- result[i] = getCacheManager(warname, dcmFactories[i]);
+ managers[i] = this.startManager(warname, cacheContainers[i]);
}
- return result;
}
- protected JBossCacheManager getCacheManager(String warname, TestDistributedCacheManagerFactory dcmFactory)
- throws Exception
+ protected JBossCacheManager<?> startManager(String warname, CacheContainer cacheContainer) throws Exception
{
- JBossCacheManager jbcm = SessionTestUtil.createManager(warname, 100, dcmFactory, null);
+ JBossCacheManager<?> manager = SessionTestUtil.createManager(warname, 100, cacheContainer, null);
JBossWebMetaData metadata = SessionTestUtil.createWebMetaData(getReplicationGranularity(), getReplicationTrigger(), true, 30);
- jbcm.init(warname, metadata);
- this.managers.add(jbcm);
- jbcm.start();
+ manager.init(warname, metadata);
+ manager.start();
- return jbcm;
+ return manager;
}
protected void validateExpectedAttributes(Map<String, Object> expected, BasicRequestHandler handler)
Modified: branches/infinispan-int/testsuite/src/main/org/jboss/test/cluster/defaultcfg/simpleweb/test/ReplicationToPassivatedSessionUnitTestCase.java
===================================================================
--- branches/infinispan-int/testsuite/src/main/org/jboss/test/cluster/defaultcfg/simpleweb/test/ReplicationToPassivatedSessionUnitTestCase.java 2010-09-01 20:34:46 UTC (rev 107941)
+++ branches/infinispan-int/testsuite/src/main/org/jboss/test/cluster/defaultcfg/simpleweb/test/ReplicationToPassivatedSessionUnitTestCase.java 2010-09-01 20:36:15 UTC (rev 107942)
@@ -24,12 +24,11 @@
import java.io.File;
import java.util.Collections;
-import java.util.HashSet;
-import java.util.Set;
import junit.framework.Test;
import junit.framework.TestCase;
+import org.infinispan.manager.CacheContainer;
import org.jboss.logging.Logger;
import org.jboss.metadata.web.jboss.JBossWebMetaData;
import org.jboss.metadata.web.jboss.ReplicationGranularity;
@@ -38,7 +37,6 @@
import org.jboss.test.cluster.testutil.SessionTestUtil;
import org.jboss.test.cluster.web.mocks.SetAttributesRequestHandler;
import org.jboss.web.tomcat.service.session.JBossCacheManager;
-import org.jboss.web.tomcat.service.session.distributedcache.spi.TestDistributedCacheManagerFactory;
/**
* Unit tests of session expiration
@@ -47,13 +45,13 @@
*/
public class ReplicationToPassivatedSessionUnitTestCase extends TestCase
{
- protected static TestDistributedCacheManagerFactory[] dcmFactories = new TestDistributedCacheManagerFactory[2];
+ protected static CacheContainer[] cacheContainers = new CacheContainer[2];
protected static long testId = System.currentTimeMillis();
protected Logger log = Logger.getLogger(getClass());
- protected Set<JBossCacheManager> managers = new HashSet<JBossCacheManager>();
+ protected JBossCacheManager<?>[] managers = new JBossCacheManager[cacheContainers.length];
public ReplicationToPassivatedSessionUnitTestCase(String name)
{
@@ -64,7 +62,7 @@
{
File tmpDir = new File(System.getProperty("java.io.tmpdir"));
File root = new File(tmpDir, ReplicationToPassivatedSessionUnitTestCase.class.getSimpleName());
- return CacheConfigTestSetup.getTestSetup(ReplicationToPassivatedSessionUnitTestCase.class, dcmFactories, false, root.getAbsolutePath(), true, false);
+ return CacheConfigTestSetup.getTestSetup(ReplicationToPassivatedSessionUnitTestCase.class, cacheContainers, false, root.getAbsolutePath(), true);
}
@Override
@@ -76,10 +74,13 @@
}
finally
{
- for (JBossCacheManager manager : managers)
- manager.stop();
-
- managers.clear();
+ for (JBossCacheManager<?> manager : managers)
+ {
+ if (manager != null)
+ {
+ manager.stop();
+ }
+ }
}
}
@@ -100,30 +101,28 @@
String warname = String.valueOf(++testId);
// A war with a maxInactive of 30 mins and a maxIdle of 1
- JBossCacheManager[] mgrs = getCacheManagers(warname, 1800000, 1, -1);
- JBossCacheManager jbcm0 = mgrs[0];
- JBossCacheManager jbcm1 = mgrs[1];
+ this.startManagers(warname, 1800000, 1, -1);
Object value = "0";
SetAttributesRequestHandler setHandler = new SetAttributesRequestHandler(Collections.singletonMap("count", value), false);
- SessionTestUtil.invokeRequest(jbcm0, setHandler, null);
+ SessionTestUtil.invokeRequest(managers[0], setHandler, null);
String id = setHandler.getSessionId();
SessionTestUtil.sleepThread(1100);
- jbcm0.backgroundProcess();
- jbcm1.backgroundProcess();
+ managers[0].backgroundProcess();
+ managers[1].backgroundProcess();
value = "1";
setHandler = new SetAttributesRequestHandler(Collections.singletonMap("count", value), false);
- SessionTestUtil.invokeRequest(jbcm0, setHandler, id);
+ SessionTestUtil.invokeRequest(managers[0], setHandler, id);
assertEquals("0", setHandler.getCheckedAttributes().get("count"));
value = "2";
setHandler = new SetAttributesRequestHandler(Collections.singletonMap("count", value), false);
- SessionTestUtil.invokeRequest(jbcm1, setHandler, id);
+ SessionTestUtil.invokeRequest(managers[1], setHandler, id);
assertEquals("1", setHandler.getCheckedAttributes().get("count"));
}
@@ -135,44 +134,35 @@
String warname = String.valueOf(++testId);
// A war with a maxInactive of 30 mins and a maxIdle of 1
- JBossCacheManager[] mgrs = getCacheManagers(warname, 1800000, 1, -1);
- JBossCacheManager jbcm0 = mgrs[0];
- JBossCacheManager jbcm1 = mgrs[1];
+ this.startManagers(warname, 1800000, 1, -1);
Object value = "0";
SetAttributesRequestHandler setHandler = new SetAttributesRequestHandler(Collections.singletonMap("count", value), false);
- SessionTestUtil.invokeRequest(jbcm0, setHandler, null);
+ SessionTestUtil.invokeRequest(managers[0], setHandler, null);
String id = setHandler.getSessionId();
SessionTestUtil.sleepThread(1100);
- jbcm0.backgroundProcess();
- jbcm1.backgroundProcess();
+ managers[0].backgroundProcess();
+ managers[1].backgroundProcess();
value = "1";
setHandler = new SetAttributesRequestHandler(Collections.singletonMap("count", value), false);
- SessionTestUtil.invokeRequest(jbcm1, setHandler, id);
+ SessionTestUtil.invokeRequest(managers[1], setHandler, id);
assertEquals("0", setHandler.getCheckedAttributes().get("count"));
}
- protected JBossCacheManager[] getCacheManagers(String warname, int maxInactive, int maxIdle, int maxUnreplicated)
- throws Exception
+ protected void startManagers(String warname, int maxInactive, int maxIdle, int maxUnreplicated) throws Exception
{
- JBossCacheManager jbcm0 = SessionTestUtil.createManager(warname, maxInactive, dcmFactories[0], null);
- JBossWebMetaData metadata = SessionTestUtil.createWebMetaData(getReplicationGranularity(), getReplicationTrigger(), -1, true, maxIdle, -1, true, maxUnreplicated);
- jbcm0.init(warname, metadata);
- this.managers.add(jbcm0);
- jbcm0.start();
-
- JBossCacheManager jbcm1 = SessionTestUtil.createManager(warname, maxInactive, dcmFactories[1], null);
- metadata = SessionTestUtil.createWebMetaData(getReplicationGranularity(), getReplicationTrigger(), -1, true, maxIdle, -1, true, -1);
- jbcm1.init(warname, metadata);
- this.managers.add(jbcm1);
- jbcm1.start();
-
- return new JBossCacheManager[]{jbcm0, jbcm1};
+ for (int i = 0; i < cacheContainers.length; ++i)
+ {
+ managers[i] = SessionTestUtil.createManager(warname, maxInactive, cacheContainers[i], null);
+ JBossWebMetaData metadata = SessionTestUtil.createWebMetaData(getReplicationGranularity(), getReplicationTrigger(), -1, true, maxIdle, -1, true, (i == 0) ? maxUnreplicated : -1);
+ managers[i].init(warname, metadata);
+ managers[i].start();
+ }
}
}
Modified: branches/infinispan-int/testsuite/src/main/org/jboss/test/cluster/defaultcfg/simpleweb/test/SessionBasedMaxUnreplicatedIntervalTestCase.java
===================================================================
--- branches/infinispan-int/testsuite/src/main/org/jboss/test/cluster/defaultcfg/simpleweb/test/SessionBasedMaxUnreplicatedIntervalTestCase.java 2010-09-01 20:34:46 UTC (rev 107941)
+++ branches/infinispan-int/testsuite/src/main/org/jboss/test/cluster/defaultcfg/simpleweb/test/SessionBasedMaxUnreplicatedIntervalTestCase.java 2010-09-01 20:36:15 UTC (rev 107942)
@@ -24,12 +24,11 @@
import java.util.Collections;
import java.util.HashMap;
-import java.util.HashSet;
import java.util.Map;
-import java.util.Set;
import junit.framework.Test;
+import org.infinispan.manager.CacheContainer;
import org.jboss.logging.Logger;
import org.jboss.metadata.web.jboss.JBossWebMetaData;
import org.jboss.metadata.web.jboss.ReplicationGranularity;
@@ -41,7 +40,6 @@
import org.jboss.test.cluster.web.mocks.MutableObject;
import org.jboss.test.cluster.web.mocks.SetAttributesRequestHandler;
import org.jboss.web.tomcat.service.session.JBossCacheManager;
-import org.jboss.web.tomcat.service.session.distributedcache.spi.TestDistributedCacheManagerFactory;
/**
* Tests of handling of ClusteredSession.maxUnreplicatedInterval. This base
@@ -51,15 +49,15 @@
*/
public class SessionBasedMaxUnreplicatedIntervalTestCase extends JBossTestCase
{
- protected static TestDistributedCacheManagerFactory[] dcmFactories = new TestDistributedCacheManagerFactory[2];
+ protected static CacheContainer[] cacheContainers = new CacheContainer[2];
protected static long testId = System.currentTimeMillis();
protected static boolean useBuddyRepl = Boolean.valueOf(System.getProperty("jbosstest.cluster.web.cache.br")).booleanValue();
- protected Logger log = Logger.getLogger(getClass());
+ protected Logger log = Logger.getLogger(getClass());
- protected Set<JBossCacheManager> managers = new HashSet<JBossCacheManager>();
+ protected JBossCacheManager<?>[] managers = new JBossCacheManager[cacheContainers.length];
protected Map<String, Object> allAttributes;
protected Map<String, Object> immutables;
@@ -72,7 +70,7 @@
public static Test suite() throws Exception
{
- return CacheConfigTestSetup.getTestSetup(SessionBasedMaxUnreplicatedIntervalTestCase.class, dcmFactories, false, null, !useBuddyRepl, false);
+ return CacheConfigTestSetup.getTestSetup(SessionBasedMaxUnreplicatedIntervalTestCase.class, cacheContainers, false, null, !useBuddyRepl);
}
@@ -102,10 +100,13 @@
{
super.tearDown();
- for (JBossCacheManager manager : managers)
- manager.stop();
-
- managers.clear();
+ for (JBossCacheManager<?> manager : managers)
+ {
+ if (manager != null)
+ {
+ manager.stop();
+ }
+ }
}
protected ReplicationGranularity getReplicationGranularity()
@@ -159,13 +160,11 @@
int maxUnrep = testZero ? 0 : 1;
// A war with a maxInactive of 3 secs and a maxUnreplicated of 0 or 1
- JBossCacheManager[] mgrs = getCacheManagers(warname, 3, maxUnrep);
- JBossCacheManager jbcm0 = mgrs[0];
- JBossCacheManager jbcm1 = mgrs[1];
+ startManagers(warname, 3, maxUnrep);
// Establish session.
SetAttributesRequestHandler setHandler = new SetAttributesRequestHandler(allAttributes, false);
- SessionTestUtil.invokeRequest(jbcm0, setHandler, null);
+ SessionTestUtil.invokeRequest(managers[0], setHandler, null);
validateNewSession(setHandler);
@@ -173,7 +172,7 @@
// Now make a request that will not trigger replication unless the interval is exceeded
BasicRequestHandler getHandler = new BasicRequestHandler(immutables.keySet(), false);
- SessionTestUtil.invokeRequest(jbcm0, getHandler, setHandler.getSessionId());
+ SessionTestUtil.invokeRequest(managers[0], getHandler, setHandler.getSessionId());
validateExpectedAttributes(immutables, getHandler);
@@ -183,7 +182,7 @@
// Fail over and confirm all is well
getHandler = new BasicRequestHandler(allAttributes.keySet(), false);
- SessionTestUtil.invokeRequest(jbcm1, getHandler, setHandler.getSessionId());
+ SessionTestUtil.invokeRequest(managers[1], getHandler, setHandler.getSessionId());
validateExpectedAttributes(allAttributes, getHandler);
}
@@ -206,19 +205,17 @@
String warname = String.valueOf(++testId);
// A war with a maxInactive of 3 secs and a maxUnreplicated of 1
- JBossCacheManager[] mgrs = getCacheManagers(warname, 3, 1);
- JBossCacheManager jbcm0 = mgrs[0];
- JBossCacheManager jbcm1 = mgrs[1];
+ startManagers(warname, 3, 1);
SetAttributesRequestHandler setHandler = new SetAttributesRequestHandler(allAttributes, false);
- SessionTestUtil.invokeRequest(jbcm0, setHandler, null);
+ SessionTestUtil.invokeRequest(managers[0], setHandler, null);
// Sleep less than the maxUnreplicated time so next request shouldn't trigger timestamp repl
Thread.sleep(500);
// Now make a request that will not trigger replication unless the interval is exceeded
BasicRequestHandler getHandler = new BasicRequestHandler(immutables.keySet(), false);
- SessionTestUtil.invokeRequest(jbcm0, getHandler, setHandler.getSessionId());
+ SessionTestUtil.invokeRequest(managers[0], getHandler, setHandler.getSessionId());
validateExpectedAttributes(immutables, getHandler);
@@ -228,7 +225,7 @@
// Fail over and confirm the session was expired
getHandler = new BasicRequestHandler(allAttributes.keySet(), false);
- SessionTestUtil.invokeRequest(jbcm1, getHandler, setHandler.getSessionId());
+ SessionTestUtil.invokeRequest(managers[1], getHandler, setHandler.getSessionId());
validateNewSession(getHandler);
}
@@ -246,57 +243,49 @@
String warname = String.valueOf(++testId);
- JBossCacheManager[] mgrs = getCacheManagers(warname, 3, 2);
- JBossCacheManager jbcm0 = mgrs[0];
- JBossCacheManager jbcm1 = mgrs[1];
+ startManagers(warname, 3, 2);
SetAttributesRequestHandler setHandler1 = new SetAttributesRequestHandler(allAttributes, false);
- SessionTestUtil.invokeRequest(jbcm0, setHandler1, null);
+ SessionTestUtil.invokeRequest(managers[0], setHandler1, null);
String id1 = setHandler1.getSessionId();
SetAttributesRequestHandler setHandler2 = new SetAttributesRequestHandler(allAttributes, false);
- SessionTestUtil.invokeRequest(jbcm0, setHandler2, null);
+ SessionTestUtil.invokeRequest(managers[0], setHandler2, null);
String id2 = setHandler2.getSessionId();
// Overage the sessions
Thread.sleep(3010);
// Try to force out the overaged sessions
- jbcm1.backgroundProcess();
+ managers[1].backgroundProcess();
// Confirm they are still there
- assertNotNull(jbcm1.getDistributedCacheManager().getSessionData(id1, false));
- assertNotNull(jbcm1.getDistributedCacheManager().getSessionData(id2, false));
+ assertNotNull(managers[1].getDistributedCacheManager().getSessionData(id1, false));
+ assertNotNull(managers[1].getDistributedCacheManager().getSessionData(id2, false));
// Access one to prove it gets expired once the manager can see its real timestamp
BasicRequestHandler getHandler = new BasicRequestHandler(allAttributes.keySet(), false);
- SessionTestUtil.invokeRequest(jbcm1, getHandler, setHandler1.getSessionId());
+ SessionTestUtil.invokeRequest(managers[1], getHandler, setHandler1.getSessionId());
validateNewSession(getHandler);
// Sleep past the grace period
Thread.sleep(2010);
// The get restored a new fresh session with the first id, but the 2nd
// one is still there and overaged. Try to force it out
- jbcm1.backgroundProcess();
- assertNull(jbcm1.getDistributedCacheManager().getSessionData(id2, false));
+ managers[1].backgroundProcess();
+ assertNull(managers[1].getDistributedCacheManager().getSessionData(id2, false));
}
- protected JBossCacheManager[] getCacheManagers(String warname, int maxInactive, int maxUnreplicated)
- throws Exception
+ protected void startManagers(String warname, int maxInactive, int maxUnreplicated) throws Exception
{
- JBossCacheManager jbcm0 = SessionTestUtil.createManager(warname, maxInactive, dcmFactories[0], null);
- JBossWebMetaData metadata = SessionTestUtil.createWebMetaData(getReplicationGranularity(), getReplicationTrigger(), true, maxUnreplicated);
- jbcm0.init(warname, metadata);
- this.managers.add(jbcm0);
- jbcm0.start();
-
- JBossCacheManager jbcm1 = SessionTestUtil.createManager(warname, maxInactive, dcmFactories[1], null);
- metadata = SessionTestUtil.createWebMetaData(getReplicationGranularity(), getReplicationTrigger(), true, maxUnreplicated);
- jbcm1.init(warname, metadata);
- this.managers.add(jbcm1);
- jbcm1.start();
-
- return new JBossCacheManager[]{jbcm0, jbcm1};
+ for (int i = 0; i < cacheContainers.length; ++i)
+ {
+ managers[i] = SessionTestUtil.createManager(warname, maxInactive, cacheContainers[i], null);
+ JBossWebMetaData metadata = SessionTestUtil.createWebMetaData(getReplicationGranularity(), getReplicationTrigger(), true, maxUnreplicated);
+ managers[i].init(warname, metadata);
+
+ managers[i].start();
+ }
}
protected void validateExpectedAttributes(Map<String, Object> expected, BasicRequestHandler handler)
Modified: branches/infinispan-int/testsuite/src/main/org/jboss/test/cluster/defaultcfg/simpleweb/test/SessionCountUnitTestCase.java
===================================================================
--- branches/infinispan-int/testsuite/src/main/org/jboss/test/cluster/defaultcfg/simpleweb/test/SessionCountUnitTestCase.java 2010-09-01 20:34:46 UTC (rev 107941)
+++ branches/infinispan-int/testsuite/src/main/org/jboss/test/cluster/defaultcfg/simpleweb/test/SessionCountUnitTestCase.java 2010-09-01 20:36:15 UTC (rev 107942)
@@ -23,20 +23,18 @@
package org.jboss.test.cluster.defaultcfg.simpleweb.test;
import java.io.File;
-import java.util.HashSet;
-import java.util.Set;
import junit.framework.TestCase;
import org.apache.catalina.Manager;
import org.apache.catalina.Session;
+import org.infinispan.manager.CacheContainer;
+import org.infinispan.manager.EmbeddedCacheManager;
import org.jboss.logging.Logger;
import org.jboss.metadata.web.jboss.JBossWebMetaData;
import org.jboss.test.cluster.testutil.JGroupsSystemPropertySupport;
import org.jboss.test.cluster.testutil.SessionTestUtil;
import org.jboss.web.tomcat.service.session.JBossCacheManager;
-import org.jboss.web.tomcat.service.session.distributedcache.spi.DistributedCacheManagerFactory;
-import org.jboss.web.tomcat.service.session.distributedcache.spi.TestDistributedCacheManagerFactory;
/**
* Unit tests of session count management.
@@ -51,7 +49,8 @@
private static long testCount = System.currentTimeMillis();
private JGroupsSystemPropertySupport jgroupsSupport;
- private Set<TestDistributedCacheManagerFactory> dcmFactories = new HashSet<TestDistributedCacheManagerFactory>();
+ private EmbeddedCacheManager[] cacheContainers = new EmbeddedCacheManager[2];
+ private JBossCacheManager<?>[] managers = new JBossCacheManager[cacheContainers.length];
private String tempDir;
/**
@@ -95,21 +94,22 @@
{
jgroupsSupport.restoreProperties();
}
-
- for (TestDistributedCacheManagerFactory factory : dcmFactories)
- {
- try
+
+ for (JBossCacheManager<?> manager: managers)
+ {
+ if (manager != null)
{
- factory.cleanup(true);
+ manager.stop();
}
- catch (Exception e)
+ }
+
+ for (CacheContainer cacheContainer: cacheContainers)
+ {
+ if (cacheContainer != null)
{
- log.error(e.getMessage(), e);
+ cacheContainer.stop();
}
-
}
-
- dcmFactories.clear();
}
finally
{
@@ -127,40 +127,42 @@
++testCount;
- JBossCacheManager jbcm = SessionTestUtil.createManager("test" + testCount, 5, true, null, false, false, null);
+ cacheContainers[0] = SessionTestUtil.createCacheContainer(true, null, false, false);
+ cacheContainers[0].start();
+ managers[0] = SessionTestUtil.createManager("test" + testCount, 5, cacheContainers[0], null);
JBossWebMetaData webMetaData = SessionTestUtil.createWebMetaData(2);
- jbcm.init("test.war", webMetaData);
+ managers[0].init("test.war", webMetaData);
- jbcm.start();
+ managers[0].start();
- assertFalse("Passivation is disabled", jbcm.isPassivationEnabled());
- assertEquals("Correct max active count", 2, jbcm.getMaxActiveAllowed());
+ assertFalse("Passivation is disabled", managers[0].isPassivationEnabled());
+ assertEquals("Correct max active count", 2, managers[0].getMaxActiveAllowed());
// Set up a session
- Session sess1 = createAndUseSession(jbcm, "1", true, true);
+ Session sess1 = createAndUseSession(managers[0], "1", true, true);
- assertEquals("Session count correct", 1, jbcm.getActiveSessionCount());
- assertEquals("Local session count correct", 1, jbcm.getLocalActiveSessionCount());
+ assertEquals("Session count correct", 1, managers[0].getActiveSessionCount());
+ assertEquals("Local session count correct", 1, managers[0].getLocalActiveSessionCount());
- createAndUseSession(jbcm, "2", true, true);
+ createAndUseSession(managers[0], "2", true, true);
- assertEquals("Session count correct", 2, jbcm.getActiveSessionCount());
- assertEquals("Local session count correct", 2, jbcm.getLocalActiveSessionCount());
+ assertEquals("Session count correct", 2, managers[0].getActiveSessionCount());
+ assertEquals("Local session count correct", 2, managers[0].getLocalActiveSessionCount());
// Should fail to create a 3rd
- createAndUseSession(jbcm, "3", false, false);
+ createAndUseSession(managers[0], "3", false, false);
// Confirm a session timeout clears space
sess1.setMaxInactiveInterval(1);
SessionTestUtil.sleepThread(1100);
- createAndUseSession(jbcm, "3", true, true);
+ createAndUseSession(managers[0], "3", true, true);
- assertEquals("Session count correct", 2, jbcm.getActiveSessionCount());
- assertEquals("Local session count correct", 2, jbcm.getLocalActiveSessionCount());
- assertEquals("Created session count correct", 3, jbcm.getCreatedSessionCount());
- assertEquals("Expired session count correct", 1, jbcm.getExpiredSessionCount());
+ assertEquals("Session count correct", 2, managers[0].getActiveSessionCount());
+ assertEquals("Local session count correct", 2, managers[0].getLocalActiveSessionCount());
+ assertEquals("Created session count correct", 3, managers[0].getCreatedSessionCount());
+ assertEquals("Expired session count correct", 1, managers[0].getExpiredSessionCount());
}
public void testStandaloneMaxSessionsWithMaxIdle()
@@ -170,52 +172,53 @@
++testCount;
String passDir = getPassivationDir(testCount, 1);
- JBossCacheManager jbcm = SessionTestUtil.createManager("test" + testCount, 5, true, passDir, false, false, null);
+ cacheContainers[0] = SessionTestUtil.createCacheContainer(true, passDir, false, false);
+ cacheContainers[0].start();
+ managers[0] = SessionTestUtil.createManager("test" + testCount, 5, cacheContainers[0], null);
JBossWebMetaData webMetaData = SessionTestUtil.createWebMetaData(1, true, 1, -1);
- jbcm.init("test.war", webMetaData);
+ managers[0].init("test.war", webMetaData);
- jbcm.start();
+ managers[0].start();
- assertTrue("Passivation is enabled", jbcm.isPassivationEnabled());
- assertEquals("Correct max active count", 1, jbcm.getMaxActiveAllowed());
- assertEquals("Correct max idle time", 1, jbcm.getPassivationMaxIdleTime());
- assertEquals("Correct min idle time", -1, jbcm.getPassivationMinIdleTime());
+ assertTrue("Passivation is enabled", managers[0].isPassivationEnabled());
+ assertEquals("Correct max active count", 1, managers[0].getMaxActiveAllowed());
+ assertEquals("Correct max idle time", 1, managers[0].getPassivationMaxIdleTime());
+ assertEquals("Correct min idle time", -1, managers[0].getPassivationMinIdleTime());
// Set up a session
- Session sess1 = createAndUseSession(jbcm, "1", true, true);
+ Session sess1 = createAndUseSession(managers[0], "1", true, true);
- assertEquals("Session count correct", 1, jbcm.getActiveSessionCount());
- assertEquals("Local session count correct", 1, jbcm.getLocalActiveSessionCount());
+ assertEquals("Session count correct", 1, managers[0].getActiveSessionCount());
+ assertEquals("Local session count correct", 1, managers[0].getLocalActiveSessionCount());
// Should fail to create a 2nd
- createAndUseSession(jbcm, "2", false, false);
+ createAndUseSession(managers[0], "2", false, false);
// Confirm a session timeout clears space
sess1.setMaxInactiveInterval(1);
SessionTestUtil.sleepThread(1100);
- createAndUseSession(jbcm, "2", true, true);
+ createAndUseSession(managers[0], "2", true, true);
- assertEquals("Session count correct", 1, jbcm.getActiveSessionCount());
- assertEquals("Local session count correct", 1, jbcm.getLocalActiveSessionCount());
- assertEquals("Created session count correct", 2, jbcm.getCreatedSessionCount());
- assertEquals("Expired session count correct", 1, jbcm.getExpiredSessionCount());
- assertEquals("Passivated session count correct", 0, jbcm.getPassivatedSessionCount());
+ assertEquals("Session count correct", 1, managers[0].getActiveSessionCount());
+ assertEquals("Local session count correct", 1, managers[0].getLocalActiveSessionCount());
+ assertEquals("Created session count correct", 2, managers[0].getCreatedSessionCount());
+ assertEquals("Expired session count correct", 1, managers[0].getExpiredSessionCount());
+ assertEquals("Passivated session count correct", 0, managers[0].getPassivatedSessionCount());
// Sleep past maxIdleTime
SessionTestUtil.sleepThread(1100);
- assertEquals("Passivated session count correct", 0, jbcm.getPassivatedSessionCount());
+ assertEquals("Passivated session count correct", 0, managers[0].getPassivatedSessionCount());
- createAndUseSession(jbcm, "3", true, true);
+ createAndUseSession(managers[0], "3", true, true);
- assertEquals("Session count correct", 1, jbcm.getActiveSessionCount());
- assertEquals("Local session count correct", 1, jbcm.getLocalActiveSessionCount());
- assertEquals("Created session count correct", 3, jbcm.getCreatedSessionCount());
- assertEquals("Expired session count correct", 1, jbcm.getExpiredSessionCount());
- assertEquals("Passivated session count correct", 1, jbcm.getPassivatedSessionCount());
-
+ assertEquals("Session count correct", 1, managers[0].getActiveSessionCount());
+ assertEquals("Local session count correct", 1, managers[0].getLocalActiveSessionCount());
+ assertEquals("Created session count correct", 3, managers[0].getCreatedSessionCount());
+ assertEquals("Expired session count correct", 1, managers[0].getExpiredSessionCount());
+ assertEquals("Passivated session count correct", 1, managers[0].getPassivatedSessionCount());
}
public void testStandaloneMaxSessionsWithMinIdle() throws Exception
@@ -224,51 +227,53 @@
++testCount;
String passDir = getPassivationDir(testCount, 1);
- JBossCacheManager jbcm = SessionTestUtil.createManager("test" + testCount, 5, true, passDir, false, false, null);
+ cacheContainers[0] = SessionTestUtil.createCacheContainer(true, passDir, false, false);
+ cacheContainers[0].start();
+ managers[0] = SessionTestUtil.createManager("test" + testCount, 5, cacheContainers[0], null);
JBossWebMetaData webMetaData = SessionTestUtil.createWebMetaData(1, true, 3, 1);
- jbcm.init("test.war", webMetaData);
+ managers[0].init("test.war", webMetaData);
- jbcm.start();
+ managers[0].start();
- assertTrue("Passivation is enabled", jbcm.isPassivationEnabled());
- assertEquals("Correct max active count", 1, jbcm.getMaxActiveAllowed());
- assertEquals("Correct max idle time", 3, jbcm.getPassivationMaxIdleTime());
- assertEquals("Correct min idle time", 1, jbcm.getPassivationMinIdleTime());
+ assertTrue("Passivation is enabled", managers[0].isPassivationEnabled());
+ assertEquals("Correct max active count", 1, managers[0].getMaxActiveAllowed());
+ assertEquals("Correct max idle time", 3, managers[0].getPassivationMaxIdleTime());
+ assertEquals("Correct min idle time", 1, managers[0].getPassivationMinIdleTime());
// Set up a session
- Session sess1 = createAndUseSession(jbcm, "1", true, true);
+ Session sess1 = createAndUseSession(managers[0], "1", true, true);
- assertEquals("Session count correct", 1, jbcm.getActiveSessionCount());
- assertEquals("Local session count correct", 1, jbcm.getLocalActiveSessionCount());
+ assertEquals("Session count correct", 1, managers[0].getActiveSessionCount());
+ assertEquals("Local session count correct", 1, managers[0].getLocalActiveSessionCount());
// Should fail to create a 2nd
- createAndUseSession(jbcm, "2", false, false);
+ createAndUseSession(managers[0], "2", false, false);
// Confirm a session timeout clears space
sess1.setMaxInactiveInterval(1);
SessionTestUtil.sleepThread(1100);
- createAndUseSession(jbcm, "2", true, false);
+ createAndUseSession(managers[0], "2", true, false);
- assertEquals("Session count correct", 1, jbcm.getActiveSessionCount());
- assertEquals("Local session count correct", 1, jbcm.getLocalActiveSessionCount());
- assertEquals("Created session count correct", 2, jbcm.getCreatedSessionCount());
- assertEquals("Expired session count correct", 1, jbcm.getExpiredSessionCount());
+ assertEquals("Session count correct", 1, managers[0].getActiveSessionCount());
+ assertEquals("Local session count correct", 1, managers[0].getLocalActiveSessionCount());
+ assertEquals("Created session count correct", 2, managers[0].getCreatedSessionCount());
+ assertEquals("Expired session count correct", 1, managers[0].getExpiredSessionCount());
// Sleep past minIdleTime
SessionTestUtil.sleepThread(1100);
// assertTrue("Session 2 still valid", sess2.isValid());
- assertEquals("Passivated session count correct", 0, jbcm.getPassivatedSessionCount());
+ assertEquals("Passivated session count correct", 0, managers[0].getPassivatedSessionCount());
- createAndUseSession(jbcm, "3", true, true);
+ createAndUseSession(managers[0], "3", true, true);
- assertEquals("Session count correct", 1, jbcm.getActiveSessionCount());
- assertEquals("Local session count correct", 1, jbcm.getLocalActiveSessionCount());
- assertEquals("Created session count correct", 3, jbcm.getCreatedSessionCount());
- assertEquals("Expired session count correct", 1, jbcm.getExpiredSessionCount());
- assertEquals("Passivated session count correct", 1, jbcm.getPassivatedSessionCount());
+ assertEquals("Session count correct", 1, managers[0].getActiveSessionCount());
+ assertEquals("Local session count correct", 1, managers[0].getLocalActiveSessionCount());
+ assertEquals("Created session count correct", 3, managers[0].getCreatedSessionCount());
+ assertEquals("Expired session count correct", 1, managers[0].getExpiredSessionCount());
+ assertEquals("Passivated session count correct", 1, managers[0].getPassivatedSessionCount());
}
public void testReplicatedMaxSessions() throws Exception
@@ -276,54 +281,48 @@
log.info("Enter testReplicatedMaxSessions");
++testCount;
- JBossCacheManager jbcm0 = SessionTestUtil.createManager("test" + testCount, 1, false, null, false, false, null);
-
JBossWebMetaData webMetaData = SessionTestUtil.createWebMetaData(1);
- jbcm0.init("test.war", webMetaData);
+ for (int i = 0; i < cacheContainers.length; ++i)
+ {
+ cacheContainers[i] = SessionTestUtil.createCacheContainer(false, null, false, false);
+ cacheContainers[i].start();
+
+ managers[i] = SessionTestUtil.createManager("test" + testCount, 1, cacheContainers[i], null);
+ managers[i].init("test.war", webMetaData);
+ managers[1].start();
+
+ assertFalse("Passivation is disabled", managers[i].isPassivationEnabled());
+ assertEquals("Correct max active count", 1, managers[i].getMaxActiveAllowed());
+ assertEquals("Correct max inactive interval", 1, managers[i].getMaxInactiveInterval());
+ }
- jbcm0.start();
-
- assertFalse("Passivation is disabled", jbcm0.isPassivationEnabled());
- assertEquals("Correct max active count", 1, jbcm0.getMaxActiveAllowed());
- assertEquals("Correct max inactive interval", 1, jbcm0.getMaxInactiveInterval());
-
- JBossCacheManager jbcm1 = SessionTestUtil.createManager("test" + testCount, 1, false, null, false, false, null);
-
- jbcm1.init("test.war", webMetaData);
-
- jbcm1.start();
-
- assertFalse("Passivation is disabled", jbcm1.isPassivationEnabled());
- assertEquals("Correct max active count", 1, jbcm1.getMaxActiveAllowed());
- assertEquals("Correct max inactive interval", 1, jbcm1.getMaxInactiveInterval());
-
// Set up a session
- Session sess1 = createAndUseSession(jbcm0, "1", true, true);
+ Session sess1 = createAndUseSession(managers[0], "1", true, true);
- assertEquals("Session count correct", 1, jbcm0.getActiveSessionCount());
- assertEquals("Local session count correct", 1, jbcm0.getLocalActiveSessionCount());
- assertEquals("Session count correct", 1, jbcm1.getActiveSessionCount());
- assertEquals("Local session count correct", 0, jbcm1.getLocalActiveSessionCount());
+ assertEquals("Session count correct", 1, managers[0].getActiveSessionCount());
+ assertEquals("Local session count correct", 1, managers[0].getLocalActiveSessionCount());
+ assertEquals("Session count correct", 1, managers[1].getActiveSessionCount());
+ assertEquals("Local session count correct", 0, managers[1].getLocalActiveSessionCount());
// Should fail to create a 2nd
- createAndUseSession(jbcm1, "2", false, false);
+ createAndUseSession(managers[1], "2", false, false);
// Confirm a session timeout clears space
sess1.setMaxInactiveInterval(1);
- useSession(jbcm0, "1");
- SessionTestUtil.sleepThread(jbcm0.getMaxInactiveInterval() * 1000 + 100);
+ useSession(managers[0], "1");
+ SessionTestUtil.sleepThread(managers[0].getMaxInactiveInterval() * 1000 + 100);
- createAndUseSession(jbcm1, "2", true, true);
+ createAndUseSession(managers[1], "2", true, true);
- assertEquals("Session count correct", 2, jbcm0.getActiveSessionCount());
- assertEquals("Local session count correct", 1, jbcm0.getLocalActiveSessionCount());
- assertEquals("Created session count correct", 1, jbcm0.getCreatedSessionCount());
- assertEquals("Expired session count correct", 0, jbcm0.getExpiredSessionCount());
+ assertEquals("Session count correct", 2, managers[0].getActiveSessionCount());
+ assertEquals("Local session count correct", 1, managers[0].getLocalActiveSessionCount());
+ assertEquals("Created session count correct", 1, managers[0].getCreatedSessionCount());
+ assertEquals("Expired session count correct", 0, managers[0].getExpiredSessionCount());
- assertEquals("Session count correct", 1, jbcm1.getActiveSessionCount());
- assertEquals("Local session count correct", 1, jbcm0.getLocalActiveSessionCount());
- assertEquals("Created session count correct", 1, jbcm0.getCreatedSessionCount());
- assertEquals("Expired session count correct", 0, jbcm0.getExpiredSessionCount());
+ assertEquals("Session count correct", 1, managers[1].getActiveSessionCount());
+ assertEquals("Local session count correct", 1, managers[0].getLocalActiveSessionCount());
+ assertEquals("Created session count correct", 1, managers[0].getCreatedSessionCount());
+ assertEquals("Expired session count correct", 0, managers[0].getExpiredSessionCount());
}
public void testReplicatedMaxSessionsWithMaxIdle() throws Exception
@@ -331,62 +330,54 @@
log.info("Enter testReplicatedMaxSessionsWithMaxIdle");
++testCount;
- String passDir = getPassivationDir(testCount, 1);
- JBossCacheManager jbcm0 = SessionTestUtil.createManager("test" + testCount, 1, false, passDir, false, false, null);
-
JBossWebMetaData webMetaData = SessionTestUtil.createWebMetaData(1, true, 1, -1);
- jbcm0.init("test.war", webMetaData);
+ for (int i = 0; i < cacheContainers.length; ++i)
+ {
+ String passDir = getPassivationDir(testCount, i + 1);
+ cacheContainers[i] = SessionTestUtil.createCacheContainer(false, passDir, false, false);
+ cacheContainers[i].start();
+
+ managers[i] = SessionTestUtil.createManager("test" + testCount, 1, cacheContainers[i], null);
+ managers[i].init("test.war", webMetaData);
+ managers[i].start();
+
+ assertTrue("Passivation is enabled", managers[i].isPassivationEnabled());
+ assertEquals("Correct max active count", 1, managers[i].getMaxActiveAllowed());
+ assertEquals("Correct max idle time", 1, managers[i].getPassivationMaxIdleTime());
+ assertEquals("Correct min idle time", -1, managers[i].getPassivationMinIdleTime());
+ }
- jbcm0.start();
-
- assertTrue("Passivation is enabled", jbcm0.isPassivationEnabled());
- assertEquals("Correct max active count", 1, jbcm0.getMaxActiveAllowed());
- assertEquals("Correct max idle time", 1, jbcm0.getPassivationMaxIdleTime());
- assertEquals("Correct min idle time", -1, jbcm0.getPassivationMinIdleTime());
-
- passDir = getPassivationDir(testCount, 2);
- JBossCacheManager jbcm1 = SessionTestUtil.createManager("test" + testCount, 1, false, passDir, false, false, null);
-
- jbcm1.init("test.war", webMetaData);
-
- jbcm1.start();
-
- assertTrue("Passivation is enabled", jbcm1.isPassivationEnabled());
- assertEquals("Correct max active count", 1, jbcm1.getMaxActiveAllowed());
- assertEquals("Correct max idle time", 1, jbcm1.getPassivationMaxIdleTime());
- assertEquals("Correct min idle time", -1, jbcm1.getPassivationMinIdleTime());
-
// Set up a session
- createAndUseSession(jbcm0, "1", true, true);
+ createAndUseSession(managers[0], "1", true, true);
- assertEquals("Session count correct", 1, jbcm0.getActiveSessionCount());
- assertEquals("Local session count correct", 1, jbcm0.getLocalActiveSessionCount());
- assertEquals("Passivated session count correct", 0, jbcm0.getPassivatedSessionCount());
- assertEquals("Session count correct", 1, jbcm1.getActiveSessionCount());
- assertEquals("Local session count correct", 0, jbcm1.getLocalActiveSessionCount());
- assertEquals("Passivated session count correct", 0, jbcm1.getPassivatedSessionCount());
+ assertEquals("Session count correct", 1, managers[0].getActiveSessionCount());
+ assertEquals("Local session count correct", 1, managers[0].getLocalActiveSessionCount());
+ assertEquals("Passivated session count correct", 0, managers[0].getPassivatedSessionCount());
+ assertEquals("Session count correct", 1, managers[1].getActiveSessionCount());
+ assertEquals("Local session count correct", 0, managers[1].getLocalActiveSessionCount());
+ assertEquals("Passivated session count correct", 0, managers[1].getPassivatedSessionCount());
// Should fail to create a 2nd
- createAndUseSession(jbcm1, "2", false, false);
+ createAndUseSession(managers[1], "2", false, false);
// Sleep past maxIdleTime
SessionTestUtil.sleepThread(1100);
- assertEquals("Passivated session count correct", 0, jbcm1.getPassivatedSessionCount());
+ assertEquals("Passivated session count correct", 0, managers[1].getPassivatedSessionCount());
- createAndUseSession(jbcm1, "2", true, true);
+ createAndUseSession(managers[1], "2", true, true);
- assertEquals("Session count correct", 2, jbcm0.getActiveSessionCount());
- assertEquals("Local session count correct", 1, jbcm0.getLocalActiveSessionCount());
- assertEquals("Created session count correct", 1, jbcm0.getCreatedSessionCount());
- assertEquals("Expired session count correct", 0, jbcm0.getExpiredSessionCount());
- assertEquals("Passivated session count correct", 0, jbcm0.getPassivatedSessionCount());
+ assertEquals("Session count correct", 2, managers[0].getActiveSessionCount());
+ assertEquals("Local session count correct", 1, managers[0].getLocalActiveSessionCount());
+ assertEquals("Created session count correct", 1, managers[0].getCreatedSessionCount());
+ assertEquals("Expired session count correct", 0, managers[0].getExpiredSessionCount());
+ assertEquals("Passivated session count correct", 0, managers[0].getPassivatedSessionCount());
- assertEquals("Session count correct", 1, jbcm1.getActiveSessionCount());
- assertEquals("Local session count correct", 1, jbcm1.getLocalActiveSessionCount());
- assertEquals("Created session count correct", 1, jbcm1.getCreatedSessionCount());
- assertEquals("Expired session count correct", 0, jbcm1.getExpiredSessionCount());
- assertEquals("Passivated session count correct", 1, jbcm1.getPassivatedSessionCount());
+ assertEquals("Session count correct", 1, managers[1].getActiveSessionCount());
+ assertEquals("Local session count correct", 1, managers[1].getLocalActiveSessionCount());
+ assertEquals("Created session count correct", 1, managers[1].getCreatedSessionCount());
+ assertEquals("Expired session count correct", 0, managers[1].getExpiredSessionCount());
+ assertEquals("Passivated session count correct", 1, managers[1].getPassivatedSessionCount());
}
public void testReplicatedMaxSessionsWithMinIdle() throws Exception
@@ -394,62 +385,54 @@
log.info("Enter testReplicatedMaxSessionsWithMinIdle");
++testCount;
- String passDir = getPassivationDir(testCount, 1);
- JBossCacheManager jbcm0 = SessionTestUtil.createManager("test" + testCount, 1, false, passDir, false, false, null);
-
JBossWebMetaData webMetaData = SessionTestUtil.createWebMetaData(1, true, 3, 1);
- jbcm0.init("test.war", webMetaData);
+ for (int i = 0; i < cacheContainers.length; ++i)
+ {
+ String passDir = getPassivationDir(testCount, i + 1);
+ cacheContainers[i] = SessionTestUtil.createCacheContainer(false, passDir, false, false);
+ cacheContainers[i].start();
+
+ managers[i] = SessionTestUtil.createManager("test" + testCount, 1, cacheContainers[i], null);
+ managers[i].init("test.war", webMetaData);
+ managers[i].start();
+
+ assertTrue("Passivation is enabled", managers[i].isPassivationEnabled());
+ assertEquals("Correct max active count", 1, managers[i].getMaxActiveAllowed());
+ assertEquals("Correct max idle time", 3, managers[i].getPassivationMaxIdleTime());
+ assertEquals("Correct min idle time", 1, managers[i].getPassivationMinIdleTime());
+ }
- jbcm0.start();
-
- assertTrue("Passivation is enabled", jbcm0.isPassivationEnabled());
- assertEquals("Correct max active count", 1, jbcm0.getMaxActiveAllowed());
- assertEquals("Correct max idle time", 3, jbcm0.getPassivationMaxIdleTime());
- assertEquals("Correct min idle time", 1, jbcm0.getPassivationMinIdleTime());
-
- passDir = getPassivationDir(testCount, 2);
- JBossCacheManager jbcm1 = SessionTestUtil.createManager("test" + testCount, 1, false, passDir, false, false, null);
-
- jbcm1.init("test.war", webMetaData);
-
- jbcm1.start();
-
- assertTrue("Passivation is enabled", jbcm1.isPassivationEnabled());
- assertEquals("Correct max active count", 1, jbcm1.getMaxActiveAllowed());
- assertEquals("Correct max idle time", 3, jbcm1.getPassivationMaxIdleTime());
- assertEquals("Correct min idle time", 1, jbcm1.getPassivationMinIdleTime());
-
// Set up a session
- createAndUseSession(jbcm0, "1", true, true);
+ createAndUseSession(managers[0], "1", true, true);
- assertEquals("Session count correct", 1, jbcm0.getActiveSessionCount());
- assertEquals("Local session count correct", 1, jbcm0.getLocalActiveSessionCount());
- assertEquals("Passivated session count correct", 0, jbcm0.getPassivatedSessionCount());
- assertEquals("Session count correct", 1, jbcm1.getActiveSessionCount());
- assertEquals("Local session count correct", 0, jbcm1.getLocalActiveSessionCount());
- assertEquals("Passivated session count correct", 0, jbcm0.getPassivatedSessionCount());
+ assertEquals("Session count correct", 1, managers[0].getActiveSessionCount());
+ assertEquals("Local session count correct", 1, managers[0].getLocalActiveSessionCount());
+ assertEquals("Passivated session count correct", 0, managers[0].getPassivatedSessionCount());
+ assertEquals("Session count correct", 1, managers[1].getActiveSessionCount());
+ assertEquals("Local session count correct", 0, managers[1].getLocalActiveSessionCount());
+ assertEquals("Passivated session count correct", 0, managers[0].getPassivatedSessionCount());
// Should fail to create a 2nd
- createAndUseSession(jbcm1, "2", false, false);
+ createAndUseSession(managers[1], "2", false, false);
// Sleep past maxIdleTime
SessionTestUtil.sleepThread(1100);
- assertEquals("Passivated session count correct", 0, jbcm1.getPassivatedSessionCount());
+ assertEquals("Passivated session count correct", 0, managers[1].getPassivatedSessionCount());
- createAndUseSession(jbcm1, "2", true, true);
+ createAndUseSession(managers[1], "2", true, true);
- assertEquals("Session count correct", 2, jbcm0.getActiveSessionCount());
- assertEquals("Local session count correct", 1, jbcm0.getLocalActiveSessionCount());
- assertEquals("Created session count correct", 1, jbcm0.getCreatedSessionCount());
- assertEquals("Expired session count correct", 0, jbcm0.getExpiredSessionCount());
- assertEquals("Passivated session count correct", 0, jbcm0.getPassivatedSessionCount());
+ assertEquals("Session count correct", 2, managers[0].getActiveSessionCount());
+ assertEquals("Local session count correct", 1, managers[0].getLocalActiveSessionCount());
+ assertEquals("Created session count correct", 1, managers[0].getCreatedSessionCount());
+ assertEquals("Expired session count correct", 0, managers[0].getExpiredSessionCount());
+ assertEquals("Passivated session count correct", 0, managers[0].getPassivatedSessionCount());
- assertEquals("Session count correct", 1, jbcm1.getActiveSessionCount());
- assertEquals("Local session count correct", 1, jbcm1.getLocalActiveSessionCount());
- assertEquals("Created session count correct", 1, jbcm1.getCreatedSessionCount());
- assertEquals("Expired session count correct", 0, jbcm1.getExpiredSessionCount());
- assertEquals("Passivated session count correct", 1, jbcm1.getPassivatedSessionCount());
+ assertEquals("Session count correct", 1, managers[1].getActiveSessionCount());
+ assertEquals("Local session count correct", 1, managers[1].getLocalActiveSessionCount());
+ assertEquals("Created session count correct", 1, managers[1].getCreatedSessionCount());
+ assertEquals("Expired session count correct", 0, managers[1].getExpiredSessionCount());
+ assertEquals("Passivated session count correct", 1, managers[1].getPassivatedSessionCount());
}
@@ -458,181 +441,53 @@
log.info("Enter testTotalReplication");
++testCount;
- String passDir = getPassivationDir(testCount, 1);
- JBossCacheManager jbcm0 = SessionTestUtil.createManager("test" + testCount, 1, false, passDir, true, false, null);
-
JBossWebMetaData webMetaData = SessionTestUtil.createWebMetaData(1, true, 3, 1);
- jbcm0.init("test.war", webMetaData);
+ for (int i = 0; i < cacheContainers.length; ++i)
+ {
+ String passDir = getPassivationDir(testCount, i + 1);
+ cacheContainers[i] = SessionTestUtil.createCacheContainer(false, passDir, true, false);
+ cacheContainers[i].start();
+
+ managers[i] = SessionTestUtil.createManager("test" + testCount, 1, cacheContainers[i], null);
+ managers[i].init("test.war", webMetaData);
+ managers[i].start();
+
+ assertTrue("Passivation is enabled", managers[i].isPassivationEnabled());
+ assertEquals("Correct max active count", 1, managers[i].getMaxActiveAllowed());
+ assertEquals("Correct max idle time", 3, managers[i].getPassivationMaxIdleTime());
+ assertEquals("Correct min idle time", 1, managers[i].getPassivationMinIdleTime());
+ }
- jbcm0.start();
-
- assertTrue("Passivation is enabled", jbcm0.isPassivationEnabled());
- assertEquals("Correct max active count", 1, jbcm0.getMaxActiveAllowed());
- assertEquals("Correct max idle time", 3, jbcm0.getPassivationMaxIdleTime());
- assertEquals("Correct min idle time", 1, jbcm0.getPassivationMinIdleTime());
-
- passDir = getPassivationDir(testCount, 2);
- JBossCacheManager jbcm1 = SessionTestUtil.createManager("test" + testCount, 1, false, passDir, true, false, null);
-
- jbcm1.init("test.war", webMetaData);
-
- jbcm1.start();
-
- assertTrue("Passivation is enabled", jbcm1.isPassivationEnabled());
- assertEquals("Correct max active count", 1, jbcm1.getMaxActiveAllowed());
- assertEquals("Correct max idle time", 3, jbcm1.getPassivationMaxIdleTime());
- assertEquals("Correct min idle time", 1, jbcm1.getPassivationMinIdleTime());
-
// Set up a session
- createAndUseSession(jbcm0, "1", true, true);
+ createAndUseSession(managers[0], "1", true, true);
- assertEquals("Session count correct", 1, jbcm0.getActiveSessionCount());
- assertEquals("Local session count correct", 1, jbcm0.getLocalActiveSessionCount());
- assertEquals("Session count correct", 1, jbcm1.getActiveSessionCount());
- assertEquals("Local session count correct", 0, jbcm1.getLocalActiveSessionCount());
+ assertEquals("Session count correct", 1, managers[0].getActiveSessionCount());
+ assertEquals("Local session count correct", 1, managers[0].getLocalActiveSessionCount());
+ assertEquals("Session count correct", 1, managers[1].getActiveSessionCount());
+ assertEquals("Local session count correct", 0, managers[1].getLocalActiveSessionCount());
// Should fail to create a 2nd
- createAndUseSession(jbcm1, "2", false, false);
+ createAndUseSession(managers[1], "2", false, false);
// Sleep past maxIdleTime
SessionTestUtil.sleepThread(1100);
- assertEquals("Passivated session count correct", 0, jbcm1.getPassivatedSessionCount());
+ assertEquals("Passivated session count correct", 0, managers[1].getPassivatedSessionCount());
- createAndUseSession(jbcm1, "2", true, true);
+ createAndUseSession(managers[1], "2", true, true);
- assertEquals("Session count correct", 2, jbcm0.getActiveSessionCount());
- assertEquals("Local session count correct", 1, jbcm0.getLocalActiveSessionCount());
- assertEquals("Created session count correct", 1, jbcm0.getCreatedSessionCount());
- assertEquals("Expired session count correct", 0, jbcm0.getExpiredSessionCount());
+ assertEquals("Session count correct", 2, managers[0].getActiveSessionCount());
+ assertEquals("Local session count correct", 1, managers[0].getLocalActiveSessionCount());
+ assertEquals("Created session count correct", 1, managers[0].getCreatedSessionCount());
+ assertEquals("Expired session count correct", 0, managers[0].getExpiredSessionCount());
- assertEquals("Session count correct", 1, jbcm1.getActiveSessionCount());
- assertEquals("Local session count correct", 1, jbcm0.getLocalActiveSessionCount());
- assertEquals("Created session count correct", 1, jbcm0.getCreatedSessionCount());
- assertEquals("Expired session count correct", 0, jbcm0.getExpiredSessionCount());
+ assertEquals("Session count correct", 1, managers[1].getActiveSessionCount());
+ assertEquals("Local session count correct", 1, managers[0].getLocalActiveSessionCount());
+ assertEquals("Created session count correct", 1, managers[0].getCreatedSessionCount());
+ assertEquals("Expired session count correct", 0, managers[0].getExpiredSessionCount());
}
- public void testRegionBasedMarshalling() throws Exception
- {
- log.info("Enter testRegionBasedMarshalling");
-
- ++testCount;
- String passDir = getPassivationDir(testCount, 1);
- JBossCacheManager jbcm0 = SessionTestUtil.createManager("test" + testCount, 1, false, passDir, false, true, null);
-
- JBossWebMetaData webMetaData = SessionTestUtil.createWebMetaData(1, true, 3, 1);
- jbcm0.init("test.war", webMetaData);
-
- jbcm0.start();
-
- assertTrue("Passivation is enabled", jbcm0.isPassivationEnabled());
- assertEquals("Correct max active count", 1, jbcm0.getMaxActiveAllowed());
- assertEquals("Correct max idle time", 3, jbcm0.getPassivationMaxIdleTime());
- assertEquals("Correct min idle time", 1, jbcm0.getPassivationMinIdleTime());
-
- passDir = getPassivationDir(testCount, 2);
- JBossCacheManager jbcm1 = SessionTestUtil.createManager("test" + testCount, 1, false, passDir, false, true, null);
-
- jbcm1.init("test.war", webMetaData);
-
- jbcm1.start();
-
- assertTrue("Passivation is enabled", jbcm1.isPassivationEnabled());
- assertEquals("Correct max active count", 1, jbcm1.getMaxActiveAllowed());
- assertEquals("Correct max idle time", 3, jbcm1.getPassivationMaxIdleTime());
- assertEquals("Correct min idle time", 1, jbcm1.getPassivationMinIdleTime());
-
- // Set up a session
- createAndUseSession(jbcm0, "1", true, true);
-
- assertEquals("Session count correct", 1, jbcm0.getActiveSessionCount());
- assertEquals("Local session count correct", 1, jbcm0.getLocalActiveSessionCount());
- assertEquals("Session count correct", 1, jbcm1.getActiveSessionCount());
- assertEquals("Local session count correct", 0, jbcm1.getLocalActiveSessionCount());
-
- // Should fail to create a 2nd
- createAndUseSession(jbcm1, "2", false, false);
-
- // Sleep past maxIdleTime
- SessionTestUtil.sleepThread(1100);
-
- assertEquals("Passivated session count correct", 0, jbcm1.getPassivatedSessionCount());
-
- createAndUseSession(jbcm1, "2", true, true);
-
- assertEquals("Session count correct", 2, jbcm0.getActiveSessionCount());
- assertEquals("Local session count correct", 1, jbcm0.getLocalActiveSessionCount());
- assertEquals("Created session count correct", 1, jbcm0.getCreatedSessionCount());
- assertEquals("Expired session count correct", 0, jbcm0.getExpiredSessionCount());
-
- assertEquals("Session count correct", 1, jbcm1.getActiveSessionCount());
- assertEquals("Local session count correct", 1, jbcm0.getLocalActiveSessionCount());
- assertEquals("Created session count correct", 1, jbcm0.getCreatedSessionCount());
- assertEquals("Expired session count correct", 0, jbcm0.getExpiredSessionCount());
-
- }
-
- public void testTotalReplicationWithMarshalling() throws Exception
- {
- log.info("Enter testTotalReplicationWithMarshalling");
-
- ++testCount;
- String passDir = getPassivationDir(testCount, 1);
- JBossCacheManager jbcm0 = SessionTestUtil.createManager("test" + testCount, 1, false, passDir, true, true, null);
-
- JBossWebMetaData webMetaData = SessionTestUtil.createWebMetaData(1, true, 3, 1);
- jbcm0.init("test.war", webMetaData);
-
- jbcm0.start();
-
- assertTrue("Passivation is enabled", jbcm0.isPassivationEnabled());
- assertEquals("Correct max active count", 1, jbcm0.getMaxActiveAllowed());
- assertEquals("Correct max idle time", 3, jbcm0.getPassivationMaxIdleTime());
- assertEquals("Correct min idle time", 1, jbcm0.getPassivationMinIdleTime());
-
- passDir = getPassivationDir(testCount, 2);
- JBossCacheManager jbcm1 = SessionTestUtil.createManager("test" + testCount, 1, false, passDir, true, true, null);
-
- jbcm1.init("test.war", webMetaData);
-
- jbcm1.start();
-
- assertTrue("Passivation is enabled", jbcm1.isPassivationEnabled());
- assertEquals("Correct max active count", 1, jbcm1.getMaxActiveAllowed());
- assertEquals("Correct max idle time", 3, jbcm1.getPassivationMaxIdleTime());
- assertEquals("Correct min idle time", 1, jbcm1.getPassivationMinIdleTime());
-
- // Set up a session
- createAndUseSession(jbcm0, "1", true, true);
-
- assertEquals("Session count correct", 1, jbcm0.getActiveSessionCount());
- assertEquals("Local session count correct", 1, jbcm0.getLocalActiveSessionCount());
- assertEquals("Session count correct", 1, jbcm1.getActiveSessionCount());
- assertEquals("Local session count correct", 0, jbcm1.getLocalActiveSessionCount());
-
- // Should fail to create a 2nd
- createAndUseSession(jbcm1, "2", false, false);
-
- // Sleep past maxIdleTime
- SessionTestUtil.sleepThread(1100);
-
- assertEquals("Passivated session count correct", 0, jbcm1.getPassivatedSessionCount());
-
- createAndUseSession(jbcm1, "2", true, true);
-
- assertEquals("Session count correct", 2, jbcm0.getActiveSessionCount());
- assertEquals("Local session count correct", 1, jbcm0.getLocalActiveSessionCount());
- assertEquals("Created session count correct", 1, jbcm0.getCreatedSessionCount());
- assertEquals("Expired session count correct", 0, jbcm0.getExpiredSessionCount());
-
- assertEquals("Session count correct", 1, jbcm1.getActiveSessionCount());
- assertEquals("Local session count correct", 1, jbcm0.getLocalActiveSessionCount());
- assertEquals("Created session count correct", 1, jbcm0.getCreatedSessionCount());
- assertEquals("Expired session count correct", 0, jbcm0.getExpiredSessionCount());
-
- }
-
public void testStandaloneRedeploy() throws Exception
{
log.info("Enter testStandaloneRedeploy");
@@ -652,99 +507,99 @@
{
++testCount;
String passDir = getPassivationDir(testCount, 1);
- DistributedCacheManagerFactory factory = SessionTestUtil.createDistributedCacheManagerFactory(true, passDir, false, false, false);
- JBossCacheManager jbcm = SessionTestUtil.createManager("test" + testCount, 300, factory, null);
+ cacheContainers[0] = SessionTestUtil.createCacheContainer(true, passDir, false, false);
+ cacheContainers[0].start();
+ managers[0] = SessionTestUtil.createManager("test" + testCount, 300, cacheContainers[0], null);
JBossWebMetaData webMetaData = SessionTestUtil.createWebMetaData(2, true, 3, 1);
- jbcm.init("test.war", webMetaData);
+ managers[0].init("test.war", webMetaData);
- jbcm.start();
+ managers[0].start();
- assertTrue("Passivation is enabled", jbcm.isPassivationEnabled());
- assertEquals("Correct max active count", 2, jbcm.getMaxActiveAllowed());
- assertEquals("Correct max idle time", 3, jbcm.getPassivationMaxIdleTime());
- assertEquals("Correct min idle time", 1, jbcm.getPassivationMinIdleTime());
+ assertTrue("Passivation is enabled", managers[0].isPassivationEnabled());
+ assertEquals("Correct max active count", 2, managers[0].getMaxActiveAllowed());
+ assertEquals("Correct max idle time", 3, managers[0].getPassivationMaxIdleTime());
+ assertEquals("Correct min idle time", 1, managers[0].getPassivationMinIdleTime());
// Set up a session
- createAndUseSession(jbcm, "1", true, true);
+ createAndUseSession(managers[0], "1", true, true);
- assertEquals("Session count correct", 1, jbcm.getActiveSessionCount());
- assertEquals("Local session count correct", 1, jbcm.getLocalActiveSessionCount());
+ assertEquals("Session count correct", 1, managers[0].getActiveSessionCount());
+ assertEquals("Local session count correct", 1, managers[0].getLocalActiveSessionCount());
// And a 2nd
- createAndUseSession(jbcm, "2", true, true);
+ createAndUseSession(managers[0], "2", true, true);
- assertEquals("Session count correct", 2, jbcm.getActiveSessionCount());
- assertEquals("Local session count correct", 2, jbcm.getLocalActiveSessionCount());
- assertEquals("Created session count correct", 2, jbcm.getCreatedSessionCount());
- assertEquals("Expired session count correct", 0, jbcm.getExpiredSessionCount());
+ assertEquals("Session count correct", 2, managers[0].getActiveSessionCount());
+ assertEquals("Local session count correct", 2, managers[0].getLocalActiveSessionCount());
+ assertEquals("Created session count correct", 2, managers[0].getCreatedSessionCount());
+ assertEquals("Expired session count correct", 0, managers[0].getExpiredSessionCount());
// Sleep past minIdleTime
SessionTestUtil.sleepThread(1100);
- assertEquals("Passivated session count correct", 0, jbcm.getPassivatedSessionCount());
+ assertEquals("Passivated session count correct", 0, managers[0].getPassivatedSessionCount());
- createAndUseSession(jbcm, "3", true, true);
+ createAndUseSession(managers[0], "3", true, true);
- assertEquals("Session count correct", 2, jbcm.getActiveSessionCount());
- assertEquals("Local session count correct", 2, jbcm.getLocalActiveSessionCount());
- assertEquals("Created session count correct", 3, jbcm.getCreatedSessionCount());
- assertEquals("Expired session count correct", 0, jbcm.getExpiredSessionCount());
- assertEquals("Passivated session count correct", 1, jbcm.getPassivatedSessionCount());
+ assertEquals("Session count correct", 2, managers[0].getActiveSessionCount());
+ assertEquals("Local session count correct", 2, managers[0].getLocalActiveSessionCount());
+ assertEquals("Created session count correct", 3, managers[0].getCreatedSessionCount());
+ assertEquals("Expired session count correct", 0, managers[0].getExpiredSessionCount());
+ assertEquals("Passivated session count correct", 1, managers[0].getPassivatedSessionCount());
- jbcm.stop();
+ managers[0].stop();
if (restartCache)
{
- dcmFactories.remove(factory);
+ cacheContainers[0].stop();
passDir = getPassivationDir(testCount, 1);
- jbcm = SessionTestUtil.createManager("test" + testCount, 5, true, passDir, false, false, null);
+ cacheContainers[0] = SessionTestUtil.createCacheContainer(true, passDir, false, false);
}
- else
- {
- jbcm = SessionTestUtil.createManager("test" + testCount, 5, factory, null);
- }
- jbcm.init("test.war", webMetaData);
- jbcm.start();
+ managers[0] = SessionTestUtil.createManager("test" + testCount, 5, cacheContainers[0], null);
- assertTrue("Passivation is enabled", jbcm.isPassivationEnabled());
- assertEquals("Correct max active count", 2, jbcm.getMaxActiveAllowed());
- assertEquals("Correct max idle time", 3, jbcm.getPassivationMaxIdleTime());
- assertEquals("Correct min idle time", 1, jbcm.getPassivationMinIdleTime());
+ managers[0].init("test.war", webMetaData);
- assertEquals("Session count correct", 2, jbcm.getActiveSessionCount());
- assertEquals("Local session count correct", 0, jbcm.getLocalActiveSessionCount());
- assertEquals("Created session count correct", 0, jbcm.getCreatedSessionCount());
- assertEquals("Expired session count correct", 0, jbcm.getExpiredSessionCount());
- assertEquals("Passivated session count correct", 1, jbcm.getPassivatedSessionCount());
+ managers[0].start();
+ assertTrue("Passivation is enabled", managers[0].isPassivationEnabled());
+ assertEquals("Correct max active count", 2, managers[0].getMaxActiveAllowed());
+ assertEquals("Correct max idle time", 3, managers[0].getPassivationMaxIdleTime());
+ assertEquals("Correct min idle time", 1, managers[0].getPassivationMinIdleTime());
+
+ assertEquals("Session count correct", 2, managers[0].getActiveSessionCount());
+ assertEquals("Local session count correct", 0, managers[0].getLocalActiveSessionCount());
+ assertEquals("Created session count correct", 0, managers[0].getCreatedSessionCount());
+ assertEquals("Expired session count correct", 0, managers[0].getExpiredSessionCount());
+ assertEquals("Passivated session count correct", 1, managers[0].getPassivatedSessionCount());
+
// Sleep past minIdleTime
SessionTestUtil.sleepThread(1100);
- createAndUseSession(jbcm, "4", true, true);
+ createAndUseSession(managers[0], "4", true, true);
}
public void testReplicatedRedeploy() throws Exception
{
log.info("Enter testReplicatedRedeploy");
- replicatedWarRedeployTest(false, false, false, false, false);
+ replicatedWarRedeployTest(false, false, false, false);
}
public void testReplicatedRedeployWarAndCache() throws Exception
{
log.info("Enter testReplicatedRedeployWarAndCache");
- replicatedWarRedeployTest(true, false, false, false, false);
+ replicatedWarRedeployTest(true, false, false, false);
}
public void testReplicatedRestart() throws Exception
{
log.info("Enter testReplicatedRestart");
- replicatedWarRedeployTest(true, true, false, false, false);
+ replicatedWarRedeployTest(true, true, false, false);
}
@@ -752,117 +607,104 @@
{
log.info("Enter testReplicatedRestartWithPurge");
- replicatedWarRedeployTest(true, true, false, false, true);
+ replicatedWarRedeployTest(true, true, false, true);
}
private void replicatedWarRedeployTest(boolean restartCache,
boolean fullRestart,
boolean totalReplication,
- boolean marshalling,
boolean purgeOnStartStop)
throws Exception
{
++testCount;
- String passDir = getPassivationDir(testCount, 1);
- DistributedCacheManagerFactory factory = SessionTestUtil.createDistributedCacheManagerFactory(false, passDir, totalReplication, marshalling, purgeOnStartStop);
- JBossCacheManager jbcm = SessionTestUtil.createManager("test" + testCount, 300, factory, null);
-
JBossWebMetaData webMetaData = SessionTestUtil.createWebMetaData(2, true, 30, 1);
- jbcm.init("test.war", webMetaData);
+ for (int i = 0; i < cacheContainers.length; ++i)
+ {
+ String passDir = getPassivationDir(testCount, i + 1);
+ cacheContainers[i] = SessionTestUtil.createCacheContainer(false, passDir, totalReplication, purgeOnStartStop);
+ cacheContainers[i].start();
+
+ managers[i] = SessionTestUtil.createManager("test" + testCount, 300, cacheContainers[i], null);
+ managers[i].init("test.war", webMetaData);
+ managers[i].start();
+
+ assertTrue("Passivation is enabled", managers[i].isPassivationEnabled());
+ assertEquals("Correct max active count", 2, managers[i].getMaxActiveAllowed());
+ assertEquals("Correct max idle time", 30, managers[i].getPassivationMaxIdleTime());
+ assertEquals("Correct min idle time", 1, managers[i].getPassivationMinIdleTime());
+ }
- jbcm.start();
+ SessionTestUtil.blockUntilViewsReceived(cacheContainers, 10000);
- assertTrue("Passivation is enabled", jbcm.isPassivationEnabled());
- assertEquals("Correct max active count", 2, jbcm.getMaxActiveAllowed());
- assertEquals("Correct max idle time", 30, jbcm.getPassivationMaxIdleTime());
- assertEquals("Correct min idle time", 1, jbcm.getPassivationMinIdleTime());
-
- passDir = getPassivationDir(testCount, 2);
- DistributedCacheManagerFactory factory1 = SessionTestUtil.createDistributedCacheManagerFactory(false, passDir, totalReplication, marshalling, purgeOnStartStop);
- JBossCacheManager jbcm1 = SessionTestUtil.createManager("test" + testCount, 300, factory1, null);
-
- jbcm1.init("test.war", webMetaData);
-
- jbcm1.start();
-
- SessionTestUtil.blockUntilViewsReceived(new JBossCacheManager[]{ jbcm, jbcm1 }, 10000);
-
- assertTrue("Passivation is enabled", jbcm1.isPassivationEnabled());
- assertEquals("Correct max active count", 2, jbcm1.getMaxActiveAllowed());
- assertEquals("Correct max idle time", 30, jbcm1.getPassivationMaxIdleTime());
- assertEquals("Correct min idle time", 1, jbcm1.getPassivationMinIdleTime());
-
// Set up a session
- createAndUseSession(jbcm, "1", true, true);
+ createAndUseSession(managers[0], "1", true, true);
- assertEquals("Session count correct", 1, jbcm.getActiveSessionCount());
- assertEquals("Local session count correct", 1, jbcm.getLocalActiveSessionCount());
- assertEquals("Session count correct", 1, jbcm1.getActiveSessionCount());
- assertEquals("Local session count correct", 0, jbcm1.getLocalActiveSessionCount());
+ assertEquals("Session count correct", 1, managers[0].getActiveSessionCount());
+ assertEquals("Local session count correct", 1, managers[0].getLocalActiveSessionCount());
+ assertEquals("Session count correct", 1, managers[1].getActiveSessionCount());
+ assertEquals("Local session count correct", 0, managers[1].getLocalActiveSessionCount());
// Create a 2nd
- createAndUseSession(jbcm1, "2", true, true);
+ createAndUseSession(managers[1], "2", true, true);
- assertEquals("Session count correct", 2, jbcm.getActiveSessionCount());
- assertEquals("Local session count correct", 1, jbcm.getLocalActiveSessionCount());
- assertEquals("Created session count correct", 1, jbcm.getCreatedSessionCount());
- assertEquals("Expired session count correct", 0, jbcm.getExpiredSessionCount());
- assertEquals("Session count correct", 2, jbcm1.getActiveSessionCount());
- assertEquals("Local session count correct", 1, jbcm1.getLocalActiveSessionCount());
- assertEquals("Created session count correct", 1, jbcm1.getCreatedSessionCount());
- assertEquals("Expired session count correct", 0, jbcm1.getExpiredSessionCount());
+ assertEquals("Session count correct", 2, managers[0].getActiveSessionCount());
+ assertEquals("Local session count correct", 1, managers[0].getLocalActiveSessionCount());
+ assertEquals("Created session count correct", 1, managers[0].getCreatedSessionCount());
+ assertEquals("Expired session count correct", 0, managers[0].getExpiredSessionCount());
+ assertEquals("Session count correct", 2, managers[1].getActiveSessionCount());
+ assertEquals("Local session count correct", 1, managers[1].getLocalActiveSessionCount());
+ assertEquals("Created session count correct", 1, managers[1].getCreatedSessionCount());
+ assertEquals("Expired session count correct", 0, managers[1].getExpiredSessionCount());
// Sleep past minIdleTime
SessionTestUtil.sleepThread(1100);
- assertEquals("Passivated session count correct", 0, jbcm1.getPassivatedSessionCount());
+ assertEquals("Passivated session count correct", 0, managers[1].getPassivatedSessionCount());
- createAndUseSession(jbcm1, "3", true, true);
+ createAndUseSession(managers[1], "3", true, true);
// jbcm has 3 active because receipt of repl doesn't trigger passivation
- assertEquals("Session count correct", 3, jbcm.getActiveSessionCount());
- assertEquals("Local session count correct", 1, jbcm.getLocalActiveSessionCount());
- assertEquals("Created session count correct", 1, jbcm.getCreatedSessionCount());
- assertEquals("Expired session count correct", 0, jbcm.getExpiredSessionCount());
- assertEquals("Passivated session count correct", 0, jbcm.getPassivatedSessionCount());
+ assertEquals("Session count correct", 3, managers[0].getActiveSessionCount());
+ assertEquals("Local session count correct", 1, managers[0].getLocalActiveSessionCount());
+ assertEquals("Created session count correct", 1, managers[0].getCreatedSessionCount());
+ assertEquals("Expired session count correct", 0, managers[0].getExpiredSessionCount());
+ assertEquals("Passivated session count correct", 0, managers[0].getPassivatedSessionCount());
// jbcm1 only has 2 active since it passivated one when it created 3rd
- assertEquals("Session count correct", 2, jbcm1.getActiveSessionCount());
+ assertEquals("Session count correct", 2, managers[1].getActiveSessionCount());
// Both active sessions are local, as the remote session is oldest so we passivate it first
- assertEquals("Local session count correct", 2, jbcm1.getLocalActiveSessionCount());
- assertEquals("Created session count correct", 2, jbcm1.getCreatedSessionCount());
- assertEquals("Expired session count correct", 0, jbcm1.getExpiredSessionCount());
- assertEquals("Passivated session count correct", 1, jbcm1.getPassivatedSessionCount());
+ assertEquals("Local session count correct", 2, managers[1].getLocalActiveSessionCount());
+ assertEquals("Created session count correct", 2, managers[1].getCreatedSessionCount());
+ assertEquals("Expired session count correct", 0, managers[1].getExpiredSessionCount());
+ assertEquals("Passivated session count correct", 1, managers[1].getPassivatedSessionCount());
if (fullRestart)
{
- jbcm1.stop();
- dcmFactories.remove(factory1);
+ managers[1].stop();
+ cacheContainers[1].stop();
}
- jbcm.stop();
+ managers[0].stop();
if (restartCache)
{
- dcmFactories.remove(factory);
+ cacheContainers[0].stop();
- passDir = getPassivationDir(testCount, 1);
- factory = SessionTestUtil.createDistributedCacheManagerFactory(false, passDir, totalReplication, marshalling, purgeOnStartStop);
- jbcm = SessionTestUtil.createManager("test" + testCount, 300, factory, null);
+ String passDir = getPassivationDir(testCount, 1);
+ cacheContainers[0] = SessionTestUtil.createCacheContainer(false, passDir, totalReplication, purgeOnStartStop);
+ cacheContainers[0].start();
}
- else
- {
- jbcm = SessionTestUtil.createManager("test" + testCount, 300, factory, null);
- }
- jbcm.init("test.war", webMetaData);
- jbcm.start();
+ managers[0] = SessionTestUtil.createManager("test" + testCount, 300, cacheContainers[0], null);
- assertTrue("Passivation is enabled", jbcm.isPassivationEnabled());
- assertEquals("Correct max active count", 2, jbcm.getMaxActiveAllowed());
- assertEquals("Correct max idle time", 30, jbcm.getPassivationMaxIdleTime());
- assertEquals("Correct min idle time", 1, jbcm.getPassivationMinIdleTime());
+ managers[0].init("test.war", webMetaData);
+ managers[0].start();
+ assertTrue("Passivation is enabled", managers[0].isPassivationEnabled());
+ assertEquals("Correct max active count", 2, managers[0].getMaxActiveAllowed());
+ assertEquals("Correct max idle time", 30, managers[0].getPassivationMaxIdleTime());
+ assertEquals("Correct min idle time", 1, managers[0].getPassivationMinIdleTime());
+
// Do we expect content?
boolean expectContent = true;
// First, see if we expect a purge on redeploy
@@ -872,46 +714,46 @@
// on redeploy
if (expectPurge)
{
- expectContent = !fullRestart && (!totalReplication || marshalling);
+ expectContent = !fullRestart && !totalReplication;
}
if (expectContent)
{
- assertEquals("Session count correct", 2, jbcm.getActiveSessionCount());
- assertEquals("Local session count correct", 0, jbcm.getLocalActiveSessionCount());
- assertEquals("Created session count correct", 0, jbcm.getCreatedSessionCount());
- assertEquals("Expired session count correct", 0, jbcm.getExpiredSessionCount());
- assertEquals("Passivated session count correct", 1, jbcm.getPassivatedSessionCount());
+ assertEquals("Session count correct", 2, managers[0].getActiveSessionCount());
+ assertEquals("Local session count correct", 0, managers[0].getLocalActiveSessionCount());
+ assertEquals("Created session count correct", 0, managers[0].getCreatedSessionCount());
+ assertEquals("Expired session count correct", 0, managers[0].getExpiredSessionCount());
+ assertEquals("Passivated session count correct", 1, managers[0].getPassivatedSessionCount());
}
else
{
- assertEquals("Session count correct", 0, jbcm.getActiveSessionCount());
- assertEquals("Local session count correct", 0, jbcm.getLocalActiveSessionCount());
- assertEquals("Created session count correct", 0, jbcm.getCreatedSessionCount());
- assertEquals("Expired session count correct", 0, jbcm.getExpiredSessionCount());
- assertEquals("Passivated session count correct", 0, jbcm.getPassivatedSessionCount());
+ assertEquals("Session count correct", 0, managers[0].getActiveSessionCount());
+ assertEquals("Local session count correct", 0, managers[0].getLocalActiveSessionCount());
+ assertEquals("Created session count correct", 0, managers[0].getCreatedSessionCount());
+ assertEquals("Expired session count correct", 0, managers[0].getExpiredSessionCount());
+ assertEquals("Passivated session count correct", 0, managers[0].getPassivatedSessionCount());
}
if (!fullRestart)
{
- assertEquals("Session count correct", 2, jbcm1.getActiveSessionCount());
- assertEquals("Local session count correct", 2, jbcm1.getLocalActiveSessionCount());
- assertEquals("Created session count correct", 2, jbcm1.getCreatedSessionCount());
- assertEquals("Expired session count correct", 0, jbcm1.getExpiredSessionCount());
- assertEquals("Passivated session count correct", 1, jbcm1.getPassivatedSessionCount());
+ assertEquals("Session count correct", 2, managers[1].getActiveSessionCount());
+ assertEquals("Local session count correct", 2, managers[1].getLocalActiveSessionCount());
+ assertEquals("Created session count correct", 2, managers[1].getCreatedSessionCount());
+ assertEquals("Expired session count correct", 0, managers[1].getExpiredSessionCount());
+ assertEquals("Passivated session count correct", 1, managers[1].getPassivatedSessionCount());
}
// Sleep past minIdleTime
SessionTestUtil.sleepThread(1100);
- createAndUseSession(jbcm, "4", true, true);
+ createAndUseSession(managers[0], "4", true, true);
}
public void testTotalReplicatedRedeploy() throws Exception
{
log.info("Enter testTotalReplicatedRedeploy");
- replicatedWarRedeployTest(false, false, true, false, false);
+ replicatedWarRedeployTest(false, false, true, false);
}
@@ -919,7 +761,7 @@
{
log.info("Enter testTotalReplicatedRedeployWarAndCache");
- replicatedWarRedeployTest(true, false, true, false, false);
+ replicatedWarRedeployTest(true, false, true, false);
}
@@ -927,7 +769,7 @@
{
log.info("Enter testTotalReplicatedRestart");
- replicatedWarRedeployTest(true, true, true, false, false);
+ replicatedWarRedeployTest(true, true, true, false);
}
@@ -935,80 +777,14 @@
{
log.info("Enter testTotalReplicatedRestartWithPurge");
- replicatedWarRedeployTest(true, true, true, false, true);
+ replicatedWarRedeployTest(true, true, true, true);
}
- public void testMarshalledRedeploy() throws Exception
+ private Session createAndUseSession(JBossCacheManager<?> manager, String id, boolean canCreate, boolean access) throws Exception
{
- log.info("Enter testMarshalledRedeploy");
-
- replicatedWarRedeployTest(false, false, false, true, false);
-
- }
-
- public void testMarshalledRedeployWarAndCache() throws Exception
- {
- log.info("Enter testMarshalledRedeployWarAndCache");
-
- replicatedWarRedeployTest(true, false, false, true, false);
-
- }
-
- public void testMarshalledRestart() throws Exception
- {
- log.info("Enter testMarshalledRestart");
-
- replicatedWarRedeployTest(true, true, false, true, false);
-
- }
-
- public void testMarshalledRestartWithPurge() throws Exception
- {
- log.info("Enter testMarshalledRestartWithPurge");
-
- replicatedWarRedeployTest(true, true, false, true, true);
-
- }
-
- public void testTotalMarshalledRedeploy() throws Exception
- {
- log.info("Enter testTotalMarshalledRedeploy");
-
- replicatedWarRedeployTest(false, false, true, true, false);
-
- }
-
- public void testTotalMarshalledRedeployWarAndCache() throws Exception
- {
- log.info("Enter testTotalMarshalledRedeployWarAndCache");
-
- replicatedWarRedeployTest(true, false, true, true, false);
-
- }
-
- public void testTotalMarshalledRestart() throws Exception
- {
- log.info("Enter testTotalMarshalledRestart");
-
- replicatedWarRedeployTest(true, true, true, true, false);
-
- }
-
- public void testTotalMarshalledRestartWithPurge() throws Exception
- {
- log.info("Enter testTotalMarshalledRestartWithPurge");
-
- replicatedWarRedeployTest(true, true, true, true, true);
-
- }
-
- private Session createAndUseSession(JBossCacheManager jbcm, String id,
- boolean canCreate, boolean access)
- throws Exception
- {
// Shift to Manager interface when we simulate Tomcat
- Manager mgr = jbcm;
+ Manager mgr = manager;
Session sess = mgr.findSession(id);
assertNull("session does not exist", sess);
try
@@ -1031,7 +807,7 @@
sess.access();
sess.getSession().setAttribute("test", "test");
- jbcm.storeSession(sess);
+ manager.storeSession(sess);
sess.endAccess();
}
@@ -1039,18 +815,17 @@
return sess;
}
- private void useSession(JBossCacheManager jbcm, String id)
- throws Exception
+ private void useSession(JBossCacheManager<?> manager, String id) throws Exception
{
// Shift to Manager interface when we simulate Tomcat
- Manager mgr = jbcm;
+ Manager mgr = manager;
Session sess = mgr.findSession(id);
assertNotNull("session exists", sess);
sess.access();
sess.getSession().setAttribute("test", "test");
- jbcm.storeSession(sess);
+ manager.storeSession(sess);
sess.endAccess();
}
Modified: branches/infinispan-int/testsuite/src/main/org/jboss/test/cluster/defaultcfg/simpleweb/test/SessionExpirationUnitTestCase.java
===================================================================
--- branches/infinispan-int/testsuite/src/main/org/jboss/test/cluster/defaultcfg/simpleweb/test/SessionExpirationUnitTestCase.java 2010-09-01 20:34:46 UTC (rev 107941)
+++ branches/infinispan-int/testsuite/src/main/org/jboss/test/cluster/defaultcfg/simpleweb/test/SessionExpirationUnitTestCase.java 2010-09-01 20:36:15 UTC (rev 107942)
@@ -22,18 +22,15 @@
package org.jboss.test.cluster.defaultcfg.simpleweb.test;
-import java.util.HashSet;
-import java.util.Set;
-
import junit.framework.TestCase;
import org.apache.catalina.Session;
+import org.infinispan.manager.CacheContainer;
import org.jboss.logging.Logger;
import org.jboss.metadata.web.jboss.JBossWebMetaData;
import org.jboss.test.cluster.testutil.JGroupsSystemPropertySupport;
import org.jboss.test.cluster.testutil.SessionTestUtil;
import org.jboss.web.tomcat.service.session.JBossCacheManager;
-import org.jboss.web.tomcat.service.session.distributedcache.spi.TestDistributedCacheManagerFactory;
/**
* Unit tests of session expiration
@@ -50,7 +47,8 @@
private static long testCount = System.currentTimeMillis();
private JGroupsSystemPropertySupport jgroupsSupport;
- private Set<TestDistributedCacheManagerFactory> dcmFactories = new HashSet<TestDistributedCacheManagerFactory>();
+ private CacheContainer[] cacheContainers = new CacheContainer[2];
+ private JBossCacheManager<?>[] managers = new JBossCacheManager[cacheContainers.length];
/**
* Create a new SessionExpirationUnitTestCase.
@@ -85,20 +83,21 @@
jgroupsSupport.restoreProperties();
}
- for (TestDistributedCacheManagerFactory factory : dcmFactories)
- {
- try
+ for (JBossCacheManager<?> manager: managers)
+ {
+ if (manager != null)
{
- factory.cleanup(true);
+ manager.stop();
}
- catch (Exception e)
+ }
+
+ for (CacheContainer cacheContainer: cacheContainers)
+ {
+ if (cacheContainer != null)
{
- log.error(e.getMessage(), e);
+ cacheContainer.stop();
}
-
}
-
- dcmFactories.clear();
}
}
@@ -112,58 +111,54 @@
log.info("Enter testMaxInactiveIntervalReplication");
++testCount;
-
- JBossCacheManager jbcm0= SessionTestUtil.createManager("test" + testCount, 5, false, null, true, true, null);
-
JBossWebMetaData webMetaData = SessionTestUtil.createWebMetaData(2);
- jbcm0.init("test.war", webMetaData);
+ for (int i = 0; i < cacheContainers.length; ++i)
+ {
+ cacheContainers[i] = SessionTestUtil.createCacheContainer(false, null, true, false);
+ cacheContainers[i].start();
+
+ managers[i] = SessionTestUtil.createManager("test" + testCount, 5, cacheContainers[i], null);
+ managers[i].init("test.war", webMetaData);
+ managers[i].start();
+ }
- jbcm0.start();
-
- JBossCacheManager jbcm1 = SessionTestUtil.createManager("test" + testCount, 5, false, null, true, true, null);
-
- jbcm1.init("test.war", webMetaData);
-
- jbcm1.start();
-
// Set up a session
String id = "1";
- Session sess = jbcm0.findSession(id);
+ Session sess = managers[0].findSession(id);
assertNull("session does not exist", sess);
- sess = jbcm0.createSession(id);
+ sess = managers[0].createSession(id);
sess.access();
sess.getSession().setAttribute("test", "test");
- jbcm0.storeSession(sess);
+ managers[0].storeSession(sess);
sess.endAccess();
- assertEquals("Session count correct", 1, jbcm0.getActiveSessionCount());
- assertEquals("Local session count correct", 1, jbcm0.getLocalActiveSessionCount());
- assertEquals("Session count correct", 1, jbcm1.getActiveSessionCount());
- assertEquals("Local session count correct", 0, jbcm1.getLocalActiveSessionCount());
+ assertEquals("Session count correct", 1, managers[0].getActiveSessionCount());
+ assertEquals("Local session count correct", 1, managers[0].getLocalActiveSessionCount());
+ assertEquals("Session count correct", 1, managers[1].getActiveSessionCount());
+ assertEquals("Local session count correct", 0, managers[1].getLocalActiveSessionCount());
// Confirm a session timeout clears space
- sess = jbcm0.findSession(id);
+ sess = managers[0].findSession(id);
sess.access();
sess.setMaxInactiveInterval(1);
- jbcm0.storeSession(sess);
+ managers[0].storeSession(sess);
sess.endAccess();
SessionTestUtil.sleepThread(1005);
- jbcm1.backgroundProcess();
+ managers[1].backgroundProcess();
- assertEquals("Session count correct", 1, jbcm0.getActiveSessionCount());
- assertEquals("Local session count correct", 1, jbcm0.getLocalActiveSessionCount());
- assertEquals("Session count correct", 0, jbcm1.getActiveSessionCount());
- assertEquals("Local session count correct", 0, jbcm1.getLocalActiveSessionCount());
+ assertEquals("Session count correct", 1, managers[0].getActiveSessionCount());
+ assertEquals("Local session count correct", 1, managers[0].getLocalActiveSessionCount());
+ assertEquals("Session count correct", 0, managers[1].getActiveSessionCount());
+ assertEquals("Local session count correct", 0, managers[1].getLocalActiveSessionCount());
- jbcm0.backgroundProcess();
+ managers[0].backgroundProcess();
- assertEquals("Session count correct", 0, jbcm0.getActiveSessionCount());
- assertEquals("Local session count correct", 0, jbcm0.getLocalActiveSessionCount());
- assertEquals("Session count correct", 0, jbcm1.getActiveSessionCount());
- assertEquals("Local session count correct", 0, jbcm1.getLocalActiveSessionCount());
+ assertEquals("Session count correct", 0, managers[0].getActiveSessionCount());
+ assertEquals("Local session count correct", 0, managers[0].getLocalActiveSessionCount());
+ assertEquals("Session count correct", 0, managers[1].getActiveSessionCount());
+ assertEquals("Local session count correct", 0, managers[1].getLocalActiveSessionCount());
}
-
}
Modified: branches/infinispan-int/testsuite/src/main/org/jboss/test/cluster/defaultcfg/simpleweb/test/StoppedManagerUnitTestCase.java
===================================================================
--- branches/infinispan-int/testsuite/src/main/org/jboss/test/cluster/defaultcfg/simpleweb/test/StoppedManagerUnitTestCase.java 2010-09-01 20:34:46 UTC (rev 107941)
+++ branches/infinispan-int/testsuite/src/main/org/jboss/test/cluster/defaultcfg/simpleweb/test/StoppedManagerUnitTestCase.java 2010-09-01 20:36:15 UTC (rev 107942)
@@ -22,18 +22,15 @@
package org.jboss.test.cluster.defaultcfg.simpleweb.test;
-import java.util.HashSet;
-import java.util.Set;
-
import junit.framework.TestCase;
import org.apache.catalina.Manager;
import org.apache.catalina.Session;
+import org.infinispan.manager.CacheContainer;
import org.jboss.logging.Logger;
import org.jboss.metadata.web.jboss.JBossWebMetaData;
import org.jboss.test.cluster.testutil.SessionTestUtil;
import org.jboss.web.tomcat.service.session.JBossCacheManager;
-import org.jboss.web.tomcat.service.session.distributedcache.spi.TestDistributedCacheManagerFactory;
/**
* Tests that a stopped session manager reacts correctly to Manager API calls.
@@ -48,7 +45,8 @@
private static long testCount = System.currentTimeMillis();
- private Set<TestDistributedCacheManagerFactory> dcmFactories = new HashSet<TestDistributedCacheManagerFactory>();
+ private CacheContainer cacheContainer;
+ private JBossCacheManager<?> manager;
/**
* Create a new SessionCountUnitTestCase.
@@ -69,22 +67,15 @@
}
finally
{
-
-
- for (TestDistributedCacheManagerFactory factory : dcmFactories)
- {
- try
- {
- factory.cleanup(true);
- }
- catch (Exception e)
- {
- log.error(e.getMessage(), e);
- }
-
+ if (manager != null)
+ {
+ manager.stop();
}
- dcmFactories.clear();
+ if (cacheContainer != null)
+ {
+ cacheContainer.stop();
+ }
}
}
@@ -94,45 +85,44 @@
++testCount;
- JBossCacheManager jbcm = SessionTestUtil.createManager("test" + testCount, 30, true, null, false, false, null);
+ cacheContainer = SessionTestUtil.createCacheContainer(true, null, false, false);
+ manager = SessionTestUtil.createManager("test" + testCount, 30, cacheContainer, null);
JBossWebMetaData webMetaData = SessionTestUtil.createWebMetaData(100);
- jbcm.init("test.war", webMetaData);
+ manager.init("test.war", webMetaData);
- jbcm.start();
+ manager.start();
// Set up a session
- Session sess1 = createAndUseSession(jbcm, "1", true, true);
- Session sess2 = createAndUseSession(jbcm, "2", true, true);
+ Session sess1 = createAndUseSession(manager, "1", true, true);
+ Session sess2 = createAndUseSession(manager, "2", true, true);
// Sanity check
- Session[] sessions = jbcm.findSessions();
+ Session[] sessions = manager.findSessions();
assertNotNull(sessions);
assertEquals(2, sessions.length);
- jbcm.stop();
+ manager.stop();
- assertNull(jbcm.findSession("1"));
- assertNull(jbcm.findSession("2"));
- assertNull(jbcm.findSessions());
- assertNull(jbcm.createEmptySession());
- assertNull(jbcm.createSession());
- assertNull(jbcm.createSession("3"));
+ assertNull(manager.findSession("1"));
+ assertNull(manager.findSession("2"));
+ assertNull(manager.findSessions());
+ assertNull(manager.createEmptySession());
+ assertNull(manager.createSession());
+ assertNull(manager.createSession("3"));
assertFalse(sess1.isValid());
assertFalse(sess2.isValid());
- jbcm.add(sess1); // shouldn't blow up
+ manager.add(sess1); // shouldn't blow up
assertFalse(sess1.isValid());
- jbcm.remove(sess2);
+ manager.remove(sess2);
}
- private Session createAndUseSession(JBossCacheManager jbcm, String id,
- boolean canCreate, boolean access)
- throws Exception
+ private Session createAndUseSession(JBossCacheManager<?> manager, String id, boolean canCreate, boolean access) throws Exception
{
// Shift to Manager interface when we simulate Tomcat
- Manager mgr = jbcm;
+ Manager mgr = manager;
Session sess = mgr.findSession(id);
assertNull("session does not exist", sess);
try
@@ -155,7 +145,7 @@
sess.access();
sess.getSession().setAttribute("test", "test");
- jbcm.storeSession(sess);
+ manager.storeSession(sess);
sess.endAccess();
}
Modified: branches/infinispan-int/testsuite/src/main/org/jboss/test/cluster/testutil/CacheConfigTestSetup.java
===================================================================
--- branches/infinispan-int/testsuite/src/main/org/jboss/test/cluster/testutil/CacheConfigTestSetup.java 2010-09-01 20:34:46 UTC (rev 107941)
+++ branches/infinispan-int/testsuite/src/main/org/jboss/test/cluster/testutil/CacheConfigTestSetup.java 2010-09-01 20:36:15 UTC (rev 107942)
@@ -29,9 +29,8 @@
import junit.framework.Test;
import junit.framework.TestSuite;
+import org.infinispan.manager.CacheContainer;
import org.jboss.test.JBossTestSetup;
-import org.jboss.web.tomcat.service.session.distributedcache.spi.DistributedCacheManagerFactory;
-import org.jboss.web.tomcat.service.session.distributedcache.spi.TestDistributedCacheManagerFactory;
/**
* @author Brian Stansberry
@@ -39,19 +38,17 @@
*/
public class CacheConfigTestSetup extends JBossTestSetup
{
- public static Test getTestSetup(Class<?> clazz, final TestDistributedCacheManagerFactory[] dcmFactories, final boolean local, final String passivationDir, final boolean totalReplication, final boolean marshalling)
- throws Exception
+ public static Test getTestSetup(Class<?> clazz, final CacheContainer[] cacheContainers, final boolean local, final String passivationDir, final boolean totalReplication) throws Exception
{
final TestSuite suite = new TestSuite();
suite.addTest(new TestSuite(clazz));
- return new CacheConfigTestSetup(suite, dcmFactories, local, passivationDir, totalReplication, marshalling);
+ return new CacheConfigTestSetup(suite, cacheContainers, local, passivationDir, totalReplication);
}
- private DistributedCacheManagerFactory[] dcmFactories;
+ private CacheContainer[] cacheContainers;
private String passivationDir;
private boolean local;
private boolean totalReplication;
- private boolean marshalling;
private final List<String> cleanupPaths = new ArrayList<String>();
/**
@@ -60,19 +57,18 @@
* @param test
* @throws Exception
*/
- public CacheConfigTestSetup(Test test, TestDistributedCacheManagerFactory[] dcmFactories, boolean local, String passivationDir, boolean totalReplication, final boolean marshalling) throws Exception
+ public CacheConfigTestSetup(Test test, CacheContainer[] cacheContainers, boolean local, String passivationDir, boolean totalReplication) throws Exception
{
super(test);
- this.dcmFactories = dcmFactories;
+ this.cacheContainers = cacheContainers;
this.passivationDir = passivationDir;
this.local = local;
this.totalReplication = totalReplication;
- this.marshalling = marshalling;
}
protected void setUp() throws Exception
{
- if (dcmFactories == null) return;
+ if (cacheContainers == null) return;
JGroupsSystemPropertySupport jgSupport = new JGroupsSystemPropertySupport();
try
@@ -95,14 +91,15 @@
}
}
long now = System.currentTimeMillis();
- for (int i = 0; i < dcmFactories.length; i++)
+ for (int i = 0; i < cacheContainers.length; i++)
{
String cacheStore = (passivationDir == null ? null : new File(passivationDir, String.valueOf( now + i)).getAbsolutePath());
if (cacheStore != null)
{
cleanupPaths.add(0, cacheStore);
}
- dcmFactories[i] = SessionTestUtil.createDistributedCacheManagerFactory(local, cacheStore, totalReplication, marshalling, true);
+ cacheContainers[i] = SessionTestUtil.createCacheContainer(local, cacheStore, totalReplication, true);
+ cacheContainers[i].start();
}
}
finally
@@ -119,6 +116,11 @@
protected void tearDown() throws Exception
{
+ for (CacheContainer cacheContainer: cacheContainers)
+ {
+ cacheContainer.stop();
+ }
+
for (String path : cleanupPaths)
{
SessionTestUtil.cleanFilesystem(path);
Modified: branches/infinispan-int/testsuite/src/main/org/jboss/test/cluster/testutil/SessionTestUtil.java
===================================================================
--- branches/infinispan-int/testsuite/src/main/org/jboss/test/cluster/testutil/SessionTestUtil.java 2010-09-01 20:34:46 UTC (rev 107941)
+++ branches/infinispan-int/testsuite/src/main/org/jboss/test/cluster/testutil/SessionTestUtil.java 2010-09-01 20:36:15 UTC (rev 107942)
@@ -55,10 +55,9 @@
import org.infinispan.loaders.file.FileCacheStoreConfig;
import org.infinispan.manager.CacheContainer;
import org.infinispan.manager.DefaultCacheManager;
+import org.infinispan.manager.EmbeddedCacheManager;
import org.infinispan.remoting.transport.Address;
-import org.infinispan.transaction.tm.BatchModeTransactionManager;
import org.infinispan.util.concurrent.IsolationLevel;
-import org.jboss.ha.ispn.DefaultCacheContainerRegistry;
import org.jboss.logging.Logger;
import org.jboss.metadata.javaee.spec.EmptyMetaData;
import org.jboss.metadata.web.jboss.JBossWebMetaData;
@@ -77,8 +76,9 @@
import org.jboss.test.cluster.web.mocks.RequestHandlerValve;
import org.jboss.web.tomcat.service.session.JBossCacheManager;
import org.jboss.web.tomcat.service.session.distributedcache.ispn.CacheSource;
-import org.jboss.web.tomcat.service.session.distributedcache.spi.DistributedCacheManagerFactory;
+import org.jboss.web.tomcat.service.session.distributedcache.ispn.DistributedCacheManagerFactory;
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.TestDistributedCacheManagerFactory;
/**
@@ -95,8 +95,8 @@
private static final Logger log = Logger.getLogger(SessionTestUtil.class);
private static final String[] STRING_ONLY_TYPES = { String.class.getName() };
private static final String[] STRING_BOOLEAN_TYPES = { String.class.getName(), boolean.class.getName() };
-
- public static JBossCacheManager createManager(String warName, int maxInactiveInterval,
+/*
+ public static JBossCacheManager<?> createManager(String warName, int maxInactiveInterval,
boolean local, String passivationDir,
boolean totalReplication, boolean marshalling,
String jvmRoute) throws Exception
@@ -105,37 +105,91 @@
totalReplication, marshalling, false, jvmRoute);
}
- public static JBossCacheManager createManager(String warName, int maxInactiveInterval,
+ public static JBossCacheManager<?> createManager(String warName, int maxInactiveInterval,
boolean local, String passivationDir,
boolean totalReplication, boolean marshalling,
boolean purgeCacheLoader,
String jvmRoute) throws Exception
{
- DistributedCacheManagerFactory factory = createDistributedCacheManagerFactory(local, passivationDir, totalReplication, marshalling, purgeCacheLoader);
- return createManager(warName, maxInactiveInterval, factory, jvmRoute);
+ EmbeddedCacheManager cacheContainer = createCacheContainer(local, passivationDir, totalReplication, marshalling, purgeCacheLoader);
+ return createManager(warName, maxInactiveInterval, cacheContainer, jvmRoute);
}
-
- public static JBossCacheManager createManager(String warName,
+*/
+ public static JBossCacheManager<?> createManager(String warName,
int maxInactiveInterval,
- DistributedCacheManagerFactory factory,
+ final CacheContainer cacheContainer,
String jvmRoute)
{
- if (factory == null)
+ if (cacheContainer == null)
+ {
throw new IllegalStateException("Failed to initialize distributedManagerFactory");
+ }
- JBossCacheManager jbcm = new JBossCacheManager(factory);
- jbcm.setSnapshotMode(SnapshotMode.INSTANT);
+ DistributedCacheManagerFactory factory = new DistributedCacheManagerFactory();
+ CacheSource source = new CacheSource()
+ {
+ @Override
+ public <K, V> Cache<K, V> getCache(LocalDistributableSessionManager manager)
+ {
+ return cacheContainer.getCache(manager.getContextName());
+ }
+ };
- setupContainer(warName, jvmRoute, jbcm);
+ factory.setCacheSource(source);
+ JBossCacheManager<OutgoingDistributableSessionData> manager = new JBossCacheManager<OutgoingDistributableSessionData>(factory);
+ manager.setSnapshotMode(SnapshotMode.INSTANT);
+
+ setupContainer(warName, jvmRoute, manager);
+
// Do this after assigning the manager to the container, or else
// the container's setting will override ours
// Can't just set the container as their config is per minute not per second
- jbcm.setMaxInactiveInterval(maxInactiveInterval);
+ manager.setMaxInactiveInterval(maxInactiveInterval);
- return jbcm;
+ return manager;
}
+ public static EmbeddedCacheManager createCacheContainer(boolean local, String passivationDir, boolean totalReplication, boolean purgeCacheLoader) throws Exception
+ {
+ GlobalConfiguration globalConfig = local ? GlobalConfiguration.getNonClusteredDefault() : GlobalConfiguration.getClusteredDefault();
+
+ Configuration config = new Configuration();
+ config.setInvocationBatchingEnabled(true);
+ config.setIsolationLevel(IsolationLevel.REPEATABLE_READ);
+ config.setSyncReplTimeout(20000);
+ config.setLockAcquisitionTimeout(15000);
+ config.setCacheMode(local ? CacheMode.LOCAL : (totalReplication ? CacheMode.REPL_SYNC : CacheMode.DIST_SYNC));
+
+ // Block for commits -- no races between test driver and replication
+ config.setSyncCommitPhase(true);
+ config.setSyncRollbackPhase(true);
+
+ if (passivationDir != null)
+ {
+ CacheLoaderManagerConfig managerConfig = new CacheLoaderManagerConfig();
+ managerConfig.setPassivation(true);
+ managerConfig.setShared(true);
+
+ FileCacheStoreConfig fileConfig = new FileCacheStoreConfig();
+ fileConfig.setLocation(passivationDir);
+ fileConfig.setFetchPersistentState(true);
+ fileConfig.setPurgeOnStartup(purgeCacheLoader);
+ fileConfig.setIgnoreModifications(false);
+
+ managerConfig.setCacheLoaderConfigs(Collections.<CacheLoaderConfig>singletonList(fileConfig));
+
+ config.setCacheLoaderManagerConfig(managerConfig);
+ }
+
+ if (config.getCacheMode().isDistributed())
+ {
+ config.setNumOwners(2);
+ }
+
+ return new DefaultCacheManager(globalConfig, config);
+ }
+/*
public static DistributedCacheManagerFactory createDistributedCacheManagerFactory(boolean local, String passivationDir,
boolean totalReplication, boolean marshalling, boolean purgeCacheLoader) throws Exception
{
@@ -192,7 +246,7 @@
return factory;
}
-
+*/
public static void setupContainer(String warName, String jvmRoute, Manager mgr)
{
MockEngine engine = new MockEngine();
@@ -394,32 +448,6 @@
}
/**
- * Loops, continually calling {@link #areCacheViewsComplete(JBossCacheManager[])}
- * until it either returns true or <code>timeout</code> ms have elapsed.
- *
- * @param cacheManager caches which must all have consistent views
- * @param timeout max number of ms to loop
- * @throws RuntimeException if <code>timeout</code> ms have elapse without
- * all caches having the same number of members.
- */
- public static void blockUntilViewsReceived(JBossCacheManager[] cacheManager, long timeout)
- {
- long failTime = System.currentTimeMillis() + timeout;
-
- while (System.currentTimeMillis() < failTime)
- {
- sleepThread(100);
- if (areCacheViewsComplete(cacheManager))
- {
- return;
- }
- }
-
- throw new RuntimeException("timed out before caches had complete views");
- }
-
-
- /**
* Loops, continually calling {@link #areCacheViewsComplete(TestDistributedCacheManagerFactory[])}
* until it either returns true or <code>timeout</code> ms have elapsed.
*
@@ -428,14 +456,14 @@
* @throws RuntimeException if <code>timeout</code> ms have elapse without
* all caches having the same number of members.
*/
- public static void blockUntilViewsReceived(TestDistributedCacheManagerFactory[] dcmFactories, long timeout)
+ public static void blockUntilViewsReceived(EmbeddedCacheManager[] cacheContainers, long timeout)
{
long failTime = System.currentTimeMillis() + timeout;
while (System.currentTimeMillis() < failTime)
{
sleepThread(100);
- if (areCacheViewsComplete(dcmFactories))
+ if (areCacheViewsComplete(cacheContainers))
{
return;
}
@@ -444,37 +472,8 @@
throw new RuntimeException("timed out before caches had complete views");
}
-
-
/**
* Checks each cache to see if the number of elements in the array
- * returned by {@link EmbeddedCacheManager#getMembers()} matches the size of
- * the <code>dcmFactories</code> parameter.
- *
- * @param cacheManager factory whose caches should form a View
- * @return <code>true</code> if all caches have
- * <code>factories.length</code> members; false otherwise
- * @throws IllegalStateException if any of the caches have MORE view
- * members than factories.length
- */
- public static boolean areCacheViewsComplete(JBossCacheManager[] cacheManager)
- {
- int memberCount = cacheManager.length;
-
- for (int i = 0; i < memberCount; i++)
- {
- if (!isCacheViewComplete( memberCount, true))
- {
- return false;
- }
- }
-
- return true;
-
- }
-
- /**
- * Checks each cache to see if the number of elements in the array
* returned by {@link TestDistributedCacheFactory#getMembers()} matches the size of
* the <code>dcmFactories</code> parameter.
*
@@ -484,18 +483,16 @@
* @throws IllegalStateException if any of the caches have MORE view
* members than factories.length
*/
- public static boolean areCacheViewsComplete(TestDistributedCacheManagerFactory[] dcmFactories)
+ public static boolean areCacheViewsComplete(EmbeddedCacheManager[] cacheContainers)
{
- return areCacheViewsComplete(dcmFactories, true);
+ return areCacheViewsComplete(cacheContainers, true);
}
- public static boolean areCacheViewsComplete(TestDistributedCacheManagerFactory[] dcmFactories, boolean barfIfTooManyMembers)
+ public static boolean areCacheViewsComplete(EmbeddedCacheManager[] cacheContainers, boolean barfIfTooManyMembers)
{
- int memberCount = dcmFactories.length;
-
- for (int i = 0; i < memberCount; i++)
+ for (EmbeddedCacheManager cacheContainer: cacheContainers)
{
- if (!isCacheViewComplete(dcmFactories[i], memberCount, barfIfTooManyMembers))
+ if (!isCacheViewComplete(cacheContainer, cacheContainers.length, barfIfTooManyMembers))
{
return false;
}
@@ -504,9 +501,9 @@
return true;
}
- public static boolean isCacheViewComplete(int memberCount, boolean barfIfTooManyMembers)
+ public static boolean isCacheViewComplete(EmbeddedCacheManager cacheContainer, int memberCount, boolean barfIfTooManyMembers)
{
- List<Address> members = DefaultCacheContainerRegistry.getInstance().getCacheContainer("web-session").getMembers();
+ List<Address> members = cacheContainer.getMembers();
if (members == null || memberCount > members.size())
{
return false;
@@ -516,43 +513,8 @@
if (barfIfTooManyMembers)
{
// This is an exceptional condition
- StringBuffer sb = new StringBuffer("Cache had ");
- sb.append(members.size());
- sb.append(" members; expecting ");
- sb.append(memberCount);
- sb.append(". Members were (");
- for (int j = 0; j < members.size(); j++)
- {
- if (j > 0)
- {
- sb.append(", ");
- }
- sb.append(members.get(j));
- }
- sb.append(')');
-
- throw new IllegalStateException(sb.toString());
- }
- else return false;
- }
-
- return true;
- }
-
- public static boolean isCacheViewComplete(TestDistributedCacheManagerFactory factory, int memberCount, boolean barfIfTooManyMembers)
- {
- List<Object> members = factory.getMembers();
- if (members == null || memberCount > members.size())
- {
- return false;
- }
- else if (memberCount < members.size())
- {
- if (barfIfTooManyMembers)
- {
- // This is an exceptional condition
StringBuffer sb = new StringBuffer("Cache at address ");
- sb.append(factory.getLocalAddress());
+ sb.append(cacheContainer.getAddress());
sb.append(" had ");
sb.append(members.size());
sb.append(" members; expecting ");
More information about the jboss-cvs-commits
mailing list