Move expires check to dedicated method.

Introduce helper method to unify expiry check and simplify control flow.

Original Pull Request: #1961
This commit is contained in:
Christoph Strobl
2021-02-10 12:47:41 +01:00
parent e46246721f
commit 4df8e44818
2 changed files with 40 additions and 22 deletions

View File

@@ -706,10 +706,10 @@ public class RedisKeyValueAdapterTests {
assertThat(template.hasKey("persons:1:phantom")).isTrue();
}
@Test // DATAREDIS-1955
@Test // GH-1955
void phantomKeyIsDeletedWhenPutWithNegativeTimeToLiveAndOldEntryTimeToLiveWasPositiveAndWhenShadowCopyIsTurnedOn() {
ExpiringPerson rand = new ExpiringPerson();
rand.id = "1";
rand.ttl = 3000L;
adapter.put("1", rand, "persons");
@@ -723,21 +723,21 @@ public class RedisKeyValueAdapterTests {
assertThat(template.hasKey("persons:1:phantom")).isFalse();
}
@Test // DATAREDIS-1955
@Test // GH-1955
void updateWithRefreshTtlAndWithoutPositiveTtlShouldDeletePhantomKey() {
ExpiringPerson person = new ExpiringPerson();
person.id = "1";
person.ttl = 100L;
adapter.put("1", person, "persons");
assertThat(template.getExpire("persons:1:phantom")).isPositive();
PartialUpdate<ExpiringPerson> update = new PartialUpdate<>("1", ExpiringPerson.class) //
.refreshTtl(true);
.set("ttl", -1L).refreshTtl(true);
adapter.update(update);
assertThat(template.getExpire("persons:1")).isNotPositive();
assertThat(template.hasKey("persons:1:phantom")).isFalse();
}