[jboss-cvs] JBossAS SVN: r91366 - in trunk: testsuite/src/main/org/jboss/test/cluster/defaultcfg/simpleweb/test and 3 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Jul 17 00:07:23 EDT 2009


Author: bstansberry at jboss.com
Date: 2009-07-17 00:07:22 -0400 (Fri, 17 Jul 2009)
New Revision: 91366

Added:
   trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/web/test/PersistentManagerUndeployTestCase.java
Modified:
   trunk/testsuite/imports/sections/cluster.xml
   trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/simpleweb/test/DriverManagerPersistentStoreUnitTestCase.java
   trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/simpleweb/test/PersistentStoreSessionCountUnitTestCase.java
   trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/simpleweb/test/PersistentStoreSessionNotificationPolicyTestCase.java
   trunk/tomcat/src/main/org/jboss/web/tomcat/service/session/ClusteredSession.java
   trunk/tomcat/src/main/org/jboss/web/tomcat/service/session/persistent/AbstractPersistentManager.java
   trunk/tomcat/src/main/org/jboss/web/tomcat/service/session/persistent/PersistentStoreDistributedCacheManager.java
   trunk/tomcat/src/main/org/jboss/web/tomcat/service/session/persistent/RDBMSStoreBase.java
Log:
[JBAS-7095] Fix issue with removing sessions from db on undeploy

Modified: trunk/testsuite/imports/sections/cluster.xml
===================================================================
--- trunk/testsuite/imports/sections/cluster.xml	2009-07-17 01:08:38 UTC (rev 91365)
+++ trunk/testsuite/imports/sections/cluster.xml	2009-07-17 04:07:22 UTC (rev 91366)
@@ -604,6 +604,100 @@
          </fileset>
        </ear> 
       
+      <!-- DataSourcePersistentManager Tests -->
+      <copy todir="${build.lib}"
+         file="${build.resources}/cluster/persistent/httpsession-ds.xml"
+         overwrite="true"/>
+      
+      <jar destfile="${build.lib}/disable-manager-override.beans">
+         <fileset dir="${build.classes}">
+            <include name="org/jboss/test/cluster/web/persistent/ManagerOverrideDisabler.class"/>
+         </fileset>
+         <metainf dir="${build.resources}/cluster/persistent/">
+            <include name="disable-manager-override-jboss-beans.xml"/>
+         </metainf>
+      </jar>
+      
+      <!-- build http-cross-ctx-first-persistent.jar -->
+      <war warfile="${build.lib}/http-cross-ctx-first-persistent.war"
+         webxml="${build.resources}/cluster/http/http-cross-ctx-first/WEB-INF/web.xml">
+         <webinf dir="${build.resources}/cluster/persistent/WEB-INF">
+            <include name="context.xml"/>
+         </webinf>
+          <classes dir="${build.classes}">
+             <include name="org/jboss/test/cluster/web/Person.class"/>
+             <include name="org/jboss/test/cluster/web/CacheHelper*"/>
+             <include name="org/jboss/test/cluster/web/BindingListener.class"/>
+             <include name="org/jboss/test/cluster/web/DeserializationSensor.class"/>
+          </classes>
+         <fileset dir="${build.resources}/cluster/http/http-cross-ctx-first">
+            <include name="*.jsp"/>
+         </fileset>
+      </war>
+      
+      <!-- build http-cross-ctx-second-persistent.jar -->
+      <war warfile="${build.lib}/http-cross-ctx-second-persistent.war"
+         webxml="${build.resources}/cluster/http/http-cross-ctx-second/WEB-INF/web.xml">
+         <webinf dir="${build.resources}/cluster/persistent/WEB-INF">
+            <include name="context.xml"/>
+         </webinf>
+          <classes dir="${build.classes}">
+             <include name="org/jboss/test/cluster/web/Person.class"/>
+             <include name="org/jboss/test/cluster/web/CacheHelper*"/>
+             <include name="org/jboss/test/cluster/web/BindingListener.class"/>
+             <include name="org/jboss/test/cluster/web/DeserializationSensor.class"/>
+          </classes>
+         <fileset dir="${build.resources}/cluster/http/http-cross-ctx-second">
+            <include name="*.jsp"/>
+         </fileset>
+      </war>
+      
+      <!-- build http-cross-ctx-third-persistent.jar -->
+      <war warfile="${build.lib}/http-cross-ctx-third-persistent.war"
+         webxml="${build.resources}/cluster/http/http-cross-ctx-third/WEB-INF/web.xml">
+         <webinf dir="${build.resources}/cluster/persistent/WEB-INF">
+            <include name="context.xml"/>
+         </webinf>
+          <classes dir="${build.classes}">
+             <include name="org/jboss/test/cluster/web/Person.class"/>
+             <include name="org/jboss/test/cluster/web/CacheHelper*"/>
+             <include name="org/jboss/test/cluster/web/BindingListener.class"/>
+             <include name="org/jboss/test/cluster/web/DeserializationSensor.class"/>
+          </classes>
+         <fileset dir="${build.resources}/cluster/http/http-cross-ctx-third">
+            <include name="*.jsp"/>
+         </fileset>
+      </war>
+        
+      <ear earfile="${build.lib}/http-cross-ctx-persistent.ear"
+         appxml="${build.resources}/cluster/persistent/META-INF/application.xml">
+         <fileset dir="${build.lib}">
+            <include name="http-cross-ctx-first-persistent.war"/>
+            <include name="http-cross-ctx-second-persistent.war"/>
+            <include name="http-cross-ctx-third-persistent.war"/>
+         </fileset>
+      </ear>
+      
+      <war warfile="${build.lib}/http-scoped-persistent.war"
+         webxml="${build.resources}/cluster/http/http-scoped/WEB-INF/web.xml">
+         <webinf dir="${build.resources}/cluster/persistent/WEB-INF">
+            <include name="context.xml"/>
+         </webinf>
+         <classes dir="${build.classes}">
+            <include name="org/jboss/test/cluster/web/Person.class"/>
+            <include name="org/jboss/test/cluster/web/CacheHelper*"/>
+            <include
+               name="org/jboss/test/cluster/web/BindingListener.class"/>
+            <include
+               name="org/jboss/test/cluster/web/DeserializationSensor.class"/>
+         </classes>
+         
+         <fileset dir="${build.resources}/cluster/http/http-scoped">
+            <include name="*.jsp"/>
+            <include name="*.html"/>
+         </fileset>
+      </war>
+      
       <jar destfile="${build.lib}/rdbmsstore-tablesetup.jar">
          <metainf dir="${build.resources}/cluster/persistent">
             <include name="rdbmsstore-tablesetup-jboss-beans.xml"/>
