Search in sources :

Example 1 with AppendRequest

use of com.couchbase.client.core.msg.kv.AppendRequest in project couchbase-jvm-clients by couchbase.

the class ReactiveBinaryCollection method append.

/**
 * Appends binary content to the document with custom options.
 *
 * @param id the document id which is used to uniquely identify it.
 * @param content the binary content to append to the document.
 * @param options custom options to customize the append behavior.
 * @return a {@link MutationResult} once completed.
 * @throws DocumentNotFoundException the given document id is not found in the collection.
 * @throws CasMismatchException if the document has been concurrently modified on the server.
 * @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<MutationResult> append(final String id, final byte[] content, final AppendOptions options) {
    return Mono.defer(() -> {
        notNull(options, "AppendOptions", () -> ReducedKeyValueErrorContext.create(id, async.collectionIdentifier()));
        AppendOptions.Built opts = options.build();
        AppendRequest request = async.appendRequest(id, content, opts);
        return Reactor.wrap(request, AppendAccessor.append(core, request, id, opts.persistTo(), opts.replicateTo()), true);
    });
}
Also used : AppendOptions(com.couchbase.client.java.kv.AppendOptions) AppendRequest(com.couchbase.client.core.msg.kv.AppendRequest)

Example 2 with AppendRequest

use of com.couchbase.client.core.msg.kv.AppendRequest in project couchbase-jvm-clients by couchbase.

the class AsyncBinaryCollection method appendRequest.

AppendRequest appendRequest(final String id, final byte[] content, final AppendOptions.Built opts) {
    notNullOrEmpty(id, "Id", () -> ReducedKeyValueErrorContext.create(id, collectionIdentifier));
    notNull(content, "Content", () -> 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_APPEND, opts.parentSpan().orElse(null));
    AppendRequest request = new AppendRequest(timeout, coreContext, collectionIdentifier, retryStrategy, id, content, opts.cas(), opts.durabilityLevel(), span);
    request.context().clientContext(opts.clientContext());
    return request;
}
Also used : Duration(java.time.Duration) AppendRequest(com.couchbase.client.core.msg.kv.AppendRequest) RetryStrategy(com.couchbase.client.core.retry.RetryStrategy) RequestSpan(com.couchbase.client.core.cnc.RequestSpan)

Example 3 with AppendRequest

use of com.couchbase.client.core.msg.kv.AppendRequest in project couchbase-jvm-clients by couchbase.

the class MutationTokenIntegrationTest method tokenOnAppend.

@Test
void tokenOnAppend() throws Exception {
    String id = UUID.randomUUID().toString();
    byte[] content = "hello".getBytes(UTF_8);
    UpsertRequest upsertRequest = new UpsertRequest(id, content, 0, false, 0, kvTimeout, core.context(), collectionIdentifier, env.retryStrategy(), Optional.empty(), null);
    core.send(upsertRequest);
    UpsertResponse upsertResponse = upsertRequest.response().get();
    assertTrue(upsertResponse.status().success());
    assertMutationToken(upsertResponse.mutationToken());
    AppendRequest appendRequest = new AppendRequest(kvTimeout, core.context(), collectionIdentifier, env.retryStrategy(), id, ", world".getBytes(UTF_8), upsertResponse.cas(), Optional.empty(), null);
    core.send(appendRequest);
    AppendResponse appendResponse = appendRequest.response().get();
    assertTrue(appendResponse.status().success());
    assertMutationToken(appendResponse.mutationToken());
}
Also used : UpsertResponse(com.couchbase.client.core.msg.kv.UpsertResponse) UpsertRequest(com.couchbase.client.core.msg.kv.UpsertRequest) AppendResponse(com.couchbase.client.core.msg.kv.AppendResponse) AppendRequest(com.couchbase.client.core.msg.kv.AppendRequest) CoreIntegrationTest(com.couchbase.client.core.util.CoreIntegrationTest) Test(org.junit.jupiter.api.Test)

Aggregations

AppendRequest (com.couchbase.client.core.msg.kv.AppendRequest)3 RequestSpan (com.couchbase.client.core.cnc.RequestSpan)1 AppendResponse (com.couchbase.client.core.msg.kv.AppendResponse)1 UpsertRequest (com.couchbase.client.core.msg.kv.UpsertRequest)1 UpsertResponse (com.couchbase.client.core.msg.kv.UpsertResponse)1 RetryStrategy (com.couchbase.client.core.retry.RetryStrategy)1 CoreIntegrationTest (com.couchbase.client.core.util.CoreIntegrationTest)1 AppendOptions (com.couchbase.client.java.kv.AppendOptions)1 Duration (java.time.Duration)1 Test (org.junit.jupiter.api.Test)1