|
40 | 40 | import org.springframework.data.couchbase.CouchbaseClientFactory;
|
41 | 41 | import org.springframework.data.couchbase.SimpleCouchbaseClientFactory;
|
42 | 42 | import org.springframework.data.couchbase.domain.Config;
|
| 43 | +import org.springframework.data.couchbase.domain.PersonValue; |
43 | 44 | import org.springframework.data.couchbase.domain.User;
|
44 | 45 | import org.springframework.data.couchbase.domain.UserAnnotated;
|
45 | 46 | import org.springframework.data.couchbase.util.ClusterAwareIntegrationTests;
|
@@ -146,44 +147,6 @@ void upsertWithExpiryAnnotation() {
|
146 | 147 | }
|
147 | 148 | }
|
148 | 149 |
|
149 |
| - @Test |
150 |
| - void replaceWithExpiry() { |
151 |
| - User user = new User(UUID.randomUUID().toString(), "firstname", "lastname"); |
152 |
| - try { |
153 |
| - User modified = couchbaseTemplate.upsertById(User.class).withExpiry(Duration.ofSeconds(1)).one(user); |
154 |
| - couchbaseTemplate.replaceById(User.class).withExpiry(Duration.ofSeconds(1)).one(user); |
155 |
| - assertEquals(user, modified); |
156 |
| - sleepSecs(2); |
157 |
| - User found = couchbaseTemplate.findById(User.class).one(user.getId()); |
158 |
| - assertNull(found, "found should have been null as document should be expired"); |
159 |
| - } finally { |
160 |
| - try { |
161 |
| - couchbaseTemplate.removeById().one(user.getId()); |
162 |
| - } catch (DataRetrievalFailureException e) { |
163 |
| - // |
164 |
| - } |
165 |
| - } |
166 |
| - } |
167 |
| - |
168 |
| - @Test |
169 |
| - void replaceWithExpiryAnnotation() { |
170 |
| - UserAnnotated user = new UserAnnotated(UUID.randomUUID().toString(), "firstname", "lastname"); |
171 |
| - try { |
172 |
| - UserAnnotated modified = couchbaseTemplate.upsertById(UserAnnotated.class).one(user); |
173 |
| - modified = couchbaseTemplate.replaceById(UserAnnotated.class).one(user); |
174 |
| - assertEquals(user, modified); |
175 |
| - sleepSecs(6); |
176 |
| - User found = couchbaseTemplate.findById(UserAnnotated.class).one(user.getId()); |
177 |
| - assertNull(found, "found should have been null as document should be expired"); |
178 |
| - } finally { |
179 |
| - try { |
180 |
| - couchbaseTemplate.removeById().one(user.getId()); |
181 |
| - } catch (DataRetrievalFailureException e) { |
182 |
| - // |
183 |
| - } |
184 |
| - } |
185 |
| - } |
186 |
| - |
187 | 150 | @Test
|
188 | 151 | void findDocWhichDoesNotExist() {
|
189 | 152 | assertNull(couchbaseTemplate.findById(User.class).one(UUID.randomUUID().toString()));
|
@@ -293,6 +256,50 @@ void existsById() {
|
293 | 256 |
|
294 | 257 | }
|
295 | 258 |
|
| 259 | + @Test |
| 260 | + @IgnoreWhen(clusterTypes = ClusterType.MOCKED) |
| 261 | + void saveAndFindImmutableById() { |
| 262 | + PersonValue personValue = new PersonValue(null, 123, "f", "l"); |
| 263 | + System.out.println("personValue: " + personValue); |
| 264 | + // personValue = personValue.withVersion(123); |
| 265 | + PersonValue inserted = null; |
| 266 | + PersonValue upserted = null; |
| 267 | + PersonValue replaced = null; |
| 268 | + |
| 269 | + try { |
| 270 | + |
| 271 | + inserted = couchbaseTemplate.insertById(PersonValue.class).one(personValue); |
| 272 | + assertNotEquals(0, inserted.getVersion()); |
| 273 | + PersonValue foundInserted = couchbaseTemplate.findById(PersonValue.class).one(inserted.getId()); |
| 274 | + assertNotNull(foundInserted, "inserted personValue not found"); |
| 275 | + assertEquals(inserted, foundInserted); |
| 276 | + |
| 277 | + // upsert will be inserted |
| 278 | + couchbaseTemplate.removeById().one(inserted.getId()); |
| 279 | + upserted = couchbaseTemplate.upsertById(PersonValue.class).one(inserted); |
| 280 | + assertNotEquals(0, upserted.getVersion()); |
| 281 | + PersonValue foundUpserted = couchbaseTemplate.findById(PersonValue.class).one(upserted.getId()); |
| 282 | + assertNotNull(foundUpserted, "upserted personValue not found"); |
| 283 | + assertEquals(upserted, foundUpserted); |
| 284 | + |
| 285 | + // upsert will be replaced |
| 286 | + upserted = couchbaseTemplate.upsertById(PersonValue.class).one(inserted); |
| 287 | + assertNotEquals(0, upserted.getVersion()); |
| 288 | + PersonValue foundUpserted2 = couchbaseTemplate.findById(PersonValue.class).one(upserted.getId()); |
| 289 | + assertNotNull(foundUpserted2, "upserted personValue not found"); |
| 290 | + assertEquals(upserted, foundUpserted2); |
| 291 | + |
| 292 | + replaced = couchbaseTemplate.replaceById(PersonValue.class).one(upserted); |
| 293 | + assertNotEquals(0, replaced.getVersion()); |
| 294 | + PersonValue foundReplaced = couchbaseTemplate.findById(PersonValue.class).one(replaced.getId()); |
| 295 | + assertNotNull(foundReplaced, "replaced personValue not found"); |
| 296 | + assertEquals(replaced, foundReplaced); |
| 297 | + |
| 298 | + } finally { |
| 299 | + couchbaseTemplate.removeById().one(inserted.getId()); |
| 300 | + } |
| 301 | + } |
| 302 | + |
296 | 303 | private void sleepSecs(int i) {
|
297 | 304 | try {
|
298 | 305 | Thread.sleep(i * 1000);
|
|
0 commit comments