Search in sources :

Example 6 with GetAnyReplicaOptions

use of com.couchbase.client.java.kv.GetAnyReplicaOptions in project spring-data-couchbase by spring-projects.

the class ReactiveCouchbaseTemplateQueryCollectionIntegrationTests method findFromReplicasByIdOptions.

@Test
public void findFromReplicasByIdOptions() {
    // 5
    GetAnyReplicaOptions options = GetAnyReplicaOptions.getAnyReplicaOptions().timeout(Duration.ofNanos(1000));
    Airport saved = template.insertById(Airport.class).inScope(otherScope).inCollection(otherCollection).one(vie.withIcao("low712")).block();
    try {
        Airport found = template.findFromReplicasById(Airport.class).inScope(otherScope).inCollection(otherCollection).withOptions(options).any(saved.getId()).block();
        assertNull(found, "should not have found document in short timeout");
    } finally {
        template.removeById().inScope(otherScope).inCollection(otherCollection).one(saved.getId()).block();
    }
}
Also used : Airport(org.springframework.data.couchbase.domain.Airport) GetAnyReplicaOptions(com.couchbase.client.java.kv.GetAnyReplicaOptions) Test(org.junit.jupiter.api.Test)

Example 7 with GetAnyReplicaOptions

use of com.couchbase.client.java.kv.GetAnyReplicaOptions in project spring-data-couchbase by spring-projects.

the class ReactiveCouchbaseTemplateQueryCollectionIntegrationTests method findFromReplicasById.

@Test
public void findFromReplicasById() {
    // 5
    GetAnyReplicaOptions options = GetAnyReplicaOptions.getAnyReplicaOptions().timeout(Duration.ofSeconds(10));
    Airport saved = template.insertById(Airport.class).inScope(scopeName).inCollection(collectionName).one(vie.withIcao("lowb")).block();
    try {
        Airport found = template.findFromReplicasById(Airport.class).inScope(scopeName).inCollection(collectionName).withOptions(options).any(saved.getId()).block();
        assertEquals(saved, found);
    } finally {
        template.removeById().inScope(scopeName).inCollection(collectionName).one(saved.getId()).block();
    }
}
Also used : Airport(org.springframework.data.couchbase.domain.Airport) GetAnyReplicaOptions(com.couchbase.client.java.kv.GetAnyReplicaOptions) Test(org.junit.jupiter.api.Test)

Example 8 with GetAnyReplicaOptions

use of com.couchbase.client.java.kv.GetAnyReplicaOptions in project couchbase-jvm-clients by couchbase.

the class ReactiveCollection method getAnyReplica.

/**
 * Reads all available replicas, and returns the first found.
 * <p>
 * If the read requests all fail, the mono emits nothing.
 *
 * @param id the document id.
 * @param options the custom options.
 * @return a mono containing the first available replica.
 */
public Mono<GetReplicaResult> getAnyReplica(final String id, final GetAnyReplicaOptions options) {
    GetAnyReplicaOptions.Built opts = options.build();
    final Transcoder transcoder = Optional.ofNullable(opts.transcoder()).orElse(environment().transcoder());
    return ReplicaHelper.getAnyReplicaReactive(core, asyncCollection.collectionIdentifier(), id, opts.timeout().orElse(environment().timeoutConfig().kvTimeout()), opts.retryStrategy().orElse(environment().retryStrategy()), opts.clientContext(), opts.parentSpan().orElse(null)).map(response -> GetReplicaResult.from(response, transcoder));
}
Also used : Transcoder(com.couchbase.client.java.codec.Transcoder) GetAnyReplicaOptions(com.couchbase.client.java.kv.GetAnyReplicaOptions)

Aggregations

GetAnyReplicaOptions (com.couchbase.client.java.kv.GetAnyReplicaOptions)8 Test (org.junit.jupiter.api.Test)6 Airport (org.springframework.data.couchbase.domain.Airport)6 Transcoder (com.couchbase.client.java.codec.Transcoder)2