Search in sources :

Example 11 with MutationResult

use of com.couchbase.client.java.kv.MutationResult in project couchbase-jvm-clients by couchbase.

the class KeyValueIntegrationTest method remove.

@Test
void remove() {
    String id = UUID.randomUUID().toString();
    JsonObject expected = JsonObject.create().put("foo", true);
    MutationResult insert = collection.insert(id, expected, insertOptions().expiry(Duration.ofSeconds(2)));
    assertTrue(insert.cas() != 0);
    assertThrows(CasMismatchException.class, () -> collection.remove(id, removeOptions().cas(insert.cas() + 100)));
    MutationResult result = collection.remove(id);
    assertTrue(result.cas() != insert.cas());
    assertThrows(DocumentNotFoundException.class, () -> collection.remove(id));
}
Also used : JsonObject(com.couchbase.client.java.json.JsonObject) MutationResult(com.couchbase.client.java.kv.MutationResult) JavaIntegrationTest(com.couchbase.client.java.util.JavaIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 12 with MutationResult

use of com.couchbase.client.java.kv.MutationResult in project couchbase-jvm-clients by couchbase.

the class KeyValueIntegrationTest method replace.

@Test
void replace() {
    String id = UUID.randomUUID().toString();
    MutationResult upsert = collection.upsert(id, JsonObject.create().put("foo", true));
    assertTrue(upsert.cas() != 0);
    assertThrows(CasMismatchException.class, () -> collection.replace(id, JsonObject.create(), replaceOptions().cas(upsert.cas() + 1)));
    JsonObject expected = JsonObject.create().put("foo", false);
    MutationResult replaced = collection.replace(id, expected);
    assertTrue(replaced.cas() != 0);
    assertTrue(upsert.cas() != replaced.cas());
    assertEquals(expected, collection.get(id).contentAsObject());
    assertThrows(DocumentNotFoundException.class, () -> collection.replace("some_doc", JsonObject.create()));
}
Also used : JsonObject(com.couchbase.client.java.json.JsonObject) MutationResult(com.couchbase.client.java.kv.MutationResult) JavaIntegrationTest(com.couchbase.client.java.util.JavaIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 13 with MutationResult

use of com.couchbase.client.java.kv.MutationResult in project couchbase-jvm-clients by couchbase.

the class MutationTokenIntegrationTest method tokenOnReplace.

@Test
void tokenOnReplace() {
    String id = UUID.randomUUID().toString();
    MutationResult result = collection.upsert(id, JsonObject.create());
    assertMutationToken(result.mutationToken());
    MutationResult replace = collection.replace(id, JsonObject.create().put("foo", true));
    assertMutationToken(replace.mutationToken());
}
Also used : MutationResult(com.couchbase.client.java.kv.MutationResult) JavaIntegrationTest(com.couchbase.client.java.util.JavaIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 14 with MutationResult

use of com.couchbase.client.java.kv.MutationResult in project couchbase-jvm-clients by couchbase.

the class MutationTokenIntegrationTest method tokenOnAppend.

@Test
void tokenOnAppend() {
    String id = UUID.randomUUID().toString();
    byte[] helloBytes = "Hello, ".getBytes(UTF_8);
    byte[] worldBytes = "World!".getBytes(UTF_8);
    MutationResult upsert = collection.upsert(id, helloBytes, upsertOptions().transcoder(RawBinaryTranscoder.INSTANCE));
    assertMutationToken(upsert.mutationToken());
    MutationResult append = collection.binary().append(id, worldBytes);
    assertMutationToken(append.mutationToken());
}
Also used : MutationResult(com.couchbase.client.java.kv.MutationResult) JavaIntegrationTest(com.couchbase.client.java.util.JavaIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 15 with MutationResult

use of com.couchbase.client.java.kv.MutationResult in project couchbase-jvm-clients by couchbase.

the class MutationTokenIntegrationTest method tokenOnPrepend.

@Test
void tokenOnPrepend() {
    String id = UUID.randomUUID().toString();
    byte[] helloBytes = "Hello, ".getBytes(UTF_8);
    byte[] worldBytes = "World!".getBytes(UTF_8);
    MutationResult upsert = collection.upsert(id, helloBytes, upsertOptions().transcoder(RawBinaryTranscoder.INSTANCE));
    assertMutationToken(upsert.mutationToken());
    MutationResult prepend = collection.binary().prepend(id, worldBytes);
    assertMutationToken(prepend.mutationToken());
}
Also used : MutationResult(com.couchbase.client.java.kv.MutationResult) JavaIntegrationTest(com.couchbase.client.java.util.JavaIntegrationTest) Test(org.junit.jupiter.api.Test)

Aggregations

MutationResult (com.couchbase.client.java.kv.MutationResult)42 JavaIntegrationTest (com.couchbase.client.java.util.JavaIntegrationTest)40 Test (org.junit.jupiter.api.Test)40 JsonObject (com.couchbase.client.java.json.JsonObject)16 IgnoreWhen (com.couchbase.client.test.IgnoreWhen)13 GetResult (com.couchbase.client.java.kv.GetResult)11 SearchQuery.queryString (com.couchbase.client.java.search.SearchQuery.queryString)5 SearchResult (com.couchbase.client.java.search.result.SearchResult)5 DocumentNotFoundException (com.couchbase.client.core.error.DocumentNotFoundException)4 TimeoutException (com.couchbase.client.core.error.TimeoutException)3 Bucket (com.couchbase.client.java.Bucket)2 Collection (com.couchbase.client.java.Collection)2 ExistsResult (com.couchbase.client.java.kv.ExistsResult)2 QueryOptions (com.couchbase.client.java.query.QueryOptions)2 QueryResult (com.couchbase.client.java.query.QueryResult)2 ReactiveQueryResult (com.couchbase.client.java.query.ReactiveQueryResult)2 CasMismatchException (com.couchbase.client.core.error.CasMismatchException)1 CouchbaseException (com.couchbase.client.core.error.CouchbaseException)1 DocumentExistsException (com.couchbase.client.core.error.DocumentExistsException)1 RateLimitedException (com.couchbase.client.core.error.RateLimitedException)1