added persistence support for clearing ReplicatingCacheManager and ReplicatingCache; added session garbage collection upon SecurityService construction

Change-Id: I78475411ef01916678e383922d9d0bd11dfd5aec
This commit is contained in:
Axel Uhl
2019-01-18 13:45:12 +01:00
parent eb587c7959
commit 546cac6548
8 changed files with 62 additions and 14 deletions
@@ -84,4 +84,33 @@ public class SessionPersistenceTest {
mof.removeSession(cacheName, session);
assertTrue(dof.loadSessionsByCacheName().isEmpty());
}
@Test
public void testSessionExpiry() throws InterruptedException {
final String cacheName = "shiroSessionCache";
final String host = "myHost";
final String id = UUID.randomUUID().toString();
final Date start = new Date();
final Date last = new Date();
final long timeout = 5000l; // 5s
final SimpleSession session = new SimpleSession();
session.setId(id);
session.setHost(host);
session.setStartTimestamp(start);
session.setLastAccessTime(last);
session.setTimeout(timeout);
mof.storeSession(cacheName, session);
final Map<String, Set<Session>> sessions = dof.loadSessionsByCacheName();
// expecting the session to be still there because the 10s haven't expired yet:
final Session readSession = sessions.get(cacheName).iterator().next();
assertEquals(session, readSession);
assertEquals(id, readSession.getId());
assertEquals(host, readSession.getHost());
assertEquals(start, readSession.getStartTimestamp());
assertEquals(last, readSession.getLastAccessTime());
assertEquals(timeout, readSession.getTimeout());
Thread.sleep(timeout);
final Map<String, Set<Session>> sessionsWithoutExpired = dof.loadSessionsByCacheName();
assertTrue(sessionsWithoutExpired.isEmpty());
}
}