use of com.couchbase.client.java.kv.MutationResult in project couchbase-jvm-clients by couchbase.
the class EntityInsertWithDurability method main.
public static void main(String... args) {
/*
* Connect to the cluster and open a collection to work with.
*/
Cluster cluster = Cluster.connect("127.0.0.1", "Administrator", "password");
Bucket bucket = cluster.bucket("travel-sample");
Collection collection = bucket.defaultCollection();
String id = "p02";
MutationResult result = collection.insert(id, new Person("Jon Henry", 34, null, null), insertOptions().durability(DurabilityLevel.MAJORITY_AND_PERSIST_TO_ACTIVE).timeout(Duration.ofSeconds(30)));
}
use of com.couchbase.client.java.kv.MutationResult in project couchbase-jvm-clients by couchbase.
the class QueryCollectionIntegrationTest method consistentWith.
// Test for MB-46876
@Test
void consistentWith() {
String id = UUID.randomUUID().toString();
Scope scope = cluster.bucket(config().bucketname()).scope(SCOPE_NAME);
Collection collection = scope.collection(COLLECTION_NAME);
MutationResult mr = collection.insert(id, FOO_CONTENT);
QueryOptions options = queryOptions().consistentWith(MutationState.from(mr.mutationToken().get())).parameters(JsonArray.from(id));
QueryResult result = scope.query("select * from `" + COLLECTION_NAME + "` where meta().id=$1", options);
List<JsonObject> rows = result.rowsAs(JsonObject.class);
assertEquals(1, rows.size());
assertEquals(FOO_CONTENT, rows.get(0).getObject(COLLECTION_NAME));
}
use of com.couchbase.client.java.kv.MutationResult in project couchbase-jvm-clients by couchbase.
the class QueryIntegrationTest method consistentWith.
@Test
void consistentWith() {
String id = UUID.randomUUID().toString();
MutationResult mr = collection.insert(id, FOO_CONTENT);
QueryOptions options = queryOptions().consistentWith(MutationState.from(mr.mutationToken().get())).parameters(JsonArray.from(id));
QueryResult result = cluster.query("select " + bucketName + ".* from " + bucketName + " where meta().id=$1", options);
List<JsonObject> rows = result.rowsAs(JsonObject.class);
assertEquals(1, rows.size());
assertEquals(FOO_CONTENT, rows.get(0));
}
use of com.couchbase.client.java.kv.MutationResult in project couchbase-jvm-clients by couchbase.
the class SearchIntegrationTest method simpleSearch.
@Test
void simpleSearch() throws Throwable {
String docId = UUID.randomUUID().toString();
MutationResult insertResult = collection.insert(docId, mapOf("name", "michael"));
try {
// should not have to retry here, but newly-created index is flaky
runWithRetry(Duration.ofSeconds(30), () -> {
SearchResult result = cluster.searchQuery(indexName, queryString("michael"), searchOptions().consistentWith(MutationState.from(insertResult.mutationToken().get())));
List<String> actualDocIds = result.rows().stream().map(SearchRow::id).collect(toList());
// make assertion inside the retry, because newly-created index sometimes returns
// no rows even though we specified mutation tokens for consistency :-/
assertEquals(listOf(docId), actualDocIds);
});
} finally {
collection.remove(docId);
}
}
use of com.couchbase.client.java.kv.MutationResult in project couchbase-jvm-clients by couchbase.
the class SearchIntegrationTest method searchMatchOperatorOr.
@Test
void searchMatchOperatorOr() throws Throwable {
String docId1 = UUID.randomUUID().toString();
String docId2 = UUID.randomUUID().toString();
MutationResult insertResult1 = collection.insert(docId1, mapOf("name", "milly"));
MutationResult insertResult2 = collection.insert(docId2, mapOf("name", "tilly"));
try {
runWithRetry(Duration.ofSeconds(30), () -> {
SearchResult result = cluster.searchQuery(indexName, match("milly tilly").operator(MatchOperator.OR), searchOptions().consistentWith(MutationState.from(insertResult1.mutationToken().get(), insertResult2.mutationToken().get())));
List<String> actualDocIds = result.rows().stream().map(SearchRow::id).collect(toList());
assertEquals(listOf(docId1, docId2), actualDocIds);
});
} finally {
collection.remove(docId1);
collection.remove(docId2);
}
}
Aggregations