[jboss-cvs] JBossAS SVN: r58505 - in branches/JBoss_4_0_3_SP1_CP: testsuite/src/main/org/jboss/test/cluster/test tomcat/src/main/org/jboss/web/tomcat/tc5/session

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Nov 17 17:13:52 EST 2006


Author: vivekl at redhat.com
Date: 2006-11-17 17:13:49 -0500 (Fri, 17 Nov 2006)
New Revision: 58505

Modified:
   branches/JBoss_4_0_3_SP1_CP/testsuite/src/main/org/jboss/test/cluster/test/SimpleTestCase.java
   branches/JBoss_4_0_3_SP1_CP/tomcat/src/main/org/jboss/web/tomcat/tc5/session/ClusteredSession.java
   branches/JBoss_4_0_3_SP1_CP/tomcat/src/main/org/jboss/web/tomcat/tc5/session/JBossCacheManager.java
Log:
ASPATCH-116: JBAS-3814: Port JBAS-2403 Fix to 4.0.3.SP1

Modified: branches/JBoss_4_0_3_SP1_CP/testsuite/src/main/org/jboss/test/cluster/test/SimpleTestCase.java
===================================================================
--- branches/JBoss_4_0_3_SP1_CP/testsuite/src/main/org/jboss/test/cluster/test/SimpleTestCase.java	2006-11-17 20:39:04 UTC (rev 58504)
+++ branches/JBoss_4_0_3_SP1_CP/testsuite/src/main/org/jboss/test/cluster/test/SimpleTestCase.java	2006-11-17 22:13:49 UTC (rev 58505)
@@ -96,4 +96,50 @@
       assertNull("Http session get", attr);
    }
 
+   /**
+    * Test for JBAS-2403, ensuring that session activity on one node in
+    * the cluster prevents timeout of the session on another node.
+    * 
+    * @throws Exception
+    */
+   public void testReplicationPreventsTimeout()
+      throws Exception
+   {
+      String attr  = "";
+      String attr2 = "";
+      getLog().debug("Enter testReplicationPreventsTimeout");
+
+      String setURLName = "/http-sr/testsessionreplication.jsp";
+      String getURLName = "/http-sr/getattribute.jsp";
+
+      getLog().debug(setURLName + ":::::::" + getURLName);
+
+      // Create an instance of HttpClient.
+      HttpClient client = new HttpClient();
+
+      // Set the session attribute first
+      makeGet(client, baseURL0_ +setURLName);
+      
+      sleepThread(30000);
+      // Set it again to ensure replication occurs
+      attr = makeGetWithState(client, baseURL0_ +setURLName);
+      // Get the Attribute set by testsessionreplication.jsp
+      attr = makeGetWithState(client, baseURL0_ +getURLName);
+      assertNotNull("Http session get", attr);
+      
+      // Sleep 35 secs.  This plus the previous 30 secs is enough to
+      // expire the session on the other node
+      sleepThread(35000);
+      
+      // Switch to the other server and check the attribute
+      setCookieDomainToThisServer(client, servers_[1]);
+      attr2 = makeGetWithState(client, baseURL1_ +getURLName);
+      
+      // Check the result
+      assertEquals("Http session replication attribtues retrieved from both servers ", attr, attr2);
+      
+      getLog().debug("Replication has kept the session alive");
+      getLog().debug("Exit testReplicationPreventsTimeout");
+   }
+
 }

Modified: branches/JBoss_4_0_3_SP1_CP/tomcat/src/main/org/jboss/web/tomcat/tc5/session/ClusteredSession.java
===================================================================
--- branches/JBoss_4_0_3_SP1_CP/tomcat/src/main/org/jboss/web/tomcat/tc5/session/ClusteredSession.java	2006-11-17 20:39:04 UTC (rev 58504)
+++ branches/JBoss_4_0_3_SP1_CP/tomcat/src/main/org/jboss/web/tomcat/tc5/session/ClusteredSession.java	2006-11-17 22:13:49 UTC (rev 58505)
@@ -332,7 +332,59 @@
      boolean expireLocally = false;
      expire(notify, expireLocally);
    }
+   
+  
+   /**
+    * Override the {@link StandardSession#isValid() superclass method}
+    * to call {@ #isValid(boolean) isValid(true)}.
+    */
+   public boolean isValid()
+   {
+      return isValid(true);
+   }
+   
+   /**
+    * Returns whether the current session is still valid, but
+    * only calls {@link #expire(boolean)} for timed-out sessions
+    * if <code>expireIfInvalid</code> is <code>true</code>.
+    * 
+    * @param expireIfInvalid  <code>true</code> if sessions that have
+    *                         been timed out should be expired
+    */
+   public boolean isValid(boolean expireIfInvalid)
+   {
+      if (this.expiring)
+      {
+         return true;
+      }
 
+      if (!this.isValid)
+      {
+         return false;
+      }
+
+      if (accessCount > 0)
+      {
+         return true;
+      }
+
+      if (maxInactiveInterval >= 0)
+      {
+         long timeNow = System.currentTimeMillis();
+         int timeIdle = (int) ((timeNow - thisAccessedTime) / 1000L);
+         if (timeIdle >= maxInactiveInterval)
+         {
+            if (expireIfInvalid)
+               expire(true);
+            else
+               return false;
+         }
+      }
+
+      return (this.isValid);
+      
+   }   
+
   /**
    * Override here to reverse the order of manager session removal and
    * attribute removal.

Modified: branches/JBoss_4_0_3_SP1_CP/tomcat/src/main/org/jboss/web/tomcat/tc5/session/JBossCacheManager.java
===================================================================
--- branches/JBoss_4_0_3_SP1_CP/tomcat/src/main/org/jboss/web/tomcat/tc5/session/JBossCacheManager.java	2006-11-17 20:39:04 UTC (rev 58504)
+++ branches/JBoss_4_0_3_SP1_CP/tomcat/src/main/org/jboss/web/tomcat/tc5/session/JBossCacheManager.java	2006-11-17 22:13:49 UTC (rev 58505)
@@ -680,6 +680,20 @@
                if(doTx)
                   tm.begin();
 
+               // JBAS-2403. Check for outdated sessions where we think
+               // the local copy has timed out.  If found, refresh the
+               // session from the cache in case that might change the timeout
+               if (session.isOutdated() && session.isValid(false) == false) {
+                  String realId = getRealId(session.getId());
+                  // JBAS-2792 don't assign the result of loadSession to session
+                  // just update the object from the cache or fall through if
+                  // the session has been removed from the cache
+                  loadSession(realId);
+               }
+               
+               // Do a normal invalidation check that will expire any
+               // sessions that have timed out
+
                if (!session.isValid()) continue;
             }
             catch (Exception ex)




More information about the jboss-cvs-commits mailing list