Search in sources :

Example 1 with JsonObject

use of org.apache.jackrabbit.oak.commons.json.JsonObject in project jackrabbit-oak by apache.

the class ClusterViewTest method testOneActiveOneInactive.

@Test
public void testOneActiveOneInactive() throws Exception {
    String clusterId = UUID.randomUUID().toString();
    ClusterViewBuilder builder = new ClusterViewBuilder(10, 2);
    ClusterView view = builder.active(2).inactive(3).asView(clusterId);
    // {"seq":10,"id":"35f60ed3-508d-4a81-b812-89f07f57db20","me":2,"active":[2],"deactivating":[],"inactive":[3]}
    JsonObject o = asJsonObject(view);
    Map<String, String> props = o.getProperties();
    assertEquals("10", props.get("seq"));
    assertEquals(clusterId, unwrapString(props.get("id")));
    assertEquals("2", props.get("me"));
    assertEquals(asJsonArray(2), props.get("active"));
    assertEquals(asJsonArray(), props.get("deactivating"));
    assertEquals(asJsonArray(3), props.get("inactive"));
}
Also used : JsonObject(org.apache.jackrabbit.oak.commons.json.JsonObject) Test(org.junit.Test)

Example 2 with JsonObject

use of org.apache.jackrabbit.oak.commons.json.JsonObject in project jackrabbit-oak by apache.

the class ClusterViewTest method testSeveralActiveOneInactive.

@Test
public void testSeveralActiveOneInactive() throws Exception {
    String clusterId = UUID.randomUUID().toString();
    ClusterViewBuilder builder = new ClusterViewBuilder(10, 2);
    ClusterView view = builder.active(2, 5, 6).inactive(3).asView(clusterId);
    // {"seq":10,"id":"35f60ed3-508d-4a81-b812-89f07f57db20","me":2,"active":[2],"deactivating":[],"inactive":[3]}
    JsonObject o = asJsonObject(view);
    Map<String, String> props = o.getProperties();
    assertEquals("10", props.get("seq"));
    assertEquals("true", props.get("final"));
    assertEquals(clusterId, unwrapString(props.get("id")));
    assertEquals("2", props.get("me"));
    assertEquals(asJsonArray(2, 5, 6), props.get("active"));
    assertEquals(asJsonArray(), props.get("deactivating"));
    assertEquals(asJsonArray(3), props.get("inactive"));
}
Also used : JsonObject(org.apache.jackrabbit.oak.commons.json.JsonObject) Test(org.junit.Test)

Example 3 with JsonObject

use of org.apache.jackrabbit.oak.commons.json.JsonObject in project jackrabbit-oak by apache.

the class ClusterViewTest method testOneActiveOnly.

@Test
public void testOneActiveOnly() throws Exception {
    String clusterId = UUID.randomUUID().toString();
    ClusterViewBuilder builder = new ClusterViewBuilder(10, 21);
    ClusterView view = builder.active(21).asView(clusterId);
    // {"seq":10,"id":"35f60ed3-508d-4a81-b812-89f07f57db20","me":2,"active":[2],"deactivating":[],"inactive":[3]}
    JsonObject o = asJsonObject(view);
    Map<String, String> props = o.getProperties();
    assertEquals("10", props.get("seq"));
    assertEquals(clusterId, unwrapString(props.get("id")));
    assertEquals("21", props.get("me"));
    assertEquals(asJsonArray(21), props.get("active"));
    assertEquals(asJsonArray(), props.get("deactivating"));
    assertEquals(asJsonArray(), props.get("inactive"));
}
Also used : JsonObject(org.apache.jackrabbit.oak.commons.json.JsonObject) Test(org.junit.Test)

Example 4 with JsonObject

use of org.apache.jackrabbit.oak.commons.json.JsonObject in project jackrabbit-oak by apache.

the class RandomizedClusterTest method normalize.

private static String normalize(String json) {
    JsopTokenizer t = new JsopTokenizer(json);
    t.read('{');
    JsonObject o = JsonObject.create(t);
    JsopBuilder w = new JsopBuilder();
    o.toJson(w);
    return w.toString();
}
Also used : JsopBuilder(org.apache.jackrabbit.oak.commons.json.JsopBuilder) JsonObject(org.apache.jackrabbit.oak.commons.json.JsonObject) JsopTokenizer(org.apache.jackrabbit.oak.commons.json.JsopTokenizer)

Example 5 with JsonObject

use of org.apache.jackrabbit.oak.commons.json.JsonObject in project jackrabbit-oak by apache.

the class NodeCounterIndexTest method getCost.

private double getCost(String xpath) throws ParseException {
    String plan = executeXPathQuery("explain measure " + xpath);
    String cost = plan.substring(plan.lastIndexOf('{'));
    JsonObject json = parseJson(cost);
    double c = Double.parseDouble(json.getProperties().get("a"));
    return c;
}
Also used : JsonObject(org.apache.jackrabbit.oak.commons.json.JsonObject)

Aggregations

JsonObject (org.apache.jackrabbit.oak.commons.json.JsonObject)12 Test (org.junit.Test)6 JsopTokenizer (org.apache.jackrabbit.oak.commons.json.JsopTokenizer)3 Node (javax.jcr.Node)2 QueryManager (javax.jcr.query.QueryManager)1 QueryResult (javax.jcr.query.QueryResult)1 Row (javax.jcr.query.Row)1 JsopBuilder (org.apache.jackrabbit.oak.commons.json.JsopBuilder)1