Skip to content

Commit 662a84b

Browse files
committed
DATACOUCH-672 - reinstate replace expiry tests (#289)
Co-authored-by: mikereiche <[email protected]>
1 parent 69e0a1d commit 662a84b

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

src/test/java/org/springframework/data/couchbase/core/CouchbaseTemplateKeyValueIntegrationTests.java

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
import static org.junit.jupiter.api.Assertions.assertEquals;
2020
import static org.junit.jupiter.api.Assertions.assertFalse;
21+
import static org.junit.jupiter.api.Assertions.assertNotEquals;
22+
import static org.junit.jupiter.api.Assertions.assertNotNull;
2123
import static org.junit.jupiter.api.Assertions.assertNull;
2224
import static org.junit.jupiter.api.Assertions.assertThrows;
2325
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -147,6 +149,44 @@ void upsertWithExpiryAnnotation() {
147149
}
148150
}
149151

152+
@Test
153+
void replaceWithExpiry() {
154+
User user = new User(UUID.randomUUID().toString(), "firstname", "lastname");
155+
try {
156+
User modified = couchbaseTemplate.upsertById(User.class).withExpiry(Duration.ofSeconds(1)).one(user);
157+
couchbaseTemplate.replaceById(User.class).withExpiry(Duration.ofSeconds(1)).one(user);
158+
assertEquals(user, modified);
159+
sleepSecs(2);
160+
User found = couchbaseTemplate.findById(User.class).one(user.getId());
161+
assertNull(found, "found should have been null as document should be expired");
162+
} finally {
163+
try {
164+
couchbaseTemplate.removeById().one(user.getId());
165+
} catch (DataRetrievalFailureException e) {
166+
//
167+
}
168+
}
169+
}
170+
171+
@Test
172+
void replaceWithExpiryAnnotation() {
173+
UserAnnotated user = new UserAnnotated(UUID.randomUUID().toString(), "firstname", "lastname");
174+
try {
175+
UserAnnotated modified = couchbaseTemplate.upsertById(UserAnnotated.class).one(user);
176+
modified = couchbaseTemplate.replaceById(UserAnnotated.class).one(user);
177+
assertEquals(user, modified);
178+
sleepSecs(6);
179+
User found = couchbaseTemplate.findById(UserAnnotated.class).one(user.getId());
180+
assertNull(found, "found should have been null as document should be expired");
181+
} finally {
182+
try {
183+
couchbaseTemplate.removeById().one(user.getId());
184+
} catch (DataRetrievalFailureException e) {
185+
//
186+
}
187+
}
188+
}
189+
150190
@Test
151191
void findDocWhichDoesNotExist() {
152192
assertNull(couchbaseTemplate.findById(User.class).one(UUID.randomUUID().toString()));

0 commit comments

Comments
 (0)