Browse Source

Polish contribution

See gh-35013
pull/35405/head
Sam Brannen 6 months ago
parent
commit
4d2cc4ae97
  1. 2
      spring-web/src/main/java/org/springframework/web/server/session/InMemoryWebSessionStore.java
  2. 33
      spring-web/src/test/java/org/springframework/web/server/session/InMemoryWebSessionStoreTests.java

2
spring-web/src/main/java/org/springframework/web/server/session/InMemoryWebSessionStore.java

@ -283,7 +283,7 @@ public class InMemoryWebSessionStore implements WebSessionStore { @@ -283,7 +283,7 @@ public class InMemoryWebSessionStore implements WebSessionStore {
private void checkMaxSessionsLimit() {
if (sessions.size() >= maxSessions) {
expiredSessionChecker.removeExpiredSessions(clock.instant());
if (sessions.size() >= maxSessions && !sessions.containsKey(this.getId())) {
if (sessions.size() >= maxSessions && !sessions.containsKey(this.id.get())) {
throw new IllegalStateException("Max sessions limit reached: " + sessions.size());
}
}

33
spring-web/src/test/java/org/springframework/web/server/session/InMemoryWebSessionStoreTests.java

@ -160,21 +160,40 @@ class InMemoryWebSessionStoreTests { @@ -160,21 +160,40 @@ class InMemoryWebSessionStoreTests {
@Test
void updateSession() {
WebSession oneWebSession = insertSession();
WebSession session = insertSession();
StepVerifier.create(oneWebSession.save())
StepVerifier.create(session.save())
.expectComplete()
.verify();
}
@Test
void updateSession_whenMaxSessionsReached() {
WebSession onceWebSession = insertSession();
IntStream.range(1, 10000).forEach(i -> insertSession());
@Test // gh-35013
void updateSessionAfterMaxSessionLimitIsExceeded() {
this.store.setMaxSessions(10);
WebSession session = insertSession();
assertNumSessions(1);
IntStream.rangeClosed(1, 9).forEach(i -> insertSession());
assertNumSessions(10);
// Updating an existing session should succeed.
StepVerifier.create(session.save())
.expectComplete()
.verify();
assertNumSessions(10);
// Saving an additional new session should fail.
assertThatIllegalStateException()
.isThrownBy(this::insertSession)
.withMessage("Max sessions limit reached: 10");
assertNumSessions(10);
StepVerifier.create(onceWebSession.save())
// Updating an existing session again should still succeed.
StepVerifier.create(session.save())
.expectComplete()
.verify();
assertNumSessions(10);
}

Loading…
Cancel
Save