Search in sources :

Example 1 with DecrementRequest

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());
}
Also used : InsertResponse(com.couchbase.client.core.msg.kv.InsertResponse) InsertRequest(com.couchbase.client.core.msg.kv.InsertRequest) DecrementRequest(com.couchbase.client.core.msg.kv.DecrementRequest) DecrementResponse(com.couchbase.client.core.msg.kv.DecrementResponse) CoreIntegrationTest(com.couchbase.client.core.util.CoreIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 2 with DecrementRequest

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);
    });
}
Also used : DecrementOptions(com.couchbase.client.java.kv.DecrementOptions) DecrementRequest(com.couchbase.client.core.msg.kv.DecrementRequest)

Example 3 with DecrementRequest

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;
}
Also used : DecrementRequest(com.couchbase.client.core.msg.kv.DecrementRequest) Duration(java.time.Duration) RetryStrategy(com.couchbase.client.core.retry.RetryStrategy) RequestSpan(com.couchbase.client.core.cnc.RequestSpan)

Aggregations

DecrementRequest (com.couchbase.client.core.msg.kv.DecrementRequest)3 RequestSpan (com.couchbase.client.core.cnc.RequestSpan)1 DecrementResponse (com.couchbase.client.core.msg.kv.DecrementResponse)1 InsertRequest (com.couchbase.client.core.msg.kv.InsertRequest)1 InsertResponse (com.couchbase.client.core.msg.kv.InsertResponse)1 RetryStrategy (com.couchbase.client.core.retry.RetryStrategy)1 CoreIntegrationTest (com.couchbase.client.core.util.CoreIntegrationTest)1 DecrementOptions (com.couchbase.client.java.kv.DecrementOptions)1 Duration (java.time.Duration)1 Test (org.junit.jupiter.api.Test)1