use of com.couchbase.client.core.msg.kv.IncrementRequest in project couchbase-jvm-clients by couchbase.
the class MutationTokenIntegrationTest method tokenOnIncrement.
@Test
void tokenOnIncrement() throws Exception {
String id = UUID.randomUUID().toString();
byte[] content = "1".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());
IncrementRequest incrementRequest = new IncrementRequest(kvTimeout, core.context(), collectionIdentifier, env.retryStrategy(), id, 1, Optional.empty(), 0, Optional.empty(), null);
core.send(incrementRequest);
IncrementResponse incrementResponse = incrementRequest.response().get();
assertTrue(incrementResponse.status().success());
assertMutationToken(incrementResponse.mutationToken());
}
use of com.couchbase.client.core.msg.kv.IncrementRequest in project couchbase-jvm-clients by couchbase.
the class ReactiveBinaryCollection method increment.
/**
* Increments 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 increment 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> increment(final String id, final IncrementOptions options) {
return Mono.defer(() -> {
notNull(options, "IncrementOptions", () -> ReducedKeyValueErrorContext.create(id, async.collectionIdentifier()));
IncrementOptions.Built opts = options.build();
IncrementRequest request = async.incrementRequest(id, opts);
return Reactor.wrap(request, CounterAccessor.increment(core, request, id, opts.persistTo(), opts.replicateTo()), true);
});
}
use of com.couchbase.client.core.msg.kv.IncrementRequest in project couchbase-jvm-clients by couchbase.
the class AsyncBinaryCollection method incrementRequest.
IncrementRequest incrementRequest(final String id, final IncrementOptions.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_INCREMENT, opts.parentSpan().orElse(null));
long expiry = opts.expiry().encode();
IncrementRequest request = new IncrementRequest(timeout, coreContext, collectionIdentifier, retryStrategy, id, opts.delta(), opts.initial(), expiry, opts.durabilityLevel(), span);
request.context().clientContext(opts.clientContext());
return request;
}
Aggregations