Search in sources :

Example 21 with VertexProperty

use of org.apache.tinkerpop.gremlin.structure.VertexProperty in project titan by thinkaurelius.

the class TitanEventualGraphTest method processTx.

private void processTx(TitanTransaction tx, int txid, long vid, long uid) {
    TitanVertex v = getV(tx, vid);
    TitanVertex u = getV(tx, uid);
    assertEquals(5.0, v.<Double>value("weight").doubleValue(), 0.00001);
    VertexProperty p = getOnlyElement(v.properties("weight"));
    assertEquals(1, p.<Integer>value("sig").intValue());
    sign(v.property("weight", 6.0), txid);
    p = getOnlyElement(v.properties("name"));
    assertEquals(1, p.<Integer>value("sig").intValue());
    assertEquals("John", p.value());
    p.remove();
    sign(v.property("name", "Bob"), txid);
    for (String pkey : new String[] { "value", "valuef" }) {
        p = getOnlyElement(v.properties(pkey));
        assertEquals(1, p.<Integer>value("sig").intValue());
        assertEquals(2, p.value());
        sign((TitanVertexProperty) p, txid);
    }
    Edge e = getOnlyElement(v.query().direction(OUT).labels("es").edges());
    assertEquals(1, e.<Integer>value("sig").intValue());
    e.remove();
    sign(v.addEdge("es", u), txid);
    e = getOnlyElement(v.query().direction(OUT).labels("o2o").edges());
    assertEquals(1, e.<Integer>value("sig").intValue());
    sign((TitanEdge) e, txid);
    e = getOnlyElement(v.query().direction(OUT).labels("o2m").edges());
    assertEquals(1, e.<Integer>value("sig").intValue());
    e.remove();
    sign(v.addEdge("o2m", u), txid);
    for (String label : new String[] { "em", "emf" }) {
        e = getOnlyElement(v.query().direction(OUT).labels(label).edges());
        assertEquals(1, e.<Integer>value("sig").intValue());
        sign((TitanEdge) e, txid);
    }
}
Also used : VertexProperty(org.apache.tinkerpop.gremlin.structure.VertexProperty) Edge(org.apache.tinkerpop.gremlin.structure.Edge)

Example 22 with VertexProperty

use of org.apache.tinkerpop.gremlin.structure.VertexProperty in project janusgraph by JanusGraph.

the class JanusGraphTest method testCreateDelete.

// Add more removal operations, different transaction contexts
@Test
public void testCreateDelete() {
    makeKey("weight", Double.class);
    PropertyKey uid = makeVertexIndexedUniqueKey("uid", Integer.class);
    ((StandardEdgeLabelMaker) mgmt.makeEdgeLabel("knows")).sortKey(uid).sortOrder(Order.DESC).directed().make();
    mgmt.makeEdgeLabel("father").multiplicity(Multiplicity.MANY2ONE).make();
    finishSchema();
    JanusGraphVertex v1 = graph.addVertex(), v3 = graph.addVertex("uid", 445);
    Edge e = v3.addEdge("knows", v1, "uid", 111);
    Edge e2 = v1.addEdge("friend", v3);
    assertEquals(111, e.<Integer>value("uid").intValue());
    graph.tx().commit();
    v3 = getV(graph, v3);
    assertEquals(445, v3.<Integer>value("uid").intValue());
    e = Iterables.getOnlyElement(v3.query().direction(Direction.OUT).labels("knows").edges());
    assertEquals(111, e.<Integer>value("uid").intValue());
    assertEquals(e, getE(graph, e.id()));
    assertEquals(e, getE(graph, e.id().toString()));
    VertexProperty p = getOnlyElement(v3.properties("uid"));
    p.remove();
    v3.property("uid", 353);
    e = Iterables.getOnlyElement(v3.query().direction(Direction.OUT).labels("knows").edges());
    e.property("uid", 222);
    e2 = Iterables.getOnlyElement(v1.query().direction(Direction.OUT).labels("friend").edges());
    e2.property("uid", 1);
    e2.property("weight", 2.0);
    assertEquals(1, e2.<Integer>value("uid").intValue());
    assertEquals(2.0, e2.<Double>value("weight"), 0.0001);
    clopen();
    v3 = getV(graph, v3.id());
    assertEquals(353, v3.<Integer>value("uid").intValue());
    e = Iterables.getOnlyElement(v3.query().direction(Direction.OUT).labels("knows").edges());
    assertEquals(222, e.<Integer>value("uid").intValue());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) JanusGraphVertex(org.janusgraph.core.JanusGraphVertex) VertexProperty(org.apache.tinkerpop.gremlin.structure.VertexProperty) JanusGraphVertexProperty(org.janusgraph.core.JanusGraphVertexProperty) AbstractEdge(org.janusgraph.graphdb.relations.AbstractEdge) JanusGraphEdge(org.janusgraph.core.JanusGraphEdge) Edge(org.apache.tinkerpop.gremlin.structure.Edge) PropertyKey(org.janusgraph.core.PropertyKey) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test)

Example 23 with VertexProperty

use of org.apache.tinkerpop.gremlin.structure.VertexProperty in project janusgraph by JanusGraph.

the class JanusGraphTest method testGlobalGraphIndexingAndQueriesForInternalIndexes.

/* ==================================================================================
                            GLOBAL GRAPH QUERIES
     ==================================================================================*/
/**
 * Tests index definitions and their correct application for internal indexes only
 */
