Search in sources :

Example 6 with InsertResponse

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

the class SubDocumentMutateIntegrationTest method insertContent.

private byte[] insertContent(String id, String in) {
    byte[] content = in.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 = null;
    try {
        insertResponse = insertRequest.response().get();
    } catch (InterruptedException | ExecutionException e) {
        fail("Failed with " + e);
    }
    assertTrue(insertResponse.status().success());
    return content;
}
Also used : InsertResponse(com.couchbase.client.core.msg.kv.InsertResponse) InsertRequest(com.couchbase.client.core.msg.kv.InsertRequest) ExecutionException(java.util.concurrent.ExecutionException)

Example 7 with InsertResponse

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

the class ObserveIntegrationTest method failsFastIfTooManyReplicasRequested.

@Test
@IgnoreWhen(replicasGreaterThan = 1)
void failsFastIfTooManyReplicasRequested() {
    String id = UUID.randomUUID().toString();
    InsertResponse insertResponse = performInsert(id);
    assertTrue(insertResponse.mutationToken().isPresent());
    final ObserveContext ctx = new ObserveContext(core.context(), Observe.ObservePersistTo.THREE, Observe.ObserveReplicateTo.NONE, insertResponse.mutationToken(), 0, cid, id, false, env.timeoutConfig().kvTimeout(), null);
    assertThrows(ReplicaNotConfiguredException.class, () -> Observe.poll(ctx).timeout(MAX_WAIT).block());
    final ObserveContext ctx2 = new ObserveContext(core.context(), Observe.ObservePersistTo.NONE, Observe.ObserveReplicateTo.TWO, insertResponse.mutationToken(), 0, cid, id, false, env.timeoutConfig().kvTimeout(), null);
    assertThrows(ReplicaNotConfiguredException.class, () -> Observe.poll(ctx2).timeout(MAX_WAIT).block());
    final ObserveContext ctx3 = new ObserveContext(core.context(), Observe.ObservePersistTo.FOUR, Observe.ObserveReplicateTo.THREE, insertResponse.mutationToken(), 0, cid, id, false, env.timeoutConfig().kvTimeout(), null);
    assertThrows(ReplicaNotConfiguredException.class, () -> Observe.poll(ctx3).timeout(MAX_WAIT).block());
}
Also used : InsertResponse(com.couchbase.client.core.msg.kv.InsertResponse) ObserveContext(com.couchbase.client.core.service.kv.ObserveContext) IgnoreWhen(com.couchbase.client.test.IgnoreWhen) CoreIntegrationTest(com.couchbase.client.core.util.CoreIntegrationTest)

Example 8 with InsertResponse

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

the class KeyValueIntegrationTest method insertAndGet.

/**
 * Validate that an inserted document can be read subsequently.
 */
@Test
void insertAndGet() 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) CoreIntegrationTest(com.couchbase.client.core.util.CoreIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 9 with InsertResponse

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

the class MutationTokenIntegrationTest method tokenOnInsert.

@Test
void tokenOnInsert() 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, env.retryStrategy(), Optional.empty(), null);
    core.send(insertRequest);
    InsertResponse insertResponse = insertRequest.response().get();
    assertTrue(insertResponse.status().success());
    assertMutationToken(insertResponse.mutationToken());
}
Also used : InsertResponse(com.couchbase.client.core.msg.kv.InsertResponse) InsertRequest(com.couchbase.client.core.msg.kv.InsertRequest) CoreIntegrationTest(com.couchbase.client.core.util.CoreIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 10 with InsertResponse

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

the class MutationTokenIntegrationTest method tokenOnIncrement.

@Test
void tokenOnIncrement() throws Exception {
    String id = UUID.randomUUID().toString();
    byte[] content = "1".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());
    IncrementRequest incrementRequest = new IncrementRequest(kvTimeout, core.context(), collectionIdentifier, env.retryStrategy(), id, 1, Optional.empty(), 0, Optional.empty(), null);
    core.send(incrementRequest);
    IncrementResponse incrementResponse = incrementRequest.response().get();
    assertTrue(incrementResponse.status().success());
    assertMutationToken(incrementResponse.mutationToken());
}
Also used : InsertResponse(com.couchbase.client.core.msg.kv.InsertResponse) IncrementRequest(com.couchbase.client.core.msg.kv.IncrementRequest) InsertRequest(com.couchbase.client.core.msg.kv.InsertRequest) IncrementResponse(com.couchbase.client.core.msg.kv.IncrementResponse) CoreIntegrationTest(com.couchbase.client.core.util.CoreIntegrationTest) Test(org.junit.jupiter.api.Test)

Aggregations

InsertResponse (com.couchbase.client.core.msg.kv.InsertResponse)12 InsertRequest (com.couchbase.client.core.msg.kv.InsertRequest)8 CoreIntegrationTest (com.couchbase.client.core.util.CoreIntegrationTest)8 ObserveContext (com.couchbase.client.core.service.kv.ObserveContext)4 Test (org.junit.jupiter.api.Test)4 GetRequest (com.couchbase.client.core.msg.kv.GetRequest)2 GetResponse (com.couchbase.client.core.msg.kv.GetResponse)2 ExecutionException (java.util.concurrent.ExecutionException)2 ReplicaNotConfiguredException (com.couchbase.client.core.error.ReplicaNotConfiguredException)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 RemoveResponse (com.couchbase.client.core.msg.kv.RemoveResponse)1 IgnoreWhen (com.couchbase.client.test.IgnoreWhen)1