@@ -730,80 +824,7 @@
         <zipfileset dir="${build.resources}/cluster/ejb2/basic"
            fullpath="META-INF/jboss.xml" includes="pooledha-jboss.xml"/>
      </jar> 
-      
-      <!-- DataSourcePersistentManager Tests -->
-      <copy todir="${build.lib}"
-         file="${build.resources}/cluster/persistent/httpsession-ds.xml"
-         overwrite="true"/>
-      
-      <jar destfile="${build.lib}/disable-manager-override.beans">
-         <fileset dir="${build.classes}">
-            <include name="org/jboss/test/cluster/web/persistent/ManagerOverrideDisabler.class"/>
-         </fileset>
-         <metainf dir="${build.resources}/cluster/persistent/">
-            <include name="disable-manager-override-jboss-beans.xml"/>
-         </metainf>
-      </jar>
-      
-      <!-- build http-cross-ctx-first-persistent.jar -->
-      <war warfile="${build.lib}/http-cross-ctx-first-persistent.war"
-         webxml="${build.resources}/cluster/http/http-cross-ctx-first/WEB-INF/web.xml">
-         <webinf dir="${build.resources}/cluster/persistent/WEB-INF">
-            <include name="context.xml"/>
-         </webinf>
-          <classes dir="${build.classes}">
-             <include name="org/jboss/test/cluster/web/Person.class"/>
-             <include name="org/jboss/test/cluster/web/CacheHelper*"/>
-             <include name="org/jboss/test/cluster/web/BindingListener.class"/>
-             <include name="org/jboss/test/cluster/web/DeserializationSensor.class"/>
-          </classes>
-         <fileset dir="${build.resources}/cluster/http/http-cross-ctx-first">
-            <include name="*.jsp"/>
-         </fileset>
-      </war>
-      
-      <!-- build http-cross-ctx-second-persistent.jar -->
-      <war warfile="${build.lib}/http-cross-ctx-second-persistent.war"
-         webxml="${build.resources}/cluster/http/http-cross-ctx-second/WEB-INF/web.xml">
-         <webinf dir="${build.resources}/cluster/persistent/WEB-INF">
-            <include name="context.xml"/>
-         </webinf>
-          <classes dir="${build.classes}">
-             <include name="org/jboss/test/cluster/web/Person.class"/>
-             <include name="org/jboss/test/cluster/web/CacheHelper*"/>
-             <include name="org/jboss/test/cluster/web/BindingListener.class"/>
-             <include name="org/jboss/test/cluster/web/DeserializationSensor.class"/>
-          </classes>
-         <fileset dir="${build.resources}/cluster/http/http-cross-ctx-second">
-            <include name="*.jsp"/>
-         </fileset>
-      </war>
-      
-      <!-- build http-cross-ctx-third-persistent.jar -->
-      <war warfile="${build.lib}/http-cross-ctx-third-persistent.war"
-         webxml="${build.resources}/cluster/http/http-cross-ctx-third/WEB-INF/web.xml">
-         <webinf dir="${build.resources}/cluster/persistent/WEB-INF">
-            <include name="context.xml"/>
-         </webinf>
-          <classes dir="${build.classes}">
-             <include name="org/jboss/test/cluster/web/Person.class"/>
-             <include name="org/jboss/test/cluster/web/CacheHelper*"/>
-             <include name="org/jboss/test/cluster/web/BindingListener.class"/>
-             <include name="org/jboss/test/cluster/web/DeserializationSensor.class"/>
-          </classes>
-         <fileset dir="${build.resources}/cluster/http/http-cross-ctx-third">
-            <include name="*.jsp"/>
-         </fileset>
-      </war>
-        
-      <ear earfile="${build.lib}/http-cross-ctx-persistent.ear"
-         appxml="${build.resources}/cluster/persistent/META-INF/application.xml">
-         <fileset dir="${build.lib}">
-            <include name="http-cross-ctx-first-persistent.war"/>
-            <include name="http-cross-ctx-second-persistent.war"/>
-            <include name="http-cross-ctx-third-persistent.war"/>
-         </fileset>
-      </ear>
+   	
    </target>  
  
 

