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));
}
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());
}
}
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());
}
}
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();
}
}
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());
}
}
Aggregations