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));
}
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()));
}
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());
}
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());
}
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());
}
Aggregations