Search in sources :

Example 21 with MutationResult

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);
    }
}
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 22 with MutationResult

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);
    }
}
Also used : SearchRowLocations(com.couchbase.client.java.search.result.SearchRowLocations) 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 23 with MutationResult

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());
}
Also used : DocumentNotFoundException(com.couchbase.client.core.error.DocumentNotFoundException) CasMismatchException(com.couchbase.client.core.error.CasMismatchException) MutationResult(com.couchbase.client.java.kv.MutationResult) JavaIntegrationTest(com.couchbase.client.java.util.JavaIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 24 with MutationResult

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

Example 25 with MutationResult

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;
        }
    });
}
Also used : GetResult(com.couchbase.client.java.kv.GetResult) DocumentNotFoundException(com.couchbase.client.core.error.DocumentNotFoundException) JsonObject(com.couchbase.client.java.json.JsonObject) MutationResult(com.couchbase.client.java.kv.MutationResult) IgnoreWhen(com.couchbase.client.test.IgnoreWhen) 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