Search in sources :

Example 56 with JsonObject

use of com.couchbase.client.java.json.JsonObject in project couchbase-jvm-clients by couchbase.

the class SubdocMutateIntegrationTest method twoCommandsOneFails.

@Test
@IgnoreWhen(clusterTypes = ClusterType.CAVES)
void twoCommandsOneFails() {
    JsonObject content = JsonObject.create().put("foo1", "bar_orig_1").put("foo2", "bar_orig_2");
    String docId = prepare(content);
    assertThrows(PathExistsException.class, () -> coll.mutateIn(docId, Arrays.asList(MutateInSpec.insert("foo0", "bar0"), MutateInSpec.insert("foo1", "bar1"), MutateInSpec.remove("foo3"))));
    JsonObject updated = getContent(docId);
    assertEquals("bar_orig_1", updated.getString("foo1"));
}
Also used : JsonObject(com.couchbase.client.java.json.JsonObject) IgnoreWhen(com.couchbase.client.test.IgnoreWhen) JavaIntegrationTest(com.couchbase.client.java.util.JavaIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 57 with JsonObject

use of com.couchbase.client.java.json.JsonObject in project couchbase-jvm-clients by couchbase.

the class SubdocMutateIntegrationTest method insertExpandMacroSEQ_NOXattr.

@Test
@IgnoreWhen(clusterTypes = { ClusterType.MOCKED, ClusterType.CAVES })
void insertExpandMacroSEQ_NOXattr() {
    JsonObject updatedContent = checkSingleOpSuccessXattr(JsonObject.create(), Arrays.asList(MutateInSpec.insert("x.foo", MutateInMacro.SEQ_NO).xattr()));
    assertNotEquals(MutateInMacro.SEQ_NO.value(), updatedContent.getString("foo"));
}
Also used : JsonObject(com.couchbase.client.java.json.JsonObject) IgnoreWhen(com.couchbase.client.test.IgnoreWhen) JavaIntegrationTest(com.couchbase.client.java.util.JavaIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 58 with JsonObject

use of com.couchbase.client.java.json.JsonObject in project couchbase-jvm-clients by couchbase.

the class AnalyticsCollectionIntegrationTest method performsDataverseCollectionQuery.

@Test
void performsDataverseCollectionQuery() {
    cluster.analyticsQuery("ALTER COLLECTION `" + bucket.name() + "`.`" + scopeName + "`.`" + collectionName + "` ENABLE ANALYTICS");
    // REQUEST_PLUS makes query hang
    // AnalyticsOptions opts = AnalyticsOptions.analyticsOptions().scanConsistency(AnalyticsScanConsistency.REQUEST_PLUS);
    // Ensure doc ingested by analytics
    waitUntilCondition(() -> singletonMap(delimitedDataverseName, singletonMap(collectionName, 0L)).equals(analytics.getPendingMutations()));
    Scope scope = cluster.bucket(config().bucketname()).scope(scopeName);
    AnalyticsResult result = scope.analyticsQuery("SELECT * FROM `" + bucket.name() + "`.`" + scopeName + "`.`" + collectionName + "` WHERE `" + collectionName + "`.foo=\"bar\"");
    List<JsonObject> rows = result.rowsAs(JsonObject.class);
    assertFalse(rows.isEmpty());
}
Also used : JsonObject(com.couchbase.client.java.json.JsonObject) AnalyticsResult(com.couchbase.client.java.analytics.AnalyticsResult) JavaIntegrationTest(com.couchbase.client.java.util.JavaIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 59 with JsonObject

use of com.couchbase.client.java.json.JsonObject in project couchbase-jvm-clients by couchbase.

the class AnalyticsCollectionIntegrationTest method performsDataverseQuery.

@Test
void performsDataverseQuery() {
    // default
    analytics.createDataset(dataset, bucket.name());
    analytics.createDataverse(dataverse);
    analytics.createDataset(dataset, bucket.name(), createDatasetAnalyticsOptions().dataverseName(dataverse));
    // REQUEST_PLUS makes query hang
    // AnalyticsOptions opts = AnalyticsOptions.analyticsOptions().scanConsistency(AnalyticsScanConsistency.REQUEST_PLUS).timeout(Duration.ofSeconds(300));
    AnalyticsResult result = cluster.analyticsQuery("SELECT * FROM " + dataverse + "." + dataset + " where " + dataset + ".test= \"hello\"");
    List<JsonObject> rows = result.rowsAs(JsonObject.class);
    assertFalse(!rows.isEmpty());
    AnalyticsMetaData meta = result.metaData();
    assertFalse(meta.clientContextId().isEmpty());
    assertTrue(meta.signature().isPresent());
    assertFalse(meta.requestId().isEmpty());
    assertEquals(AnalyticsStatus.SUCCESS, meta.status());
    assertFalse(meta.metrics().elapsedTime().isZero());
    assertFalse(meta.metrics().executionTime().isZero());
    assertEquals(rows.size(), meta.metrics().resultCount());
    // assertEquals(rows.size(), meta.metrics().processedObjects()); // fails
    // assertTrue(meta.metrics().resultSize() > 0); // fails
    assertTrue(meta.warnings().isEmpty());
// assertEquals(1, meta.metrics().errorCount()); //fails
}
Also used : JsonObject(com.couchbase.client.java.json.JsonObject) AnalyticsResult(com.couchbase.client.java.analytics.AnalyticsResult) AnalyticsMetaData(com.couchbase.client.java.analytics.AnalyticsMetaData) JavaIntegrationTest(com.couchbase.client.java.util.JavaIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 60 with JsonObject

use of com.couchbase.client.java.json.JsonObject in project couchbase-jvm-clients by couchbase.

the class AnalyticsIntegrationTest method performsDataverseQuery.

@Test
void performsDataverseQuery() {
    AnalyticsResult result = cluster.analyticsQuery("SELECT DataverseName FROM Metadata.`Dataverse`");
    List<JsonObject> rows = result.rowsAs(JsonObject.class);
    assertFalse(rows.isEmpty());
    for (JsonObject row : rows) {
        assertNotNull(row.get("DataverseName"));
    }
    AnalyticsMetaData meta = result.metaData();
    assertFalse(meta.clientContextId().isEmpty());
    assertTrue(meta.signature().isPresent());
    assertFalse(meta.requestId().isEmpty());
    assertEquals(AnalyticsStatus.SUCCESS, meta.status());
    assertFalse(meta.metrics().elapsedTime().isZero());
    assertFalse(meta.metrics().executionTime().isZero());
    assertEquals(rows.size(), meta.metrics().resultCount());
    assertEquals(rows.size(), meta.metrics().processedObjects());
    assertTrue(meta.metrics().resultSize() > 0);
    assertTrue(meta.warnings().isEmpty());
    assertEquals(0, meta.metrics().errorCount());
}
Also used : JsonObject(com.couchbase.client.java.json.JsonObject) AnalyticsResult(com.couchbase.client.java.analytics.AnalyticsResult) AnalyticsMetaData(com.couchbase.client.java.analytics.AnalyticsMetaData) JavaIntegrationTest(com.couchbase.client.java.util.JavaIntegrationTest) Test(org.junit.jupiter.api.Test)

Aggregations

JsonObject (com.couchbase.client.java.json.JsonObject)189 Test (org.junit.jupiter.api.Test)145 JavaIntegrationTest (com.couchbase.client.java.util.JavaIntegrationTest)119 IgnoreWhen (com.couchbase.client.test.IgnoreWhen)39 JsonArray (com.couchbase.client.java.json.JsonArray)18 QueryResult (com.couchbase.client.java.query.QueryResult)16 GetResult (com.couchbase.client.java.kv.GetResult)15 MutationResult (com.couchbase.client.java.kv.MutationResult)15 QueryOptions (com.couchbase.client.java.query.QueryOptions)15 ReactiveQueryResult (com.couchbase.client.java.query.ReactiveQueryResult)15 RequestSpan (com.couchbase.client.core.cnc.RequestSpan)6 RetryStrategy (com.couchbase.client.core.retry.RetryStrategy)6 Collection (com.couchbase.client.java.Collection)6 ReplaceBodyWithXattr (com.couchbase.client.java.kv.ReplaceBodyWithXattr)6 Duration (java.time.Duration)6 DisplayName (org.junit.jupiter.api.DisplayName)6 CouchbaseUtilTest (org.talend.components.couchbase.CouchbaseUtilTest)6 ArrayList (java.util.ArrayList)5 TestData (org.talend.components.couchbase.TestData)5 MutateInResult (com.couchbase.client.java.kv.MutateInResult)4