Issue #1318
This commit is contained in:
parent
ae0cef97c2
commit
5015ed5173
|
@ -59,11 +59,12 @@ public class SessionEvictionFailureTest
|
||||||
*/
|
*/
|
||||||
public static class MockSessionDataStore extends AbstractSessionDataStore
|
public static class MockSessionDataStore extends AbstractSessionDataStore
|
||||||
{
|
{
|
||||||
public boolean _nextResult;
|
public boolean[] _nextStoreResult;
|
||||||
|
public int i = 0;
|
||||||
|
|
||||||
public void setNextResult (boolean goodOrBad)
|
public MockSessionDataStore (boolean[] results)
|
||||||
{
|
{
|
||||||
_nextResult = goodOrBad;
|
_nextStoreResult = results;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -108,7 +109,7 @@ public class SessionEvictionFailureTest
|
||||||
@Override
|
@Override
|
||||||
public void doStore(String id, SessionData data, long lastSaveTime) throws Exception
|
public void doStore(String id, SessionData data, long lastSaveTime) throws Exception
|
||||||
{
|
{
|
||||||
if (!_nextResult)
|
if (_nextStoreResult != null && !_nextStoreResult[i++])
|
||||||
{
|
{
|
||||||
throw new IllegalStateException("Testing store");
|
throw new IllegalStateException("Testing store");
|
||||||
}
|
}
|
||||||
|
@ -132,6 +133,12 @@ public class SessionEvictionFailureTest
|
||||||
*/
|
*/
|
||||||
public static class MockSessionDataStoreFactory extends AbstractSessionDataStoreFactory
|
public static class MockSessionDataStoreFactory extends AbstractSessionDataStoreFactory
|
||||||
{
|
{
|
||||||
|
public boolean[] _nextStoreResults;
|
||||||
|
|
||||||
|
public void setNextStoreResults(boolean[] storeResults)
|
||||||
|
{
|
||||||
|
_nextStoreResults = storeResults;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see org.eclipse.jetty.server.session.SessionDataStoreFactory#getSessionDataStore(org.eclipse.jetty.server.session.SessionHandler)
|
* @see org.eclipse.jetty.server.session.SessionDataStoreFactory#getSessionDataStore(org.eclipse.jetty.server.session.SessionHandler)
|
||||||
|
@ -139,7 +146,7 @@ public class SessionEvictionFailureTest
|
||||||
@Override
|
@Override
|
||||||
public SessionDataStore getSessionDataStore(SessionHandler handler) throws Exception
|
public SessionDataStore getSessionDataStore(SessionHandler handler) throws Exception
|
||||||
{
|
{
|
||||||
return new MockSessionDataStore();
|
return new MockSessionDataStore(_nextStoreResults);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -208,7 +215,7 @@ public class SessionEvictionFailureTest
|
||||||
TestServer server = new TestServer (0, inactivePeriod, scavengePeriod, cacheFactory, storeFactory);
|
TestServer server = new TestServer (0, inactivePeriod, scavengePeriod, cacheFactory, storeFactory);
|
||||||
ServletContextHandler context = server.addContext(contextPath);
|
ServletContextHandler context = server.addContext(contextPath);
|
||||||
context.getSessionHandler().getSessionCache().setSaveOnInactiveEviction(true);
|
context.getSessionHandler().getSessionCache().setSaveOnInactiveEviction(true);
|
||||||
MockSessionDataStore ds = new MockSessionDataStore();
|
MockSessionDataStore ds = new MockSessionDataStore(new boolean[] {true, false, true, false, true});
|
||||||
context.getSessionHandler().getSessionCache().setSessionDataStore(ds);
|
context.getSessionHandler().getSessionCache().setSessionDataStore(ds);
|
||||||
|
|
||||||
TestServlet servlet = new TestServlet();
|
TestServlet servlet = new TestServlet();
|
||||||
|
@ -226,7 +233,6 @@ public class SessionEvictionFailureTest
|
||||||
String url = "http://localhost:" + port1 + contextPath + servletMapping;
|
String url = "http://localhost:" + port1 + contextPath + servletMapping;
|
||||||
|
|
||||||
// Create the session
|
// Create the session
|
||||||
ds.setNextResult(true);
|
|
||||||
ContentResponse response = client.GET(url + "?action=init");
|
ContentResponse response = client.GET(url + "?action=init");
|
||||||
assertEquals(HttpServletResponse.SC_OK,response.getStatus());
|
assertEquals(HttpServletResponse.SC_OK,response.getStatus());
|
||||||
String sessionCookie = response.getHeaders().get("Set-Cookie");
|
String sessionCookie = response.getHeaders().get("Set-Cookie");
|
||||||
|
@ -234,13 +240,10 @@ public class SessionEvictionFailureTest
|
||||||
// Mangle the cookie, replacing Path with $Path, etc.
|
// Mangle the cookie, replacing Path with $Path, etc.
|
||||||
sessionCookie = sessionCookie.replaceFirst("(\\W)(P|p)ath=", "$1\\$Path=");
|
sessionCookie = sessionCookie.replaceFirst("(\\W)(P|p)ath=", "$1\\$Path=");
|
||||||
|
|
||||||
ds.setNextResult(false);
|
|
||||||
|
|
||||||
//Wait for the eviction period to expire - save on evict should fail but session
|
//Wait for the eviction period to expire - save on evict should fail but session
|
||||||
//should remain in the cache
|
//should remain in the cache
|
||||||
pause(evictionPeriod);
|
pause(evictionPeriod+(int)(evictionPeriod*0.5));
|
||||||
|
|
||||||
ds.setNextResult(true);
|
|
||||||
|
|
||||||
// Make another request to see if the session is still in the cache and can be used,
|
// Make another request to see if the session is still in the cache and can be used,
|
||||||
//allow it to be saved this time
|
//allow it to be saved this time
|
||||||
|
@ -249,12 +252,11 @@ public class SessionEvictionFailureTest
|
||||||
response = request.send();
|
response = request.send();
|
||||||
assertEquals(HttpServletResponse.SC_OK,response.getStatus());
|
assertEquals(HttpServletResponse.SC_OK,response.getStatus());
|
||||||
assertNull(response.getHeaders().get("Set-Cookie")); //check that the cookie wasn't reset
|
assertNull(response.getHeaders().get("Set-Cookie")); //check that the cookie wasn't reset
|
||||||
ds.setNextResult(false);
|
|
||||||
|
|
||||||
//Wait for the eviction period to expire again
|
//Wait for the eviction period to expire again
|
||||||
pause(evictionPeriod);
|
pause(evictionPeriod+(int)(evictionPeriod*0.5));
|
||||||
|
|
||||||
ds.setNextResult(true);
|
|
||||||
|
|
||||||
request = client.newRequest(url + "?action=test");
|
request = client.newRequest(url + "?action=test");
|
||||||
request.header("Cookie", sessionCookie);
|
request.header("Cookie", sessionCookie);
|
||||||
|
|
Loading…
Reference in New Issue