Fix session test timeouts
This commit is contained in:
parent
07c45149d4
commit
c727518d5c
|
@ -78,7 +78,7 @@ public class SessionExpiryTest extends AbstractSessionExpiryTest
|
|||
public void testSessionExpiry() throws Exception
|
||||
{
|
||||
super.testSessionExpiry();
|
||||
try{_testSupport.assertSessions(0);}catch(Exception e){ Assert.fail(e.getMessage());}
|
||||
_testSupport.deleteSessions();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -92,7 +92,6 @@ public class SessionExpiryTest extends AbstractSessionExpiryTest
|
|||
public void verifySessionDestroyed(TestHttpSessionListener listener, String sessionId)
|
||||
{
|
||||
super.verifySessionDestroyed(listener, sessionId);
|
||||
try{_testSupport.assertSessions(0);}catch(Exception e){ Assert.fail(e.getMessage());}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -54,7 +54,7 @@ import org.junit.Test;
|
|||
* AbstractCreateAndInvalidateTest
|
||||
*
|
||||
* Test that creating a session and invalidating it before the request exits the session
|
||||
* does not result in the session being in mongo
|
||||
* does not result in the session being persisted
|
||||
*/
|
||||
public abstract class AbstractCreateAndInvalidateTest{
|
||||
|
||||
|
@ -88,7 +88,7 @@ public abstract class AbstractCreateAndInvalidateTest{
|
|||
* Create and then invalidate a session in the same request.
|
||||
* @throws Exception
|
||||
*/
|
||||
//@Test
|
||||
@Test
|
||||
public void testSessionCreateAndInvalidate() throws Exception
|
||||
{
|
||||
String contextPath = "";
|
||||
|
@ -132,7 +132,7 @@ public abstract class AbstractCreateAndInvalidateTest{
|
|||
* completes.
|
||||
* @throws Exception
|
||||
*/
|
||||
//@Test
|
||||
@Test
|
||||
public void testSessionCreateForward () throws Exception
|
||||
{
|
||||
String contextPath = "";
|
||||
|
@ -162,7 +162,7 @@ public abstract class AbstractCreateAndInvalidateTest{
|
|||
ContentResponse response = client.GET(url+"?action=forward");
|
||||
assertEquals(HttpServletResponse.SC_OK,response.getStatus());
|
||||
|
||||
//check that the sessions exist in mongo
|
||||
//check that the sessions exist persisted
|
||||
checkSession(_servlet._id, true);
|
||||
checkSessionByKey (_servlet._id, "0_0_0_0:", true);
|
||||
checkSessionByKey (_servlet._id, "0_0_0_0:_contextB", true);
|
||||
|
|
|
@ -65,8 +65,7 @@ public abstract class AbstractLastAccessTimeTest
|
|||
String servletMapping = "/server";
|
||||
int maxInactivePeriod = 8; //session will timeout after 8 seconds
|
||||
int scavengePeriod = 2; //scavenging occurs every 2 seconds
|
||||
int idlePassivatePeriod = -1; //dont check for idle sessions to passivate
|
||||
AbstractTestServer server1 = createServer(0, maxInactivePeriod, scavengePeriod, idlePassivatePeriod);
|
||||
AbstractTestServer server1 = createServer(0, maxInactivePeriod, scavengePeriod, SessionCache.NEVER_EVICT);
|
||||
TestServlet servlet1 = new TestServlet();
|
||||
ServletHolder holder1 = new ServletHolder(servlet1);
|
||||
ServletContextHandler context = server1.addContext(contextPath);
|
||||
|
@ -80,7 +79,7 @@ public abstract class AbstractLastAccessTimeTest
|
|||
{
|
||||
server1.start();
|
||||
int port1=server1.getPort();
|
||||
AbstractTestServer server2 = createServer(0, maxInactivePeriod, scavengePeriod, idlePassivatePeriod);
|
||||
AbstractTestServer server2 = createServer(0, maxInactivePeriod, scavengePeriod, SessionCache.NEVER_EVICT);
|
||||
ServletContextHandler context2 = server2.addContext(contextPath);
|
||||
context2.addServlet(TestServlet.class, servletMapping);
|
||||
SessionHandler m2 = context2.getSessionHandler();
|
||||
|
@ -130,7 +129,7 @@ public abstract class AbstractLastAccessTimeTest
|
|||
|
||||
// At this point, session1 should be eligible for expiration.
|
||||
// Let's wait for the scavenger to run, waiting 2.5 times the scavenger period
|
||||
Thread.sleep(scavengePeriod * 2500L);
|
||||
Thread.sleep(maxInactivePeriod+(scavengePeriod * 2500L));
|
||||
|
||||
//check that the session was not scavenged over on server1 by ensuring that the SessionListener destroy method wasn't called
|
||||
assertFalse(listener1._destroys.contains(AbstractTestServer.extractSessionId(sessionCookie)));
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
package org.eclipse.jetty.server.session;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -46,7 +47,7 @@ public abstract class AbstractLocalSessionScavengingTest
|
|||
{
|
||||
try
|
||||
{
|
||||
Thread.sleep(scavengePeriod * 2500L);
|
||||
Thread.sleep(scavengePeriod * 1000L);
|
||||
}
|
||||
catch (InterruptedException e)
|
||||
{
|
||||
|
@ -59,10 +60,9 @@ public abstract class AbstractLocalSessionScavengingTest
|
|||
{
|
||||
String contextPath = "";
|
||||
String servletMapping = "/server";
|
||||
int inactivePeriod = 1;
|
||||
int scavengePeriod = 2;
|
||||
int evictionSec = 20;
|
||||
AbstractTestServer server1 = createServer(0, inactivePeriod, scavengePeriod, evictionSec);
|
||||
int inactivePeriod = 4;
|
||||
int scavengePeriod = 1;
|
||||
AbstractTestServer server1 = createServer(0, inactivePeriod, scavengePeriod, SessionCache.NEVER_EVICT);
|
||||
ServletContextHandler context1 = server1.addContext(contextPath);
|
||||
context1.addServlet(TestServlet.class, servletMapping);
|
||||
|
||||
|
@ -70,7 +70,7 @@ public abstract class AbstractLocalSessionScavengingTest
|
|||
{
|
||||
server1.start();
|
||||
int port1 = server1.getPort();
|
||||
AbstractTestServer server2 = createServer(0, inactivePeriod, scavengePeriod * 3, evictionSec);
|
||||
AbstractTestServer server2 = createServer(0, inactivePeriod, scavengePeriod * 2, SessionCache.NEVER_EVICT);
|
||||
ServletContextHandler context2 = server2.addContext(contextPath);
|
||||
context2.addServlet(TestServlet.class, servletMapping);
|
||||
|
||||
|
@ -103,8 +103,8 @@ public abstract class AbstractLocalSessionScavengingTest
|
|||
assertEquals(HttpServletResponse.SC_OK,response2.getStatus());
|
||||
SessionHandler m2 = context2.getSessionHandler();
|
||||
|
||||
// Wait for the scavenger to run on node1, waiting 2.5 times the scavenger period
|
||||
pause(scavengePeriod);
|
||||
// Wait for the scavenger to run on node1
|
||||
pause(inactivePeriod+(2*scavengePeriod));
|
||||
|
||||
assertEquals(1, m1.getSessionsCreated());
|
||||
|
||||
|
@ -116,9 +116,9 @@ public abstract class AbstractLocalSessionScavengingTest
|
|||
|
||||
assertEquals(1, m1.getSessionsCreated());
|
||||
|
||||
// Wait for the scavenger to run on node2, waiting 2 times the scavenger period
|
||||
// Wait for the scavenger to run on node2, waiting 3 times the scavenger period
|
||||
// This ensures that the scavenger on node2 runs at least once.
|
||||
pause(scavengePeriod);
|
||||
pause(inactivePeriod+(2*scavengePeriod));
|
||||
|
||||
// Check that node2 does not have any local session cached
|
||||
request = client.newRequest(urls[1] + "?action=check");
|
||||
|
@ -156,6 +156,7 @@ public abstract class AbstractLocalSessionScavengingTest
|
|||
else if ("test".equals(action))
|
||||
{
|
||||
HttpSession session = request.getSession(false);
|
||||
assertNotNull(session);
|
||||
session.setAttribute("test", "test");
|
||||
}
|
||||
else if ("check".equals(action))
|
||||
|
|
|
@ -62,7 +62,7 @@ public abstract class AbstractNewSessionTest
|
|||
{
|
||||
String servletMapping = "/server";
|
||||
int scavengePeriod = 3;
|
||||
AbstractTestServer server = createServer(0, 1, scavengePeriod, 4);
|
||||
AbstractTestServer server = createServer(0, 1, scavengePeriod, SessionCache.NEVER_EVICT);
|
||||
ServletContextHandler context = server.addContext("/");
|
||||
context.addServlet(TestServlet.class, servletMapping);
|
||||
String contextPath = "";
|
||||
|
|
|
@ -73,7 +73,7 @@ public abstract class AbstractProxySerializationTest
|
|||
String contextPath = "";
|
||||
String servletMapping = "/server";
|
||||
int scavengePeriod = 10;
|
||||
AbstractTestServer server = createServer(0, 20, scavengePeriod, 20);
|
||||
AbstractTestServer server = createServer(0, 20, scavengePeriod, SessionCache.NEVER_EVICT);
|
||||
ServletContextHandler context = server.addContext(contextPath);
|
||||
|
||||
InputStream is = this.getClass().getClassLoader().getResourceAsStream("proxy-serialization.jar");
|
||||
|
|
|
@ -50,7 +50,7 @@ public abstract class AbstractReentrantRequestSessionTest
|
|||
{
|
||||
String contextPath = "";
|
||||
String servletMapping = "/server";
|
||||
AbstractTestServer server = createServer(0, 100, 400, 10);
|
||||
AbstractTestServer server = createServer(0, 100, 400, SessionCache.NEVER_EVICT);
|
||||
server.addContext(contextPath).addServlet(TestServlet.class, servletMapping);
|
||||
try
|
||||
{
|
||||
|
|
|
@ -55,9 +55,7 @@ public abstract class AbstractRemoveSessionTest
|
|||
{
|
||||
String contextPath = "";
|
||||
String servletMapping = "/server";
|
||||
int scavengePeriod = 3;
|
||||
int inspectionPeriod = 1;
|
||||
AbstractTestServer server = createServer(0, 1, scavengePeriod, -1);
|
||||
AbstractTestServer server = createServer(0, -1, -1, SessionCache.NEVER_EVICT);
|
||||
ServletContextHandler context = server.addContext(contextPath);
|
||||
context.addServlet(TestServlet.class, servletMapping);
|
||||
TestEventListener testListener = new TestEventListener();
|
||||
|
|
|
@ -64,9 +64,7 @@ public abstract class AbstractSessionCookieTest
|
|||
String contextPath = "";
|
||||
String servletMapping = "/server";
|
||||
int scavengePeriod = 3;
|
||||
int inspectPeriod = 1;
|
||||
int idlePassivatePeriod = 10;
|
||||
AbstractTestServer server = createServer(0, 1, scavengePeriod,idlePassivatePeriod);
|
||||
AbstractTestServer server = createServer(0, 1, scavengePeriod,SessionCache.NEVER_EVICT);
|
||||
ServletContextHandler context = server.addContext(contextPath);
|
||||
context.addServlet(TestServlet.class, servletMapping);
|
||||
|
||||
|
|
|
@ -36,6 +36,7 @@ import javax.servlet.http.HttpSessionListener;
|
|||
import org.eclipse.jetty.client.HttpClient;
|
||||
import org.eclipse.jetty.client.api.ContentResponse;
|
||||
import org.eclipse.jetty.client.api.Request;
|
||||
import org.eclipse.jetty.server.session.Session.SessionInactivityTimeout;
|
||||
import org.eclipse.jetty.servlet.ServletContextHandler;
|
||||
import org.eclipse.jetty.servlet.ServletHolder;
|
||||
import org.junit.Test;
|
||||
|
@ -53,7 +54,7 @@ public abstract class AbstractSessionExpiryTest
|
|||
{
|
||||
try
|
||||
{
|
||||
Thread.sleep(scavengePeriod * 2500L);
|
||||
Thread.sleep(scavengePeriod * 1000L);
|
||||
}
|
||||
catch (InterruptedException e)
|
||||
{
|
||||
|
@ -78,6 +79,10 @@ public abstract class AbstractSessionExpiryTest
|
|||
};
|
||||
|
||||
|
||||
/**
|
||||
* Check session is preserved over stop/start
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
public void testSessionNotExpired() throws Exception
|
||||
{
|
||||
|
@ -85,9 +90,7 @@ public abstract class AbstractSessionExpiryTest
|
|||
String servletMapping = "/server";
|
||||
int inactivePeriod = 20;
|
||||
int scavengePeriod = 10;
|
||||
int inspectPeriod = 1;
|
||||
int idlePassivatePeriod = 8;
|
||||
AbstractTestServer server1 = createServer(0, inactivePeriod, scavengePeriod, idlePassivatePeriod);
|
||||
AbstractTestServer server1 = createServer(0, inactivePeriod, scavengePeriod, SessionCache.NEVER_EVICT);
|
||||
TestServlet servlet = new TestServlet();
|
||||
ServletHolder holder = new ServletHolder(servlet);
|
||||
server1.addContext(contextPath).addServlet(holder, servletMapping);
|
||||
|
@ -133,6 +136,11 @@ public abstract class AbstractSessionExpiryTest
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check that a session that expires whilst the server is stopped will not be
|
||||
* able to be used when the server restarts
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
public void testSessionExpiry() throws Exception
|
||||
{
|
||||
|
@ -140,10 +148,9 @@ public abstract class AbstractSessionExpiryTest
|
|||
|
||||
String contextPath = "";
|
||||
String servletMapping = "/server";
|
||||
int inactivePeriod = 2;
|
||||
int inactivePeriod = 4;
|
||||
int scavengePeriod = 1;
|
||||
int inspectPeriod = 1;
|
||||
AbstractTestServer server1 = createServer(0, inactivePeriod, scavengePeriod, -1);
|
||||
AbstractTestServer server1 = createServer(0, inactivePeriod, scavengePeriod, SessionCache.NEVER_EVICT);
|
||||
TestServlet servlet = new TestServlet();
|
||||
ServletHolder holder = new ServletHolder(servlet);
|
||||
ServletContextHandler context = server1.addContext(contextPath);
|
||||
|
@ -176,12 +183,15 @@ public abstract class AbstractSessionExpiryTest
|
|||
//now stop the server
|
||||
server1.stop();
|
||||
|
||||
//and wait until the expiry time has passed
|
||||
//and wait until the session should have expired
|
||||
pause(inactivePeriod);
|
||||
|
||||
//restart the server
|
||||
server1.start();
|
||||
|
||||
//and wait until the scavenger has run
|
||||
pause(inactivePeriod+(scavengePeriod*2));
|
||||
|
||||
port1 = server1.getPort();
|
||||
url = "http://localhost:" + port1 + contextPath + servletMapping;
|
||||
|
||||
|
@ -189,11 +199,10 @@ public abstract class AbstractSessionExpiryTest
|
|||
Request request = client.newRequest(url + "?action=test");
|
||||
request.getHeaders().add("Cookie", sessionCookie);
|
||||
ContentResponse response2 = request.send();
|
||||
|
||||
assertEquals(HttpServletResponse.SC_OK,response2.getStatus());
|
||||
|
||||
//and wait until the expiry time has passed
|
||||
pause(inactivePeriod);
|
||||
|
||||
String cookie2 = response2.getHeaders().get("Set-Cookie");
|
||||
assertTrue (!cookie2.equals(sessionCookie));
|
||||
verifySessionDestroyed (listener, sessionId);
|
||||
}
|
||||
finally
|
||||
|
|
|
@ -81,7 +81,7 @@ public abstract class AbstractSessionInvalidateAndCreateTest
|
|||
{
|
||||
try
|
||||
{
|
||||
Thread.sleep(scavengePeriod * 3000L);
|
||||
Thread.sleep(scavengePeriod * 1000L);
|
||||
}
|
||||
catch (InterruptedException e)
|
||||
{
|
||||
|
@ -94,8 +94,8 @@ public abstract class AbstractSessionInvalidateAndCreateTest
|
|||
{
|
||||
String contextPath = "";
|
||||
String servletMapping = "/server";
|
||||
int inactivePeriod = 1;
|
||||
int scavengePeriod = 2;
|
||||
int inactivePeriod = 6;
|
||||
int scavengePeriod = 3;
|
||||
AbstractTestServer server = createServer(0, inactivePeriod, scavengePeriod, SessionCache.NEVER_EVICT);
|
||||
ServletContextHandler context = server.addContext(contextPath);
|
||||
TestServlet servlet = new TestServlet();
|
||||
|
@ -130,8 +130,8 @@ public abstract class AbstractSessionInvalidateAndCreateTest
|
|||
ContentResponse response2 = request2.send();
|
||||
assertEquals(HttpServletResponse.SC_OK,response2.getStatus());
|
||||
|
||||
// Wait for the scavenger to run, waiting 3 times the scavenger period
|
||||
pause(scavengePeriod);
|
||||
// Wait for the scavenger to run
|
||||
pause(inactivePeriod+scavengePeriod);
|
||||
|
||||
//test that the session created in the last test is scavenged:
|
||||
//the HttpSessionListener should have been called when session1 was invalidated and session2 was scavenged
|
||||
|
|
Loading…
Reference in New Issue