|
18 | 18 |
|
19 | 19 | import static org.junit.jupiter.api.Assertions.assertEquals;
|
20 | 20 | 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; |
21 | 23 | import static org.junit.jupiter.api.Assertions.assertNull;
|
22 | 24 | import static org.junit.jupiter.api.Assertions.assertThrows;
|
23 | 25 | import static org.junit.jupiter.api.Assertions.assertTrue;
|
@@ -147,6 +149,44 @@ void upsertWithExpiryAnnotation() {
|
147 | 149 | }
|
148 | 150 | }
|
149 | 151 |
|
| 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 | + |
150 | 190 | @Test
|
151 | 191 | void findDocWhichDoesNotExist() {
|
152 | 192 | assertNull(couchbaseTemplate.findById(User.class).one(UUID.randomUUID().toString()));
|
|
0 commit comments