Skip to content

Commit 95784a8

Browse files
committed
test coverage
1 parent e2b39be commit 95784a8

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package org.springframework.session.data.redis;
1818

1919
import java.nio.charset.StandardCharsets;
20+
import java.time.Duration;
2021
import java.util.Map;
2122
import java.util.UUID;
2223
import java.util.concurrent.TimeUnit;
@@ -151,6 +152,22 @@ void saveThenSaveSessionKeyAndShadowKeyWith5MinutesDifference() {
151152
assertThat(differenceInSeconds).isEqualTo(300);
152153
}
153154

155+
156+
@Test
157+
void saveNonExpiringThenSaveSessionKeyAndShadowKeyWithNoDifference() {
158+
RedisSession toSave = this.repository.createSession();
159+
String expectedAttributeName = "a";
160+
String expectedAttributeValue = "b";
161+
toSave.setAttribute(expectedAttributeName, expectedAttributeValue);
162+
toSave.setMaxInactiveInterval(Duration.ofMillis(-1));
163+
164+
this.repository.save(toSave);
165+
166+
Long sessionKeyExpire = this.redis.getExpire("RedisIndexedSessionRepositoryITests:sessions:" + toSave.getId(),
167+
TimeUnit.SECONDS);
168+
assertThat(sessionKeyExpire).isEqualTo(-1);
169+
}
170+
154171
@Test
155172
void putAllOnSingleAttrDoesNotRemoveOld() {
156173
RedisSession toSave = this.repository.createSession();

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,22 @@ void saveSetAttribute() {
271271
map(RedisIndexedSessionRepository.getSessionAttrNameKey(attrName), session.getAttribute(attrName)));
272272
}
273273

274+
@Test
275+
void saveNonExpiring() {
276+
RedisSession session = this.redisRepository.new RedisSession(new MapSession(), false);
277+
session.setMaxInactiveInterval(Duration.ofSeconds(-1));
278+
279+
given(this.redisOperations.<String, Object>boundHashOps(anyString())).willReturn(this.boundHashOperations);
280+
given(this.redisOperations.boundSetOps(anyString())).willReturn(this.boundSetOperations);
281+
given(this.redisOperations.boundValueOps(anyString())).willReturn(this.boundValueOperations);
282+
283+
this.redisRepository.save(session);
284+
285+
verify(this.boundHashOperations, never()).expire(-1, TimeUnit.SECONDS);
286+
assertThat(getDelta())
287+
.isEqualTo(map(RedisSessionMapper.MAX_INACTIVE_INTERVAL_KEY, -1));
288+
}
289+
274290
@Test
275291
void saveRemoveAttribute() {
276292
String attrName = "attrName";

0 commit comments

Comments
 (0)