Search in sources :

Example 1 with IncrementRequest

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

Example 2 with IncrementRequest

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

Example 3 with IncrementRequest

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

Aggregations

IncrementRequest (com.couchbase.client.core.msg.kv.IncrementRequest)3 RequestSpan (com.couchbase.client.core.cnc.RequestSpan)1 IncrementResponse (com.couchbase.client.core.msg.kv.IncrementResponse)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 IncrementOptions (com.couchbase.client.java.kv.IncrementOptions)1 Duration (java.time.Duration)1 Test (org.junit.jupiter.api.Test)1