[jboss-cvs] JBossAS SVN: r79773 - in trunk/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
Mon Oct 20 17:55:50 EDT 2008


Author: bstansberry at jboss.com
Date: 2008-10-20 17:55:50 -0400 (Mon, 20 Oct 2008)
New Revision: 79773

Added:
   trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/simpleweb/test/ReplicationToPassivatedSessionUnitTestCase.java
Modified:
   trunk/testsuite/src/main/org/jboss/test/cluster/testutil/CacheConfigTestSetup.java
Log:
[JBAS-5942] Reapply r79544, r 79545, r79550 commits

Copied: trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/simpleweb/test/ReplicationToPassivatedSessionUnitTestCase.java (from rev 79544, trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/simpleweb/test/ReplicationToPassivatedSessionUnitTestCase.java)
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/simpleweb/test/ReplicationToPassivatedSessionUnitTestCase.java	                        (rev 0)
+++ trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/simpleweb/test/ReplicationToPassivatedSessionUnitTestCase.java	2008-10-20 21:55:50 UTC (rev 79773)
@@ -0,0 +1,187 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.test.cluster.defaultcfg.simpleweb.test;
+
+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.jboss.cache.pojo.PojoCache;
+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.JGroupsSystemPropertySupport;
+import org.jboss.test.cluster.testutil.SessionTestUtil;
+import org.jboss.test.cluster.web.mocks.SetAttributesRequestHandler;
+import org.jboss.web.tomcat.service.session.JBossCacheManager;
+
+/**
+ * Unit tests of session expiration
+ * 
+ * TODO move some of the other expiration tests here where we can
+ * more closely control the test timing
+ * 
+ * @author Brian Stansberry
+ */
+public class ReplicationToPassivatedSessionUnitTestCase extends TestCase
+{
+   protected static PojoCache[] pojoCaches = new PojoCache[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 Set<JBossCacheManager> managers = new HashSet<JBossCacheManager>();
+   private String tempDir;
+   
+   public ReplicationToPassivatedSessionUnitTestCase(String name)
+   {
+      super(name);
+   }
+   
+   public static Test suite() throws Exception
+   {
+      File tmpDir = new File(System.getProperty("java.io.tmpdir"));
+      File root = new File(tmpDir, ReplicationToPassivatedSessionUnitTestCase.class.getSimpleName());
+      return CacheConfigTestSetup.getTestSetup(ReplicationToPassivatedSessionUnitTestCase.class, pojoCaches, false, root.getAbsolutePath(), !useBuddyRepl, false);
+   }
+
+   @Override
+   protected void tearDown() throws Exception
+   {
+      try
+      {
+         super.tearDown();
+      }
+      finally
+      {         
+         SessionTestUtil.clearDistributedCacheManagerFactory();
+         
+         for (JBossCacheManager manager : managers)      
+            manager.stop();
+         
+         managers.clear();
+      }
+   }
+   
+   protected ReplicationGranularity getReplicationGranularity()
+   {
+      return ReplicationGranularity.SESSION;
+   }
+   
+   protected ReplicationTrigger getReplicationTrigger()
+   {
+      return ReplicationTrigger.SET_AND_NON_PRIMITIVE_GET;
+   }
+   
+   public void testReplicationToPassivatedSession() throws Exception
+   {
+      log.info("++++ Starting testReplicationToPassivatedSession ++++");
+      
+      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];
+      
+      Object value = "0";
+      SetAttributesRequestHandler setHandler = new SetAttributesRequestHandler(Collections.singletonMap("count", value), false);
+      SessionTestUtil.invokeRequest(jbcm0, setHandler, null);
+      
+      String id = setHandler.getSessionId();
+      
+      SessionTestUtil.sleepThread(1100); 
+      
+      jbcm0.backgroundProcess();
+      jbcm1.backgroundProcess();     
+      
+      value = "1";
+      setHandler = new SetAttributesRequestHandler(Collections.singletonMap("count", value), false);
+      SessionTestUtil.invokeRequest(jbcm0, setHandler, id);
+      
+      assertEquals("0", setHandler.getCheckedAttributes().get("count"));
+      
+      value = "2";
+      setHandler = new SetAttributesRequestHandler(Collections.singletonMap("count", value), false);
+      SessionTestUtil.invokeRequest(jbcm1, setHandler, id);
+      
+      assertEquals("1", setHandler.getCheckedAttributes().get("count"));
+   }
+   
+   public void testFailoverToPassivatedSession() throws Exception
+   {
+      log.info("++++ Starting testFailoverToPassivatedSession ++++");
+      
+      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];
+      
+      Object value = "0";
+      SetAttributesRequestHandler setHandler = new SetAttributesRequestHandler(Collections.singletonMap("count", value), false);
+      SessionTestUtil.invokeRequest(jbcm0, setHandler, null);
+      
+      String id = setHandler.getSessionId();
+      
+      SessionTestUtil.sleepThread(1100); 
+      
+      jbcm0.backgroundProcess();
+      jbcm1.backgroundProcess();     
+      
+      value = "1";
+      setHandler = new SetAttributesRequestHandler(Collections.singletonMap("count", value), false);
+      SessionTestUtil.invokeRequest(jbcm1, setHandler, id);
+      
+      assertEquals("0", setHandler.getCheckedAttributes().get("count"));
+   }
+   
+   protected JBossCacheManager[] getCacheManagers(String warname, int maxInactive, int maxIdle, int maxUnreplicated)
+      throws Exception
+   {
+      JBossCacheManager jbcm0 = SessionTestUtil.createManager(warname, maxInactive, pojoCaches[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, pojoCaches[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};
+   }
+
+}

Modified: trunk/testsuite/src/main/org/jboss/test/cluster/testutil/CacheConfigTestSetup.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/cluster/testutil/CacheConfigTestSetup.java	2008-10-20 21:32:29 UTC (rev 79772)
+++ trunk/testsuite/src/main/org/jboss/test/cluster/testutil/CacheConfigTestSetup.java	2008-10-20 21:55:50 UTC (rev 79773)
@@ -22,6 +22,8 @@
 
 package org.jboss.test.cluster.testutil;
 
+import java.io.File;
+
 import junit.framework.Test;
 import junit.framework.TestSuite;
 
@@ -78,7 +80,8 @@
          
          for (int i = 0; i < pojoCaches.length; i++)
          {
-            pojoCaches[i] = SessionTestUtil.createCache(local, passivationDir, totalReplication, marshalling, null);
+            String cacheStore = (passivationDir == null ? null : new File(passivationDir, String.valueOf(i)).getAbsolutePath());
+            pojoCaches[i] = SessionTestUtil.createCache(local, cacheStore, totalReplication, marshalling, null);
          }
       }
       finally




More information about the jboss-cvs-commits mailing list