use of com.couchbase.client.core.msg.kv.DecrementRequest in project couchbase-jvm-clients by couchbase.
the class MutationTokenIntegrationTest method tokenOnDecrement.
@Test
void tokenOnDecrement() throws Exception {
String id = UUID.randomUUID().toString();
byte[] content = "10".getBytes(UTF_8);
InsertRequest insertRequest = new InsertRequest(id, content, 0, 0, kvTimeout, core.context(), collectionIdentifier, env.retryStrategy(), Optional.empty(), null);
core.send(insertRequest);
InsertResponse insertResponse = insertRequest.response().get();
assertTrue(insertResponse.status().success());
assertMutationToken(insertResponse.mutationToken());
DecrementRequest decrementRequest = new DecrementRequest(kvTimeout, core.context(), collectionIdentifier, env.retryStrategy(), id, 1, Optional.empty(), 0, Optional.empty(), null);
core.send(decrementRequest);
DecrementResponse decrementResponse = decrementRequest.response().get();
assertTrue(decrementResponse.status().success());
assertMutationToken(decrementResponse.mutationToken());
}
use of com.couchbase.client.core.msg.kv.DecrementRequest in project couchbase-jvm-clients by couchbase.
the class ReactiveBinaryCollection method decrement.
/**
* Decrements the counter document by one or the number defined in the options.
*
* @param id the document id which is used to uniquely identify it.
* @param options custom options to customize the decrement behavior.
* @return a {@link CounterResult} once completed.
* @throws DocumentNotFoundException the given document id is not found in the collection.
* @throws TimeoutException if the operation times out before getting a result.
* @throws CouchbaseException for all other error reasons (acts as a base type and catch-all).
*/
public Mono<CounterResult> decrement(final String id, final DecrementOptions options) {
return Mono.defer(() -> {
notNull(options, "DecrementOptions", () -> ReducedKeyValueErrorContext.create(id, async.collectionIdentifier()));
DecrementOptions.Built opts = options.build();
DecrementRequest request = async.decrementRequest(id, opts);
return Reactor.wrap(request, CounterAccessor.decrement(core, request, id, opts.persistTo(), opts.replicateTo()), true);
});
}
use of com.couchbase.client.core.msg.kv.DecrementRequest in project couchbase-jvm-clients by couchbase.
the class AsyncBinaryCollection method decrementRequest.
DecrementRequest decrementRequest(final String id, final DecrementOptions.Built opts) {
notNullOrEmpty(id, "Id", () -> ReducedKeyValueErrorContext.create(id, collectionIdentifier));
Duration timeout = decideKvTimeout(opts, environment.timeoutConfig());
RetryStrategy retryStrategy = opts.retryStrategy().orElse(environment.retryStrategy());
RequestSpan span = environment.requestTracer().requestSpan(TracingIdentifiers.SPAN_REQUEST_KV_DECREMENT, opts.parentSpan().orElse(null));
long expiry = opts.expiry().encode();
DecrementRequest request = new DecrementRequest(timeout, coreContext, collectionIdentifier, retryStrategy, id, opts.delta(), opts.initial(), expiry, opts.durabilityLevel(), span);
request.context().clientContext(opts.clientContext());
return request;
}
Aggregations