Skip to content

Commit 002136b

Browse files
committed
Align WebSession#save implementations with API
Closes gh-1135
1 parent 1085661 commit 002136b

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

spring-session-data-redis/src/integration-test/java/org/springframework/session/data/redis/ReactiveRedisOperationsSessionRepositoryITests.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import org.springframework.test.context.web.WebAppConfiguration;
3131

3232
import static org.assertj.core.api.Assertions.assertThat;
33+
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
3334

3435
/**
3536
* Integration tests for {@link ReactiveRedisOperationsSessionRepository}.
@@ -209,7 +210,10 @@ public void changeSessionSaveOldSessionInstance() {
209210
this.repository.save(session).block();
210211

211212
toSave.setLastAccessedTime(Instant.now());
212-
this.repository.save(toSave).block();
213+
214+
assertThatExceptionOfType(IllegalStateException.class)
215+
.isThrownBy(() -> this.repository.save(toSave).block())
216+
.withMessage("Session was invalidated");
213217

214218
assertThat(this.repository.findById(sessionId).block()).isNull();
215219
assertThat(this.repository.findById(session.getId()).block()).isNotNull();

spring-session-data-redis/src/main/java/org/springframework/session/data/redis/ReactiveRedisOperationsSessionRepository.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,9 @@ public Mono<Void> save(RedisSession session) {
156156
session.hasChangedSessionId() ? session.originalSessionId
157157
: session.getId());
158158
return this.sessionRedisOperations.hasKey(sessionKey)
159-
.flatMap((exists) -> exists ? result : Mono.empty());
159+
.flatMap((exists) -> exists ? result
160+
: Mono.error(new IllegalStateException(
161+
"Session was invalidated")));
160162
}
161163
}
162164

0 commit comments

Comments
 (0)