@Test
public void testGlobalGraphIndexingAndQueriesForInternalIndexes() {
    PropertyKey weight = makeKey("weight", Float.class);
    PropertyKey time = makeKey("time", Long.class);
    PropertyKey text = makeKey("text", String.class);
    PropertyKey name = mgmt.makePropertyKey("name").dataType(String.class).cardinality(Cardinality.LIST).make();
    EdgeLabel connect = mgmt.makeEdgeLabel("connect").signature(weight).make();
    EdgeLabel related = mgmt.makeEdgeLabel("related").signature(time).make();
    VertexLabel person = mgmt.makeVertexLabel("person").make();
    VertexLabel organization = mgmt.makeVertexLabel("organization").make();
    JanusGraphIndex edge1 = mgmt.buildIndex("edge1", Edge.class).addKey(time).addKey(weight).buildCompositeIndex();
    JanusGraphIndex edge2 = mgmt.buildIndex("edge2", Edge.class).indexOnly(connect).addKey(text).buildCompositeIndex();
    JanusGraphIndex prop1 = mgmt.buildIndex("prop1", JanusGraphVertexProperty.class).addKey(time).buildCompositeIndex();
    JanusGraphIndex prop2 = mgmt.buildIndex("prop2", JanusGraphVertexProperty.class).addKey(weight).addKey(text).buildCompositeIndex();
    JanusGraphIndex vertex1 = mgmt.buildIndex("vertex1", Vertex.class).addKey(time).indexOnly(person).unique().buildCompositeIndex();
    JanusGraphIndex vertex12 = mgmt.buildIndex("vertex12", Vertex.class).addKey(text).indexOnly(person).buildCompositeIndex();
    JanusGraphIndex vertex2 = mgmt.buildIndex("vertex2", Vertex.class).addKey(time).addKey(name).indexOnly(organization).buildCompositeIndex();
    JanusGraphIndex vertex3 = mgmt.buildIndex("vertex3", Vertex.class).addKey(name).buildCompositeIndex();
    // ########### INSPECTION & FAILURE ##############
    assertTrue(mgmt.containsRelationType("name"));
    assertTrue(mgmt.containsGraphIndex("prop1"));
    assertFalse(mgmt.containsGraphIndex("prop3"));
    assertEquals(2, Iterables.size(mgmt.getGraphIndexes(Edge.class)));
    assertEquals(2, Iterables.size(mgmt.getGraphIndexes(JanusGraphVertexProperty.class)));
    assertEquals(4, Iterables.size(mgmt.getGraphIndexes(Vertex.class)));
    assertNull(mgmt.getGraphIndex("balblub"));
    edge1 = mgmt.getGraphIndex("edge1");
    edge2 = mgmt.getGraphIndex("edge2");
    prop1 = mgmt.getGraphIndex("prop1");
    prop2 = mgmt.getGraphIndex("prop2");
    vertex1 = mgmt.getGraphIndex("vertex1");
    vertex12 = mgmt.getGraphIndex("vertex12");
    vertex2 = mgmt.getGraphIndex("vertex2");
    vertex3 = mgmt.getGraphIndex("vertex3");
    assertTrue(vertex1.isUnique());
    assertFalse(edge2.isUnique());
    assertEquals("prop1", prop1.name());
    assertTrue(Vertex.class.isAssignableFrom(vertex3.getIndexedElement()));
    assertTrue(JanusGraphVertexProperty.class.isAssignableFrom(prop1.getIndexedElement()));
    assertTrue(Edge.class.isAssignableFrom(edge2.getIndexedElement()));
    assertEquals(2, vertex2.getFieldKeys().length);
    assertEquals(1, vertex1.getFieldKeys().length);
    try {
        // Parameters not supported
        mgmt.buildIndex("blablub", Vertex.class).addKey(text, Mapping.TEXT.asParameter()).buildCompositeIndex();
        fail();
    } catch (IllegalArgumentException ignored) {
    }
    try {
        // Name already in use
        mgmt.buildIndex("edge1", Vertex.class).addKey(weight).buildCompositeIndex();
        fail();
    } catch (IllegalArgumentException ignored) {
    }
    try {
        // ImplicitKeys not allowed
        mgmt.buildIndex("jupdup", Vertex.class).addKey(ImplicitKey.ID).buildCompositeIndex();
        fail();
    } catch (IllegalArgumentException ignored) {
    }
    try {
        // Unique is only allowed for vertex
        mgmt.buildIndex("edgexyz", Edge.class).addKey(time).unique().buildCompositeIndex();
        fail();
    } catch (IllegalArgumentException ignored) {
    }
    // ########### END INSPECTION & FAILURE ##############
    finishSchema();
    clopen();
    text = mgmt.getPropertyKey("text");
    time = mgmt.getPropertyKey("time");
    weight = mgmt.getPropertyKey("weight");
    // ########### INSPECTION & FAILURE (copied from above) ##############
    assertTrue(mgmt.containsRelationType("name"));
    assertTrue(mgmt.containsGraphIndex("prop1"));
    assertFalse(mgmt.containsGraphIndex("prop3"));
    assertEquals(2, Iterables.size(mgmt.getGraphIndexes(Edge.class)));
    assertEquals(2, Iterables.size(mgmt.getGraphIndexes(JanusGraphVertexProperty.class)));
    assertEquals(4, Iterables.size(mgmt.getGraphIndexes(Vertex.class)));
    assertNull(mgmt.getGraphIndex("balblub"));
    edge1 = mgmt.getGraphIndex("edge1");
    edge2 = mgmt.getGraphIndex("edge2");
    prop1 = mgmt.getGraphIndex("prop1");
    prop2 = mgmt.getGraphIndex("prop2");
    vertex1 = mgmt.getGraphIndex("vertex1");
    vertex12 = mgmt.getGraphIndex("vertex12");
    vertex2 = mgmt.getGraphIndex("vertex2");
    vertex3 = mgmt.getGraphIndex("vertex3");
    assertTrue(vertex1.isUnique());
    assertFalse(edge2.isUnique());
    assertEquals("prop1", prop1.name());
    assertTrue(Vertex.class.isAssignableFrom(vertex3.getIndexedElement()));
    assertTrue(JanusGraphVertexProperty.class.isAssignableFrom(prop1.getIndexedElement()));
    assertTrue(Edge.class.isAssignableFrom(edge2.getIndexedElement()));
    assertEquals(2, vertex2.getFieldKeys().length);
    assertEquals(1, vertex1.getFieldKeys().length);
    try {
        // Parameters not supported
        mgmt.buildIndex("blablub", Vertex.class).addKey(text, Mapping.TEXT.asParameter()).buildCompositeIndex();
        fail();
    } catch (IllegalArgumentException ignored) {
    }
    try {
        // Name already in use
        mgmt.buildIndex("edge1", Vertex.class).addKey(weight).buildCompositeIndex();
        fail();
    } catch (IllegalArgumentException ignored) {
    }
    try {
        // ImplicitKeys not allowed
        mgmt.buildIndex("jupdup", Vertex.class).addKey(ImplicitKey.ID).buildCompositeIndex();
        fail();
    } catch (IllegalArgumentException ignored) {
    }
    try {
        // Unique is only allowed for vertex
        mgmt.buildIndex("edgexyz", Edge.class).addKey(time).unique().buildCompositeIndex();
        fail();
    } catch (IllegalArgumentException ignored) {
    }
    // ########### END INSPECTION & FAILURE ##############
    final int numV = 100;
    final boolean sorted = true;
    JanusGraphVertex[] ns = new JanusGraphVertex[numV];
    String[] strings = { "aaa", "bbb", "ccc", "ddd" };
    for (int i = 0; i < numV; i++) {
        ns[i] = tx.addVertex(i % 2 == 0 ? "person" : "organization");
        VertexProperty p1 = ns[i].property("name", "v" + i);
        VertexProperty p2 = ns[i].property("name", "u" + (i % 5));
        double w = (i * 0.5) % 5;
        String txt = strings[i % (strings.length)];
        ns[i].property(VertexProperty.Cardinality.single, "weight", w);
        ns[i].property(VertexProperty.Cardinality.single, "time", (long) i);
        ns[i].property(VertexProperty.Cardinality.single, "text", txt);
        for (VertexProperty p : new VertexProperty[] { p1, p2 }) {
            p.property("weight", w);
            p.property("time", (long) i);
            p.property("text", txt);
        }
        // previous or self-loop
        JanusGraphVertex u = ns[(i > 0 ? i - 1 : i)];
        for (String label : new String[] { "connect", "related" }) {
            Edge e = ns[i].addEdge(label, u, "weight", (w++) % 5, "time", (long) i, "text", txt);
        }
    }
    // ########## QUERIES ################
    evaluateQuery(tx.query().has("time", Cmp.EQUAL, 10).has("weight", Cmp.EQUAL, 0), ElementCategory.EDGE, 1, new boolean[] { true, sorted }, edge1.name());
    evaluateQuery(tx.query().has("time", Contain.IN, ImmutableList.of(10, 20, 30)).has("weight", Cmp.EQUAL, 0), ElementCategory.EDGE, 3, new boolean[] { true, sorted }, edge1.name());
    evaluateQuery(tx.query().has("time", Cmp.EQUAL, 10).has("weight", Cmp.EQUAL, 0).has("text", Cmp.EQUAL, strings[10 % strings.length]), ElementCategory.EDGE, 1, new boolean[] { false, sorted }, edge1.name());
    evaluateQuery(tx.query().has("time", Cmp.EQUAL, 10).has("weight", Cmp.EQUAL, 1), ElementCategory.EDGE, 1, new boolean[] { true, sorted }, edge1.name());
    evaluateQuery(tx.query().has("time", Cmp.EQUAL, 20).has("weight", Cmp.EQUAL, 0), ElementCategory.EDGE, 1, new boolean[] { true, sorted }, edge1.name());
    evaluateQuery(tx.query().has("time", Cmp.EQUAL, 20).has("weight", Cmp.EQUAL, 3), ElementCategory.EDGE, 0, new boolean[] { true, sorted }, edge1.name());
    evaluateQuery(tx.query().has("text", Cmp.EQUAL, strings[0]).has(LABEL_NAME, "connect"), ElementCategory.EDGE, numV / strings.length, new boolean[] { true, sorted }, edge2.name());
    evaluateQuery(tx.query().has("text", Cmp.EQUAL, strings[0]).has(LABEL_NAME, "connect").limit(10), ElementCategory.EDGE, 10, new boolean[] { true, sorted }, edge2.name());
    evaluateQuery(tx.query().has("text", Cmp.EQUAL, strings[0]), ElementCategory.EDGE, numV / strings.length * 2, new boolean[] { false, sorted });
    evaluateQuery(tx.query().has("weight", Cmp.EQUAL, 1.5), ElementCategory.EDGE, numV / 10 * 2, new boolean[] { false, sorted });
    evaluateQuery(tx.query().has("time", Cmp.EQUAL, 50), ElementCategory.PROPERTY, 2, new boolean[] { true, sorted }, prop1.name());
    evaluateQuery(tx.query().has("weight", Cmp.EQUAL, 0.0).has("text", Cmp.EQUAL, strings[0]), ElementCategory.PROPERTY, 2 * numV / (4 * 5), new boolean[] { true, sorted }, prop2.name());
    evaluateQuery(tx.query().has("weight", Cmp.EQUAL, 0.0).has("text", Cmp.EQUAL, strings[0]).has("time", Cmp.EQUAL, 0), ElementCategory.PROPERTY, 2, new boolean[] { true, sorted }, prop2.name(), prop1.name());
    evaluateQuery(tx.query().has("weight", Cmp.EQUAL, 1.5), ElementCategory.PROPERTY, 2 * numV / 10, new boolean[] { false, sorted });
    evaluateQuery(tx.query().has("time", Cmp.EQUAL, 50).has(LABEL_NAME, "person"), ElementCategory.VERTEX, 1, new boolean[] { true, sorted }, vertex1.name());
    evaluateQuery(tx.query().has("text", Cmp.EQUAL, strings[2]).has(LABEL_NAME, "person"), ElementCategory.VERTEX, numV / strings.length, new boolean[] { true, sorted }, vertex12.name());
    evaluateQuery(tx.query().has("text", Cmp.EQUAL, strings[3]).has(LABEL_NAME, "person"), ElementCategory.VERTEX, 0, new boolean[] { true, sorted }, vertex12.name());
    evaluateQuery(tx.query().has("text", Cmp.EQUAL, strings[2]).has(LABEL_NAME, "person").has("time", Cmp.EQUAL, 2), ElementCategory.VERTEX, 1, new boolean[] { true, sorted }, vertex12.name(), vertex1.name());
    evaluateQuery(tx.query().has("time", Cmp.EQUAL, 51).has("name", Cmp.EQUAL, "v51").has(LABEL_NAME, "organization"), ElementCategory.VERTEX, 1, new boolean[] { true, sorted }, vertex2.name());
    evaluateQuery(tx.query().has("time", Cmp.EQUAL, 51).has("name", Cmp.EQUAL, "u1").has(LABEL_NAME, "organization"), ElementCategory.VERTEX, 1, new boolean[] { true, sorted }, vertex2.name());
    evaluateQuery(tx.query().has("time", Contain.IN, ImmutableList.of(51, 61, 71, 31, 41)).has("name", Cmp.EQUAL, "u1").has(LABEL_NAME, "organization"), ElementCategory.VERTEX, 5, new boolean[] { true, sorted }, vertex2.name());
    evaluateQuery(tx.query().has("time", Contain.IN, ImmutableList.of()), ElementCategory.VERTEX, 0, new boolean[] { true, false });
    // this query is not fitted because NOT_IN must be filtered in-memory to satisfy has("time")
    evaluateQuery(tx.query().has("text", Cmp.EQUAL, strings[2]).has(LABEL_NAME, "person").has("time", Contain.NOT_IN, ImmutableList.of()), ElementCategory.VERTEX, numV / strings.length, new boolean[] { false, sorted }, vertex12.name());
    evaluateQuery(tx.query().has("time", Cmp.EQUAL, 51).has(LABEL_NAME, "organization"), ElementCategory.VERTEX, 1, new boolean[] { false, sorted });
    evaluateQuery(tx.query().has("name", Cmp.EQUAL, "u1"), ElementCategory.VERTEX, numV / 5, new boolean[] { true, sorted }, vertex3.name());
    evaluateQuery(tx.query().has("name", Cmp.EQUAL, "v1"), ElementCategory.VERTEX, 1, new boolean[] { true, sorted }, vertex3.name());
    evaluateQuery(tx.query().has("name", Cmp.EQUAL, "v1").has(LABEL_NAME, "organization"), ElementCategory.VERTEX, 1, new boolean[] { false, sorted }, vertex3.name());
    clopen();
    // ########## QUERIES (copied from above) ################
    evaluateQuery(tx.query().has("time", Cmp.EQUAL, 10).has("weight", Cmp.EQUAL, 0), ElementCategory.EDGE, 1, new boolean[] { true, sorted }, edge1.name());
    evaluateQuery(tx.query().has("time", Contain.IN, ImmutableList.of(10, 20, 30)).has("weight", Cmp.EQUAL, 0), ElementCategory.EDGE, 3, new boolean[] { true, sorted }, edge1.name());
    evaluateQuery(tx.query().has("time", Cmp.EQUAL, 10).has("weight", Cmp.EQUAL, 0).has("text", Cmp.EQUAL, strings[10 % strings.length]), ElementCategory.EDGE, 1, new boolean[] { false, sorted }, edge1.name());
    evaluateQuery(tx.query().has("time", Cmp.EQUAL, 10).has("weight", Cmp.EQUAL, 1), ElementCategory.EDGE, 1, new boolean[] { true, sorted }, edge1.name());
    evaluateQuery(tx.query().has("time", Cmp.EQUAL, 20).has("weight", Cmp.EQUAL, 0), ElementCategory.EDGE, 1, new boolean[] { true, sorted }, edge1.name());
    evaluateQuery(tx.query().has("time", Cmp.EQUAL, 20).has("weight", Cmp.EQUAL, 3), ElementCategory.EDGE, 0, new boolean[] { true, sorted }, edge1.name());
    evaluateQuery(tx.query().has("text", Cmp.EQUAL, strings[0]).has(LABEL_NAME, "connect"), ElementCategory.EDGE, numV / strings.length, new boolean[] { true, sorted }, edge2.name());
    evaluateQuery(tx.query().has("text", Cmp.EQUAL, strings[0]).has(LABEL_NAME, "connect").limit(10), ElementCategory.EDGE, 10, new boolean[] { true, sorted }, edge2.name());
    evaluateQuery(tx.query().has("text", Cmp.EQUAL, strings[0]), ElementCategory.EDGE, numV / strings.length * 2, new boolean[] { false, sorted });
    evaluateQuery(tx.query().has("weight", Cmp.EQUAL, 1.5), ElementCategory.EDGE, numV / 10 * 2, new boolean[] { false, sorted });
    evaluateQuery(tx.query().has("time", Cmp.EQUAL, 50), ElementCategory.PROPERTY, 2, new boolean[] { true, sorted }, prop1.name());
    evaluateQuery(tx.query().has("weight", Cmp.EQUAL, 0.0).has("text", Cmp.EQUAL, strings[0]), ElementCategory.PROPERTY, 2 * numV / (4 * 5), new boolean[] { true, sorted }, prop2.name());
    evaluateQuery(tx.query().has("weight", Cmp.EQUAL, 0.0).has("text", Cmp.EQUAL, strings[0]).has("time", Cmp.EQUAL, 0), ElementCategory.PROPERTY, 2, new boolean[] { true, sorted }, prop2.name(), prop1.name());
    evaluateQuery(tx.query().has("weight", Cmp.EQUAL, 1.5), ElementCategory.PROPERTY, 2 * numV / 10, new boolean[] { false, sorted });
    evaluateQuery(tx.query().has("time", Cmp.EQUAL, 50).has(LABEL_NAME, "person"), ElementCategory.VERTEX, 1, new boolean[] { true, sorted }, vertex1.name());
    evaluateQuery(tx.query().has("text", Cmp.EQUAL, strings[2]).has(LABEL_NAME, "person"), ElementCategory.VERTEX, numV / strings.length, new boolean[] { true, sorted }, vertex12.name());
    evaluateQuery(tx.query().has("text", Cmp.EQUAL, strings[3]).has(LABEL_NAME, "person"), ElementCategory.VERTEX, 0, new boolean[] { true, sorted }, vertex12.name());
    evaluateQuery(tx.query().has("text", Cmp.EQUAL, strings[2]).has(LABEL_NAME, "person").has("time", Cmp.EQUAL, 2), ElementCategory.VERTEX, 1, new boolean[] { true, sorted }, vertex12.name(), vertex1.name());
    evaluateQuery(tx.query().has("time", Cmp.EQUAL, 51).has("name", Cmp.EQUAL, "v51").has(LABEL_NAME, "organization"), ElementCategory.VERTEX, 1, new boolean[] { true, sorted }, vertex2.name());
    evaluateQuery(tx.query().has("time", Cmp.EQUAL, 51).has("name", Cmp.EQUAL, "u1").has(LABEL_NAME, "organization"), ElementCategory.VERTEX, 1, new boolean[] { true, sorted }, vertex2.name());
    evaluateQuery(tx.query().has("time", Contain.IN, ImmutableList.of(51, 61, 71, 31, 41)).has("name", Cmp.EQUAL, "u1").has(LABEL_NAME, "organization"), ElementCategory.VERTEX, 5, new boolean[] { true, sorted }, vertex2.name());
    evaluateQuery(tx.query().has("time", Cmp.EQUAL, 51).has(LABEL_NAME, "organization"), ElementCategory.VERTEX, 1, new boolean[] { false, sorted });
    evaluateQuery(tx.query().has("name", Cmp.EQUAL, "u1"), ElementCategory.VERTEX, numV / 5, new boolean[] { true, sorted }, vertex3.name());
    evaluateQuery(tx.query().has("name", Cmp.EQUAL, "v1"), ElementCategory.VERTEX, 1, new boolean[] { true, sorted }, vertex3.name());
    evaluateQuery(tx.query().has("name", Cmp.EQUAL, "v1").has(LABEL_NAME, "organization"), ElementCategory.VERTEX, 1, new boolean[] { false, sorted }, vertex3.name());
    evaluateQuery(tx.query().has("time", Contain.IN, ImmutableList.of()), ElementCategory.VERTEX, 0, new boolean[] { true, false });
    // this query is not fitted because NOT_IN must be filtered in-memory to satisfy has("time")
    evaluateQuery(tx.query().has("text", Cmp.EQUAL, strings[2]).has(LABEL_NAME, "person").has("time", Contain.NOT_IN, ImmutableList.of()), ElementCategory.VERTEX, numV / strings.length, new boolean[] { false, sorted }, vertex12.name());
    // Update in transaction
    for (int i = 0; i < numV / 2; i++) {
        JanusGraphVertex v = getV(tx, ns[i]);
        v.remove();
    }
    ns = new JanusGraphVertex[numV * 3 / 2];
    for (int i = numV; i < numV * 3 / 2; i++) {
        ns[i] = tx.addVertex(i % 2 == 0 ? "person" : "organization");
        VertexProperty p1 = ns[i].property("name", "v" + i);
        VertexProperty p2 = ns[i].property("name", "u" + (i % 5));
        double w = (i * 0.5) % 5;
        String txt = strings[i % (strings.length)];
        ns[i].property(VertexProperty.Cardinality.single, "weight", w);
        ns[i].property(VertexProperty.Cardinality.single, "time", (long) i);
        ns[i].property(VertexProperty.Cardinality.single, "text", txt);
        for (VertexProperty p : new VertexProperty[] { p1, p2 }) {
            p.property("weight", w);
            p.property("time", (long) i);
            p.property("text", txt);
        }
        // previous or self-loop
        JanusGraphVertex u = ns[(i > numV ? i - 1 : i)];
        for (String label : new String[] { "connect", "related" }) {
            Edge e = ns[i].addEdge(label, u, "weight", (w++) % 5, "time", (long) i, "text", txt);
        }
    }
    // ######### UPDATED QUERIES ##########
    evaluateQuery(tx.query().has("time", Cmp.EQUAL, 10).has("weight", Cmp.EQUAL, 0), ElementCategory.EDGE, 0, new boolean[] { true, sorted }, edge1.name());
    evaluateQuery(tx.query().has("time", Cmp.EQUAL, numV + 10).has("weight", Cmp.EQUAL, 0), ElementCategory.EDGE, 1, new boolean[] { true, sorted }, edge1.name());
    evaluateQuery(tx.query().has("text", Cmp.EQUAL, strings[0]).has(LABEL_NAME, "connect").limit(10), ElementCategory.EDGE, 10, new boolean[] { true, sorted }, edge2.name());
    evaluateQuery(tx.query().has("weight", Cmp.EQUAL, 1.5), ElementCategory.EDGE, numV / 10 * 2, new boolean[] { false, sorted });
    evaluateQuery(tx.query().has("time", Cmp.EQUAL, 20), ElementCategory.PROPERTY, 0, new boolean[] { true, sorted }, prop1.name());
    evaluateQuery(tx.query().has("time", Cmp.EQUAL, numV + 20), ElementCategory.PROPERTY, 2, new boolean[] { true, sorted }, prop1.name());
    evaluateQuery(tx.query().has("time", Cmp.EQUAL, 30).has(LABEL_NAME, "person"), ElementCategory.VERTEX, 0, new boolean[] { true, sorted }, vertex1.name());
    evaluateQuery(tx.query().has("time", Cmp.EQUAL, numV + 30).has(LABEL_NAME, "person"), ElementCategory.VERTEX, 1, new boolean[] { true, sorted }, vertex1.name());
    evaluateQuery(tx.query().has("name", Cmp.EQUAL, "u1"), ElementCategory.VERTEX, numV / 5, new boolean[] { true, sorted }, vertex3.name());
    // ######### END UPDATED QUERIES ##########
    newTx();
    // ######### UPDATED QUERIES (copied from above) ##########
    evaluateQuery(tx.query().has("time", Cmp.EQUAL, 10).has("weight", Cmp.EQUAL, 0), ElementCategory.EDGE, 0, new boolean[] { true, sorted }, edge1.name());
    evaluateQuery(tx.query().has("time", Cmp.EQUAL, numV + 10).has("weight", Cmp.EQUAL, 0), ElementCategory.EDGE, 1, new boolean[] { true, sorted }, edge1.name());
    evaluateQuery(tx.query().has("text", Cmp.EQUAL, strings[0]).has(LABEL_NAME, "connect").limit(10), ElementCategory.EDGE, 10, new boolean[] { true, sorted }, edge2.name());
    evaluateQuery(tx.query().has("weight", Cmp.EQUAL, 1.5), ElementCategory.EDGE, numV / 10 * 2, new boolean[] { false, sorted });
    evaluateQuery(tx.query().has("time", Cmp.EQUAL, 20), ElementCategory.PROPERTY, 0, new boolean[] { true, sorted }, prop1.name());
    evaluateQuery(tx.query().has("time", Cmp.EQUAL, numV + 20), ElementCategory.PROPERTY, 2, new boolean[] { true, sorted }, prop1.name());
    evaluateQuery(tx.query().has("time", Cmp.EQUAL, 30).has(LABEL_NAME, "person"), ElementCategory.VERTEX, 0, new boolean[] { true, sorted }, vertex1.name());
    evaluateQuery(tx.query().has("time", Cmp.EQUAL, numV + 30).has(LABEL_NAME, "person"), ElementCategory.VERTEX, 1, new boolean[] { true, sorted }, vertex1.name());
    evaluateQuery(tx.query().has("name", Cmp.EQUAL, "u1"), ElementCategory.VERTEX, numV / 5, new boolean[] { true, sorted }, vertex3.name());
// *** INDIVIDUAL USE CASE TESTS ******
}
Also used : CacheVertex(org.janusgraph.graphdb.vertices.CacheVertex) JanusGraphVertex(org.janusgraph.core.JanusGraphVertex) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) EdgeLabel(org.janusgraph.core.EdgeLabel) JanusGraphVertexProperty(org.janusgraph.core.JanusGraphVertexProperty) VertexLabel(org.janusgraph.core.VertexLabel) BaseVertexLabel(org.janusgraph.graphdb.types.system.BaseVertexLabel) JanusGraphVertex(org.janusgraph.core.JanusGraphVertex) JanusGraphIndex(org.janusgraph.core.schema.JanusGraphIndex) VertexProperty(org.apache.tinkerpop.gremlin.structure.VertexProperty) JanusGraphVertexProperty(org.janusgraph.core.JanusGraphVertexProperty) AbstractEdge(org.janusgraph.graphdb.relations.AbstractEdge) JanusGraphEdge(org.janusgraph.core.JanusGraphEdge) Edge(org.apache.tinkerpop.gremlin.structure.Edge) PropertyKey(org.janusgraph.core.PropertyKey) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test)

