Ensure stale interval set for tests.

This commit is contained in:
Jan Bartel 2015-10-01 17:59:45 +10:00
parent 98c0570474
commit dafb354d4b
6 changed files with 39 additions and 9 deletions

View File

@ -22,7 +22,6 @@ import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
@ -70,6 +69,7 @@ public class GCloudSessionManager extends AbstractSessionManager
public static final String KIND = "GCloudSession";
public static final int DEFAULT_MAX_QUERY_RESULTS = 100;
public static final long DEFAULT_SCAVENGE_SEC = 600;
/**
* Sessions known to this node held in memory
@ -88,7 +88,7 @@ public class GCloudSessionManager extends AbstractSessionManager
protected Scheduler.Task _task; //scavenge task
protected Scheduler _scheduler;
protected Scavenger _scavenger;
protected long _scavengeIntervalMs = 0; //0 means no scavenging
protected long _scavengeIntervalMs = 1000L * DEFAULT_SCAVENGE_SEC; //10mins
protected boolean _ownScheduler;
private Datastore _datastore;
@ -692,7 +692,6 @@ public class GCloudSessionManager extends AbstractSessionManager
_sessions = new ConcurrentHashMap<String, Session>();
//try and use a common scheduler, fallback to own
//TODO check against starting with a 0 scavenge interval
_scheduler = getSessionHandler().getServer().getBean(Scheduler.class);
if (_scheduler == null)
{
@ -863,9 +862,6 @@ public class GCloudSessionManager extends AbstractSessionManager
}
}
public long getStaleIntervalSec()
{

View File

@ -316,11 +316,14 @@ public class GCloudSessionTestSupport
QueryResults<Entity> results = _ds.run(query);
assertNotNull(results);
System.err.println("SESSIONS::::::::");
while (results.hasNext())
{
Entity e = results.next();
System.err.println(e.getString("clusterId")+" expires at "+e.getLong("expiry"));
}
System.err.println("END OF SESSIONS::::::::");
}
public void assertSessions(int count) throws Exception

View File

@ -35,6 +35,7 @@ import com.google.gcloud.datastore.DatastoreFactory;
public class GCloudTestServer extends AbstractTestServer
{
static int __workers=0;
public static int STALE_INTERVAL_SEC = 1;
@ -78,7 +79,7 @@ public class GCloudTestServer extends AbstractTestServer
{
GCloudSessionManager sessionManager = new GCloudSessionManager();
sessionManager.setSessionIdManager((GCloudSessionIdManager)_sessionIdManager);
sessionManager.setStaleIntervalSec(1);
sessionManager.setStaleIntervalSec(STALE_INTERVAL_SEC);
sessionManager.setScavengeIntervalSec(_scavengePeriod);
return sessionManager;

View File

@ -65,7 +65,18 @@ public class InvalidationSessionTest extends AbstractInvalidationSessionTest
@Override
public void pause()
{
// TODO Auto-generated method stub
//This test moves around a session between 2 nodes. After it is invalidated on the 1st node,
//it will still be in the memory of the 2nd node. We need to wait until after the stale time
//has expired on node2 for it to reload the session and discover it has been deleted.
try
{
Thread.currentThread().sleep((2*GCloudTestServer.STALE_INTERVAL_SEC)*1000);
}
catch (Exception e)
{
e.printStackTrace();
}
}
}

View File

@ -83,4 +83,20 @@ public class SessionExpiryTest extends AbstractSessionExpiryTest
_testSupport.assertSessions(0);
}
@Override
public void verifySessionCreated(TestHttpSessionListener listener, String sessionId)
{
super.verifySessionCreated(listener, sessionId);
try{ _testSupport.listSessions(); _testSupport.assertSessions(1);}catch(Exception e) {e.printStackTrace();}
}
@Override
public void verifySessionDestroyed(TestHttpSessionListener listener, String sessionId)
{
super.verifySessionDestroyed(listener, sessionId);
try{ _testSupport.listSessions(); _testSupport.assertSessions(0);}catch(Exception e) {e.printStackTrace();}
}
}

View File

@ -83,19 +83,22 @@ public abstract class AbstractInvalidationSessionTest
assertTrue(sessionCookie != null);
// Mangle the cookie, replacing Path with $Path, etc.
sessionCookie = sessionCookie.replaceFirst("(\\W)(P|p)ath=", "$1\\$Path=");
// Be sure the session is also present in node2
Request request2 = client.newRequest(urls[1] + "?action=increment");
request2.header("Cookie", sessionCookie);
ContentResponse response2 = request2.send();
assertEquals(HttpServletResponse.SC_OK,response2.getStatus());
// Invalidate on node1
Request request1 = client.newRequest(urls[0] + "?action=invalidate");
request1.header("Cookie", sessionCookie);
response1 = request1.send();
assertEquals(HttpServletResponse.SC_OK, response1.getStatus());
pause();