Issue #411 Add more debug log for mongosessionmanager and remove debug printlns

This commit is contained in:
Jan Bartel 2016-03-11 15:11:23 +11:00
parent 2af81781cd
commit d82b5ad65a
4 changed files with 83 additions and 7 deletions

View File

@ -557,8 +557,10 @@ public abstract class AbstractSession implements AbstractSessionManager.SessionI
@Override
public void setMaxInactiveInterval(int secs)
{
if (secs < 0)
if (secs <= 0)
LOG.warn("Session {} is now immortal (maxInactiveInterval={})", _clusterId, secs);
else if (LOG.isDebugEnabled())
LOG.debug("Session {} maxInactiveInterval={}", _clusterId, secs);
_maxIdleMs=(long)secs*1000L;
}

View File

@ -627,8 +627,10 @@ public abstract class AbstractSessionManager extends ContainerLifeCycle implemen
public void setMaxInactiveInterval(int seconds)
{
_dftMaxIdleSecs=seconds;
if (_dftMaxIdleSecs < 0)
if (_dftMaxIdleSecs <= 0)
__log.warn("Sessions created by this manager are immortal (default maxInactiveInterval={})"+_dftMaxIdleSecs);
else if (__log.isDebugEnabled())
__log.debug("SessionManager default maxInactiveInterval={}", _dftMaxIdleSecs);
}
/* ------------------------------------------------------------ */

View File

@ -139,7 +139,6 @@ public class IdleSessionTest
//Test trying to de-idle an expired session (ie before the scavenger can get to it)
System.err.println("\n TESTING DEIDLE EXPIRED\n");
//make a request to set up a session on the server
response = client.GET(url + "?action=init");
assertEquals(HttpServletResponse.SC_OK,response.getStatus());
@ -153,14 +152,12 @@ public class IdleSessionTest
//stop the scavenger
((MongoTestServer.TestMongoSessionIdManager)server1.getServer().getSessionIdManager()).cancelScavenge();
System.err.println("SCAVENGE STOPPED");
//check that the session is idle
checkSessionIdle();
System.err.println("WAITING FOR EXPIRY TIME TO PASS");
//wait until the session should be expired
pause (inactivePeriod + (inactivePeriod/2));
System.err.println("EXPIRY TIME PASSED");
//make a request to try and deidle the session
//make another request to de-idle the session

View File

@ -191,6 +191,55 @@ public class SessionExpiryTest extends AbstractSessionExpiryTest
}
@Test
public void testChangeNewSessionTimeout () throws Exception
{
String contextPath = "";
String servletMapping = "/server";
int inactivePeriod = 10;
int scavengePeriod = 1;
AbstractTestServer server1 = createServer(0, inactivePeriod, scavengePeriod);
ImmediateChangeTimeoutServlet servlet = new ImmediateChangeTimeoutServlet();
ServletHolder holder = new ServletHolder(servlet);
ServletContextHandler context = server1.addContext(contextPath);
context.addServlet(holder, servletMapping);
TestHttpSessionListener listener = new TestHttpSessionListener();
context.getSessionHandler().addEventListener(listener);
server1.start();
int port1 = server1.getPort();
try
{
HttpClient client = new HttpClient();
client.start();
String url = "http://localhost:" + port1 + contextPath + servletMapping;
inactivePeriod = 5; //change from the sessionmanager configured default
//make a request to set up a session on the server and change its inactive setting straight away
ContentResponse response1 = client.GET(url + "?action=init&val="+inactivePeriod);
assertEquals(HttpServletResponse.SC_OK,response1.getStatus());
String sessionCookie = response1.getHeaders().get("Set-Cookie");
assertTrue(sessionCookie != null);
// Mangle the cookie, replacing Path with $Path, etc.
sessionCookie = sessionCookie.replaceFirst("(\\W)(P|p)ath=", "$1\\$Path=");
String sessionId = AbstractTestServer.extractSessionId(sessionCookie);
DBCollection sessions = ((MongoSessionIdManager)((MongoTestServer)server1).getServer().getSessionIdManager()).getSessions();
verifySessionCreated(listener,sessionId);
//verify that the session timeout is the new value and not the default
verifySessionTimeout(sessions, sessionId, inactivePeriod);
}
finally
{
server1.stop();
}
}
public void verifySessionTimeout (DBCollection sessions, String id, int sec) throws Exception
{
assertNotNull(sessions);
@ -268,5 +317,31 @@ public class SessionExpiryTest extends AbstractSessionExpiryTest
}
}
}
public static class ImmediateChangeTimeoutServlet extends HttpServlet
{
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse httpServletResponse) throws ServletException, IOException
{
String action = request.getParameter("action");
if ("init".equals(action))
{
HttpSession session = request.getSession(true);
assertNotNull(session);
String tmp = request.getParameter("val");
int val = (StringUtil.isBlank(tmp)?0:Integer.valueOf(tmp.trim()));
session.setMaxInactiveInterval(val);
}
else if ("change".equals(action))
{
String tmp = request.getParameter("val");
int val = (StringUtil.isBlank(tmp)?0:Integer.valueOf(tmp.trim()));
HttpSession session = request.getSession(false);
assertNotNull(session);
session.setMaxInactiveInterval(val);
}
}
}
}