log.info("++++ Starting testRemoteExpirationGracePeriod ++++");
String warname = String.valueOf(++testId);
JBossCacheManager[] mgrs = getCacheManagers(warname, 3, 2);
JBossCacheManager jbcm0 = mgrs[0];
JBossCacheManager jbcm1 = mgrs[1];
SetAttributesRequestHandler setHandler1 = new SetAttributesRequestHandler(allAttributes, false);
SessionTestUtil.invokeRequest(jbcm0, setHandler1, null);
Fqn session1Fqn = Fqn.fromString(SessionTestUtil.getSessionFqn(warname, setHandler1.getSessionId()));
SetAttributesRequestHandler setHandler2 = new SetAttributesRequestHandler(allAttributes, false);
SessionTestUtil.invokeRequest(jbcm0, setHandler2, null);
Fqn session2Fqn = Fqn.fromString(SessionTestUtil.getSessionFqn(warname, setHandler2.getSessionId()));
// Overage the sessions
Thread.sleep(3010);
// Try to force out the overaged sessions
jbcm1.backgroundProcess();
// Confirm they are still there
// FIXME -- avoid direct cache operations
assertNotNull(pojoCaches[1].getCache().get(session1Fqn, CacheHelper.VERSION_KEY));
assertNotNull(pojoCaches[1].getCache().get(session2Fqn, CacheHelper.VERSION_KEY));
// Access one to prove it gets expired once the manager can see its real timestamp
BasicRequestHandler getHandler = new BasicRequestHandler(allAttributes.keySet(), false);
SessionTestUtil.invokeRequest(jbcm1, getHandler, setHandler1.getSessionId());
validateNewSession(getHandler);
// Sleep past the grace period
Thread.sleep(2010);
// The get restored a new fresh session with the first id, but the 2nd
// one is still there and overaged. Try to force it out
jbcm1.backgroundProcess();
// FIXME -- avoid direct cache operations
assertNull(pojoCaches[1].getCache().get(session2Fqn, CacheHelper.VERSION_KEY));
}