use of com.couchbase.client.java.kv.MutationResult in project couchbase-jvm-clients by couchbase.
the class SearchIntegrationTest method searchMatchOperatorAndMiss.
@Test
void searchMatchOperatorAndMiss() throws Throwable {
String docId1 = UUID.randomUUID().toString();
String docId2 = UUID.randomUUID().toString();
MutationResult insertResult1 = collection.insert(docId1, mapOf("name", "billy"));
MutationResult insertResult2 = collection.insert(docId2, mapOf("name", "silly"));
try {
runWithRetry(Duration.ofSeconds(10), () -> {
SearchResult result = cluster.searchQuery(indexName, match("silly billy").operator(MatchOperator.AND), searchOptions().consistentWith(MutationState.from(insertResult1.mutationToken().get(), insertResult2.mutationToken().get())));
List<String> actualDocIds = result.rows().stream().map(SearchRow::id).collect(toList());
assertTrue(actualDocIds.isEmpty());
});
} finally {
collection.remove(docId1);
collection.remove(docId2);
}
}
use of com.couchbase.client.java.kv.MutationResult in project couchbase-jvm-clients by couchbase.
the class SearchIntegrationTest method searchIncludeLocations.
@Test
void searchIncludeLocations() throws Throwable {
String docId = UUID.randomUUID().toString();
MutationResult insertResult = collection.insert(docId, mapOf("name", "billy"));
try {
runWithRetry(Duration.ofSeconds(30), () -> {
SearchResult result = cluster.searchQuery(indexName, queryString("billy"), searchOptions().consistentWith(MutationState.from(insertResult.mutationToken().get())).includeLocations(true));
List<SearchRowLocations> locationsList = result.rows().stream().map(SearchRow::locations).filter(opt -> opt.isPresent()).map(Optional::get).collect(toList());
assertTrue(!locationsList.isEmpty());
});
} finally {
collection.remove(docId);
}
}
use of com.couchbase.client.java.kv.MutationResult in project couchbase-jvm-clients by couchbase.
the class KeyValueErrorIntegrationTest method verifyReplaceExceptions.
@Test
void verifyReplaceExceptions() {
DocumentNotFoundException thrown = assertThrows(DocumentNotFoundException.class, () -> collection.replace(UUID.randomUUID().toString(), "bar"));
assertNotNull(thrown.context());
assertThrows(InvalidArgumentException.class, () -> collection.replace("foo", null));
assertThrows(InvalidArgumentException.class, () -> collection.replace(null, "bar"));
assertThrows(InvalidArgumentException.class, () -> collection.replace("foo", "bar", null));
String id = UUID.randomUUID().toString();
MutationResult result = collection.upsert(id, "bar");
CasMismatchException mismatch = assertThrows(CasMismatchException.class, () -> collection.replace(id, "bar", replaceOptions().cas(result.cas() + 1)));
assertNotNull(mismatch.context());
}
use of com.couchbase.client.java.kv.MutationResult in project couchbase-jvm-clients by couchbase.
the class SubdocMutateIntegrationTest method replaceBodyWithXattrWithDurability.
@IgnoreWhen(missesCapabilities = { Capabilities.SUBDOC_REVIVE_DOCUMENT })
@Test
void replaceBodyWithXattrWithDurability() {
String id = UUID.randomUUID().toString();
MutationResult mr = coll.mutateIn(id, Arrays.asList(MutateInSpec.upsert("txn", JsonObject.create()).xattr().createPath()), mutateInOptions().accessDeleted(true).createAsDeleted(true).durability(DurabilityLevel.MAJORITY).storeSemantics(StoreSemantics.INSERT));
coll.mutateIn(id, Arrays.asList(MutateInSpec.remove("txn").xattr()), mutateInOptions().accessDeleted(true).durability(DurabilityLevel.MAJORITY).storeSemantics(StoreSemantics.REVIVE));
}
use of com.couchbase.client.java.kv.MutationResult in project couchbase-jvm-clients by couchbase.
the class KeyValueIntegrationTest method getAndTouch.
/**
* This test is ignored against the mock because right now it does not bump the CAS like
* the server does when getAndTouch is called.
*
* <p>Remove the ignore as soon as https://github.com/couchbase/CouchbaseMock/issues/49 is
* fixed.</p>
*/
@Test
@IgnoreWhen(clusterTypes = { ClusterType.MOCKED })
void getAndTouch() {
String id = UUID.randomUUID().toString();
JsonObject expected = JsonObject.create().put("foo", true);
MutationResult insert = collection.insert(id, expected, insertOptions().expiry(Duration.ofSeconds(10)));
assertTrue(insert.cas() != 0);
GetResult getAndTouch = collection.getAndTouch(id, Duration.ofSeconds(1));
assertTrue(getAndTouch.cas() != 0);
assertNotEquals(insert.cas(), getAndTouch.cas());
assertEquals(expected, getAndTouch.contentAsObject());
waitUntilCondition(() -> {
try {
Thread.sleep(200);
} catch (InterruptedException e) {
// ignored.
}
try {
collection.get(id);
return false;
} catch (DocumentNotFoundException knf) {
return true;
}
});
}
Aggregations