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());
}
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);
});
}
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;
}
Aggregations