[jboss-cvs] JBossAS SVN: r57336 - in branches/JBoss_4_0_2_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
Sun Oct 1 20:00:09 EDT 2006


Author: ryan.campbell at jboss.com
Date: 2006-10-01 20:00:08 -0400 (Sun, 01 Oct 2006)
New Revision: 57336

Modified:
   branches/JBoss_4_0_2_CP/testsuite/src/main/org/jboss/test/cluster/test/SimpleTestCase.java
   branches/JBoss_4_0_2_CP/tomcat/src/main/org/jboss/web/tomcat/tc5/session/ClusteredSession.java
   branches/JBoss_4_0_2_CP/tomcat/src/main/org/jboss/web/tomcat/tc5/session/JBossCacheManager.java
Log:
ASPATCH-37: JBAS-3493: Port JBAS-2792 Fix to 4.0.2

Modified: branches/JBoss_4_0_2_CP/testsuite/src/main/org/jboss/test/cluster/test/SimpleTestCase.java
===================================================================
--- branches/JBoss_4_0_2_CP/testsuite/src/main/org/jboss/test/cluster/test/SimpleTestCase.java	2006-10-01 23:36:04 UTC (rev 57335)
+++ branches/JBoss_4_0_2_CP/testsuite/src/main/org/jboss/test/cluster/test/SimpleTestCase.java	2006-10-02 00:00:08 UTC (rev 57336)
@@ -71,10 +71,20 @@
       getLog().debug("Exit testHttpSessionReplication");
    }
 
+
+   /**
+    * Tests that sessions time out properly and that activity
+    * on one cluster node prevents timeout on another.
+    * 
+    * TODO consider having testsessionreplication.jsp set the session
+    * timeout to say 15 secs so we can shorten the sleep periods and
+    * make this test run faster. Need to confirm this won't break other tests.
+    */
    public void testSessionTimeout()
       throws Exception
    {
-      String attr = "";
+      String attr  = "";
+      String attr2 = "";
       getLog().debug("Enter testSessionTimeout");
 
       String setURLName = "/http-sr/testsessionreplication.jsp";
@@ -88,12 +98,33 @@
       // Set the session attribute first
       makeGet(client, baseURL0_ +setURLName);
 
+      sleepThread(15000);
+      
+      // 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);
-      sleepThread(65000);  // sleep for 65 seconds for session to expire
+      
+      // Sleep 50 secs.  This plus the previous 15 secs is enough to expire the
+      // session on the other node if replication failed to keep it alive
+      sleepThread(50000);
+      
+      // 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 attributes retrieved from both servers ", attr, attr2);
+      
+      getLog().debug("Replication has kept the session alive");
+      
+      sleepThread(15000);  // sleep 15 more seconds so session will expire on node0
+      setCookieDomainToThisServer(client, servers_[0]);
       attr = makeGetWithState(client, baseURL0_ +getURLName);
       assertNull("Http session get", attr);
+      
+      getLog().debug("Exit testSessionTimeout");
    }
 
 }

Modified: branches/JBoss_4_0_2_CP/tomcat/src/main/org/jboss/web/tomcat/tc5/session/ClusteredSession.java
===================================================================
--- branches/JBoss_4_0_2_CP/tomcat/src/main/org/jboss/web/tomcat/tc5/session/ClusteredSession.java	2006-10-01 23:36:04 UTC (rev 57335)
+++ branches/JBoss_4_0_2_CP/tomcat/src/main/org/jboss/web/tomcat/tc5/session/ClusteredSession.java	2006-10-02 00:00:08 UTC (rev 57336)
@@ -326,21 +326,73 @@
      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;
+      }
 
-  /**
-   * Override here to reverse the order of manager session removal and
-   * attribute removal.
-   *
-   * @param notify
-   */
-  public void expire(boolean notify)
-  {
-     boolean expireLocally = true;
-     expire(notify, expireLocally);
-  }
+      if (!this.isValid)
+      {
+         return false;
+      }
 
-  protected void expire(boolean notify, boolean expireLocally)
-  {
+      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.
+    *
+    * @param notify
+    */
+   public void expire(boolean notify)
+   {
+      boolean expireLocally = true;
+      expire(notify, expireLocally);
+   }
+
+   protected void expire(boolean notify, boolean expireLocally)
+   {
       if (log.isDebugEnabled())
       {
          log.debug("The session has expired with id: " + id + " is it local? " +expireLocally);

Modified: branches/JBoss_4_0_2_CP/tomcat/src/main/org/jboss/web/tomcat/tc5/session/JBossCacheManager.java
===================================================================
--- branches/JBoss_4_0_2_CP/tomcat/src/main/org/jboss/web/tomcat/tc5/session/JBossCacheManager.java	2006-10-01 23:36:04 UTC (rev 57335)
+++ branches/JBoss_4_0_2_CP/tomcat/src/main/org/jboss/web/tomcat/tc5/session/JBossCacheManager.java	2006-10-02 00:00:08 UTC (rev 57336)
@@ -549,6 +549,19 @@
                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