Modify to support negative numbers

This commit is contained in:
zhaokai
2021-09-22 16:19:17 +08:00
committed by Eleftheria Stein-Kousathana
parent 919a2a5c49
commit 9659f1f571
3 changed files with 42 additions and 6 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014-2019 the original author or authors.
* Copyright 2014-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -49,6 +49,7 @@ import static org.mockito.Mockito.verifyNoMoreInteractions;
* Tests for {@link ReactiveRedisSessionRepository}.
*
* @author Vedran Pavic
* @author Kai Zhao
*/
class ReactiveRedisSessionRepositoryTests {
@@ -150,6 +151,33 @@ class ReactiveRedisSessionRepositoryTests {
.isEqualTo(newSession.getLastAccessedTime().toEpochMilli());
}
@Test
void saveCustomNegativeMaxInactiveIntervalNewSession() {
given(this.redisOperations.opsForHash()).willReturn(this.hashOperations);
given(this.hashOperations.putAll(anyString(), any())).willReturn(Mono.just(true));
given(this.redisOperations.persist(anyString())).willReturn(Mono.just(true));
MapSession mapSession = new MapSession();
mapSession.setMaxInactiveInterval(Duration.ofSeconds(-1));
RedisSession newSession = this.repository.new RedisSession(mapSession, true);
StepVerifier.create(this.repository.save(newSession)).verifyComplete();
verify(this.redisOperations).opsForHash();
verify(this.hashOperations).putAll(anyString(), this.delta.capture());
verify(this.redisOperations).persist(anyString());
verifyNoMoreInteractions(this.redisOperations);
verifyNoMoreInteractions(this.hashOperations);
Map<String, Object> delta = this.delta.getAllValues().get(0);
assertThat(delta.size()).isEqualTo(3);
assertThat(delta.get(RedisSessionMapper.CREATION_TIME_KEY))
.isEqualTo(newSession.getCreationTime().toEpochMilli());
assertThat(delta.get(RedisSessionMapper.MAX_INACTIVE_INTERVAL_KEY))
.isEqualTo((int) newSession.getMaxInactiveInterval().getSeconds());
assertThat(delta.get(RedisSessionMapper.LAST_ACCESSED_TIME_KEY))
.isEqualTo(newSession.getLastAccessedTime().toEpochMilli());
}
@Test
void saveSessionNothingChanged() {
given(this.redisOperations.hasKey(anyString())).willReturn(Mono.just(true));