Search in sources :

Example 1 with InsertRequest

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

the class ObserveIntegrationTest method performInsert.

/**
 * Helper method to write a new document which can then be observed.
 *
 * @param id the document id.
 * @return returns the response to use for observe.
 */
private InsertResponse performInsert(final String id) {
    byte[] content = "hello, world".getBytes(UTF_8);
    InsertRequest insertRequest = new InsertRequest(id, content, 0, 0, env.timeoutConfig().kvTimeout(), core.context(), cid, env.retryStrategy(), Optional.empty(), null);
    core.send(insertRequest);
    InsertResponse insertResponse;
    try {
        insertResponse = insertRequest.response().get();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    assertTrue(insertResponse.status().success());
    assertTrue(insertResponse.cas() != 0);
    return insertResponse;
}
Also used : InsertResponse(com.couchbase.client.core.msg.kv.InsertResponse) InsertRequest(com.couchbase.client.core.msg.kv.InsertRequest) ReplicaNotConfiguredException(com.couchbase.client.core.error.ReplicaNotConfiguredException)

Example 2 with InsertRequest

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

the class TransportEncryptionIntegrationTest method runKeyValueOperation.

private void runKeyValueOperation(Core core, CoreEnvironment env) throws Exception {
    String id = UUID.randomUUID().toString();
    byte[] content = "hello, world".getBytes(UTF_8);
    InsertRequest insertRequest = new InsertRequest(id, content, 0, 0, kvTimeout, core.context(), CollectionIdentifier.fromDefault(config().bucketname()), env.retryStrategy(), Optional.empty(), null);
    core.send(insertRequest);
    InsertResponse insertResponse = insertRequest.response().get();
    assertTrue(insertResponse.status().success());
    GetRequest getRequest = new GetRequest(id, kvTimeout, core.context(), CollectionIdentifier.fromDefault(config().bucketname()), env.retryStrategy(), null);
    core.send(getRequest);
    GetResponse getResponse = getRequest.response().get();
    assertTrue(getResponse.status().success());
    assertArrayEquals(content, getResponse.content());
    assertTrue(getResponse.cas() != 0);
}
Also used : InsertResponse(com.couchbase.client.core.msg.kv.InsertResponse) InsertRequest(com.couchbase.client.core.msg.kv.InsertRequest) GetRequest(com.couchbase.client.core.msg.kv.GetRequest) GetResponse(com.couchbase.client.core.msg.kv.GetResponse)

Example 3 with InsertRequest

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

the class KeyValueIntegrationTest method shortCircuitCollectionsIfNotAvailable.

@Test
@IgnoreWhen(hasCapabilities = { Capabilities.COLLECTIONS })
void shortCircuitCollectionsIfNotAvailable() {
    String id = UUID.randomUUID().toString();
    byte[] content = "hello, world".getBytes(UTF_8);
    InsertRequest insertRequest = new InsertRequest(id, content, 0, 0, kvTimeout, core.context(), new CollectionIdentifier(config().bucketname(), Optional.of(CollectionIdentifier.DEFAULT_SCOPE), Optional.of("my_collection_name")), env.retryStrategy(), Optional.empty(), null);
    core.send(insertRequest);
    ExecutionException exception = assertThrows(ExecutionException.class, () -> insertRequest.response().get());
    assertTrue(exception.getCause() instanceof FeatureNotAvailableException);
    InsertRequest insertRequest2 = new InsertRequest(id, content, 0, 0, kvTimeout, core.context(), new CollectionIdentifier(config().bucketname(), Optional.of("my_custom_scope"), Optional.of(CollectionIdentifier.DEFAULT_COLLECTION)), env.retryStrategy(), Optional.empty(), null);
    core.send(insertRequest2);
    exception = assertThrows(ExecutionException.class, () -> insertRequest2.response().get());
    assertTrue(exception.getCause() instanceof FeatureNotAvailableException);
}
Also used : FeatureNotAvailableException(com.couchbase.client.core.error.FeatureNotAvailableException) InsertRequest(com.couchbase.client.core.msg.kv.InsertRequest) ExecutionException(java.util.concurrent.ExecutionException) CollectionIdentifier(com.couchbase.client.core.io.CollectionIdentifier) IgnoreWhen(com.couchbase.client.test.IgnoreWhen) CoreIntegrationTest(com.couchbase.client.core.util.CoreIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 4 with InsertRequest

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

the class MutationTokenIntegrationTest method tokenOnDecrement.

@Test
void tokenOnDecrement() throws Exception {
    String id = UUID.randomUUID().toString();
    byte[] content = "10".getBytes(UTF_8);
    InsertRequest insertRequest = new InsertRequest(id, content, 0, 0, kvTimeout, core.context(), collectionIdentifier, env.retryStrategy(), Optional.empty(), null);
    core.send(insertRequest);
    InsertResponse insertResponse = insertRequest.response().get();
    assertTrue(insertResponse.status().success());
    assertMutationToken(insertResponse.mutationToken());
    DecrementRequest decrementRequest = new DecrementRequest(kvTimeout, core.context(), collectionIdentifier, env.retryStrategy(), id, 1, Optional.empty(), 0, Optional.empty(), null);
    core.send(decrementRequest);
    DecrementResponse decrementResponse = decrementRequest.response().get();
    assertTrue(decrementResponse.status().success());
    assertMutationToken(decrementResponse.mutationToken());
}
Also used : InsertResponse(com.couchbase.client.core.msg.kv.InsertResponse) InsertRequest(com.couchbase.client.core.msg.kv.InsertRequest) DecrementRequest(com.couchbase.client.core.msg.kv.DecrementRequest) DecrementResponse(com.couchbase.client.core.msg.kv.DecrementResponse) CoreIntegrationTest(com.couchbase.client.core.util.CoreIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 5 with InsertRequest

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

the class ReactiveCollection method insert.

/**
 * Inserts a full document which does not exist yet with custom options.
 *
 * @param id the document id to insert.
 * @param content the document content to insert.
 * @param options custom options to customize the insert behavior.
 * @return a {@link Mono} completing once inserted or failed.
 */
public Mono<MutationResult> insert(final String id, Object content, final InsertOptions options) {
    return Mono.defer(() -> {
        notNull(options, "InsertOptions", () -> ReducedKeyValueErrorContext.create(id, asyncCollection.collectionIdentifier()));
        InsertOptions.Built opts = options.build();
        InsertRequest request = asyncCollection.insertRequest(id, content, opts);
        return Reactor.wrap(request, InsertAccessor.insert(core, request, id, opts.persistTo(), opts.replicateTo()), true);
    });
}
Also used : InsertRequest(com.couchbase.client.core.msg.kv.InsertRequest) InsertOptions(com.couchbase.client.java.kv.InsertOptions)

Aggregations

InsertRequest (com.couchbase.client.core.msg.kv.InsertRequest)12 InsertResponse (com.couchbase.client.core.msg.kv.InsertResponse)8 CoreIntegrationTest (com.couchbase.client.core.util.CoreIntegrationTest)6 Test (org.junit.jupiter.api.Test)6 ExecutionException (java.util.concurrent.ExecutionException)4 FeatureNotAvailableException (com.couchbase.client.core.error.FeatureNotAvailableException)2 GetRequest (com.couchbase.client.core.msg.kv.GetRequest)2 GetResponse (com.couchbase.client.core.msg.kv.GetResponse)2 IgnoreWhen (com.couchbase.client.test.IgnoreWhen)2 RequestSpan (com.couchbase.client.core.cnc.RequestSpan)1 ReplicaNotConfiguredException (com.couchbase.client.core.error.ReplicaNotConfiguredException)1 CollectionIdentifier (com.couchbase.client.core.io.CollectionIdentifier)1 DecrementRequest (com.couchbase.client.core.msg.kv.DecrementRequest)1 DecrementResponse (com.couchbase.client.core.msg.kv.DecrementResponse)1 IncrementRequest (com.couchbase.client.core.msg.kv.IncrementRequest)1 IncrementResponse (com.couchbase.client.core.msg.kv.IncrementResponse)1 RetryStrategy (com.couchbase.client.core.retry.RetryStrategy)1 Transcoder (com.couchbase.client.java.codec.Transcoder)1 InsertOptions (com.couchbase.client.java.kv.InsertOptions)1 Duration (java.time.Duration)1