use of com.couchbase.client.core.msg.kv.ReplaceRequest in project couchbase-jvm-clients by couchbase.
the class KeyValueIntegrationTest method replaceThrowsInvalidArgumentForBadPreserveExpiry.
@Test
void replaceThrowsInvalidArgumentForBadPreserveExpiry() {
byte[] content = "hello, world".getBytes(UTF_8);
final long expiry = 30;
final boolean preserveExpiry = true;
Throwable t = assertThrows(InvalidArgumentException.class, () -> new ReplaceRequest("foo", content, expiry, preserveExpiry, 0, kvTimeout, 0, core.context(), CollectionIdentifier.fromDefault(config().bucketname()), env.retryStrategy(), Optional.empty(), null));
assertTrue(t.getMessage().contains("preserveExpiry"));
}
use of com.couchbase.client.core.msg.kv.ReplaceRequest in project couchbase-jvm-clients by couchbase.
the class MutationTokenIntegrationTest method tokenOnReplace.
@Test
void tokenOnReplace() throws Exception {
String id = UUID.randomUUID().toString();
byte[] content = "hello, world".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());
ReplaceRequest replaceRequest = new ReplaceRequest(id, content, 0, false, 0, kvTimeout, upsertResponse.cas(), core.context(), collectionIdentifier, env.retryStrategy(), Optional.empty(), null);
core.send(replaceRequest);
ReplaceResponse replaceResponse = replaceRequest.response().get();
assertTrue(replaceResponse.status().success());
assertMutationToken(replaceResponse.mutationToken());
}
use of com.couchbase.client.core.msg.kv.ReplaceRequest in project couchbase-jvm-clients by couchbase.
the class AsyncCollection method replaceRequest.
/**
* Helper method to generate the replace request.
*
* @param id the document id to replace.
* @param content the document content to replace.
* @param opts custom options to customize the replace behavior.
* @return the replace request.
*/
ReplaceRequest replaceRequest(final String id, final Object content, final ReplaceOptions.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());
Transcoder transcoder = opts.transcoder() == null ? environment.transcoder() : opts.transcoder();
final RequestSpan span = environment.requestTracer().requestSpan(TracingIdentifiers.SPAN_REQUEST_KV_REPLACE, opts.parentSpan().orElse(null));
final RequestSpan encodeSpan = environment.requestTracer().requestSpan(TracingIdentifiers.SPAN_REQUEST_ENCODING, span);
long start = System.nanoTime();
Transcoder.EncodedValue encoded;
try {
encoded = transcoder.encode(content);
} finally {
encodeSpan.end();
}
long end = System.nanoTime();
long expiry = opts.expiry().encode();
ReplaceRequest request = new ReplaceRequest(id, encoded.encoded(), expiry, opts.preserveExpiry(), encoded.flags(), timeout, opts.cas(), coreContext, collectionIdentifier, retryStrategy, opts.durabilityLevel(), span);
request.context().clientContext(opts.clientContext()).encodeLatency(end - start);
return request;
}
use of com.couchbase.client.core.msg.kv.ReplaceRequest in project couchbase-jvm-clients by couchbase.
the class ReactiveCollection method replace.
/**
* Replaces a full document which already exists with custom options.
*
* @param id the document id to replace.
* @param content the document content to replace.
* @param options custom options to customize the replace behavior.
* @return a {@link Mono} completing once replaced or failed.
*/
public Mono<MutationResult> replace(final String id, Object content, final ReplaceOptions options) {
return Mono.defer(() -> {
notNull(options, "ReplaceOptions", () -> ReducedKeyValueErrorContext.create(id, asyncCollection.collectionIdentifier()));
ReplaceOptions.Built opts = options.build();
ReplaceRequest request = asyncCollection.replaceRequest(id, content, opts);
return Reactor.wrap(request, ReplaceAccessor.replace(core, request, id, opts.persistTo(), opts.replicateTo()), true);
});
}
Aggregations