Search in sources :

Example 1 with GetAnyReplicaOptions

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

the class AsyncCollection method getAnyReplica.

/**
 * Reads all available replicas, and returns the first found.
 *
 * @param id the document id.
 * @param options the custom options.
 * @return a future containing the first available replica.
 */
public CompletableFuture<GetReplicaResult> getAnyReplica(final String id, final GetAnyReplicaOptions options) {
    notNullOrEmpty(id, "Id", () -> ReducedKeyValueErrorContext.create(id, collectionIdentifier));
    notNull(options, "GetAnyReplicaOptions", () -> ReducedKeyValueErrorContext.create(id, collectionIdentifier));
    GetAnyReplicaOptions.Built opts = options.build();
    Transcoder transcoder = opts.transcoder() == null ? environment.transcoder() : opts.transcoder();
    return ReplicaHelper.getAnyReplicaAsync(core, collectionIdentifier, id, opts.timeout().orElse(environment.timeoutConfig().kvTimeout()), opts.retryStrategy().orElse(environment().retryStrategy()), opts.clientContext(), opts.parentSpan().orElse(null), response -> GetReplicaResult.from(response, transcoder));
}
Also used : Transcoder(com.couchbase.client.java.codec.Transcoder) GetAnyReplicaOptions(com.couchbase.client.java.kv.GetAnyReplicaOptions)

Example 2 with GetAnyReplicaOptions

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

the class CouchbaseTemplateQueryCollectionIntegrationTests method findFromReplicasByIdOptions.

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

Example 3 with GetAnyReplicaOptions

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

the class CouchbaseTemplateQueryCollectionIntegrationTests method findFromReplicasByIdOther.

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

Example 4 with GetAnyReplicaOptions

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

the class ReactiveCouchbaseTemplateQueryCollectionIntegrationTests method findFromReplicasByIdOther.

@Test
public void findFromReplicasByIdOther() {
    // 5
    GetAnyReplicaOptions options = GetAnyReplicaOptions.getAnyReplicaOptions().timeout(Duration.ofSeconds(10));
    Airport saved = template.insertById(Airport.class).inScope(otherScope).inCollection(otherCollection).one(vie.withIcao("lowk")).block();
    try {
        Airport found = template.findFromReplicasById(Airport.class).inScope(otherScope).inCollection(otherCollection).withOptions(options).any(saved.getId()).block();
        assertEquals(saved, found);
    } 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 5 with GetAnyReplicaOptions

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

the class CouchbaseTemplateQueryCollectionIntegrationTests method findFromReplicasById.

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

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