Skip to content

Commit 0f8d0e4

Browse files
author
Shyngys Sapraliyev
committed
#spring-projectsGH-2351 - added tests
1 parent 2ad21ab commit 0f8d0e4

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

src/test/java/org/springframework/data/redis/cache/DefaultRedisCacheWriterTests.java

+40
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
*
4545
* @author Christoph Strobl
4646
* @author Mark Paluch
47+
* @author Shyngys Sapraliyev
4748
*/
4849
@MethodSource("testParams")
4950
public class DefaultRedisCacheWriterTests {
@@ -104,6 +105,45 @@ void putShouldAddExpiringEntry() {
104105
});
105106
}
106107

108+
@ParameterizedRedisTest // GH-2351
109+
void getWithMaxIdleShouldResetEntryTtl() {
110+
111+
Duration maxIdle = Duration.ofSeconds(1);
112+
113+
doWithConnection(connection -> connection.set(binaryCacheKey, "foo".getBytes(),
114+
Expiration.from(Duration.ofMinutes(1)), SetOption.upsert()));
115+
116+
RedisCacheWriter writer = nonLockingRedisCacheWriter(connectionFactory);
117+
118+
writer.put(CACHE_NAME, binaryCacheKey, binaryCacheValue, Duration.ofSeconds(10), maxIdle);
119+
120+
doWithConnection(connection -> {
121+
assertThat(writer.get(CACHE_NAME, binaryCacheKey, maxIdle))
122+
.isEqualTo(binaryCacheValue);
123+
assertThat(connection.ttl(binaryCacheKey))
124+
.isEqualTo(maxIdle.getSeconds());
125+
});
126+
}
127+
128+
@ParameterizedRedisTest // GH-2351
129+
void getEternalMaxIdleShouldNotExpireEntry() {
130+
131+
Duration maxIdle = Duration.ZERO;
132+
133+
doWithConnection(connection -> connection.set(binaryCacheKey, "foo".getBytes()));
134+
135+
RedisCacheWriter writer = nonLockingRedisCacheWriter(connectionFactory);
136+
137+
writer.put(CACHE_NAME, binaryCacheKey, binaryCacheValue, Duration.ZERO, maxIdle);
138+
139+
doWithConnection(connection -> {
140+
assertThat(writer.get(CACHE_NAME, binaryCacheKey, maxIdle))
141+
.isEqualTo(binaryCacheValue);
142+
assertThat(connection.ttl(binaryCacheKey))
143+
.isEqualTo(-1);
144+
});
145+
}
146+
107147
@ParameterizedRedisTest // DATAREDIS-481
108148
void putShouldOverwriteExistingEternalEntry() {
109149

0 commit comments

Comments
 (0)