use of com.couchbase.client.java.kv.InsertOptions in project spring-data-couchbase by spring-projects.
the class ReactiveCouchbaseTemplateQueryCollectionIntegrationTests method replaceById.
@Test
public void replaceById() {
// 9
InsertOptions insertOptions = InsertOptions.insertOptions().timeout(Duration.ofSeconds(10));
ReplaceOptions options = ReplaceOptions.replaceOptions().timeout(Duration.ofSeconds(10));
GetOptions getOptions = GetOptions.getOptions().timeout(Duration.ofSeconds(10));
Airport saved = template.insertById(Airport.class).inScope(scopeName).inCollection(collectionName).withOptions(insertOptions).one(vie.withIcao("lowe")).block();
Airport replaced = template.replaceById(Airport.class).inScope(scopeName).inCollection(collectionName).withOptions(options).one(vie.withIcao("newIcao")).block();
try {
Airport found = template.findById(Airport.class).inScope(scopeName).inCollection(collectionName).withOptions(getOptions).one(saved.getId()).block();
assertEquals(replaced, found);
} finally {
template.removeById().inScope(scopeName).inCollection(collectionName).one(saved.getId()).block();
}
}
use of com.couchbase.client.java.kv.InsertOptions in project couchbase-jvm-clients by couchbase.
the class KeyValueReactiveCollectionIntegrationTest method reactiveTouch.
@Test
@IgnoreWhen(clusterTypes = { ClusterType.MOCKED })
void reactiveTouch() {
StepVerifier.create(docIds.concatMap(key -> reactiveCollection.touch(key, Duration.ofSeconds(1)))).expectError(DocumentNotFoundException.class).verify();
// Insert docs with expiry of 10s
InsertOptions firstOpts = InsertOptions.insertOptions().expiry(Duration.ofSeconds(10));
List<MutationResult> insertResults = docIds.concatMap(key -> reactiveCollection.insert(key, JsonObject.create().put("key", key), firstOpts)).collectList().block();
// Touch docs and update the expiry to 1s
List<MutationResult> touchResults = docIds.concatMap(key -> reactiveCollection.touch(key, Duration.ofSeconds(1))).collectList().block();
// Assert cas of insert and touch results differ
StepVerifier.create(Flux.range(0, numDocs)).thenConsumeWhile(i -> insertResults.get(i).cas() != touchResults.get(i).cas()).verifyComplete();
List<GetResult> getResults = docIds.concatMap(reactiveCollection::get).collectList().block();
StepVerifier.create(Flux.range(0, numDocs)).thenConsumeWhile(i -> getResults.get(i).cas() == touchResults.get(i).cas()).verifyComplete();
}
Aggregations