Modified: trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/simpleweb/test/DriverManagerPersistentStoreUnitTestCase.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/simpleweb/test/DriverManagerPersistentStoreUnitTestCase.java	2009-07-17 01:08:38 UTC (rev 91365)
+++ trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/simpleweb/test/DriverManagerPersistentStoreUnitTestCase.java	2009-07-17 04:07:22 UTC (rev 91366)
@@ -715,6 +715,7 @@
    public void testProcessExpires()
    {
       testee.setCleanupInterval(2);
+      testee.setMaxUnreplicatedInterval(0);
       testee.start();
       
       int existing = testee.getSize();
@@ -747,6 +748,53 @@
       assertEquals(existing, testee.getSize());
    }
 
+   /**
+    * Test method for {@link org.jboss.web.tomcat.service.session.persistent.RDBMSStoreBase#processExpires()}.
+    */
+   public void testProcessExpiresWithMaxUnreplicatedInterval()
+   {
+      testee.setCleanupInterval(1);
+      testee.setMaxUnreplicatedInterval(1);
+      testee.start();
+      
+      int existing = testee.getSize();
+      
+      DistributableSessionMetadata md = new DistributableSessionMetadata();
+      String id = nextId();
+      md.setId(id + ".full");
+      md.setCreationTime(System.currentTimeMillis());
+      md.setNew(true);
+      md.setValid(true);
+      md.setMaxInactiveInterval(2);
+      Long ts = Long.valueOf(md.getCreationTime() + 1); 
+      Map<String, Object> attrs = new HashMap<String, Object>();
+      attrs.put("key", "value");
+      OutgoingSessionGranularitySessionData sessionData = new MockOutgoingSessionData(id, 0, ts, md, attrs);
+      testee.storeSessionData(sessionData);
+      
+      sleep(500);
+      
+      testee.processExpires();
+      
+      assertEquals(Integer.valueOf(0), testee.getSessionVersion(id));
+      
+      sleep(2001);
+      
+      testee.processExpires();
+      
+      assertEquals(Integer.valueOf(0), testee.getSessionVersion(id));
+      
+      assertEquals(existing +1 , testee.getSize());
+      
+      sleep(1001);
+      
+      testee.processExpires();
+      
+      assertNull(testee.getSessionVersion(id));
+      
+      assertEquals(existing, testee.getSize());
+   }
+
    private void sleep(int sleeptime)
    {
       try

Modified: trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/simpleweb/test/PersistentStoreSessionCountUnitTestCase.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/simpleweb/test/PersistentStoreSessionCountUnitTestCase.java	2009-07-17 01:08:38 UTC (rev 91365)
+++ trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/simpleweb/test/PersistentStoreSessionCountUnitTestCase.java	2009-07-17 04:07:22 UTC (rev 91366)
@@ -577,6 +577,105 @@
       createAndUseSession(mgr0, "4", true, true); 
    }
    
