[Jboss-cvs] JBossAS SVN: r56064 - branches/JBoss_4_0_4_GA_JBAS-3526/testsuite/src/main/org/jboss/test/cluster/test

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Aug 18 10:33:20 EDT 2006


Author: galder.zamarreno at jboss.com
Date: 2006-08-18 10:33:16 -0400 (Fri, 18 Aug 2006)
New Revision: 56064

Added:
   branches/JBoss_4_0_4_GA_JBAS-3526/testsuite/src/main/org/jboss/test/cluster/test/SessionTestUtil.java
Modified:
   branches/JBoss_4_0_4_GA_JBAS-3526/testsuite/src/main/org/jboss/test/cluster/test/BaseTest.java
   branches/JBoss_4_0_4_GA_JBAS-3526/testsuite/src/main/org/jboss/test/cluster/test/SimpleTestCase.java
Log:
[JBAS-3526] Port the fix for JBAS-3310 to 4.0.4.GA

Modified: branches/JBoss_4_0_4_GA_JBAS-3526/testsuite/src/main/org/jboss/test/cluster/test/BaseTest.java
===================================================================
--- branches/JBoss_4_0_4_GA_JBAS-3526/testsuite/src/main/org/jboss/test/cluster/test/BaseTest.java	2006-08-18 13:54:54 UTC (rev 56063)
+++ branches/JBoss_4_0_4_GA_JBAS-3526/testsuite/src/main/org/jboss/test/cluster/test/BaseTest.java	2006-08-18 14:33:16 UTC (rev 56064)
@@ -239,7 +239,7 @@
       }
       if(sessionID == null)
       {
-         fail("setCookieDomainToThisServer(): fail to find session id. Server name: " +server);
+         fail("getSessionCookie(): fail to find session id. Server name: " +server);
       }
       log.info("Saw JSESSIONID="+sessionID);
       return sessionID;

Added: branches/JBoss_4_0_4_GA_JBAS-3526/testsuite/src/main/org/jboss/test/cluster/test/SessionTestUtil.java
===================================================================
--- branches/JBoss_4_0_4_GA_JBAS-3526/testsuite/src/main/org/jboss/test/cluster/test/SessionTestUtil.java	2006-08-18 13:54:54 UTC (rev 56063)
+++ branches/JBoss_4_0_4_GA_JBAS-3526/testsuite/src/main/org/jboss/test/cluster/test/SessionTestUtil.java	2006-08-18 14:33:16 UTC (rev 56064)
@@ -0,0 +1,91 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.test;
+
+import java.util.Iterator;
+import java.util.Set;
+
+import javax.management.MalformedObjectNameException;
+import javax.management.ObjectName;
+
+import org.jboss.cache.Fqn;
+import org.jboss.jmx.adaptor.rmi.RMIAdaptor;
+
+/**
+ * Utilities for session testing.
+ * 
+ * @author <a href="mailto://brian.stansberry@jboss.com">Brian Stansberry</a>
+ * @version $Revision: 1.2 $
+ */
+public class SessionTestUtil
+{  
+   private static final String[] TYPES = 
+   { String.class.getName(), Object.class.getName() };
+   private static final String VERSION_KEY = "VERSION";
+   
+   private static final Fqn BUDDY_BACKUP_SUBTREE_FQN = Fqn.fromString("_BUDDY_BACKUP_");
+   
+   private static final ObjectName CACHE_OBJECT_NAME;
+   static
+   {
+      try
+      {
+         CACHE_OBJECT_NAME =
+            new ObjectName("jboss.cache:service=TomcatClusteringCache");
+      }
+      catch (MalformedObjectNameException e)
+      {
+         throw new ExceptionInInitializerError(e);
+      }
+   }
+   
+   public static Object getSessionVersion(RMIAdaptor adaptor, String sessionFqn) throws Exception
+   {
+      return adaptor.invoke(CACHE_OBJECT_NAME, "get", new Object[]
+      {sessionFqn, VERSION_KEY}, TYPES);
+   }
+
+   public static Object getBuddySessionVersion(RMIAdaptor adaptor, String sessionFqn) throws Exception
+   {
+      Object replVersion = null;
+      //    Check in the buddy backup tree
+      Set buddies = (Set) adaptor.invoke(CACHE_OBJECT_NAME, "getChildrenNames", new Object[]
+      {BUDDY_BACKUP_SUBTREE_FQN}, new String[]
+      {Fqn.class.getName()});
+
+      if (buddies != null)
+      {
+         for (Iterator it = buddies.iterator(); it.hasNext() && replVersion == null;)
+         {
+            Fqn fqn = new Fqn(BUDDY_BACKUP_SUBTREE_FQN, it.next());
+            fqn = new Fqn(fqn, Fqn.fromString(sessionFqn));
+            replVersion = adaptor.invoke(CACHE_OBJECT_NAME, "get", new Object[]
+            {fqn.toString(), VERSION_KEY}, TYPES);
+         }
+      }
+
+      return replVersion;
+   }
+
+   private SessionTestUtil() {}
+}

