[jboss-cvs] JBossAS SVN: r57374 - in branches/JBoss_4_0_4_GA_CP: testsuite/src/main/org/jboss/test/cluster/test testsuite/src/resources/cluster/http testsuite/src/resources/cluster/http/http-field testsuite/src/resources/cluster/http/http-scoped tomcat/src/main/org/jboss/web/tomcat/tc5/session
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Mon Oct 2 22:35:33 EDT 2006
Author: ryan.campbell at jboss.com
Date: 2006-10-02 22:35:30 -0400 (Mon, 02 Oct 2006)
New Revision: 57374
Added:
branches/JBoss_4_0_4_GA_CP/testsuite/src/main/org/jboss/test/cluster/test/SessionTestUtil.java
Modified:
branches/JBoss_4_0_4_GA_CP/testsuite/src/main/org/jboss/test/cluster/test/BaseTest.java
branches/JBoss_4_0_4_GA_CP/testsuite/src/main/org/jboss/test/cluster/test/ScopedTestCase.java
branches/JBoss_4_0_4_GA_CP/testsuite/src/main/org/jboss/test/cluster/test/SimpleTestCase.java
branches/JBoss_4_0_4_GA_CP/testsuite/src/resources/cluster/http/getattribute.jsp
branches/JBoss_4_0_4_GA_CP/testsuite/src/resources/cluster/http/http-field/getAttribute.jsp
branches/JBoss_4_0_4_GA_CP/testsuite/src/resources/cluster/http/http-scoped/getAttribute.jsp
branches/JBoss_4_0_4_GA_CP/testsuite/src/resources/cluster/http/web.xml
branches/JBoss_4_0_4_GA_CP/tomcat/src/main/org/jboss/web/tomcat/tc5/session/ClusteredSession.java
branches/JBoss_4_0_4_GA_CP/tomcat/src/main/org/jboss/web/tomcat/tc5/session/JBossCacheManager.java
Log:
ASPATCH-56: JBAS-3526: JBAS-3310 and JBAS-3528 Patch for JBoss 4.0.4.GA
Modified: branches/JBoss_4_0_4_GA_CP/testsuite/src/main/org/jboss/test/cluster/test/BaseTest.java
===================================================================
--- branches/JBoss_4_0_4_GA_CP/testsuite/src/main/org/jboss/test/cluster/test/BaseTest.java 2006-10-03 02:20:46 UTC (rev 57373)
+++ branches/JBoss_4_0_4_GA_CP/testsuite/src/main/org/jboss/test/cluster/test/BaseTest.java 2006-10-03 02:35:30 UTC (rev 57374)
@@ -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;
Modified: branches/JBoss_4_0_4_GA_CP/testsuite/src/main/org/jboss/test/cluster/test/ScopedTestCase.java
===================================================================
--- branches/JBoss_4_0_4_GA_CP/testsuite/src/main/org/jboss/test/cluster/test/ScopedTestCase.java 2006-10-03 02:20:46 UTC (rev 57373)
+++ branches/JBoss_4_0_4_GA_CP/testsuite/src/main/org/jboss/test/cluster/test/ScopedTestCase.java 2006-10-03 02:35:30 UTC (rev 57374)
@@ -21,8 +21,13 @@
*/
package org.jboss.test.cluster.test;
+import java.io.IOException;
+import java.net.HttpURLConnection;
+
import junit.framework.Test;
+import org.apache.commons.httpclient.Header;
import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.methods.GetMethod;
import org.jboss.test.JBossClusteredTestCase;
/**
@@ -418,7 +423,71 @@
String attrRepl = makeGet(client, baseURL1_ +getSecuritySubjectUrl_);
assertTrue("javax.security.Subject did not replicate", attrRepl.indexOf("java.lang.String") > -1);
}
+
+ /**
+ * Test for JBAS-3528 (http://jira.jboss.com/jira/browse/JBAS-3528).
+ *
+ * @throws Exception
+ */
+ public void testIsNew() throws Exception
+ {
+ getLog().debug("Enter testIsNew");
+ getLog().debug(setUrl + ":::::::" + getUrl);
+
+ // Create an instance of HttpClient.
+ HttpClient client = new HttpClient();
+
+ // Set the session attribute first
+ makeGet(client, baseURL0_ +setUrl);
+
+ sleepThread(DEFAULT_SLEEP);
+
+ // Let's switch to server 2 to retrieve the session attribute.
+ setCookieDomainToThisServer(client, servers_[1]);
+ assertFalse("Session is not new", checkNew(client, baseURL1_ + getUrl));
+
+ sleepThread(DEFAULT_SLEEP);
+
+ // Let's switch to server 1 to ensure its correct there as well.
+ setCookieDomainToThisServer(client, servers_[0]);
+ assertFalse("Session is not new", checkNew(client, baseURL0_ + getUrl));
+ }
+
+
+ /**
+ * Makes a http call to the given url and confirms that a non-null
+ * header X-SessionIsNew is returned. Converts the value
+ * of the header to a boolean and returns it.
+ *
+ * @param client
+ * @param url
+ */
+ protected boolean checkNew(HttpClient client, String url)
+ {
+ getLog().info("checkNew(): trying to get from url " +url);
+
+ GetMethod method = new GetMethod(url);
+ int responseCode = 0;
+ try
+ {
+ responseCode = client.executeMethod(method);
+ } catch (IOException e)
+ {
+ e.printStackTrace();
+ fail("HttpClient executeMethod fails." +e.toString());
+ }
+ assertTrue("Get OK with url: " +url + " responseCode: " +responseCode
+ , responseCode == HttpURLConnection.HTTP_OK);
+
+ Header hdr = method.getResponseHeader("X-SessionIsNew");
+ assertNotNull("Got X-SessionIsNew header", hdr);
+ String value = hdr.getValue();
+ assertNotNull("Got non-nullX-SessionIsNew header", value);
+
+ return Boolean.valueOf(value).booleanValue();
+ }
+
protected void invalidate() throws Exception
{
// Create an instance of HttpClient.
Copied: branches/JBoss_4_0_4_GA_CP/testsuite/src/main/org/jboss/test/cluster/test/SessionTestUtil.java (from rev 57373, 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_CP/testsuite/src/main/org/jboss/test/cluster/test/SimpleTestCase.java
===================================================================
--- branches/JBoss_4_0_4_GA_CP/testsuite/src/main/org/jboss/test/cluster/test/SimpleTestCase.java 2006-10-03 02:20:46 UTC (rev 57373)
+++ branches/JBoss_4_0_4_GA_CP/testsuite/src/main/org/jboss/test/cluster/test/SimpleTestCase.java 2006-10-03 02:35:30 UTC (rev 57374)
@@ -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,33 @@
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);
- sleepThread(18000);
+ // Create a session on server 1.
+ HttpClient client1 = new HttpClient();
+ makeGet(client1, baseURL1_ +setURLName);
- // 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 +140,30 @@
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();
+ assertEquals("Session gone from distributed cache for " + sessionFqn,
+ null,
+ SessionTestUtil.getSessionVersion(adaptors[0], sessionFqn));
+ assertEquals("Session gone from distributed cache for " + sessionFqn,
+ null,
+ SessionTestUtil.getBuddySessionVersion(adaptors[0], sessionFqn));
+
getLog().debug("Exit testSessionTimeout");
}
Modified: branches/JBoss_4_0_4_GA_CP/testsuite/src/resources/cluster/http/getattribute.jsp
===================================================================
--- branches/JBoss_4_0_4_GA_CP/testsuite/src/resources/cluster/http/getattribute.jsp 2006-10-03 02:20:46 UTC (rev 57373)
+++ branches/JBoss_4_0_4_GA_CP/testsuite/src/resources/cluster/http/getattribute.jsp 2006-10-03 02:35:30 UTC (rev 57374)
@@ -3,6 +3,8 @@
String TEST_HTTP = (String) session.getAttribute("TEST_HTTP");
String flag = TEST_HTTP != null ? "true" : "false";
response.setHeader("X-SawTestHttpAttribute", flag);
+ String isNew = session.isNew() ? "true" : "false";
+ response.setHeader("X-SessionIsNew", isNew);
%>
<h2>Server info : <%=application.getServerInfo()%>:<%=request.getServerPort()%></h2>
Modified: branches/JBoss_4_0_4_GA_CP/testsuite/src/resources/cluster/http/http-field/getAttribute.jsp
===================================================================
--- branches/JBoss_4_0_4_GA_CP/testsuite/src/resources/cluster/http/http-field/getAttribute.jsp 2006-10-03 02:20:46 UTC (rev 57373)
+++ branches/JBoss_4_0_4_GA_CP/testsuite/src/resources/cluster/http/http-field/getAttribute.jsp 2006-10-03 02:35:30 UTC (rev 57374)
@@ -7,6 +7,9 @@
<%@ page import="org.jboss.test.cluster.web.aop.Student"%>
<%
+ String isNew = session.isNew() ? "true" : "false";
+ response.setHeader("X-SessionIsNew", isNew);
+
Student ben = (Student)session.getAttribute("TEST_PERSON");
String flag = ben != null ? "true" : "false";
response.setHeader("X-SawTestHttpAttribute", flag);
Modified: branches/JBoss_4_0_4_GA_CP/testsuite/src/resources/cluster/http/http-scoped/getAttribute.jsp
===================================================================
--- branches/JBoss_4_0_4_GA_CP/testsuite/src/resources/cluster/http/http-scoped/getAttribute.jsp 2006-10-03 02:20:46 UTC (rev 57373)
+++ branches/JBoss_4_0_4_GA_CP/testsuite/src/resources/cluster/http/http-scoped/getAttribute.jsp 2006-10-03 02:35:30 UTC (rev 57374)
@@ -3,8 +3,11 @@
%>
<% Person joe = ((Person)session.getAttribute("TEST_PERSON"));
- String flag = joe != null ? "true" : "false";
- response.setHeader("X-SawTestHttpAttribute", flag);
+ String flag = joe != null ? "true" : "false";
+ response.setHeader("X-SawTestHttpAttribute", flag);
+
+ String isNew = session.isNew() ? "true" : "false";
+ response.setHeader("X-SessionIsNew", isNew);
%>
<%= ((Person)session.getAttribute("TEST_PERSON")).getName() %>
Modified: branches/JBoss_4_0_4_GA_CP/testsuite/src/resources/cluster/http/web.xml
===================================================================
--- branches/JBoss_4_0_4_GA_CP/testsuite/src/resources/cluster/http/web.xml 2006-10-03 02:20:46 UTC (rev 57373)
+++ branches/JBoss_4_0_4_GA_CP/testsuite/src/resources/cluster/http/web.xml 2006-10-03 02:35:30 UTC (rev 57374)
@@ -5,14 +5,13 @@
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
- <distributable/>
<display-name>Welcome to JBoss</display-name>
<description>
Welcome to JBoss
</description>
+ <distributable/>
-
-<!-- timeout is set to 60 seconds -->
+ <!-- timeout is set to 60 seconds -->
<session-config>
<session-timeout>1</session-timeout>
</session-config>
Modified: branches/JBoss_4_0_4_GA_CP/tomcat/src/main/org/jboss/web/tomcat/tc5/session/ClusteredSession.java
===================================================================
--- branches/JBoss_4_0_4_GA_CP/tomcat/src/main/org/jboss/web/tomcat/tc5/session/ClusteredSession.java 2006-10-03 02:20:46 UTC (rev 57373)
+++ branches/JBoss_4_0_4_GA_CP/tomcat/src/main/org/jboss/web/tomcat/tc5/session/ClusteredSession.java 2006-10-03 02:35:30 UTC (rev 57374)
@@ -150,11 +150,31 @@
*/
protected transient long lastReplicated;
+ /**
+ * Maximum percentage of the inactive interval this session
+ * should be allowed to go unreplicated if access to the
+ * session doesn't mark it as dirty. Drives the calculation
+ * of maxUnreplicatedInterval.
+ */
protected transient int maxUnreplicatedFactor = 80;
+ /**
+ * Maximum number of milliseconds this session
+ * should be allowed to go unreplicated if access to the
+ * session doesn't mark it as dirty.
+ */
protected transient long maxUnreplicatedInterval;
+ /**
+ * Whether any of this session's attributes implement
+ * HttpSessionActivationListener.
+ */
protected transient Boolean hasActivationListener;
+
+ /**
+ * Has this session only been accessed once?
+ */
+ protected transient boolean firstAccess;
/**
* The string manager for this package.
@@ -179,6 +199,7 @@
super(manager);
invalidationPolicy = manager.getInvalidateSessionPolicy();
this.useJK = useJK;
+ this.firstAccess = true;
calcMaxUnreplicatedInterval();
}
@@ -441,11 +462,33 @@
{
super.access();
+ // JBAS-3528. If it's not the first access, make sure
+ // the 'new' flag is correct
+ if (!firstAccess && isNew)
+ {
+ setNew(false);
+ }
+
if (invalidationPolicy == WebMetaData.SESSION_INVALIDATE_ACCESS)
{
this.sessionMetadataDirty();
}
}
+
+
+ public void endAccess()
+ {
+ super.endAccess();
+
+ if (firstAccess)
+ {
+ firstAccess = false;
+ // Tomcat marks the session as non new, but that's not really
+ // accurate per SRV.7.2, as the second request hasn't come in yet
+ // So, we fix that
+ isNew = false;
+ }
+ }
public Object getAttribute(String name)
{
@@ -1074,6 +1117,10 @@
// We no longer know if we have an activationListener
hasActivationListener = null;
+ // If the session has been replicated, any subsequent
+ // access cannot be the first.
+ this.firstAccess = false;
+
// TODO uncomment when work on JBAS-1900 is completed
// // Session notes -- for FORM auth apps, allow replicated session
// // to be used without requiring a new login
Modified: branches/JBoss_4_0_4_GA_CP/tomcat/src/main/org/jboss/web/tomcat/tc5/session/JBossCacheManager.java
===================================================================
--- branches/JBoss_4_0_4_GA_CP/tomcat/src/main/org/jboss/web/tomcat/tc5/session/JBossCacheManager.java 2006-10-03 02:20:46 UTC (rev 57373)
+++ branches/JBoss_4_0_4_GA_CP/tomcat/src/main/org/jboss/web/tomcat/tc5/session/JBossCacheManager.java 2006-10-03 02:35:30 UTC (rev 57374)
@@ -1109,23 +1109,23 @@
log_.error("processSessionExpire: failed with exception: " + ex, ex);
throw ex;
}
+ }
- // Next, handle any unloaded sessions that are stale
+ // Next, handle any unloaded sessions that are stale
- long now = System.currentTimeMillis();
- Map unloaded = new HashMap(unloadedSessions_);
- Set entries = unloaded.entrySet();
- for (Iterator it = entries.iterator(); it.hasNext(); )
+ long now = System.currentTimeMillis();
+ Map unloaded = new HashMap(unloadedSessions_);
+ Set entries = unloaded.entrySet();
+ for (Iterator it = entries.iterator(); it.hasNext(); )
+ {
+ Map.Entry entry = (Map.Entry) it.next();
+ Long last = (Long) entry.getValue();
+ int elapsed = (int) ((now - last.longValue()) / 1000L);
+ if (elapsed >= maxInactiveInterval_)
{
- Map.Entry entry = (Map.Entry) it.next();
- Long last = (Long) entry.getValue();
- int elapsed = (int) ((now - last.longValue()) / 1000L);
- if (elapsed >= maxInactiveInterval_)
- {
- String realId = (String) entry.getKey();
- proxy_.removeSessionLocal(realId);
- unloadedSessions_.remove(realId);
- }
+ String realId = (String) entry.getKey();
+ proxy_.removeSessionLocal(realId);
+ unloadedSessions_.remove(realId);
}
}
}
More information about the jboss-cvs-commits
mailing list