+   public void testNoPassivationRedeploy() throws Exception
+   {
+      log.info("Enter testoPassivationRedeploy");
+      
+      noPassivationRedeployTest(false);
+   }
+   
+   public void testoPassivationRestart() throws Exception
+   {
+      log.info("Enter testoPassivationRestart");
+      
+      noPassivationRedeployTest(true);      
+   }
+   
+   private void noPassivationRedeployTest(boolean fullRestart)
+         throws Exception
+   {
+      ++testCount;
+      DataSourcePersistentManager mgr0 = PersistentSessionTestUtil.createManager("test" + testCount, 300, null);
+      PersistentSessionTestUtil.configureManager(mgr0, 1);
+      
+      mgr0.start();
+      
+      assertFalse("Passivation is disabled", mgr0.isPassivationEnabled());
+      assertEquals("Correct max active count", 1, mgr0.getMaxActiveAllowed());
+      assertEquals("Correct max idle time", -1, mgr0.getPassivationMaxIdleTime());
+      assertEquals("Correct min idle time", -1, mgr0.getPassivationMinIdleTime());
+      
+      DataSourcePersistentManager mgr1 = PersistentSessionTestUtil.createManager("test" + testCount, 300, null);
+      PersistentSessionTestUtil.configureManager(mgr1, 1);
+      
+      mgr1.start();
+      
+      assertFalse("Passivation is disabled", mgr1.isPassivationEnabled());
+      assertEquals("Correct max active count", 1, mgr1.getMaxActiveAllowed());
+      assertEquals("Correct max idle time", -1, mgr1.getPassivationMaxIdleTime());
+      assertEquals("Correct min idle time", -1, mgr1.getPassivationMinIdleTime());
+      
+      // Set up a session
+      createAndUseSession(mgr0, "1", true, true);
+      
+      assertEquals("Session count correct", 1, mgr0.getActiveSessionCount());
+      assertEquals("Local session count correct", 1, mgr0.getLocalActiveSessionCount());    
+      assertEquals("Session count correct", 0, mgr1.getActiveSessionCount());
+      assertEquals("Local session count correct", 0, mgr1.getLocalActiveSessionCount());
+      
+      // Create a 2nd
+      createAndUseSession(mgr1, "2", true, true);     
+      
+      assertEquals("Session count correct", 1, mgr0.getActiveSessionCount());
+      assertEquals("Local session count correct", 1, mgr0.getLocalActiveSessionCount());     
+      assertEquals("Created session count correct", 1, mgr0.getCreatedSessionCount());
+      assertEquals("Expired session count correct", 0, mgr0.getExpiredSessionCount());
+      assertEquals("Session count correct", 1, mgr1.getActiveSessionCount());
+      assertEquals("Local session count correct", 1, mgr1.getLocalActiveSessionCount());     
+      assertEquals("Created session count correct", 1, mgr1.getCreatedSessionCount());
+      assertEquals("Expired session count correct", 0, mgr1.getExpiredSessionCount());
+      
+      if (fullRestart)
+      {
+        mgr1.stop();
+      }
+      
+      mgr0.stop();
+      
+      mgr0 = PersistentSessionTestUtil.createManager("test" + testCount, 300, null);
+      PersistentSessionTestUtil.configureManager(mgr0, 1);
+      
+      mgr0.start();
+      
+      assertFalse("Passivation is disabled", mgr0.isPassivationEnabled());
+      assertEquals("Correct max active count", 1, mgr0.getMaxActiveAllowed());
+      assertEquals("Correct max idle time", -1, mgr0.getPassivationMaxIdleTime());
+      assertEquals("Correct min idle time", -1, mgr0.getPassivationMinIdleTime());   
+      
+//      int expected = (totalReplication && marshalling && fullRestart) ? 0 : 2;
+      int expected = 2;
+      assertEquals("Session count correct", 0, mgr0.getActiveSessionCount());
+      assertEquals("Local session count correct", 0, mgr0.getLocalActiveSessionCount());
+      assertEquals("Created session count correct", 0, mgr0.getCreatedSessionCount());
+      assertEquals("Expired session count correct", 0, mgr0.getExpiredSessionCount());
+//      expected = (totalReplication && !(marshalling && fullRestart)) ? 1 : 0;
+      expected = 1;
+      assertEquals("Passivated session count correct", 0, mgr0.getPassivatedSessionCount());
+      
+      if (!fullRestart)
+      {
+         assertEquals("Session count correct", 1, mgr1.getActiveSessionCount());
+         assertEquals("Local session count correct", 1, mgr1.getLocalActiveSessionCount());
+         assertEquals("Created session count correct", 1, mgr1.getCreatedSessionCount());
+         assertEquals("Expired session count correct", 0, mgr1.getExpiredSessionCount());
+         assertEquals("Passivated session count correct", 0, mgr1.getPassivatedSessionCount());
+      }
+      // Sleep past minIdleTime
+      SessionTestUtil.sleepThread(1100);
+      
+      createAndUseSession(mgr0, "4", true, true); 
+   }
+   
    private Session createAndUseSession(DataSourcePersistentManager dspm, String id, 
                            boolean canCreate, boolean access)
          throws Exception

