use of com.couchbase.client.java.kv.MutationResult in project couchbase-jvm-clients by couchbase.
the class KeyValueIntegrationTest method getWithProjection.
@Test
void getWithProjection() {
String id = UUID.randomUUID().toString();
JsonObject content = JsonObject.create().put("foo", "bar").put("created", true).put("age", 12);
MutationResult mutationResult = collection.upsert(id, content);
assertTrue(mutationResult.cas() != 0);
GetResult getResult = collection.get(id, getOptions().project("foo", "created", "notfound"));
assertTrue(getResult.cas() != 0);
assertFalse(getResult.expiryTime().isPresent());
JsonObject decoded = getResult.contentAsObject();
assertEquals("bar", decoded.getString("foo"));
assertEquals(true, decoded.getBoolean("created"));
assertFalse(decoded.containsKey("age"));
}
use of com.couchbase.client.java.kv.MutationResult in project couchbase-jvm-clients by couchbase.
the class KeyValueIntegrationTest method projectionWithExpiration.
/**
* Right now the mock does not support xattr/macro expansion so this test is
* ignored on the mock. Once the mock supports it, please remove the ignore
* annotation.
*
* <p>See https://github.com/couchbase/CouchbaseMock/issues/46</p>
*/
@Test
@IgnoreWhen(clusterTypes = { ClusterType.MOCKED })
void projectionWithExpiration() {
String id = UUID.randomUUID().toString();
JsonObject content = JsonObject.create().put("foo", "bar").put("created", true).put("age", 12);
MutationResult mutationResult = collection.upsert(id, content, upsertOptions().expiry(Duration.ofSeconds(5)));
assertTrue(mutationResult.cas() != 0);
GetResult getResult = collection.get(id, getOptions().project("foo", "created").withExpiry(true));
assertTrue(getResult.cas() != 0);
assertTrue(getResult.expiryTime().isPresent());
assertTrue(getResult.expiryTime().get().toEpochMilli() > 0);
JsonObject decoded = getResult.contentAsObject();
assertEquals("bar", decoded.getString("foo"));
assertEquals(true, decoded.getBoolean("created"));
assertFalse(decoded.containsKey("age"));
}
use of com.couchbase.client.java.kv.MutationResult in project couchbase-jvm-clients by couchbase.
the class KeyValueIntegrationTest method getAndLock.
/**
* We need to ignore this test on the mock because the mock returns TMPFAIL instead of LOCKED when the
* document is locked (which used to be the old functionality but now since XERROR is negotiated it
* returns LOCKED properly).
*
* <p>Once the mock is modified to return LOCKED, this test can also be run on the mock again.</p>
*/
@Test
@IgnoreWhen(clusterTypes = ClusterType.MOCKED)
void getAndLock() {
String id = UUID.randomUUID().toString();
JsonObject expected = JsonObject.create().put("foo", true);
MutationResult insert = collection.insert(id, expected);
assertTrue(insert.cas() != 0);
GetResult getAndLock = collection.getAndLock(id, Duration.ofSeconds(30));
assertTrue(getAndLock.cas() != 0);
assertNotEquals(insert.cas(), getAndLock.cas());
assertEquals(expected, getAndLock.contentAsObject());
TimeoutException exception = assertThrows(TimeoutException.class, () -> collection.getAndLock(id, Duration.ofSeconds(30), getAndLockOptions().timeout(Duration.ofMillis(100))));
assertEquals(EnumSet.of(RetryReason.KV_LOCKED), exception.context().requestContext().retryReasons());
assertThrows(DocumentNotFoundException.class, () -> collection.getAndLock("some_doc", Duration.ofSeconds(30)));
}
use of com.couchbase.client.java.kv.MutationResult in project couchbase-jvm-clients by couchbase.
the class KeyValueReactiveCollectionIntegrationTest method reactiveTouch.
@Test
@IgnoreWhen(clusterTypes = { ClusterType.MOCKED })
void reactiveTouch() {
StepVerifier.create(docIds.concatMap(key -> reactiveCollection.touch(key, Duration.ofSeconds(1)))).expectError(DocumentNotFoundException.class).verify();
// Insert docs with expiry of 10s
InsertOptions firstOpts = InsertOptions.insertOptions().expiry(Duration.ofSeconds(10));
List<MutationResult> insertResults = docIds.concatMap(key -> reactiveCollection.insert(key, JsonObject.create().put("key", key), firstOpts)).collectList().block();
// Touch docs and update the expiry to 1s
List<MutationResult> touchResults = docIds.concatMap(key -> reactiveCollection.touch(key, Duration.ofSeconds(1))).collectList().block();
// Assert cas of insert and touch results differ
StepVerifier.create(Flux.range(0, numDocs)).thenConsumeWhile(i -> insertResults.get(i).cas() != touchResults.get(i).cas()).verifyComplete();
List<GetResult> getResults = docIds.concatMap(reactiveCollection::get).collectList().block();
StepVerifier.create(Flux.range(0, numDocs)).thenConsumeWhile(i -> getResults.get(i).cas() == touchResults.get(i).cas()).verifyComplete();
}
use of com.couchbase.client.java.kv.MutationResult in project couchbase-jvm-clients by couchbase.
the class MutationTokenIntegrationTest method tokenOnRemove.
@Test
void tokenOnRemove() {
String id = UUID.randomUUID().toString();
MutationResult result = collection.upsert(id, JsonObject.create());
assertMutationToken(result.mutationToken());
MutationResult remove = collection.remove(id);
assertMutationToken(remove.mutationToken());
}
Aggregations