PurgeableSessionMap extends ConcurrentHashMap<String, Session> { @Scheduled(fixedDelayString = "${servlet-session-purge-delay:900000}") public void purge() { List<Session> expired = expired(); expired.forEach(s -> remove(s.getId())); logger.debug(String.format("Purged %s sessions", expired.size())); }  @Scheduled(fixedDelayString = "${servlet-session-purge-delay:900000}") void purge(); List<Session> expired();  }
@Test void doesNotDeleteActiveSessions() { sessions.put(SESSION_ID, createSession(SESSION_ID, false)); sessions.purge(); assertThat(sessions).hasSize(1); assertThat(sessions).containsKey(SESSION_ID); }
@Test void deletesActiveSessions() { sessions.put(SESSION_ID, createSession(SESSION_ID, true)); sessions.purge(); assertThat(sessions).hasSize(0); }