Search in sources :

Example 1 with MutationResult

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)));
}
Also used : Bucket(com.couchbase.client.java.Bucket) Cluster(com.couchbase.client.java.Cluster) Collection(com.couchbase.client.java.Collection) MutationResult(com.couchbase.client.java.kv.MutationResult)

Example 2 with MutationResult

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));
}
Also used : QueryResult(com.couchbase.client.java.query.QueryResult) ReactiveQueryResult(com.couchbase.client.java.query.ReactiveQueryResult) JsonObject(com.couchbase.client.java.json.JsonObject) QueryOptions(com.couchbase.client.java.query.QueryOptions) MutationResult(com.couchbase.client.java.kv.MutationResult) JavaIntegrationTest(com.couchbase.client.java.util.JavaIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 3 with MutationResult

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));
}
Also used : QueryResult(com.couchbase.client.java.query.QueryResult) ReactiveQueryResult(com.couchbase.client.java.query.ReactiveQueryResult) JsonObject(com.couchbase.client.java.json.JsonObject) QueryOptions(com.couchbase.client.java.query.QueryOptions) MutationResult(com.couchbase.client.java.kv.MutationResult) JavaIntegrationTest(com.couchbase.client.java.util.JavaIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 4 with MutationResult

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);
    }
}
Also used : SearchResult(com.couchbase.client.java.search.result.SearchResult) SearchQuery.queryString(com.couchbase.client.java.search.SearchQuery.queryString) MutationResult(com.couchbase.client.java.kv.MutationResult) JavaIntegrationTest(com.couchbase.client.java.util.JavaIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 5 with MutationResult

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);
    }
}
Also used : SearchResult(com.couchbase.client.java.search.result.SearchResult) SearchQuery.queryString(com.couchbase.client.java.search.SearchQuery.queryString) 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