Modified: trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/simpleweb/test/PersistentStoreSessionNotificationPolicyTestCase.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/simpleweb/test/PersistentStoreSessionNotificationPolicyTestCase.java	2009-07-17 01:08:38 UTC (rev 91365)
+++ trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/simpleweb/test/PersistentStoreSessionNotificationPolicyTestCase.java	2009-07-17 04:07:22 UTC (rev 91366)
@@ -466,25 +466,26 @@
       }
       else
       {
-         // With a persistent manager we don't expect invocations from
-         // mgr1. When mgr0 invalidates the session, it is gone from the
-         // DB, which prevents mgr1 "activating" it to issue notifications.
+//       BES 2009/07/15 -- following is no longer true, as expiration no longer == db removal  
+//         // With a persistent manager we don't expect invocations from
+//         // mgr1. When mgr0 invalidates the session, it is gone from the
+//         // DB, which prevents mgr1 "activating" it to issue notifications.
          assertEquals(1, hsl0.invocations.size());
          assertEquals(MockHttpSessionListener.Type.DESTROYED, hsl0.invocations.get(0));
-         assertEquals(0, hsl1.invocations.size());
-//         assertEquals(1, hsl1.invocations.size());
-//         assertEquals(MockHttpSessionListener.Type.DESTROYED, hsl1.invocations.get(0));
+//         assertEquals(0, hsl1.invocations.size());
+         assertEquals(1, hsl1.invocations.size());
+         assertEquals(MockHttpSessionListener.Type.DESTROYED, hsl1.invocations.get(0));
          assertEquals(1, hsal0.invocations.size());
          assertEquals(MockHttpSessionAttributeListener.Type.REMOVED, hsal0.invocations.get(0));
-         assertEquals(0, hsal1.invocations.size());
-//         assertEquals(1, hsal1.invocations.size());
-//         assertEquals(MockHttpSessionAttributeListener.Type.REMOVED, hsal1.invocations.get(0));
-//         assertEquals(4, SessionSpecListenerAttribute.invocations.size());
-         assertEquals(2, SessionSpecListenerAttribute.invocations.size());
-         assertEquals(SessionSpecListenerAttribute.Type.ACTIVATING, SessionSpecListenerAttribute.invocations.get(0));
-         assertEquals(SessionSpecListenerAttribute.Type.UNBOUND, SessionSpecListenerAttribute.invocations.get(1));
-//         assertEquals(SessionSpecListenerAttribute.Type.ACTIVATING, SessionSpecListenerAttribute.invocations.get(2));
-//         assertEquals(SessionSpecListenerAttribute.Type.UNBOUND, SessionSpecListenerAttribute.invocations.get(3));
+//         assertEquals(0, hsal1.invocations.size());
+         assertEquals(1, hsal1.invocations.size());
+         assertEquals(MockHttpSessionAttributeListener.Type.REMOVED, hsal1.invocations.get(0));
+         assertEquals(4, SessionSpecListenerAttribute.invocations.size());
+//         assertEquals(2, SessionSpecListenerAttribute.invocations.size());
+//         assertEquals(SessionSpecListenerAttribute.Type.ACTIVATING, SessionSpecListenerAttribute.invocations.get(0));
+//         assertEquals(SessionSpecListenerAttribute.Type.UNBOUND, SessionSpecListenerAttribute.invocations.get(1));
+         assertEquals(SessionSpecListenerAttribute.Type.ACTIVATING, SessionSpecListenerAttribute.invocations.get(2));
+         assertEquals(SessionSpecListenerAttribute.Type.UNBOUND, SessionSpecListenerAttribute.invocations.get(3));
          
          validateNoNotifications(null, null, null, null, null);
          clearNotifications(hsl0, hsal0, hsl1, hsal1, SessionSpecListenerAttribute.invocations);

Copied: trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/web/test/PersistentManagerUndeployTestCase.java (from rev 91359, branches/JBPAPP_5_0/testsuite/src/main/org/jboss/test/cluster/defaultcfg/web/test/PersistentManagerUndeployTestCase.java)
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/web/test/PersistentManagerUndeployTestCase.java	                        (rev 0)
+++ trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/web/test/PersistentManagerUndeployTestCase.java	2009-07-17 04:07:22 UTC (rev 91366)
@@ -0,0 +1,245 @@
+/*
+ * 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.web.test;
+
+import java.util.Arrays;
+import java.util.List;
+
+import junit.framework.Test;
+
+import org.apache.commons.httpclient.HttpClient;
+import org.jboss.test.cluster.testutil.DBSetupDelegate;
+import org.jboss.test.cluster.testutil.DelegatingClusteredTestCase;
+import org.jboss.test.cluster.testutil.SessionTestUtil;
+import org.jboss.test.cluster.testutil.TestSetupDelegate;
+import org.jboss.test.cluster.testutil.WebTestBase;
+import org.jboss.test.cluster.web.persistent.PersistentStoreSetupDelegate;
+
+/**
+ * Tests that a clustered session still functions properly on the second
+ * node after the webapp is undeployed from the first node.
+ * <p/>
+ * This version tests a SessionBasedClusteredSession.
+ * 
+ * @author Brian Stansberry
+ * @version $Id: UndeployTestCase.java 81084 2008-11-14 17:30:43Z dimitris at jboss.org $
+ */
+public class PersistentManagerUndeployTestCase extends WebTestBase
+{
+   protected String setUrl_;
+   protected String getUrl_;
+   protected String setUrlBase_;
+   protected String getUrlBase_;
+   
+   private static boolean deployed0_ = true;
+   private static boolean deployed1_ = true;
+   
+   public PersistentManagerUndeployTestCase(String name)
+   {
+      super(name);
+      setUrlBase_ = "setSession.jsp";
+      getUrlBase_ = "getAttribute.jsp";
+
+      concatenate();
+   }
+   
+   protected String getContextPath()
+   {
+      return "/http-scoped-persistent/";
+   }
+   
+   protected String getWarName()
+   {
+      return "http-scoped-persistent.war";
+   }
+
+   public static Test suite() throws Exception
+   {
+      String dbAddress = System.getProperty(DBSetupDelegate.DBADDRESS_PROPERTY, DBSetupDelegate.DEFAULT_ADDRESS);
+      TestSetupDelegate dbDelegate = new DBSetupDelegate(dbAddress, DBSetupDelegate.DEFAULT_PORT);
+      TestSetupDelegate storeDelegate = new PersistentStoreSetupDelegate(dbAddress, DBSetupDelegate.DEFAULT_PORT);
+      List<TestSetupDelegate> list = Arrays.asList(new TestSetupDelegate[]{dbDelegate, storeDelegate});
+      return DelegatingClusteredTestCase.getDeploySetup(PersistentManagerUndeployTestCase.class,
+                                                      "httpsession-ds.xml, disable-manager-override.beans, " +
+                                                      "http-scoped-persistent.war", list);
+   }
+
+   /**
+    * Tests creating session on a node when the 2nd node is already running,
+    * then undeploying war, then successfully reading session from 2nd node
+    *
+    * @throws Exception
+    */
+   public void testFailoverAfterFirstNodeStop()
+         throws Exception
+   {
+      String attr = "";
+      getLog().info("Enter testSecondNodeStartAfterFirstNodeStop");
+
+      getLog().debug(setUrl_ + ":::::::" + getUrl_);
+
+      deploy(true);
+      deploy(false);
+      
+      // Create an instance of HttpClient.
+      HttpClient client = new HttpClient();
+
+      // Set the session attribute first
+      makeGet(client, baseURL0_ +setUrl_);
+
+      // Create a method instance.
+      // Get the Attribute set
+      attr = makeGetWithState(client, baseURL0_ +getUrl_);
+      
+      undeploy(true);
+
+      sleepThread(DEFAULT_SLEEP);
+
+      // Make connection to server 1 and get
+      SessionTestUtil.setCookieDomainToThisServer(client, servers_[1]);
+      String attr2 = makeGetWithState(client, baseURL1_ + getUrl_);
+
+      assertEquals("Get attribute should be but is ", attr, attr2);
+      getLog().debug("Exit testSecondNodeStartAfterFirstNodeStop");
+   }
+
+   /**
+    * Tests creating session on a node then undeploying war, then deploying
+    * on 2nd node, then successfully reading session
+    *
+    * @throws Exception
+    */
+   public void testSecondNodeStartAfterFirstNodeStop()
+         throws Exception
+   {
+      String attr = "";
+      getLog().info("Enter testSecondNodeStartAfterFirstNodeStop");
+
+      getLog().debug(setUrl_ + ":::::::" + getUrl_);
+
+      deploy(true);
+      undeploy(false);
+      
+      // Create an instance of HttpClient.
+      HttpClient client = new HttpClient();
+
+      // Set the session attribute first
+      makeGet(client, baseURL0_ +setUrl_);
+
+      // Create a method instance.
+      // Get the Attribute set
+      attr = makeGetWithState(client, baseURL0_ +getUrl_);
+      
+      undeploy(true);
+      deploy(false);
+
+      sleepThread(DEFAULT_SLEEP);
+
+      // Make connection to server 1 and get
+      SessionTestUtil.setCookieDomainToThisServer(client, servers_[1]);
+      String attr2 = makeGetWithState(client, baseURL1_ + getUrl_);
+
+      assertEquals("Get attribute should be but is ", attr, attr2);
+      getLog().debug("Exit testSecondNodeStartAfterFirstNodeStop");
+   }
+
+   /**
+    * Tests creating session on a node with the 2nd node running,
+    * then undeploying war from both nodes, then deploying
+    * on 2nd node, then successfully reading session
+    *
+    * @throws Exception
+    */
+   public void testFailoverAfterFullStop()
+         throws Exception
+   {
+      String attr = "";
+      getLog().info("Enter testSecondNodeStartAfterFirstNodeStop");
+
+      getLog().debug(setUrl_ + ":::::::" + getUrl_);
+
+      deploy(true);
+      deploy(false);
+      
+      // Create an instance of HttpClient.
+      HttpClient client = new HttpClient();
+
+      // Set the session attribute first
+      makeGet(client, baseURL0_ +setUrl_);
+
+      // Create a method instance.
+      // Get the Attribute set
+      attr = makeGetWithState(client, baseURL0_ +getUrl_);
+      
+      undeploy(true);
+      undeploy(false);
+      deploy(false);
+
+      sleepThread(DEFAULT_SLEEP);
+
+      // Make connection to server 1 and get
+      SessionTestUtil.setCookieDomainToThisServer(client, servers_[1]);
+      String attr2 = makeGetWithState(client, baseURL1_ + getUrl_);
+
+      assertEquals("Get attribute should be but is ", attr, attr2);
+      getLog().debug("Exit testSecondNodeStartAfterFirstNodeStop");
+   }
+
+   protected void concatenate()
+   {
+      setUrl_ = getContextPath() +setUrlBase_;
+      getUrl_ = getContextPath() +getUrlBase_;
+   }
+   
+   protected void deploy(boolean first) throws Exception
+   {
+      if (first && !deployed0_)
+      {
+         deploy(getAdaptors()[0], getWarName());
+         getLog().debug("Deployed " + getWarName() + " on server0");
+         deployed0_ = true;
+      }
+      else if (!first && !deployed1_)
+      {
+         deploy(getAdaptors()[1], getWarName());
+         getLog().debug("Deployed " + getWarName() + " on server1");
+         deployed1_ = true;         
+      }
+   }
+   
+   protected void undeploy(boolean first) throws Exception
+   {
+      if (first && deployed0_)
+      {
+         undeploy(getAdaptors()[0], getWarName());
+         getLog().debug("Undeployed " + getWarName() + " from server0");
+         deployed0_ = false;
+      }
+      else if (!first && deployed1_)
+      {
+         undeploy(getAdaptors()[1], getWarName());
+         getLog().debug("Undeployed " + getWarName() + " from server1");
+         deployed1_ = false;         
+      }
+   }
+
+}

Modified: trunk/tomcat/src/main/org/jboss/web/tomcat/service/session/ClusteredSession.java
===================================================================
--- trunk/tomcat/src/main/org/jboss/web/tomcat/service/session/ClusteredSession.java	2009-07-17 01:08:38 UTC (rev 91365)
+++ trunk/tomcat/src/main/org/jboss/web/tomcat/service/session/ClusteredSession.java	2009-07-17 04:07:22 UTC (rev 91366)
@@ -641,14 +641,20 @@
 
    public void expire()
    {
-      expire(true);
+      boolean notify = true;
+      boolean localCall = true;
+      boolean localOnly = false;
+      expire(notify, localCall, localOnly, ClusteredSessionNotificationCause.INVALIDATE);
    }
 
    /**
     * Expires the session, but in such a way that other cluster nodes
     * are unaware of the expiration.
     *
-    * @param notify
+    * @param notify true if notifications should be to sent to registered listeners; 
+    *               false otherwise
+    * 
+    * @deprecated Will be removed in AS 6
     */
    public void expire(boolean notify)
    {
@@ -677,6 +683,7 @@
       setPrincipal(null);
       isNew = false;
       isValid = false;
+      firstAccess = true;
       manager = null;
       
       listeners.clear();
@@ -1289,7 +1296,7 @@
     
    /**
     * Returns whether the current session is still valid, but
-    * only calls {@link #expire(boolean)} for timed-out sessions
+    * only calls <code>expire</code> for timed-out sessions
     * if <code>expireIfInvalid</code> is <code>true</code>.
     * 
     * @param expireIfInvalid  <code>true</code> if sessions that have
@@ -1319,9 +1326,16 @@
          if (timeIdle >= maxInactiveInterval)
          {
             if (expireIfInvalid)
-               expire(true);
+            {
+               boolean notify = true;
+               boolean localCall = true;
+               boolean localOnly = true;
+               expire(notify, localCall, localOnly, ClusteredSessionNotificationCause.TIMEOUT);
+            }
             else
+            {
                return false;
+            }
          }
       }
 

Modified: trunk/tomcat/src/main/org/jboss/web/tomcat/service/session/persistent/AbstractPersistentManager.java
===================================================================
--- trunk/tomcat/src/main/org/jboss/web/tomcat/service/session/persistent/AbstractPersistentManager.java	2009-07-17 01:08:38 UTC (rev 91365)
+++ trunk/tomcat/src/main/org/jboss/web/tomcat/service/session/persistent/AbstractPersistentManager.java	2009-07-17 04:07:22 UTC (rev 91366)
@@ -398,6 +398,7 @@
    protected void configureStore()
    {
       store.setName(this.getContextName());
+      store.setMaxUnreplicatedInterval(getMaxUnreplicatedInterval());
       
       if (getConnectionName() != null)
       {

Modified: trunk/tomcat/src/main/org/jboss/web/tomcat/service/session/persistent/PersistentStoreDistributedCacheManager.java
===================================================================
--- trunk/tomcat/src/main/org/jboss/web/tomcat/service/session/persistent/PersistentStoreDistributedCacheManager.java	2009-07-17 01:08:38 UTC (rev 91365)
+++ trunk/tomcat/src/main/org/jboss/web/tomcat/service/session/persistent/PersistentStoreDistributedCacheManager.java	2009-07-17 04:07:22 UTC (rev 91366)
@@ -115,8 +115,7 @@
 
    public void removeSessionLocal(String realId)
    {
-      // Just remove it
-      store.remove(realId);
+      // we ignore this, as it's logically equivalent to an evict
    }
 
    public void sessionCreated(String realId)

Modified: trunk/tomcat/src/main/org/jboss/web/tomcat/service/session/persistent/RDBMSStoreBase.java
===================================================================
--- trunk/tomcat/src/main/org/jboss/web/tomcat/service/session/persistent/RDBMSStoreBase.java	2009-07-17 01:08:38 UTC (rev 91365)
+++ trunk/tomcat/src/main/org/jboss/web/tomcat/service/session/persistent/RDBMSStoreBase.java	2009-07-17 04:07:22 UTC (rev 91366)
@@ -86,6 +86,8 @@
    
    /** When we last executed the processExpires cleanup */
    private long lastCleanup = 0;
+   
+   private int maxUnreplicatedInterval = -1;
 
    /**
     * The connection username to use when trying to connect to the database.
@@ -512,6 +514,16 @@
       this.cleanupInterval = cleanupInterval;
    }
    
+   public int getMaxUnreplicatedInterval()
+   {
+      return maxUnreplicatedInterval;
+   }
+
+   public void setMaxUnreplicatedInterval(int maxUnreplicatedInterval)
+   {
+      this.maxUnreplicatedInterval = maxUnreplicatedInterval;
+   }
+
    public boolean isStarted()
    {
       return started;
@@ -760,9 +772,8 @@
                metadata.setNew("1".equals(isNew));
                metadata.setMaxInactiveInterval(rst.getInt(4));
                String valid = rst.getString(7);
-               // FIXME experiment
-//               metadata.setValid("1".equals(valid));
-               metadata.setValid(true);
+               metadata.setValid("1".equals(valid));
+//               metadata.setValid(true);
 
                Integer version = Integer.valueOf(rst.getInt(5));
                Long timestamp = Long.valueOf(rst.getLong(6));
@@ -1217,6 +1228,7 @@
       long earliest = now - interval;
       if (earliest > lastCleanup)
       {
+         long maxUnrep = this.maxUnreplicatedInterval < 0 ? 60000 : this.maxUnreplicatedInterval * 1000;
          Connection _conn = safeGetConnection();
          boolean success = false;
          try
@@ -1224,7 +1236,7 @@
             PreparedStatement preparedCleanupSql = prepareStatement(_conn, getCleanupSql());
             preparedCleanupSql.setString(1, getName());
             preparedCleanupSql.setLong(2, earliest);
-            preparedCleanupSql.setLong(3, now);
+            preparedCleanupSql.setLong(3, (now - maxUnrep));
             preparedCleanupSql.execute();
 
             _conn.commit();
@@ -1441,8 +1453,8 @@
             + getSessionIdCol() + " = ? AND " + getSessionAppCol() + " = ?";
       
       this.cleanupSql = "DELETE FROM " + getSessionTable() + " WHERE " + getSessionAppCol() + " = ?" +
-                   " AND " + getSessionLastAccessedCol() + " < ? AND " + getSessionLastAccessedCol() + " < (? - " +
-                   getSessionMaxInactiveCol() + ")";
+                   " AND " + getSessionLastAccessedCol() + " < ? AND " + getSessionLastAccessedCol() + " < (? - (" +
+                   getSessionMaxInactiveCol() + " * 1000))";
    }
 
    private void executeRemove(String id, Connection _conn) throws SQLException




More information about the jboss-cvs-commits mailing list