Example 24 with VertexProperty

use of org.apache.tinkerpop.gremlin.structure.VertexProperty in project janusgraph by JanusGraph.

the class JanusGraphTest method testSchemaTypes.

/* ==================================================================================
                            SCHEMA TESTS
     ==================================================================================*/
/**
 * Test the definition and inspection of various schema types and ensure their correct interpretation
 * within the graph
 */
@SuppressWarnings("unchecked")
@Test
public void testSchemaTypes() {
    // ---------- PROPERTY KEYS ----------------
    // Normal single-valued property key
    final PropertyKey weight = makeKey("weight", Float.class);
    // Indexed unique property key
    PropertyKey uid = makeVertexIndexedUniqueKey("uid", String.class);
    // Indexed but not unique
    final PropertyKey someId = makeVertexIndexedKey("someid", Object.class);
    // Set-valued property key
    PropertyKey name = mgmt.makePropertyKey("name").dataType(String.class).cardinality(Cardinality.SET).make();
    // List-valued property key with signature
    PropertyKey value = mgmt.makePropertyKey("value").dataType(Double.class).signature(weight).cardinality(Cardinality.LIST).make();
    // ---------- EDGE LABELS ----------------
    // Standard edge label
    EdgeLabel friend = mgmt.makeEdgeLabel("friend").make();
    // Unidirected
    EdgeLabel link = mgmt.makeEdgeLabel("link").unidirected().multiplicity(Multiplicity.MANY2ONE).make();
    // Signature label
    EdgeLabel connect = mgmt.makeEdgeLabel("connect").signature(uid).multiplicity(Multiplicity.SIMPLE).make();
    // Edge labels with different cardinalities
    EdgeLabel parent = mgmt.makeEdgeLabel("parent").multiplicity(Multiplicity.MANY2ONE).make();
    EdgeLabel child = mgmt.makeEdgeLabel("child").multiplicity(Multiplicity.ONE2MANY).make();
    EdgeLabel spouse = mgmt.makeEdgeLabel("spouse").multiplicity(Multiplicity.ONE2ONE).make();
    // ---------- VERTEX LABELS ----------------
    VertexLabel person = mgmt.makeVertexLabel("person").make();
    VertexLabel tag = mgmt.makeVertexLabel("tag").make();
    VertexLabel tweet = mgmt.makeVertexLabel("tweet").setStatic().make();
    long[] sig;
    // ######### INSPECTION & FAILURE ############
    assertTrue(mgmt.isOpen());
    assertEquals("weight", weight.toString());
    assertTrue(mgmt.containsRelationType("weight"));
    assertTrue(mgmt.containsPropertyKey("weight"));
    assertFalse(mgmt.containsEdgeLabel("weight"));
    assertTrue(mgmt.containsEdgeLabel("connect"));
    assertFalse(mgmt.containsPropertyKey("connect"));
    assertFalse(mgmt.containsRelationType("bla"));
    assertNull(mgmt.getPropertyKey("bla"));
    assertNull(mgmt.getEdgeLabel("bla"));
    assertNotNull(mgmt.getPropertyKey("weight"));
    assertNotNull(mgmt.getEdgeLabel("connect"));
    assertTrue(weight.isPropertyKey());
    assertFalse(weight.isEdgeLabel());
    assertEquals(Cardinality.SINGLE, weight.cardinality());
    assertEquals(Cardinality.SINGLE, someId.cardinality());
    assertEquals(Cardinality.SET, name.cardinality());
    assertEquals(Cardinality.LIST, value.cardinality());
    assertEquals(Object.class, someId.dataType());
    assertEquals(Float.class, weight.dataType());
    sig = ((InternalRelationType) value).getSignature();
    assertEquals(1, sig.length);
    assertEquals(weight.longId(), sig[0]);
    assertTrue(mgmt.getGraphIndex(uid.name()).isUnique());
    assertFalse(mgmt.getGraphIndex(someId.name()).isUnique());
    assertEquals("friend", friend.name());
    assertTrue(friend.isEdgeLabel());
    assertFalse(friend.isPropertyKey());
    assertEquals(Multiplicity.ONE2ONE, spouse.multiplicity());
    assertEquals(Multiplicity.ONE2MANY, child.multiplicity());
    assertEquals(Multiplicity.MANY2ONE, parent.multiplicity());
    assertEquals(Multiplicity.MULTI, friend.multiplicity());
    assertEquals(Multiplicity.SIMPLE, connect.multiplicity());
    assertTrue(link.isUnidirected());
    assertFalse(link.isDirected());
    assertFalse(child.isUnidirected());
    assertTrue(spouse.isDirected());
    assertFalse(((InternalRelationType) friend).isInvisibleType());
    assertTrue(((InternalRelationType) friend).isInvisible());
    assertEquals(0, ((InternalRelationType) friend).getSignature().length);
    sig = ((InternalRelationType) connect).getSignature();
    assertEquals(1, sig.length);
    assertEquals(uid.longId(), sig[0]);
    assertEquals(0, ((InternalRelationType) friend).getSortKey().length);
    assertEquals(Order.DEFAULT, ((InternalRelationType) friend).getSortOrder());
    assertEquals(SchemaStatus.ENABLED, ((InternalRelationType) friend).getStatus());
    assertEquals(5, Iterables.size(mgmt.getRelationTypes(PropertyKey.class)));
    assertEquals(6, Iterables.size(mgmt.getRelationTypes(EdgeLabel.class)));
    assertEquals(11, Iterables.size(mgmt.getRelationTypes(RelationType.class)));
    assertEquals(3, Iterables.size(mgmt.getVertexLabels()));
    assertEquals("tweet", tweet.name());
    assertTrue(mgmt.containsVertexLabel("person"));
    assertFalse(mgmt.containsVertexLabel("bla"));
    assertFalse(person.isPartitioned());
    assertFalse(person.isStatic());
    assertFalse(tag.isPartitioned());
    assertTrue(tweet.isStatic());
    // ------ TRY INVALID STUFF --------
    // Failures
    // No data type
    assertThrows(IllegalArgumentException.class, () -> mgmt.makePropertyKey("fid").make());
    // Already exists
    assertThrows(SchemaViolationException.class, () -> mgmt.makeEdgeLabel("link").unidirected().make());
    // signature and sort-key collide
    assertThrows(IllegalArgumentException.class, () -> ((StandardEdgeLabelMaker) mgmt.makeEdgeLabel("other")).sortKey(someId, weight).signature(someId).make());
    // sort key requires the label to be non-constrained
    assertThrows(IllegalArgumentException.class, () -> ((StandardEdgeLabelMaker) mgmt.makeEdgeLabel("other")).multiplicity(Multiplicity.SIMPLE).sortKey(weight).make());
    // sort key requires the label to be non-constrained
    assertThrows(IllegalArgumentException.class, () -> ((StandardEdgeLabelMaker) mgmt.makeEdgeLabel("other")).multiplicity(Multiplicity.MANY2ONE).sortKey(weight).make());
    // Already exists
    assertThrows(SchemaViolationException.class, () -> mgmt.makeVertexLabel("tweet").make());
    // signature key must have non-generic data type
    assertThrows(IllegalArgumentException.class, () -> mgmt.makeEdgeLabel("test").signature(someId).make());
    // try {
    // //keys must be single-valued
    // ((StandardEdgeLabelMaker)mgmt.makeEdgeLabel("other")).
    // sortKey(name, weight).make();
    // fail();
    // ######### END INSPECTION ############
    finishSchema();
    clopen();
    // Load schema types into current transaction
    final PropertyKey weight2 = mgmt.getPropertyKey("weight");
    uid = mgmt.getPropertyKey("uid");
    final PropertyKey someId2 = mgmt.getPropertyKey("someid");
    name = mgmt.getPropertyKey("name");
    value = mgmt.getPropertyKey("value");
    friend = mgmt.getEdgeLabel("friend");
    link = mgmt.getEdgeLabel("link");
    connect = mgmt.getEdgeLabel("connect");
    parent = mgmt.getEdgeLabel("parent");
    child = mgmt.getEdgeLabel("child");
    spouse = mgmt.getEdgeLabel("spouse");
    person = mgmt.getVertexLabel("person");
    tag = mgmt.getVertexLabel("tag");
    tweet = mgmt.getVertexLabel("tweet");
    // ######### INSPECTION & FAILURE (COPIED FROM ABOVE) ############
    assertTrue(mgmt.isOpen());
    assertEquals("weight", weight2.toString());
    assertTrue(mgmt.containsRelationType("weight"));
    assertTrue(mgmt.containsPropertyKey("weight"));
    assertFalse(mgmt.containsEdgeLabel("weight"));
    assertTrue(mgmt.containsEdgeLabel("connect"));
    assertFalse(mgmt.containsPropertyKey("connect"));
    assertFalse(mgmt.containsRelationType("bla"));
    assertNull(mgmt.getPropertyKey("bla"));
    assertNull(mgmt.getEdgeLabel("bla"));
    assertNotNull(mgmt.getPropertyKey("weight"));
    assertNotNull(mgmt.getEdgeLabel("connect"));
    assertTrue(weight2.isPropertyKey());
    assertFalse(weight2.isEdgeLabel());
    assertEquals(Cardinality.SINGLE, weight2.cardinality());
    assertEquals(Cardinality.SINGLE, someId2.cardinality());
    assertEquals(Cardinality.SET, name.cardinality());
    assertEquals(Cardinality.LIST, value.cardinality());
    assertEquals(Object.class, someId2.dataType());
    assertEquals(Float.class, weight2.dataType());
    sig = ((InternalRelationType) value).getSignature();
    assertEquals(1, sig.length);
    assertEquals(weight2.longId(), sig[0]);
    assertTrue(mgmt.getGraphIndex(uid.name()).isUnique());
    assertFalse(mgmt.getGraphIndex(someId2.name()).isUnique());
    assertEquals("friend", friend.name());
    assertTrue(friend.isEdgeLabel());
    assertFalse(friend.isPropertyKey());
    assertEquals(Multiplicity.ONE2ONE, spouse.multiplicity());
    assertEquals(Multiplicity.ONE2MANY, child.multiplicity());
    assertEquals(Multiplicity.MANY2ONE, parent.multiplicity());
    assertEquals(Multiplicity.MULTI, friend.multiplicity());
    assertEquals(Multiplicity.SIMPLE, connect.multiplicity());
    assertTrue(link.isUnidirected());
    assertFalse(link.isDirected());
    assertFalse(child.isUnidirected());
    assertTrue(spouse.isDirected());
    assertFalse(((InternalRelationType) friend).isInvisibleType());
    assertTrue(((InternalRelationType) friend).isInvisible());
    assertEquals(0, ((InternalRelationType) friend).getSignature().length);
    sig = ((InternalRelationType) connect).getSignature();
    assertEquals(1, sig.length);
    assertEquals(uid.longId(), sig[0]);
    assertEquals(0, ((InternalRelationType) friend).getSortKey().length);
    assertEquals(Order.DEFAULT, ((InternalRelationType) friend).getSortOrder());
    assertEquals(SchemaStatus.ENABLED, ((InternalRelationType) friend).getStatus());
    assertEquals(5, Iterables.size(mgmt.getRelationTypes(PropertyKey.class)));
    assertEquals(6, Iterables.size(mgmt.getRelationTypes(EdgeLabel.class)));
    assertEquals(11, Iterables.size(mgmt.getRelationTypes(RelationType.class)));
    assertEquals(3, Iterables.size(mgmt.getVertexLabels()));
    assertEquals("tweet", tweet.name());
    assertTrue(mgmt.containsVertexLabel("person"));
    assertFalse(mgmt.containsVertexLabel("bla"));
    assertFalse(person.isPartitioned());
    assertFalse(person.isStatic());
    assertFalse(tag.isPartitioned());
    assertTrue(tweet.isStatic());
    // ------ TRY INVALID STUFF --------
    // Failures
    assertThrows(IllegalArgumentException.class, () -> mgmt.makePropertyKey("fid").make());
    // Already exists
    assertThrows(SchemaViolationException.class, () -> mgmt.makeEdgeLabel("link").unidirected().make());
    // signature and sort-key collide
    assertThrows(IllegalArgumentException.class, () -> ((StandardEdgeLabelMaker) mgmt.makeEdgeLabel("other")).sortKey(someId2, weight2).signature(someId2).make());
    // sort key requires the label to be non-constrained
    assertThrows(IllegalArgumentException.class, () -> ((StandardEdgeLabelMaker) mgmt.makeEdgeLabel("other")).multiplicity(Multiplicity.SIMPLE).sortKey(weight2).make());
    // sort key requires the label to be non-constrained
    assertThrows(IllegalArgumentException.class, () -> ((StandardEdgeLabelMaker) mgmt.makeEdgeLabel("other")).multiplicity(Multiplicity.MANY2ONE).sortKey(weight2).make());
    // Already exists
    assertThrows(SchemaViolationException.class, () -> mgmt.makeVertexLabel("tweet").make());
    // signature key must have non-generic data type
    assertThrows(IllegalArgumentException.class, () -> mgmt.makeEdgeLabel("test").signature(someId2).make());
    // ######### END INSPECTION ############
    /*
          ####### Make sure schema semantics are honored in transactions ######
        */
    clopen();
    JanusGraphTransaction tx2;
    // shouldn't exist
    assertEmpty(tx.query().has("uid", "v1").vertices());
    JanusGraphVertex v = tx.addVertex();
    // test property keys
    v.property("uid", "v1");
    v.property("weight", 1.5);
    v.property("someid", "Hello");
    v.property("name", "Bob");
    v.property("name", "John");
    VertexProperty p = v.property("value", 11);
    p.property("weight", 22);
    v.property("value", 33.3, "weight", 66.6);
    // same values are supported for list-properties
    v.property("value", 11, "weight", 22);
    // test edges
    JanusGraphVertex v12 = tx.addVertex("person"), v13 = tx.addVertex("person");
    v12.property("uid", "v12");
    v13.property("uid", "v13");
    v12.addEdge("parent", v, "weight", 4.5);
    v13.addEdge("parent", v, "weight", 4.5);
    v.addEdge("child", v12);
    v.addEdge("child", v13);
    v.addEdge("spouse", v12);
    v.addEdge("friend", v12);
    // supports multi edges
    v.addEdge("friend", v12);
    v.addEdge("connect", v12, "uid", "e1");
    v.addEdge("link", v13);
    JanusGraphVertex v2 = tx.addVertex("tweet");
    v2.addEdge("link", v13);
    v12.addEdge("connect", v2);
    JanusGraphEdge edge;
    // ######### INSPECTION & FAILURE ############
    assertEquals(v, getOnlyElement(tx.query().has("uid", Cmp.EQUAL, "v1").vertices()));
    v = getOnlyVertex(tx.query().has("uid", Cmp.EQUAL, "v1"));
    v12 = getOnlyVertex(tx.query().has("uid", Cmp.EQUAL, "v12"));
    v13 = getOnlyVertex(tx.query().has("uid", Cmp.EQUAL, "v13"));
    // Invalid data type
    JanusGraphVertex finalV = v;
    assertThrows(SchemaViolationException.class, () -> finalV.property("weight", "x"));
    // Only one "John" should be allowed
    assertThrows(SchemaViolationException.class, () -> finalV.property(VertexProperty.Cardinality.list, "name", "John"));
    // Cannot set a property as edge
    assertThrows(IllegalArgumentException.class, () -> finalV.property("link", finalV));
    // Only one property for weight allowed
    v.property(VertexProperty.Cardinality.single, "weight", 1.0);
    assertCount(1, v.properties("weight"));
    v.property(VertexProperty.Cardinality.single, "weight", 0.5);
    assertEquals(0.5, v.<Float>value("weight").doubleValue(), 0.00001);
    assertEquals("v1", v.value("uid"));
    assertCount(2, v.properties("name"));
    for (Object prop : v.query().labels("name").properties()) {
        String nameString = ((JanusGraphVertexProperty<String>) prop).value();
        assertTrue(nameString.equals("Bob") || nameString.equals("John"));
    }
    assertTrue(Iterators.size(v.properties("value")) >= 3);
    for (Object o : v.query().labels("value").properties()) {
        JanusGraphVertexProperty<Double> prop = (JanusGraphVertexProperty<Double>) o;
        double prec = prop.value();
        assertEquals(prec * 2, prop.<Number>value("weight").doubleValue(), 0.00001);
    }
    // Ensure we can add additional values
    p = v.property("value", 44.4, "weight", 88.8);
    assertEquals(v, getOnlyElement(tx.query().has("someid", Cmp.EQUAL, "Hello").vertices()));
    // ------- EDGES -------
    try {
        // multiplicity violation
        v12.addEdge("parent", v13);
        fail();
    } catch (SchemaViolationException ignored) {
    }
    try {
        // multiplicity violation
        v13.addEdge("child", v12);
        fail();
    } catch (SchemaViolationException ignored) {
    }
    try {
        // multiplicity violation
        v13.addEdge("spouse", v12);
        fail();
    } catch (SchemaViolationException ignored) {
    }
    try {
        // multiplicity violation
        v.addEdge("spouse", v13);
        fail();
    } catch (SchemaViolationException ignored) {
    }
    assertCount(2, v.query().direction(Direction.IN).labels("parent").edges());
    assertCount(1, v12.query().direction(Direction.OUT).labels("parent").has("weight").edges());
    assertCount(1, v13.query().direction(Direction.OUT).labels("parent").has("weight").edges());
    assertEquals(v12, getOnlyElement(v.query().direction(Direction.OUT).labels("spouse").vertices()));
    edge = Iterables.getOnlyElement(v.query().direction(Direction.BOTH).labels("connect").edges());
    assertEquals(1, edge.keys().size());
    assertEquals("e1", edge.value("uid"));
    try {
        // connect is simple
        v.addEdge("connect", v12);
        fail();
    } catch (SchemaViolationException ignored) {
    }
    // Make sure "link" is unidirected
    assertCount(1, v.query().direction(Direction.BOTH).labels("link").edges());
    assertCount(0, v13.query().direction(Direction.BOTH).labels("link").edges());
    // Assert we can add more friendships
    v.addEdge("friend", v12);
    v2 = Iterables.getOnlyElement(v12.query().direction(Direction.OUT).labels("connect").vertices());
    assertEquals(v13, getOnlyElement(v2.query().direction(Direction.OUT).labels("link").vertices()));
    assertEquals(BaseVertexLabel.DEFAULT_VERTEXLABEL.name(), v.label());
    assertEquals("person", v12.label());
    assertEquals("person", v13.label());
    assertCount(4, tx.query().vertices());
    // ######### END INSPECTION & FAILURE ############
    clopen();
    // ######### INSPECTION & FAILURE (copied from above) ############
    assertEquals(v, getOnlyVertex(tx.query().has("uid", Cmp.EQUAL, "v1")));
    v = getOnlyVertex(tx.query().has("uid", Cmp.EQUAL, "v1"));
    v12 = getOnlyVertex(tx.query().has("uid", Cmp.EQUAL, "v12"));
    v13 = getOnlyVertex(tx.query().has("uid", Cmp.EQUAL, "v13"));
    JanusGraphVertex finalV1 = v;
    assertThrows(SchemaViolationException.class, () -> finalV1.property("weight", "x"));
    // Only one "John" should be allowed
    assertThrows(SchemaViolationException.class, () -> finalV1.property(VertexProperty.Cardinality.list, "name", "John"));
    // Cannot set a property as edge
    assertThrows(IllegalArgumentException.class, () -> finalV1.property("link", finalV1));
    // Only one property for weight allowed
    v.property(VertexProperty.Cardinality.single, "weight", 1.0);
    assertCount(1, v.properties("weight"));
    v.property(VertexProperty.Cardinality.single, "weight", 0.5);
    assertEquals(0.5, v.<Float>value("weight").doubleValue(), 0.00001);
    assertEquals("v1", v.value("uid"));
    assertCount(2, v.properties("name"));
    for (Object o : v.query().labels("name").properties()) {
        JanusGraphVertexProperty<String> prop = (JanusGraphVertexProperty<String>) o;
        String nameString = prop.value();
        assertTrue(nameString.equals("Bob") || nameString.equals("John"));
    }
    assertTrue(Iterables.size(v.query().labels("value").properties()) >= 3);
    for (Object o : v.query().labels("value").properties()) {
        JanusGraphVertexProperty<Double> prop = (JanusGraphVertexProperty<Double>) o;
        double prec = prop.value();
        assertEquals(prec * 2, prop.<Number>value("weight").doubleValue(), 0.00001);
    }
    // Ensure we can add additional values
    p = v.property("value", 44.4, "weight", 88.8);
    assertEquals(v, getOnlyElement(tx.query().has("someid", Cmp.EQUAL, "Hello").vertices()));
    // ------- EDGES -------
    try {
        // multiplicity violation
        v12.addEdge("parent", v13);
        fail();
    } catch (SchemaViolationException ignored) {
    }
    try {
        // multiplicity violation
        v13.addEdge("child", v12);
        fail();
    } catch (SchemaViolationException ignored) {
    }
    try {
        // multiplicity violation
        v13.addEdge("spouse", v12);
        fail();
    } catch (SchemaViolationException ignored) {
    }
    try {
        // multiplicity violation
        v.addEdge("spouse", v13);
        fail();
    } catch (SchemaViolationException ignored) {
    }
    assertCount(2, v.query().direction(Direction.IN).labels("parent").edges());
    assertCount(1, v12.query().direction(Direction.OUT).labels("parent").has("weight").edges());
    assertCount(1, v13.query().direction(Direction.OUT).labels("parent").has("weight").edges());
    assertEquals(v12, getOnlyElement(v.query().direction(Direction.OUT).labels("spouse").vertices()));
    edge = Iterables.getOnlyElement(v.query().direction(Direction.BOTH).labels("connect").edges());
    assertEquals(1, edge.keys().size());
    assertEquals("e1", edge.value("uid"));
    try {
        // connect is simple
        v.addEdge("connect", v12);
        fail();
    } catch (SchemaViolationException ignored) {
    }
    // Make sure "link" is unidirected
    assertCount(1, v.query().direction(Direction.BOTH).labels("link").edges());
    assertCount(0, v13.query().direction(Direction.BOTH).labels("link").edges());
    // Assert we can add more friendships
    v.addEdge("friend", v12);
    v2 = Iterables.getOnlyElement(v12.query().direction(Direction.OUT).labels("connect").vertices());
    assertEquals(v13, getOnlyElement(v2.query().direction(Direction.OUT).labels("link").vertices()));
    assertEquals(BaseVertexLabel.DEFAULT_VERTEXLABEL.name(), v.label());
    assertEquals("person", v12.label());
    assertEquals("person", v13.label());
    assertCount(4, tx.query().vertices());
    // ######### END INSPECTION & FAILURE ############
    // Ensure index uniqueness enforcement
    tx2 = graph.newTransaction();
    try {
        JanusGraphVertex vx = tx2.addVertex();
        try {
            // property is unique
            vx.property(VertexProperty.Cardinality.single, "uid", "v1");
            fail();
        } catch (SchemaViolationException ignored) {
        }
        vx.property(VertexProperty.Cardinality.single, "uid", "unique");
        JanusGraphVertex vx2 = tx2.addVertex();
        try {
            // property unique
            vx2.property(VertexProperty.Cardinality.single, "uid", "unique");
            fail();
        } catch (SchemaViolationException ignored) {
        }
    } finally {
        tx2.rollback();
    }
    // Ensure that v2 is really static
    v2 = getV(tx, v2);
    assertEquals("tweet", v2.label());
    try {
        v2.property(VertexProperty.Cardinality.single, "weight", 11);
        fail();
    } catch (SchemaViolationException ignored) {
    }
    try {
        v2.addEdge("friend", v12);
        fail();
    } catch (SchemaViolationException ignored) {
    }
    // Ensure that unidirected edges keep pointing to deleted vertices
    getV(tx, v13).remove();
    assertCount(1, v.query().direction(Direction.BOTH).labels("link").edges());
}
Also used : JanusGraphEdge(org.janusgraph.core.JanusGraphEdge) EdgeLabel(org.janusgraph.core.EdgeLabel) JanusGraphVertexProperty(org.janusgraph.core.JanusGraphVertexProperty) JanusGraphTransaction(org.janusgraph.core.JanusGraphTransaction) VertexLabel(org.janusgraph.core.VertexLabel) BaseVertexLabel(org.janusgraph.graphdb.types.system.BaseVertexLabel) JanusGraphVertex(org.janusgraph.core.JanusGraphVertex) InternalRelationType(org.janusgraph.graphdb.internal.InternalRelationType) SchemaViolationException(org.janusgraph.core.SchemaViolationException) VertexProperty(org.apache.tinkerpop.gremlin.structure.VertexProperty) JanusGraphVertexProperty(org.janusgraph.core.JanusGraphVertexProperty) PropertyKey(org.janusgraph.core.PropertyKey) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test)

