Add Tests for Lazy Updates of Spring Session
Ensure that the session is only modified if it is accessed. This allows for optimizations to ensure that for things like static resources there is no need for hitting a data store.
This commit is contained in:
@@ -1165,6 +1165,39 @@ public class SessionRepositoryFilterTests {
|
||||
verifyZeroInteractions(sessionRepository);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void doFilterLazySessionCreation() throws Exception {
|
||||
SessionRepository<ExpiringSession> sessionRepository = spy(new MapSessionRepository());
|
||||
|
||||
filter = new SessionRepositoryFilter<ExpiringSession>(sessionRepository);
|
||||
|
||||
doFilter(new DoInFilter(){
|
||||
@Override
|
||||
public void doFilter(HttpServletRequest wrappedRequest, HttpServletResponse wrappedResponse) throws IOException {
|
||||
}
|
||||
});
|
||||
|
||||
verifyZeroInteractions(sessionRepository);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void doFilterLazySessionUpdates() throws Exception {
|
||||
ExpiringSession session = this.sessionRepository.createSession();
|
||||
this.sessionRepository.save(session);
|
||||
SessionRepository<ExpiringSession> sessionRepository = spy(this.sessionRepository);
|
||||
setSessionCookie(session.getId());
|
||||
|
||||
filter = new SessionRepositoryFilter<ExpiringSession>(sessionRepository);
|
||||
|
||||
doFilter(new DoInFilter(){
|
||||
@Override
|
||||
public void doFilter(HttpServletRequest wrappedRequest, HttpServletResponse wrappedResponse) throws IOException {
|
||||
}
|
||||
});
|
||||
|
||||
verifyZeroInteractions(sessionRepository);
|
||||
}
|
||||
|
||||
// --- order
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user