diff --git a/src/test/java/org/springframework/data/couchbase/core/CouchbaseTemplateKeyValueIntegrationTests.java b/src/test/java/org/springframework/data/couchbase/core/CouchbaseTemplateKeyValueIntegrationTests.java index a4c0d3c55..f95f4ee42 100644 --- a/src/test/java/org/springframework/data/couchbase/core/CouchbaseTemplateKeyValueIntegrationTests.java +++ b/src/test/java/org/springframework/data/couchbase/core/CouchbaseTemplateKeyValueIntegrationTests.java @@ -18,6 +18,8 @@ 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 @@ void upsertWithExpiryAnnotation() { } } + @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()));