Example 25 with VertexProperty

use of org.apache.tinkerpop.gremlin.structure.VertexProperty in project janusgraph by JanusGraph.

the class JanusGraphTest method simpleLogTest.

public void simpleLogTest(final boolean withLogFailure) throws InterruptedException {
    final String userLogName = "test";
    final Serializer serializer = graph.getDataSerializer();
    final EdgeSerializer edgeSerializer = graph.getEdgeSerializer();
    final TimestampProvider times = graph.getConfiguration().getTimestampProvider();
    final Instant startTime = times.getTime();
    clopen(option(SYSTEM_LOG_TRANSACTIONS), true, option(LOG_BACKEND, USER_LOG), (withLogFailure ? TestMockLog.class.getName() : LOG_BACKEND.getDefaultValue()), option(TestMockLog.LOG_MOCK_FAILADD, USER_LOG), withLogFailure, option(KCVSLog.LOG_READ_LAG_TIME, USER_LOG), Duration.ofMillis(50), option(LOG_READ_INTERVAL, USER_LOG), Duration.ofMillis(250), option(LOG_SEND_DELAY, USER_LOG), Duration.ofMillis(100), option(KCVSLog.LOG_READ_LAG_TIME, TRANSACTION_LOG), Duration.ofMillis(50), option(LOG_READ_INTERVAL, TRANSACTION_LOG), Duration.ofMillis(250), option(MAX_COMMIT_TIME), Duration.ofSeconds(1));
    final String instanceId = graph.getConfiguration().getUniqueGraphId();
    PropertyKey weight = tx.makePropertyKey("weight").dataType(Float.class).cardinality(Cardinality.SINGLE).make();
    EdgeLabel knows = tx.makeEdgeLabel("knows").make();
    JanusGraphVertex n1 = tx.addVertex("weight", 10.5);
    tx.addProperties(knows, weight);
    newTx();
    final Instant[] txTimes = new Instant[4];
    // Transaction with custom user log name
    txTimes[0] = times.getTime();
    JanusGraphTransaction tx2 = graph.buildTransaction().logIdentifier(userLogName).start();
    JanusGraphVertex v1 = tx2.addVertex("weight", 111.1);
    v1.addEdge("knows", v1);
    tx2.commit();
    final long v1id = getId(v1);
    txTimes[1] = times.getTime();
    tx2 = graph.buildTransaction().logIdentifier(userLogName).start();
    JanusGraphVertex v2 = tx2.addVertex("weight", 222.2);
    v2.addEdge("knows", getV(tx2, v1id));
    tx2.commit();
    final long v2id = getId(v2);
    // Only read tx
    tx2 = graph.buildTransaction().logIdentifier(userLogName).start();
    v1 = getV(tx2, v1id);
    assertEquals(111.1, v1.<Float>value("weight").doubleValue(), 0.01);
    assertEquals(222.2, getV(tx2, v2).<Float>value("weight").doubleValue(), 0.01);
    tx2.commit();
    // Deleting transaction
    txTimes[2] = times.getTime();
    tx2 = graph.buildTransaction().logIdentifier(userLogName).start();
    v2 = getV(tx2, v2id);
    assertEquals(222.2, v2.<Float>value("weight").doubleValue(), 0.01);
    v2.remove();
    tx2.commit();
    // Edge modifying transaction
    txTimes[3] = times.getTime();
    tx2 = graph.buildTransaction().logIdentifier(userLogName).start();
    v1 = getV(tx2, v1id);
    assertEquals(111.1, v1.<Float>value("weight").doubleValue(), 0.01);
    final Edge e = Iterables.getOnlyElement(v1.query().direction(Direction.OUT).labels("knows").edges());
    assertFalse(e.property("weight").isPresent());
    e.property("weight", 44.4);
    tx2.commit();
    close();
    final Instant endTime = times.getTime();
    final ReadMarker startMarker = ReadMarker.fromTime(startTime);
    final Log transactionLog = openTxLog();
    final Log userLog = openUserLog(userLogName);
    final EnumMap<LogTxStatus, AtomicInteger> txMsgCounter = new EnumMap<>(LogTxStatus.class);
    for (final LogTxStatus status : LogTxStatus.values()) txMsgCounter.put(status, new AtomicInteger(0));
    final AtomicInteger userLogMeta = new AtomicInteger(0);
    transactionLog.registerReader(startMarker, new MessageReader() {

        @Override
        public void read(Message message) {
            final Instant msgTime = message.getTimestamp();
            assertTrue(msgTime.isAfter(startTime) || msgTime.equals(startTime));
            assertNotNull(message.getSenderId());
            final TransactionLogHeader.Entry txEntry = TransactionLogHeader.parse(message.getContent(), serializer, times);
            final TransactionLogHeader header = txEntry.getHeader();
            // System.out.println(header.getTimestamp(TimeUnit.MILLISECONDS));
            assertTrue(header.getTimestamp().isAfter(startTime) || header.getTimestamp().equals(startTime));
            assertTrue(header.getTimestamp().isBefore(msgTime) || header.getTimestamp().equals(msgTime));
            assertNotNull(txEntry.getMetadata());
            assertNull(txEntry.getMetadata().get(LogTxMeta.GROUPNAME));
            final LogTxStatus status = txEntry.getStatus();
            if (status == LogTxStatus.PRECOMMIT) {
                assertTrue(txEntry.hasContent());
                final Object logId = txEntry.getMetadata().get(LogTxMeta.LOG_ID);
                if (logId != null) {
                    assertTrue(logId instanceof String);
                    assertEquals(userLogName, logId);
                    userLogMeta.incrementAndGet();
                }
            } else if (withLogFailure) {
                assertTrue(status.isPrimarySuccess() || status == LogTxStatus.SECONDARY_FAILURE);
                if (status == LogTxStatus.SECONDARY_FAILURE) {
                    final TransactionLogHeader.SecondaryFailures secFail = txEntry.getContentAsSecondaryFailures(serializer);
                    assertTrue(secFail.failedIndexes.isEmpty());
                    assertTrue(secFail.userLogFailure);
                }
            } else {
                assertFalse(txEntry.hasContent());
                assertTrue(status.isSuccess());
            }
            txMsgCounter.get(txEntry.getStatus()).incrementAndGet();
        }

        @Override
        public void updateState() {
        }
    });
    final EnumMap<Change, AtomicInteger> userChangeCounter = new EnumMap<>(Change.class);
    for (final Change change : Change.values()) userChangeCounter.put(change, new AtomicInteger(0));
    final AtomicInteger userLogMsgCounter = new AtomicInteger(0);
    userLog.registerReader(startMarker, new MessageReader() {

        @Override
        public void read(Message message) {
            final Instant msgTime = message.getTimestamp();
            assertTrue(msgTime.isAfter(startTime) || msgTime.equals(startTime));
            assertNotNull(message.getSenderId());
            final StaticBuffer content = message.getContent();
            assertTrue(content != null && content.length() > 0);
            final TransactionLogHeader.Entry transactionEntry = TransactionLogHeader.parse(content, serializer, times);
            final Instant txTime = transactionEntry.getHeader().getTimestamp();
            assertTrue(txTime.isBefore(msgTime) || txTime.equals(msgTime));
            assertTrue(txTime.isAfter(startTime) || txTime.equals(msgTime));
            final long transactionId = transactionEntry.getHeader().getId();
            assertTrue(transactionId > 0);
            transactionEntry.getContentAsModifications(serializer).forEach(modification -> {
                assertTrue(modification.state == Change.ADDED || modification.state == Change.REMOVED);
                userChangeCounter.get(modification.state).incrementAndGet();
            });
            userLogMsgCounter.incrementAndGet();
        }

        @Override
        public void updateState() {
        }
    });
    Thread.sleep(4000);
    assertEquals(5, txMsgCounter.get(LogTxStatus.PRECOMMIT).get());
    assertEquals(4, txMsgCounter.get(LogTxStatus.PRIMARY_SUCCESS).get());
    assertEquals(1, txMsgCounter.get(LogTxStatus.COMPLETE_SUCCESS).get());
    assertEquals(4, userLogMeta.get());
    if (withLogFailure)
        assertEquals(4, txMsgCounter.get(LogTxStatus.SECONDARY_FAILURE).get());
    else
        assertEquals(4, txMsgCounter.get(LogTxStatus.SECONDARY_SUCCESS).get());
    // User-Log
    if (withLogFailure) {
        assertEquals(0, userLogMsgCounter.get());
    } else {
        assertEquals(4, userLogMsgCounter.get());
        assertEquals(7, userChangeCounter.get(Change.ADDED).get());
        assertEquals(4, userChangeCounter.get(Change.REMOVED).get());
    }
    clopen(option(VERBOSE_TX_RECOVERY), true);
    /*
        Transaction Recovery
         */
    final TransactionRecovery recovery = JanusGraphFactory.startTransactionRecovery(graph, startTime);
    /*
        Use user log processing framework
         */
    final AtomicInteger userLogCount = new AtomicInteger(0);
    final LogProcessorFramework userLogs = JanusGraphFactory.openTransactionLog(graph);
    userLogs.addLogProcessor(userLogName).setStartTime(startTime).setRetryAttempts(1).addProcessor((tx, txId, changes) -> {
        assertEquals(instanceId, txId.getInstanceId());
        // Just some reasonable upper bound
        assertTrue(txId.getTransactionId() > 0 && txId.getTransactionId() < 100);
        final Instant txTime = txId.getTransactionTime();
        // Times should be within a second
        assertTrue((txTime.isAfter(startTime) || txTime.equals(startTime)) && (txTime.isBefore(endTime) || txTime.equals(endTime)), String.format("tx timestamp %s not between start %s and end time %s", txTime, startTime, endTime));
        assertTrue(tx.containsRelationType("knows"));
        assertTrue(tx.containsRelationType("weight"));
        final EdgeLabel knows1 = tx.getEdgeLabel("knows");
        final PropertyKey weight1 = tx.getPropertyKey("weight");
        Instant txTimeMicro = txId.getTransactionTime();
        int txNo;
        if (txTimeMicro.isBefore(txTimes[1])) {
            txNo = 1;
            // v1 addition transaction
            assertEquals(1, Iterables.size(changes.getVertices(Change.ADDED)));
            assertEquals(0, Iterables.size(changes.getVertices(Change.REMOVED)));
            assertEquals(1, Iterables.size(changes.getVertices(Change.ANY)));
            assertEquals(2, Iterables.size(changes.getRelations(Change.ADDED)));
            assertEquals(1, Iterables.size(changes.getRelations(Change.ADDED, knows1)));
            assertEquals(1, Iterables.size(changes.getRelations(Change.ADDED, weight1)));
            assertEquals(2, Iterables.size(changes.getRelations(Change.ANY)));
            assertEquals(0, Iterables.size(changes.getRelations(Change.REMOVED)));
            final JanusGraphVertex v = Iterables.getOnlyElement(changes.getVertices(Change.ADDED));
            assertEquals(v1id, getId(v));
            final VertexProperty<Float> p = Iterables.getOnlyElement(changes.getProperties(v, Change.ADDED, "weight"));
            assertEquals(111.1, p.value().doubleValue(), 0.01);
            assertEquals(1, Iterables.size(changes.getEdges(v, Change.ADDED, OUT)));
            assertEquals(1, Iterables.size(changes.getEdges(v, Change.ADDED, BOTH)));
        } else if (txTimeMicro.isBefore(txTimes[2])) {
            txNo = 2;
            // v2 addition transaction
            assertEquals(1, Iterables.size(changes.getVertices(Change.ADDED)));
            assertEquals(0, Iterables.size(changes.getVertices(Change.REMOVED)));
            assertEquals(2, Iterables.size(changes.getVertices(Change.ANY)));
            assertEquals(2, Iterables.size(changes.getRelations(Change.ADDED)));
            assertEquals(1, Iterables.size(changes.getRelations(Change.ADDED, knows1)));
            assertEquals(1, Iterables.size(changes.getRelations(Change.ADDED, weight1)));
            assertEquals(2, Iterables.size(changes.getRelations(Change.ANY)));
            assertEquals(0, Iterables.size(changes.getRelations(Change.REMOVED)));
            final JanusGraphVertex v = Iterables.getOnlyElement(changes.getVertices(Change.ADDED));
            assertEquals(v2id, getId(v));
            final VertexProperty<Float> p = Iterables.getOnlyElement(changes.getProperties(v, Change.ADDED, "weight"));
            assertEquals(222.2, p.value().doubleValue(), 0.01);
            assertEquals(1, Iterables.size(changes.getEdges(v, Change.ADDED, OUT)));
            assertEquals(1, Iterables.size(changes.getEdges(v, Change.ADDED, BOTH)));
        } else if (txTimeMicro.isBefore(txTimes[3])) {
            txNo = 3;
            // v2 deletion transaction
            assertEquals(0, Iterables.size(changes.getVertices(Change.ADDED)));
            assertEquals(1, Iterables.size(changes.getVertices(Change.REMOVED)));
            assertEquals(2, Iterables.size(changes.getVertices(Change.ANY)));
            assertEquals(0, Iterables.size(changes.getRelations(Change.ADDED)));
            assertEquals(2, Iterables.size(changes.getRelations(Change.REMOVED)));
            assertEquals(1, Iterables.size(changes.getRelations(Change.REMOVED, knows1)));
            assertEquals(1, Iterables.size(changes.getRelations(Change.REMOVED, weight1)));
            assertEquals(2, Iterables.size(changes.getRelations(Change.ANY)));
            final JanusGraphVertex v = Iterables.getOnlyElement(changes.getVertices(Change.REMOVED));
            assertEquals(v2id, getId(v));
            final VertexProperty<Float> p = Iterables.getOnlyElement(changes.getProperties(v, Change.REMOVED, "weight"));
            assertEquals(222.2, p.value().doubleValue(), 0.01);
            assertEquals(1, Iterables.size(changes.getEdges(v, Change.REMOVED, OUT)));
            assertEquals(0, Iterables.size(changes.getEdges(v, Change.ADDED, BOTH)));
        } else {
            txNo = 4;
            // v1 edge modification
            assertEquals(0, Iterables.size(changes.getVertices(Change.ADDED)));
            assertEquals(0, Iterables.size(changes.getVertices(Change.REMOVED)));
            assertEquals(1, Iterables.size(changes.getVertices(Change.ANY)));
            assertEquals(1, Iterables.size(changes.getRelations(Change.ADDED)));
            assertEquals(1, Iterables.size(changes.getRelations(Change.REMOVED)));
            assertEquals(1, Iterables.size(changes.getRelations(Change.REMOVED, knows1)));
            assertEquals(2, Iterables.size(changes.getRelations(Change.ANY)));
            final JanusGraphVertex v = Iterables.getOnlyElement(changes.getVertices(Change.ANY));
            assertEquals(v1id, getId(v));
            JanusGraphEdge e1 = Iterables.getOnlyElement(changes.getEdges(v, Change.REMOVED, Direction.OUT, "knows"));
            assertFalse(e1.property("weight").isPresent());
            assertEquals(v, e1.vertex(Direction.IN));
            e1 = Iterables.getOnlyElement(changes.getEdges(v, Change.ADDED, Direction.OUT, "knows"));
            assertEquals(44.4, e1.<Float>value("weight").doubleValue(), 0.01);
            assertEquals(v, e1.vertex(Direction.IN));
        }
        // See only current state of graph in transaction
        final JanusGraphVertex v11 = getV(tx, v1id);
        assertNotNull(v11);
        assertTrue(v11.isLoaded());
        if (txNo != 2) {
            // In the transaction that adds v2, v2 will be considered "loaded"
            assertMissing(tx, v2id);
        // assertTrue(txNo + " - " + v2, v2 == null || v2.isRemoved());
        }
        assertEquals(111.1, v11.<Float>value("weight").doubleValue(), 0.01);
        assertCount(1, v11.query().direction(Direction.OUT).edges());
        userLogCount.incrementAndGet();
    }).build();
    // wait
    Thread.sleep(22000L);
    recovery.shutdown();
    long[] recoveryStats = ((StandardTransactionLogProcessor) recovery).getStatistics();
    if (withLogFailure) {
        assertEquals(1, recoveryStats[0]);
        assertEquals(4, recoveryStats[1]);
    } else {
        assertEquals(5, recoveryStats[0]);
        assertEquals(0, recoveryStats[1]);
    }
    userLogs.removeLogProcessor(userLogName);
    userLogs.shutdown();
    assertEquals(4, userLogCount.get());
}
Also used : ManagementUtil(org.janusgraph.core.util.ManagementUtil) PredicateCondition(org.janusgraph.graphdb.query.condition.PredicateCondition) CacheVertex(org.janusgraph.graphdb.vertices.CacheVertex) BasicVertexCentricQueryBuilder(org.janusgraph.graphdb.query.vertex.BasicVertexCentricQueryBuilder) DisableDefaultSchemaMaker(org.janusgraph.core.schema.DisableDefaultSchemaMaker) JanusGraphAssert.getStepMetrics(org.janusgraph.testutil.JanusGraphAssert.getStepMetrics) Cardinality(org.janusgraph.core.Cardinality) Serializer(org.janusgraph.graphdb.database.serialize.Serializer) JanusGraphVertexStep(org.janusgraph.graphdb.tinkerpop.optimize.step.JanusGraphVertexStep) Duration(java.time.Duration) Map(java.util.Map) JanusGraphAssert.assertNotContains(org.janusgraph.testutil.JanusGraphAssert.assertNotContains) Path(java.nio.file.Path) Metrics(org.apache.tinkerpop.gremlin.process.traversal.util.Metrics) EnumSet(java.util.EnumSet) IndexRepairJob(org.janusgraph.graphdb.olap.job.IndexRepairJob) PropertyKey(org.janusgraph.core.PropertyKey) OUT(org.apache.tinkerpop.gremlin.structure.Direction.OUT) JanusGraphPredicateUtils(org.janusgraph.graphdb.query.JanusGraphPredicateUtils) EdgeSerializer(org.janusgraph.graphdb.database.EdgeSerializer) Arguments(org.junit.jupiter.params.provider.Arguments) VERBOSE_TX_RECOVERY(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.VERBOSE_TX_RECOVERY) CountDownLatch(java.util.concurrent.CountDownLatch) Stream(java.util.stream.Stream) LogProcessorFramework(org.janusgraph.core.log.LogProcessorFramework) ADJUST_LIMIT(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.ADJUST_LIMIT) RELATION(org.janusgraph.graphdb.internal.RelationCategory.RELATION) SCHEMA_CONSTRAINTS(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.SCHEMA_CONSTRAINTS) Assertions.fail(org.junit.jupiter.api.Assertions.fail) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) MultiCondition(org.janusgraph.graphdb.query.condition.MultiCondition) FORCE_INDEX_USAGE(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.FORCE_INDEX_USAGE) CUSTOM_ATTRIBUTE_CLASS(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.CUSTOM_ATTRIBUTE_CLASS) JanusGraphAssert.assertCount(org.janusgraph.testutil.JanusGraphAssert.assertCount) TestGraphConfigs(org.janusgraph.testutil.TestGraphConfigs) Supplier(java.util.function.Supplier) Lists(com.google.common.collect.Lists) Change(org.janusgraph.core.log.Change) GhostVertexRemover(org.janusgraph.graphdb.olap.job.GhostVertexRemover) StreamSupport(java.util.stream.StreamSupport) QueryUtil(org.janusgraph.graphdb.query.QueryUtil) LOG_SEND_DELAY(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.LOG_SEND_DELAY) ALLOW_STALE_CONFIG(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.ALLOW_STALE_CONFIG) T(org.apache.tinkerpop.gremlin.structure.T) ExecutionException(java.util.concurrent.ExecutionException) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) IDS_STORE_NAME(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.IDS_STORE_NAME) JanusGraphVertexQuery(org.janusgraph.core.JanusGraphVertexQuery) Preconditions(com.google.common.base.Preconditions) VertexLabel(org.janusgraph.core.VertexLabel) JanusGraphConfigurationException(org.janusgraph.core.JanusGraphConfigurationException) Log(org.janusgraph.diskstorage.log.Log) Date(java.util.Date) Assertions.assertNotEquals(org.junit.jupiter.api.Assertions.assertNotEquals) Random(java.util.Random) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SchemaStatus(org.janusgraph.core.schema.SchemaStatus) NotImplementedException(org.apache.commons.lang.NotImplementedException) AbstractEdge(org.janusgraph.graphdb.relations.AbstractEdge) TextP(org.apache.tinkerpop.gremlin.process.traversal.TextP) MethodSource(org.junit.jupiter.params.provider.MethodSource) Multiplicity(org.janusgraph.core.Multiplicity) RelationType(org.janusgraph.core.RelationType) ElementLifeCycle(org.janusgraph.graphdb.internal.ElementLifeCycle) FeatureFlag(org.janusgraph.testutil.FeatureFlag) Collection(java.util.Collection) LogTxMeta(org.janusgraph.graphdb.database.log.LogTxMeta) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) JanusGraphAssert.assertEmpty(org.janusgraph.testutil.JanusGraphAssert.assertEmpty) TestCategory(org.janusgraph.TestCategory) Test(org.junit.jupiter.api.Test) Objects(java.util.Objects) RelationIdentifier(org.janusgraph.graphdb.relations.RelationIdentifier) ImplicitKey(org.janusgraph.graphdb.types.system.ImplicitKey) InternalRelationType(org.janusgraph.graphdb.internal.InternalRelationType) STORAGE_BATCH(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.STORAGE_BATCH) Order.desc(org.apache.tinkerpop.gremlin.process.traversal.Order.desc) STORAGE_BACKEND(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.STORAGE_BACKEND) JanusGraphFeature(org.janusgraph.testutil.JanusGraphFeature) JanusGraphQuery(org.janusgraph.core.JanusGraphQuery) HashSet(java.util.HashSet) VertexProperty(org.apache.tinkerpop.gremlin.structure.VertexProperty) ImmutableList(com.google.common.collect.ImmutableList) Message(org.janusgraph.diskstorage.log.Message) TRANSACTION_LOG(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.TRANSACTION_LOG) RelationCategory(org.janusgraph.graphdb.internal.RelationCategory) Arguments.arguments(org.junit.jupiter.params.provider.Arguments.arguments) GraphOfTheGodsFactory(org.janusgraph.example.GraphOfTheGodsFactory) Logger(org.slf4j.Logger) BaseVertexLabel(org.janusgraph.graphdb.types.system.BaseVertexLabel) VertexList(org.janusgraph.core.VertexList) GraphTraversal(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal) Contain(org.janusgraph.core.attribute.Contain) JanusGraphVertex(org.janusgraph.core.JanusGraphVertex) Arrays(java.util.Arrays) JanusGraphAssert.assertNotEmpty(org.janusgraph.testutil.JanusGraphAssert.assertNotEmpty) MessageReader(org.janusgraph.diskstorage.log.MessageReader) Geoshape(org.janusgraph.core.attribute.Geoshape) EDGE(org.janusgraph.graphdb.internal.RelationCategory.EDGE) JanusGraphTransaction(org.janusgraph.core.JanusGraphTransaction) WriteConfiguration(org.janusgraph.diskstorage.configuration.WriteConfiguration) StaticBuffer(org.janusgraph.diskstorage.StaticBuffer) Tag(org.junit.jupiter.api.Tag) LogTxStatus(org.janusgraph.graphdb.database.log.LogTxStatus) USE_MULTIQUERY(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.USE_MULTIQUERY) JanusGraphSchemaType(org.janusgraph.core.schema.JanusGraphSchemaType) JanusGraphFactory(org.janusgraph.core.JanusGraphFactory) EnumMap(java.util.EnumMap) TimestampProvider(org.janusgraph.diskstorage.util.time.TimestampProvider) StandardJanusGraph(org.janusgraph.graphdb.database.StandardJanusGraph) Set(java.util.Set) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) EdgeLabel(org.janusgraph.core.EdgeLabel) JanusGraphVertexProperty(org.janusgraph.core.JanusGraphVertexProperty) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) JanusGraphEdgeVertexStep(org.janusgraph.graphdb.tinkerpop.optimize.step.JanusGraphEdgeVertexStep) INITIAL_JANUSGRAPH_VERSION(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.INITIAL_JANUSGRAPH_VERSION) RelationTypeIndex(org.janusgraph.core.schema.RelationTypeIndex) GraphTraversalSource(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) Iterables(com.google.common.collect.Iterables) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) SimpleQueryProfiler(org.janusgraph.graphdb.query.profile.SimpleQueryProfiler) PermanentLockingException(org.janusgraph.diskstorage.locking.PermanentLockingException) ArrayList(java.util.ArrayList) StandardTransactionLogProcessor(org.janusgraph.graphdb.log.StandardTransactionLogProcessor) ScanMetrics(org.janusgraph.diskstorage.keycolumnvalue.scan.ScanMetrics) Cmp(org.janusgraph.core.attribute.Cmp) ConsistencyModifier(org.janusgraph.core.schema.ConsistencyModifier) JanusGraphException(org.janusgraph.core.JanusGraphException) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) StandardEdgeLabelMaker(org.janusgraph.graphdb.types.StandardEdgeLabelMaker) MAX_COMMIT_TIME(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.MAX_COMMIT_TIME) JanusGraphElement(org.janusgraph.core.JanusGraphElement) TransactionLogHeader(org.janusgraph.graphdb.database.log.TransactionLogHeader) ValueSource(org.junit.jupiter.params.provider.ValueSource) TX_CACHE_SIZE(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.TX_CACHE_SIZE) File(java.io.File) Assertions.assertArrayEquals(org.junit.jupiter.api.Assertions.assertArrayEquals) ScanJobFuture(org.janusgraph.diskstorage.keycolumnvalue.scan.ScanJobFuture) Direction(org.apache.tinkerpop.gremlin.structure.Direction) SYSTEM_LOG_TRANSACTIONS(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.SYSTEM_LOG_TRANSACTIONS) ChronoUnit(java.time.temporal.ChronoUnit) HARD_MAX_LIMIT(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.HARD_MAX_LIMIT) Traversal(org.apache.tinkerpop.gremlin.process.traversal.Traversal) GraphDatabaseConfiguration(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration) TraversalMetrics(org.apache.tinkerpop.gremlin.process.traversal.util.TraversalMetrics) SpecialIntSerializer(org.janusgraph.graphdb.serializer.SpecialIntSerializer) StandardJanusGraphTx(org.janusgraph.graphdb.transaction.StandardJanusGraphTx) LoggerFactory(org.slf4j.LoggerFactory) ConfigOption(org.janusgraph.diskstorage.configuration.ConfigOption) JanusGraphEdge(org.janusgraph.core.JanusGraphEdge) SchemaAction(org.janusgraph.core.schema.SchemaAction) Order.asc(org.apache.tinkerpop.gremlin.process.traversal.Order.asc) OrderList(org.janusgraph.graphdb.internal.OrderList) BATCH_PROPERTY_PREFETCHING(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.BATCH_PROPERTY_PREFETCHING) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) JanusGraphManagement(org.janusgraph.core.schema.JanusGraphManagement) JanusGraphIndex(org.janusgraph.core.schema.JanusGraphIndex) IndexSelectionUtil(org.janusgraph.graphdb.query.index.IndexSelectionUtil) P(org.apache.tinkerpop.gremlin.process.traversal.P) BOTH(org.apache.tinkerpop.gremlin.structure.Direction.BOTH) TransactionRecovery(org.janusgraph.core.log.TransactionRecovery) USER_LOG(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.USER_LOG) Property(org.apache.tinkerpop.gremlin.structure.Property) SchemaViolationException(org.janusgraph.core.SchemaViolationException) Mapping(org.janusgraph.core.schema.Mapping) ImmutableMap(com.google.common.collect.ImmutableMap) IndexRemoveJob(org.janusgraph.graphdb.olap.job.IndexRemoveJob) StandardPropertyKeyMaker(org.janusgraph.graphdb.types.StandardPropertyKeyMaker) Sets(com.google.common.collect.Sets) LOG_READ_INTERVAL(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.LOG_READ_INTERVAL) List(java.util.List) TempDir(org.junit.jupiter.api.io.TempDir) JanusGraphDefaultSchemaMaker(org.janusgraph.core.schema.JanusGraphDefaultSchemaMaker) GraphCentricQueryBuilder(org.janusgraph.graphdb.query.graph.GraphCentricQueryBuilder) CUSTOM_SERIALIZER_CLASS(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.CUSTOM_SERIALIZER_CLASS) AUTO_TYPE(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.AUTO_TYPE) HashMap(java.util.HashMap) LIMIT_BATCH_SIZE(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.LIMIT_BATCH_SIZE) JanusGraphAssert.assertContains(org.janusgraph.testutil.JanusGraphAssert.assertContains) Backend(org.janusgraph.diskstorage.Backend) Iterators(com.google.common.collect.Iterators) SpecialInt(org.janusgraph.graphdb.serializer.SpecialInt) ConfigElement(org.janusgraph.diskstorage.configuration.ConfigElement) DB_CACHE(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.DB_CACHE) LOG_BACKEND(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.LOG_BACKEND) IgnorePropertySchemaMaker(org.janusgraph.core.schema.IgnorePropertySchemaMaker) Edge(org.apache.tinkerpop.gremlin.structure.Edge) BackendException(org.janusgraph.diskstorage.BackendException) MANAGEMENT_LOG(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.MANAGEMENT_LOG) QueryProfiler(org.janusgraph.graphdb.query.profile.QueryProfiler) KCVSLog(org.janusgraph.diskstorage.log.kcvs.KCVSLog) Iterator(java.util.Iterator) org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__) STORAGE_READONLY(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration.STORAGE_READONLY) JanusGraph(org.janusgraph.core.JanusGraph) IN(org.apache.tinkerpop.gremlin.structure.Direction.IN) ElementCategory(org.janusgraph.graphdb.internal.ElementCategory) Order(org.janusgraph.graphdb.internal.Order) PROPERTY(org.janusgraph.graphdb.internal.RelationCategory.PROPERTY) TimeUnit(java.util.concurrent.TimeUnit) JanusGraphAssert.queryProfilerAnnotationIsPresent(org.janusgraph.testutil.JanusGraphAssert.queryProfilerAnnotationIsPresent) ManagementSystem(org.janusgraph.graphdb.database.management.ManagementSystem) ReadMarker(org.janusgraph.diskstorage.log.ReadMarker) Collections(java.util.Collections) TransactionRecovery(org.janusgraph.core.log.TransactionRecovery) Message(org.janusgraph.diskstorage.log.Message) JanusGraphEdge(org.janusgraph.core.JanusGraphEdge) MessageReader(org.janusgraph.diskstorage.log.MessageReader) JanusGraphTransaction(org.janusgraph.core.JanusGraphTransaction) JanusGraphVertex(org.janusgraph.core.JanusGraphVertex) EdgeSerializer(org.janusgraph.graphdb.database.EdgeSerializer) StaticBuffer(org.janusgraph.diskstorage.StaticBuffer) TransactionLogHeader(org.janusgraph.graphdb.database.log.TransactionLogHeader) VertexProperty(org.apache.tinkerpop.gremlin.structure.VertexProperty) JanusGraphVertexProperty(org.janusgraph.core.JanusGraphVertexProperty) LogTxStatus(org.janusgraph.graphdb.database.log.LogTxStatus) EnumMap(java.util.EnumMap) Serializer(org.janusgraph.graphdb.database.serialize.Serializer) EdgeSerializer(org.janusgraph.graphdb.database.EdgeSerializer) SpecialIntSerializer(org.janusgraph.graphdb.serializer.SpecialIntSerializer) Log(org.janusgraph.diskstorage.log.Log) KCVSLog(org.janusgraph.diskstorage.log.kcvs.KCVSLog) Instant(java.time.Instant) EdgeLabel(org.janusgraph.core.EdgeLabel) ReadMarker(org.janusgraph.diskstorage.log.ReadMarker) Change(org.janusgraph.core.log.Change) LogProcessorFramework(org.janusgraph.core.log.LogProcessorFramework) TimestampProvider(org.janusgraph.diskstorage.util.time.TimestampProvider) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) StandardTransactionLogProcessor(org.janusgraph.graphdb.log.StandardTransactionLogProcessor) AbstractEdge(org.janusgraph.graphdb.relations.AbstractEdge) JanusGraphEdge(org.janusgraph.core.JanusGraphEdge) Edge(org.apache.tinkerpop.gremlin.structure.Edge) PropertyKey(org.janusgraph.core.PropertyKey)

