Search in sources :

Example 11 with InsertOptions

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();
    }
}
Also used : Airport(org.springframework.data.couchbase.domain.Airport) ReplaceOptions(com.couchbase.client.java.kv.ReplaceOptions) InsertOptions(com.couchbase.client.java.kv.InsertOptions) GetOptions(com.couchbase.client.java.kv.GetOptions) Test(org.junit.jupiter.api.Test)

Example 12 with InsertOptions

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();
}
Also used : JavaIntegrationTest(com.couchbase.client.java.util.JavaIntegrationTest) GetResult(com.couchbase.client.java.kv.GetResult) BeforeEach(org.junit.jupiter.api.BeforeEach) InsertOptions(com.couchbase.client.java.kv.InsertOptions) StepVerifier(reactor.test.StepVerifier) Iterator(java.util.Iterator) MutationResult(com.couchbase.client.java.kv.MutationResult) ExistsResult(com.couchbase.client.java.kv.ExistsResult) ClusterType(com.couchbase.client.test.ClusterType) IgnoreWhen(com.couchbase.client.test.IgnoreWhen) AfterAll(org.junit.jupiter.api.AfterAll) Test(org.junit.jupiter.api.Test) Flux(reactor.core.publisher.Flux) List(java.util.List) BeforeAll(org.junit.jupiter.api.BeforeAll) Duration(java.time.Duration) JsonObject(com.couchbase.client.java.json.JsonObject) DocumentNotFoundException(com.couchbase.client.core.error.DocumentNotFoundException) DocumentExistsException(com.couchbase.client.core.error.DocumentExistsException) DocumentNotFoundException(com.couchbase.client.core.error.DocumentNotFoundException) GetResult(com.couchbase.client.java.kv.GetResult) InsertOptions(com.couchbase.client.java.kv.InsertOptions) MutationResult(com.couchbase.client.java.kv.MutationResult) IgnoreWhen(com.couchbase.client.test.IgnoreWhen) JavaIntegrationTest(com.couchbase.client.java.util.JavaIntegrationTest) Test(org.junit.jupiter.api.Test)

Aggregations

InsertOptions (com.couchbase.client.java.kv.InsertOptions)12 Test (org.junit.jupiter.api.Test)11 Airport (org.springframework.data.couchbase.domain.Airport)9 GetOptions (com.couchbase.client.java.kv.GetOptions)8 ReplaceOptions (com.couchbase.client.java.kv.ReplaceOptions)4 DocumentExistsException (com.couchbase.client.core.error.DocumentExistsException)1 DocumentNotFoundException (com.couchbase.client.core.error.DocumentNotFoundException)1 InsertRequest (com.couchbase.client.core.msg.kv.InsertRequest)1 JsonObject (com.couchbase.client.java.json.JsonObject)1 ExistsResult (com.couchbase.client.java.kv.ExistsResult)1 GetResult (com.couchbase.client.java.kv.GetResult)1 MutationResult (com.couchbase.client.java.kv.MutationResult)1 JavaIntegrationTest (com.couchbase.client.java.util.JavaIntegrationTest)1 ClusterType (com.couchbase.client.test.ClusterType)1 IgnoreWhen (com.couchbase.client.test.IgnoreWhen)1 Duration (java.time.Duration)1 Iterator (java.util.Iterator)1 List (java.util.List)1 AfterAll (org.junit.jupiter.api.AfterAll)1 BeforeAll (org.junit.jupiter.api.BeforeAll)1