mirror of
https://github.com/jetty/jetty.project.git
synced 2025-03-06 05:49:50 +00:00
parent
82413e1eeb
commit
58f3855ef5
@ -51,9 +51,4 @@ public class NonClusteredSessionScavengingTest extends AbstractNonClusteredSessi
|
|||||||
return FileTestHelper.newSessionDataStoreFactory();
|
return FileTestHelper.newSessionDataStoreFactory();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testNewSession() throws Exception
|
|
||||||
{
|
|
||||||
super.testNewSession();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -50,10 +50,4 @@ public class NonClusteredSessionScavengingTest extends AbstractNonClusteredSessi
|
|||||||
return GCloudSessionTestSupport.newSessionDataStoreFactory(GCloudTestSuite.__testSupport.getDatastore());
|
return GCloudSessionTestSupport.newSessionDataStoreFactory(GCloudTestSuite.__testSupport.getDatastore());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testNewSession() throws Exception
|
|
||||||
{
|
|
||||||
super.testNewSession();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -59,12 +59,4 @@ public class NonClusteredSessionScavengingTest extends AbstractNonClusteredSessi
|
|||||||
factory.setCache(__testSupport.getCache());
|
factory.setCache(__testSupport.getCache());
|
||||||
return factory;
|
return factory;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void testNewSession() throws Exception
|
|
||||||
{
|
|
||||||
super.testNewSession();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -59,13 +59,4 @@ public class NonClusteredSessionScavengingTest extends AbstractNonClusteredSessi
|
|||||||
factory.setCache(__testSupport.getCache());
|
factory.setCache(__testSupport.getCache());
|
||||||
return factory;
|
return factory;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void testNewSession() throws Exception
|
|
||||||
{
|
|
||||||
super.testNewSession();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -37,12 +37,6 @@ public class NonClusteredSessionScavengingTest extends AbstractNonClusteredSessi
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testNewSession() throws Exception
|
|
||||||
{
|
|
||||||
super.testNewSession();
|
|
||||||
}
|
|
||||||
|
|
||||||
@After
|
@After
|
||||||
public void tearDown() throws Exception
|
public void tearDown() throws Exception
|
||||||
{
|
{
|
||||||
|
@ -22,7 +22,6 @@ import org.eclipse.jetty.server.session.AbstractNonClusteredSessionScavengingTes
|
|||||||
import org.eclipse.jetty.server.session.SessionDataStoreFactory;
|
import org.eclipse.jetty.server.session.SessionDataStoreFactory;
|
||||||
import org.junit.AfterClass;
|
import org.junit.AfterClass;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* NonClusteredSessionScavengingTest
|
* NonClusteredSessionScavengingTest
|
||||||
@ -51,10 +50,4 @@ public class NonClusteredSessionScavengingTest extends AbstractNonClusteredSessi
|
|||||||
{
|
{
|
||||||
return MongoTestHelper.newSessionDataStoreFactory();
|
return MongoTestHelper.newSessionDataStoreFactory();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testNewSession() throws Exception
|
|
||||||
{
|
|
||||||
super.testNewSession();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -111,8 +111,62 @@ public abstract class AbstractNonClusteredSessionScavengingTest extends Abstract
|
|||||||
{
|
{
|
||||||
server.stop();
|
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
|
public static class TestServlet extends HttpServlet
|
||||||
{
|
{
|
||||||
String id;
|
String id;
|
||||||
@ -135,6 +189,12 @@ public abstract class AbstractNonClusteredSessionScavengingTest extends Abstract
|
|||||||
assertNotNull(s);
|
assertNotNull(s);
|
||||||
assertFalse(s.getId().equals(id));
|
assertFalse(s.getId().equals(id));
|
||||||
}
|
}
|
||||||
|
else if ("old-test".equals(action))
|
||||||
|
{
|
||||||
|
HttpSession s = request.getSession(false);
|
||||||
|
assertNotNull(s);
|
||||||
|
assertTrue(s.getId().equals(id));
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
assertTrue(false);
|
assertTrue(false);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user