Search in sources :

Example 1 with RemoveRequest

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

the class ObserveIntegrationTest method performRemove.

/**
 * Helper method to perform a remove operation that can then be observed.
 *
 * @param id the document id.
 * @return returns the response to use for observe.
 */
private RemoveResponse performRemove(final String id) {
    RemoveRequest removeRequest = new RemoveRequest(id, 0, env.timeoutConfig().kvTimeout(), core.context(), cid, env.retryStrategy(), Optional.empty(), null);
    core.send(removeRequest);
    RemoveResponse removeResponse;
    try {
        removeResponse = removeRequest.response().get();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    assertTrue(removeResponse.status().success());
    assertTrue(removeResponse.cas() != 0);
    return removeResponse;
}
Also used : RemoveResponse(com.couchbase.client.core.msg.kv.RemoveResponse) RemoveRequest(com.couchbase.client.core.msg.kv.RemoveRequest) ReplicaNotConfiguredException(com.couchbase.client.core.error.ReplicaNotConfiguredException)

Example 2 with RemoveRequest

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

the class MutationTokenIntegrationTest method tokenOnRemove.

@Test
void tokenOnRemove() 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());
    RemoveRequest removeRequest = new RemoveRequest(id, upsertResponse.cas(), kvTimeout, core.context(), collectionIdentifier, env.retryStrategy(), Optional.empty(), null);
    core.send(removeRequest);
    RemoveResponse removeResponse = removeRequest.response().get();
    assertTrue(removeResponse.status().success());
    assertMutationToken(removeResponse.mutationToken());
}
Also used : RemoveResponse(com.couchbase.client.core.msg.kv.RemoveResponse) RemoveRequest(com.couchbase.client.core.msg.kv.RemoveRequest) UpsertResponse(com.couchbase.client.core.msg.kv.UpsertResponse) UpsertRequest(com.couchbase.client.core.msg.kv.UpsertRequest) CoreIntegrationTest(com.couchbase.client.core.util.CoreIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 3 with RemoveRequest

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

the class AsyncCollection method removeRequest.

/**
 * Helper method to create the remove request.
 *
 * @param id the id of the document to remove.
 * @param opts custom options to change the default behavior.
 * @return the remove request.
 */
RemoveRequest removeRequest(final String id, final RemoveOptions.Built opts) {
    notNullOrEmpty(id, "Id", () -> ReducedKeyValueErrorContext.create(id, collectionIdentifier));
    Duration timeout = decideKvTimeout(opts, environment.timeoutConfig());
    RetryStrategy retryStrategy = opts.retryStrategy().orElse(environment.retryStrategy());
    final RequestSpan span = environment.requestTracer().requestSpan(TracingIdentifiers.SPAN_REQUEST_KV_REMOVE, opts.parentSpan().orElse(null));
    RemoveRequest request = new RemoveRequest(id, opts.cas(), timeout, coreContext, collectionIdentifier, retryStrategy, opts.durabilityLevel(), span);
    request.context().clientContext(opts.clientContext());
    return request;
}
Also used : RemoveRequest(com.couchbase.client.core.msg.kv.RemoveRequest) Duration(java.time.Duration) RetryStrategy(com.couchbase.client.core.retry.RetryStrategy) RequestSpan(com.couchbase.client.core.cnc.RequestSpan)

Example 4 with RemoveRequest

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

the class ReactiveCollection method remove.

/**
 * Removes a Document from a collection with custom options.
 *
 * @param id the id of the document to remove.
 * @param options custom options to change the default behavior.
 * @return a {@link Mono} completing once removed or failed.
 */
public Mono<MutationResult> remove(final String id, final RemoveOptions options) {
    return Mono.defer(() -> {
        notNull(options, "RemoveOptions", () -> ReducedKeyValueErrorContext.create(id, asyncCollection.collectionIdentifier()));
        RemoveOptions.Built opts = options.build();
        RemoveRequest request = asyncCollection.removeRequest(id, opts);
        return Reactor.wrap(request, RemoveAccessor.remove(core, request, id, opts.persistTo(), opts.replicateTo()), true);
    });
}
Also used : RemoveRequest(com.couchbase.client.core.msg.kv.RemoveRequest) RemoveOptions(com.couchbase.client.java.kv.RemoveOptions)

Aggregations

RemoveRequest (com.couchbase.client.core.msg.kv.RemoveRequest)4 RemoveResponse (com.couchbase.client.core.msg.kv.RemoveResponse)2 RequestSpan (com.couchbase.client.core.cnc.RequestSpan)1 ReplicaNotConfiguredException (com.couchbase.client.core.error.ReplicaNotConfiguredException)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 RemoveOptions (com.couchbase.client.java.kv.RemoveOptions)1 Duration (java.time.Duration)1 Test (org.junit.jupiter.api.Test)1