Add extra test to ensure immortal session never scavenged
This commit is contained in:
Jan Bartel 2017-03-08 17:22:47 +11:00
parent 82413e1eeb
commit 58f3855ef5
7 changed files with 62 additions and 43 deletions

View File

@ -50,10 +50,5 @@ public class NonClusteredSessionScavengingTest extends AbstractNonClusteredSessi
{
return FileTestHelper.newSessionDataStoreFactory();
}
@Test
public void testNewSession() throws Exception
{
super.testNewSession();
}
}

View File

@ -50,10 +50,4 @@ public class NonClusteredSessionScavengingTest extends AbstractNonClusteredSessi
return GCloudSessionTestSupport.newSessionDataStoreFactory(GCloudTestSuite.__testSupport.getDatastore());
}
@Test
public void testNewSession() throws Exception
{
super.testNewSession();
}
}

View File

@ -59,12 +59,4 @@ public class NonClusteredSessionScavengingTest extends AbstractNonClusteredSessi
factory.setCache(__testSupport.getCache());
return factory;
}
@Override
public void testNewSession() throws Exception
{
super.testNewSession();
}
}

View File

@ -59,13 +59,4 @@ public class NonClusteredSessionScavengingTest extends AbstractNonClusteredSessi
factory.setCache(__testSupport.getCache());
return factory;
}
@Override
public void testNewSession() throws Exception
{
super.testNewSession();
}
}

View File

@ -35,13 +35,7 @@ public class NonClusteredSessionScavengingTest extends AbstractNonClusteredSessi
{
return JdbcTestHelper.newSessionDataStoreFactory();
}
@Test
public void testNewSession() throws Exception
{
super.testNewSession();
}
@After
public void tearDown() throws Exception

View File

@ -22,7 +22,6 @@ import org.eclipse.jetty.server.session.AbstractNonClusteredSessionScavengingTes
import org.eclipse.jetty.server.session.SessionDataStoreFactory;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
/**
* NonClusteredSessionScavengingTest
@ -51,10 +50,4 @@ public class NonClusteredSessionScavengingTest extends AbstractNonClusteredSessi
{
return MongoTestHelper.newSessionDataStoreFactory();
}
@Test
public void testNewSession() throws Exception
{
super.testNewSession();
}
}

View File

@ -111,8 +111,62 @@ public abstract class AbstractNonClusteredSessionScavengingTest extends Abstract
{
server.stop();
}
}
@Test
public void testImmortalSession() throws Exception
{
String servletMapping = "/server";
int scavengePeriod = 3;
int maxInactivePeriod = 0;
DefaultSessionCacheFactory cacheFactory = new DefaultSessionCacheFactory();
cacheFactory.setEvictionPolicy(SessionCache.NEVER_EVICT);
SessionDataStoreFactory storeFactory = createSessionDataStoreFactory();
((AbstractSessionDataStoreFactory)storeFactory).setGracePeriodSec(scavengePeriod);
TestServer server = new TestServer(0, maxInactivePeriod, scavengePeriod,
cacheFactory, storeFactory);
ServletContextHandler context = server.addContext("/");
context.addServlet(TestServlet.class, servletMapping);
String contextPath = "";
try
{
server.start();
int port=server.getPort();
HttpClient client = new HttpClient();
client.start();
try
{
//create an immortal session
ContentResponse response = client.GET("http://localhost:" + port + contextPath + servletMapping + "?action=create");
assertEquals(HttpServletResponse.SC_OK,response.getStatus());
String sessionCookie = response.getHeaders().get("Set-Cookie");
assertTrue(sessionCookie != null);
// Mangle the cookie, replacing Path with $Path, etc.
sessionCookie = sessionCookie.replaceFirst("(\\W)(P|p)ath=", "$1\\$Path=");
// Let's wait for the scavenger to run
pause(2*scavengePeriod);
// Test that the session is still there
Request request = client.newRequest("http://localhost:" + port + contextPath + servletMapping + "?action=old-test");
request.header("Cookie", sessionCookie);
response = request.send();
assertEquals(HttpServletResponse.SC_OK,response.getStatus());
}
finally
{
client.stop();
}
}
finally
{
server.stop();
}
}
public static class TestServlet extends HttpServlet
{
String id;
@ -135,6 +189,12 @@ public abstract class AbstractNonClusteredSessionScavengingTest extends Abstract
assertNotNull(s);
assertFalse(s.getId().equals(id));
}
else if ("old-test".equals(action))
{
HttpSession s = request.getSession(false);
assertNotNull(s);
assertTrue(s.getId().equals(id));
}
else
{
assertTrue(false);