DATACOUCH-672 - reinstate replace expiry tests (#289)

Co-authored-by: mikereiche <michael.reiche@couchbase.com>
This commit is contained in:
Michael Reiche
2020-12-09 08:34:22 -08:00
committed by mikereiche
parent 69e0a1dc33
commit 662a84bba6

View File

@@ -18,6 +18,8 @@ package org.springframework.data.couchbase.core;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -147,6 +149,44 @@ class CouchbaseTemplateKeyValueIntegrationTests extends ClusterAwareIntegrationT
}
}
@Test
void replaceWithExpiry() {
User user = new User(UUID.randomUUID().toString(), "firstname", "lastname");
try {
User modified = couchbaseTemplate.upsertById(User.class).withExpiry(Duration.ofSeconds(1)).one(user);
couchbaseTemplate.replaceById(User.class).withExpiry(Duration.ofSeconds(1)).one(user);
assertEquals(user, modified);
sleepSecs(2);
User found = couchbaseTemplate.findById(User.class).one(user.getId());
assertNull(found, "found should have been null as document should be expired");
} finally {
try {
couchbaseTemplate.removeById().one(user.getId());
} catch (DataRetrievalFailureException e) {
//
}
}
}
@Test
void replaceWithExpiryAnnotation() {
UserAnnotated user = new UserAnnotated(UUID.randomUUID().toString(), "firstname", "lastname");
try {
UserAnnotated modified = couchbaseTemplate.upsertById(UserAnnotated.class).one(user);
modified = couchbaseTemplate.replaceById(UserAnnotated.class).one(user);
assertEquals(user, modified);
sleepSecs(6);
User found = couchbaseTemplate.findById(UserAnnotated.class).one(user.getId());
assertNull(found, "found should have been null as document should be expired");
} finally {
try {
couchbaseTemplate.removeById().one(user.getId());
} catch (DataRetrievalFailureException e) {
//
}
}
}
@Test
void findDocWhichDoesNotExist() {
assertNull(couchbaseTemplate.findById(User.class).one(UUID.randomUUID().toString()));