Aggregations

VertexProperty (org.apache.tinkerpop.gremlin.structure.VertexProperty)37 Edge (org.apache.tinkerpop.gremlin.structure.Edge)18 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)14 JanusGraphVertexProperty (org.janusgraph.core.JanusGraphVertexProperty)14 Test (org.junit.jupiter.api.Test)13 JanusGraphVertex (org.janusgraph.core.JanusGraphVertex)12 JanusGraphEdge (org.janusgraph.core.JanusGraphEdge)10 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)10 Test (org.junit.Test)9 PropertyKey (org.janusgraph.core.PropertyKey)7 PropertyKey (com.thinkaurelius.titan.core.PropertyKey)5 EdgeLabel (org.janusgraph.core.EdgeLabel)5 EdgeLabel (com.thinkaurelius.titan.core.EdgeLabel)4 TitanEdge (com.thinkaurelius.titan.core.TitanEdge)4 TitanVertex (com.thinkaurelius.titan.core.TitanVertex)4 TitanVertexProperty (com.thinkaurelius.titan.core.TitanVertexProperty)4 Instant (java.time.Instant)4 JanusGraphTransaction (org.janusgraph.core.JanusGraphTransaction)4 VertexLabel (org.janusgraph.core.VertexLabel)4 AbstractEdge (org.janusgraph.graphdb.relations.AbstractEdge)4