InMemoryWebSession cleans up expired sessions
Issue: SPR-15963
This commit is contained in:
@@ -21,6 +21,7 @@ import java.time.Instant;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.web.server.WebSession;
|
||||
|
||||
import static junit.framework.TestCase.assertSame;
|
||||
@@ -59,7 +60,7 @@ public class InMemoryWebSessionStoreTests {
|
||||
WebSession session = this.store.createWebSession().block();
|
||||
assertNotNull(session);
|
||||
session.getAttributes().put("foo", "bar");
|
||||
session.save();
|
||||
session.save().block();
|
||||
|
||||
String id = session.getId();
|
||||
WebSession retrieved = this.store.retrieveSession(id).block();
|
||||
@@ -78,7 +79,7 @@ public class InMemoryWebSessionStoreTests {
|
||||
assertNotNull(session1);
|
||||
String id = session1.getId();
|
||||
Instant time1 = session1.getLastAccessTime();
|
||||
session1.save();
|
||||
session1.save().block();
|
||||
|
||||
// Fast-forward a few seconds
|
||||
this.store.setClock(Clock.offset(this.store.getClock(), Duration.ofSeconds(5)));
|
||||
@@ -91,7 +92,46 @@ public class InMemoryWebSessionStoreTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void invalidate() throws Exception {
|
||||
public void expirationChecks() throws Exception {
|
||||
// Create 3 sessions
|
||||
WebSession session1 = this.store.createWebSession().block();
|
||||
assertNotNull(session1);
|
||||
session1.start();
|
||||
session1.save().block();
|
||||
|
||||
WebSession session2 = this.store.createWebSession().block();
|
||||
assertNotNull(session2);
|
||||
session2.start();
|
||||
session2.save().block();
|
||||
|
||||
WebSession session3 = this.store.createWebSession().block();
|
||||
assertNotNull(session3);
|
||||
session3.start();
|
||||
session3.save().block();
|
||||
|
||||
// Fast-forward 31 minutes
|
||||
this.store.setClock(Clock.offset(this.store.getClock(), Duration.ofMinutes(31)));
|
||||
|
||||
// Create 2 more sessions
|
||||
WebSession session4 = this.store.createWebSession().block();
|
||||
assertNotNull(session4);
|
||||
session4.start();
|
||||
session4.save().block();
|
||||
|
||||
WebSession session5 = this.store.createWebSession().block();
|
||||
assertNotNull(session5);
|
||||
session5.start();
|
||||
session5.save().block();
|
||||
|
||||
// Retrieve, forcing cleanup of all expired..
|
||||
assertNull(this.store.retrieveSession(session1.getId()).block());
|
||||
assertNull(this.store.retrieveSession(session2.getId()).block());
|
||||
assertNull(this.store.retrieveSession(session3.getId()).block());
|
||||
|
||||
assertNotNull(this.store.retrieveSession(session4.getId()).block());
|
||||
assertNotNull(this.store.retrieveSession(session5.getId()).block());
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user