Search in sources :

Example 1 with PrependRequest

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

the class MutationTokenIntegrationTest method tokenOnPrepend.

@Test
void tokenOnPrepend() 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());
    PrependRequest prependRequest = new PrependRequest(kvTimeout, core.context(), collectionIdentifier, env.retryStrategy(), id, ", world".getBytes(UTF_8), upsertResponse.cas(), Optional.empty(), null);
    core.send(prependRequest);
    PrependResponse prependResponse = prependRequest.response().get();
    assertTrue(prependResponse.status().success());
    assertMutationToken(prependResponse.mutationToken());
}
Also used : UpsertResponse(com.couchbase.client.core.msg.kv.UpsertResponse) UpsertRequest(com.couchbase.client.core.msg.kv.UpsertRequest) PrependRequest(com.couchbase.client.core.msg.kv.PrependRequest) PrependResponse(com.couchbase.client.core.msg.kv.PrependResponse) CoreIntegrationTest(com.couchbase.client.core.util.CoreIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 2 with PrependRequest

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

the class ReactiveBinaryCollection method prepend.

/**
 * Prepends 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 prepend 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> prepend(final String id, final byte[] content, final PrependOptions options) {
    return Mono.defer(() -> {
        notNull(options, "PrependOptions", () -> ReducedKeyValueErrorContext.create(id, async.collectionIdentifier()));
        PrependOptions.Built opts = options.build();
        PrependRequest request = async.prependRequest(id, content, opts);
        return Reactor.wrap(request, PrependAccessor.prepend(core, request, id, opts.persistTo(), opts.replicateTo()), true);
    });
}
Also used : PrependOptions(com.couchbase.client.java.kv.PrependOptions) PrependRequest(com.couchbase.client.core.msg.kv.PrependRequest)

Example 3 with PrependRequest

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

the class AsyncBinaryCollection method prependRequest.

PrependRequest prependRequest(final String id, final byte[] content, final PrependOptions.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_PREPEND, opts.parentSpan().orElse(null));
    PrependRequest request = new PrependRequest(timeout, coreContext, collectionIdentifier, retryStrategy, id, content, opts.cas(), opts.durabilityLevel(), span);
    request.context().clientContext(opts.clientContext());
    return request;
}
Also used : Duration(java.time.Duration) PrependRequest(com.couchbase.client.core.msg.kv.PrependRequest) RetryStrategy(com.couchbase.client.core.retry.RetryStrategy) RequestSpan(com.couchbase.client.core.cnc.RequestSpan)

Aggregations

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