Modified: branches/JBoss_4_0_4_GA_JBAS-3526/testsuite/src/main/org/jboss/test/cluster/test/SimpleTestCase.java
===================================================================
--- branches/JBoss_4_0_4_GA_JBAS-3526/testsuite/src/main/org/jboss/test/cluster/test/SimpleTestCase.java	2006-08-18 13:54:54 UTC (rev 56063)
+++ branches/JBoss_4_0_4_GA_JBAS-3526/testsuite/src/main/org/jboss/test/cluster/test/SimpleTestCase.java	2006-08-18 14:33:16 UTC (rev 56064)
@@ -21,8 +21,11 @@
 */
 package org.jboss.test.cluster.test;
 
+import javax.management.MBeanServerConnection;
+
 import junit.framework.Test;
 import org.apache.commons.httpclient.HttpClient;
+import org.jboss.jmx.adaptor.rmi.RMIAdaptor;
 import org.jboss.test.JBossClusteredTestCase;
 
 /**
@@ -89,10 +92,6 @@
    /**
     * 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
@@ -106,25 +105,36 @@
 
       getLog().debug(setURLName + ":::::::" + getURLName);
 
-      // Create an instance of HttpClient.
+      // Create a session on server0 
       HttpClient client = new HttpClient();
-
-      // Set the session attribute first
       makeGet(client, baseURL0_ +setURLName);
 
+      // Create a session on server 1. 
+      HttpClient client1 = new HttpClient(); 
+      makeGet(client1, baseURL1_ +setURLName); 
+      
       sleepThread(18000);
       
-      // Set it again to ensure replication occurs
+      
+      // Find out the session id and use it to build an FQN 
+      String sessionID = getSessionID(client1, servers_[1]); 
+      // Strip off the jvmRoute, if there is one 
+      sessionID = stripJvmRoute(sessionID); 
+      String sessionFqn = "/JSESSION/localhost/http-sr/" + sessionID; 
+       
+      sleepThread(6000); 
+       
+      // Set the server0 session 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 15 secs.  This plus the previous 10 secs is enough to expire the
-      // session on the other node if replication failed to keep it alive
-      sleepThread(15000);
+      // Sleep 15 secs.  This plus the previous 18 secs is enough to expire 
+      // session0 on server1 if replication failed to keep it alive 
+      sleepThread(15000); 
       
-      // Switch to the other server and check the attribute
+      // Switch to the other server and check if 1st session is alive 
       setCookieDomainToThisServer(client, servers_[1]);
       attr2 = makeGetWithState(client, baseURL1_ +getURLName);
       
@@ -133,11 +143,28 @@
       
       getLog().debug("Replication has kept the session alive");
       
-      sleepThread(6000);  // sleep 6 more seconds so session will expire on node0
+      // sleep 6 more seconds so session0 will expire on server0 
+      sleepThread(6000);   
+       
+      // Confirm first session is expired on node 0 
       setCookieDomainToThisServer(client, servers_[0]);
       attr = makeGetWithState(client, baseURL0_ +getURLName);
       assertFalse("Original session not present", attr2.equals(attr));
       
+      // sleep 45 more seconds so session 1 will expire on server0. 
+      // need a total of 70 secs -- 60 to expire and 10 to ensure the  
+      // bg thread runs. 20 secs to expire is not enough as the reduced 
+      // life of this session is not available to the manager w/o  
+      // deserializing the session 
+      sleepThread(45000); 
+       
+      // Confirm 2nd session is gone from the distributed cache on node 0 
+      RMIAdaptor[] adaptors = getAdaptors(); 
+      assertNull("Session gone from distributed cache",  
+            SessionTestUtil.getSessionVersion(adaptors[0], sessionFqn)); 
+      assertNull("Session gone from distributed cache",  
+            SessionTestUtil.getBuddySessionVersion(adaptors[0], sessionFqn));
+      
       getLog().debug("Exit testSessionTimeout");
    }
    




More information about the jboss-cvs-commits mailing list