Search in sources :

Example 41 with HugeEdge

use of com.baidu.hugegraph.structure.HugeEdge in project incubator-hugegraph by apache.

the class HugeTraverser method adjacentVertices.

protected Set<Id> adjacentVertices(Id sourceV, Set<Id> vertices, Directions dir, Id label, Set<Id> excluded, long degree, long limit) {
    if (limit == 0) {
        return ImmutableSet.of();
    }
    Set<Id> neighbors = newIdSet();
    for (Id source : vertices) {
        Iterator<Edge> edges = this.edgesOfVertex(source, dir, label, degree);
        while (edges.hasNext()) {
            HugeEdge e = (HugeEdge) edges.next();
            Id target = e.id().otherVertexId();
            boolean matchExcluded = (excluded != null && excluded.contains(target));
            if (matchExcluded || neighbors.contains(target) || sourceV.equals(target)) {
                continue;
            }
            neighbors.add(target);
            if (limit != NO_LIMIT && neighbors.size() >= limit) {
                return neighbors;
            }
        }
    }
    return neighbors;
}
Also used : HugeEdge(com.baidu.hugegraph.structure.HugeEdge) Id(com.baidu.hugegraph.backend.id.Id) HugeEdge(com.baidu.hugegraph.structure.HugeEdge) Edge(org.apache.tinkerpop.gremlin.structure.Edge)

Example 42 with HugeEdge

use of com.baidu.hugegraph.structure.HugeEdge in project incubator-hugegraph by apache.

the class SubGraphTraverser method hasMultiEdges.

private static boolean hasMultiEdges(List<Edge> edges, Id target) {
    boolean hasOutEdge = false;
    boolean hasInEdge = false;
    for (Edge edge : edges) {
        if (((HugeEdge) edge).id().otherVertexId().equals(target)) {
            if (((HugeEdge) edge).direction() == Directions.OUT) {
                hasOutEdge = true;
            } else {
                hasInEdge = true;
            }
            if (hasOutEdge && hasInEdge) {
                return true;
            }
        }
    }
    return false;
}
Also used : HugeEdge(com.baidu.hugegraph.structure.HugeEdge) HugeEdge(com.baidu.hugegraph.structure.HugeEdge) Edge(org.apache.tinkerpop.gremlin.structure.Edge)

Example 43 with HugeEdge

use of com.baidu.hugegraph.structure.HugeEdge in project incubator-hugegraph by apache.

the class EdgeCoreTest method testQueryEdgesByInvalidSysprop.

@Test
public void testQueryEdgesByInvalidSysprop() {
    HugeGraph graph = graph();
    init18Edges();
    List<Edge> edges = graph.traversal().E().hasLabel("know").toList();
    Assert.assertEquals(1, edges.size());
    HugeEdge edge = (HugeEdge) edges.get(0);
    Id id = edge.id();
    Id know = edge.schemaLabel().id();
    Assert.assertThrows(IllegalArgumentException.class, () -> {
        graph.traversal().E().hasLabel("know").has("ID", id).toList();
    }, e -> {
        Assert.assertContains("Undefined property key: 'ID'", e.getMessage());
    });
    Assert.assertThrows(IllegalArgumentException.class, () -> {
        graph.traversal().E().hasLabel("know").has("NAME", "n1").toList();
    }, e -> {
        Assert.assertContains("Undefined property key: 'NAME'", e.getMessage());
    });
    Assert.assertThrows(HugeException.class, () -> {
        ConditionQuery query = new ConditionQuery(HugeType.EDGE);
        query.eq(HugeKeys.LABEL, know);
        query.query(id);
        graph.edges(query).hasNext();
    }, e -> {
        Assert.assertContains("Not supported querying by id and conditions", e.getMessage());
    });
    Assert.assertThrows(HugeException.class, () -> {
        ConditionQuery query = new ConditionQuery(HugeType.EDGE);
        query.eq(HugeKeys.LABEL, know);
        query.eq(HugeKeys.NAME, "n1");
        graph.edges(query).hasNext();
    }, e -> {
        Assert.assertContains("Not supported querying edges by", e.getMessage());
        Assert.assertContains("NAME == n1", e.getMessage());
    });
    Assert.assertThrows(HugeException.class, () -> {
        ConditionQuery query = new ConditionQuery(HugeType.EDGE);
        query.eq(HugeKeys.LABEL, know);
        query.eq(HugeKeys.NAME, "n2");
        query.query(Condition.eq(IdGenerator.of("fake"), "n3"));
        graph.edges(query).hasNext();
    }, e -> {
        Assert.assertContains("Can't do index query with [", e.getMessage());
        Assert.assertContains("LABEL == ", e.getMessage());
        Assert.assertContains("NAME == n2", e.getMessage());
    });
}
Also used : HugeGraph(com.baidu.hugegraph.HugeGraph) ConditionQuery(com.baidu.hugegraph.backend.query.ConditionQuery) HugeEdge(com.baidu.hugegraph.structure.HugeEdge) Id(com.baidu.hugegraph.backend.id.Id) HugeEdge(com.baidu.hugegraph.structure.HugeEdge) FakeEdge(com.baidu.hugegraph.testutil.FakeObjects.FakeEdge) Edge(org.apache.tinkerpop.gremlin.structure.Edge) Test(org.junit.Test)

Example 44 with HugeEdge

use of com.baidu.hugegraph.structure.HugeEdge in project incubator-hugegraph by apache.

the class RamTableTest method testReloadAndQueryWithProperty.

@Test
public void testReloadAndQueryWithProperty() throws Exception {
    HugeGraph graph = this.graph();
    SchemaManager schema = graph.schema();
    schema.propertyKey("name").asText().create();
    schema.vertexLabel("person").properties("name").useCustomizeNumberId().create();
    schema.edgeLabel("next").sourceLabel("person").targetLabel("person").properties("name").create();
    GraphTraversalSource g = graph.traversal();
    g.addV("person").property(T.id, 1).property("name", "A").as("a").addV("person").property(T.id, 2).property("name", "B").as("b").addV("person").property(T.id, 3).property("name", "C").as("c").addV("person").property(T.id, 4).property("name", "D").as("d").addV("person").property(T.id, 5).property("name", "E").as("e").addV("person").property(T.id, 6).property("name", "F").as("f").addE("next").from("a").to("b").property("name", "ab").addE("next").from("b").to("c").property("name", "bc").addE("next").from("b").to("d").property("name", "bd").addE("next").from("c").to("d").property("name", "cd").addE("next").from("c").to("e").property("name", "ce").addE("next").from("d").to("e").property("name", "de").addE("next").from("e").to("f").property("name", "ef").addE("next").from("f").to("d").property("name", "fd").iterate();
    graph.tx().commit();
    Object ramtable = Whitebox.getInternalState(graph, "ramtable");
    Assert.assertNotNull("The ramtable is not enabled", ramtable);
    // reload ramtable
    Whitebox.invoke(graph.getClass(), "reloadRamtable", graph);
    GraphTraversal<Vertex, Vertex> vertices;
    HugeVertex vertex;
    GraphTraversal<Vertex, Edge> edges;
    HugeEdge edge;
    // A
    vertices = g.V(1).out();
    Assert.assertTrue(vertices.hasNext());
    vertex = (HugeVertex) vertices.next();
    Assert.assertFalse(vertex.isPropLoaded());
    Assert.assertEquals(2L, vertex.id().asObject());
    Assert.assertEquals("B", vertex.value("name"));
    Assert.assertFalse(vertices.hasNext());
    edges = g.V(1).outE();
    Assert.assertTrue(edges.hasNext());
    edge = (HugeEdge) edges.next();
    Assert.assertFalse(edge.isPropLoaded());
    Assert.assertEquals(Directions.OUT, edge.id().direction());
    Assert.assertEquals("ab", edge.value("name"));
    Assert.assertFalse(edges.hasNext());
    vertices = g.V(1).in();
    Assert.assertFalse(vertices.hasNext());
    edges = g.V(1).inE();
    Assert.assertFalse(edges.hasNext());
    vertices = g.V(1).both();
    Assert.assertTrue(vertices.hasNext());
    vertex = (HugeVertex) vertices.next();
    Assert.assertEquals(2L, vertex.id().asObject());
    Assert.assertEquals("B", vertex.value("name"));
    Assert.assertFalse(vertices.hasNext());
    edges = g.V(1).bothE();
    Assert.assertTrue(edges.hasNext());
    edge = (HugeEdge) edges.next();
    Assert.assertEquals(Directions.OUT, edge.id().direction());
    Assert.assertEquals("ab", edge.value("name"));
    Assert.assertFalse(edges.hasNext());
    // B
    vertices = g.V(2).out();
    Assert.assertTrue(vertices.hasNext());
    vertex = (HugeVertex) vertices.next();
    Assert.assertEquals(3L, vertex.id().asObject());
    Assert.assertEquals("C", vertex.value("name"));
    Assert.assertTrue(vertices.hasNext());
    vertex = (HugeVertex) vertices.next();
    Assert.assertEquals(4L, vertex.id().asObject());
    Assert.assertEquals("D", vertex.value("name"));
    Assert.assertFalse(vertices.hasNext());
    edges = g.V(2).outE();
    Assert.assertTrue(edges.hasNext());
    edge = (HugeEdge) edges.next();
    Assert.assertEquals(Directions.OUT, edge.id().direction());
    Assert.assertEquals("bc", edge.value("name"));
    Assert.assertTrue(edges.hasNext());
    edge = (HugeEdge) edges.next();
    Assert.assertEquals(Directions.OUT, edge.id().direction());
    Assert.assertEquals("bd", edge.value("name"));
    Assert.assertFalse(edges.hasNext());
    vertices = g.V(2).in();
    Assert.assertTrue(vertices.hasNext());
    vertex = (HugeVertex) vertices.next();
    Assert.assertEquals(1L, vertex.id().asObject());
    Assert.assertEquals("A", vertex.value("name"));
    Assert.assertFalse(vertices.hasNext());
    edges = g.V(2).inE();
    Assert.assertTrue(edges.hasNext());
    edge = (HugeEdge) edges.next();
    Assert.assertEquals(Directions.IN, edge.id().direction());
    Assert.assertEquals("ab", edge.value("name"));
    Assert.assertFalse(edges.hasNext());
    vertices = g.V(2).both();
    Assert.assertTrue(vertices.hasNext());
    vertex = (HugeVertex) vertices.next();
    Assert.assertEquals(3L, vertex.id().asObject());
    Assert.assertEquals("C", vertex.value("name"));
    Assert.assertTrue(vertices.hasNext());
    vertex = (HugeVertex) vertices.next();
    Assert.assertEquals(4L, vertex.id().asObject());
    Assert.assertEquals("D", vertex.value("name"));
    Assert.assertTrue(vertices.hasNext());
    vertex = (HugeVertex) vertices.next();
    Assert.assertEquals(1L, vertex.id().asObject());
    Assert.assertEquals("A", vertex.value("name"));
    Assert.assertFalse(vertices.hasNext());
    edges = g.V(2).bothE();
    Assert.assertTrue(edges.hasNext());
    edge = (HugeEdge) edges.next();
    Assert.assertEquals(Directions.OUT, edge.id().direction());
    Assert.assertEquals("bc", edge.value("name"));
    Assert.assertTrue(edges.hasNext());
    edge = (HugeEdge) edges.next();
    Assert.assertEquals(Directions.OUT, edge.id().direction());
    Assert.assertEquals("bd", edge.value("name"));
    Assert.assertTrue(edges.hasNext());
    edge = (HugeEdge) edges.next();
    Assert.assertEquals(Directions.IN, edge.id().direction());
    Assert.assertEquals("ab", edge.value("name"));
    Assert.assertFalse(edges.hasNext());
    // C
    vertices = g.V(3).out();
    Assert.assertTrue(vertices.hasNext());
    vertex = (HugeVertex) vertices.next();
    Assert.assertEquals(4L, vertex.id().asObject());
    Assert.assertEquals("D", vertex.value("name"));
    Assert.assertTrue(vertices.hasNext());
    vertex = (HugeVertex) vertices.next();
    Assert.assertEquals(5L, vertex.id().asObject());
    Assert.assertEquals("E", vertex.value("name"));
    Assert.assertFalse(vertices.hasNext());
    edges = g.V(3).outE();
    Assert.assertTrue(edges.hasNext());
    edge = (HugeEdge) edges.next();
    Assert.assertEquals(Directions.OUT, edge.id().direction());
    Assert.assertEquals("cd", edge.value("name"));
    Assert.assertTrue(edges.hasNext());
    edge = (HugeEdge) edges.next();
    Assert.assertEquals(Directions.OUT, edge.id().direction());
    Assert.assertEquals("ce", edge.value("name"));
    Assert.assertFalse(edges.hasNext());
    vertices = g.V(3).in();
    Assert.assertTrue(vertices.hasNext());
    vertex = (HugeVertex) vertices.next();
    Assert.assertEquals(2L, vertex.id().asObject());
    Assert.assertEquals("B", vertex.value("name"));
    Assert.assertFalse(vertices.hasNext());
    edges = g.V(3).inE();
    Assert.assertTrue(edges.hasNext());
    edge = (HugeEdge) edges.next();
    Assert.assertEquals(Directions.IN, edge.id().direction());
    Assert.assertEquals("bc", edge.value("name"));
    Assert.assertFalse(edges.hasNext());
    vertices = g.V(3).both();
    Assert.assertTrue(vertices.hasNext());
    vertex = (HugeVertex) vertices.next();
    Assert.assertEquals(4L, vertex.id().asObject());
    Assert.assertEquals("D", vertex.value("name"));
    Assert.assertTrue(vertices.hasNext());
    vertex = (HugeVertex) vertices.next();
    Assert.assertEquals(5L, vertex.id().asObject());
    Assert.assertEquals("E", vertex.value("name"));
    Assert.assertTrue(vertices.hasNext());
    vertex = (HugeVertex) vertices.next();
    Assert.assertEquals(2L, vertex.id().asObject());
    Assert.assertEquals("B", vertex.value("name"));
    Assert.assertFalse(vertices.hasNext());
    edges = g.V(3).bothE();
    Assert.assertTrue(edges.hasNext());
    edge = (HugeEdge) edges.next();
    Assert.assertEquals(Directions.OUT, edge.id().direction());
    Assert.assertEquals("cd", edge.value("name"));
    Assert.assertTrue(edges.hasNext());
    edge = (HugeEdge) edges.next();
    Assert.assertEquals(Directions.OUT, edge.id().direction());
    Assert.assertEquals("ce", edge.value("name"));
    Assert.assertTrue(edges.hasNext());
    edge = (HugeEdge) edges.next();
    Assert.assertEquals(Directions.IN, edge.id().direction());
    Assert.assertEquals("bc", edge.value("name"));
    Assert.assertFalse(edges.hasNext());
    // D
    vertices = g.V(4).out();
    Assert.assertTrue(vertices.hasNext());
    vertex = (HugeVertex) vertices.next();
    Assert.assertEquals(5L, vertex.id().asObject());
    Assert.assertEquals("E", vertex.value("name"));
    Assert.assertFalse(vertices.hasNext());
    edges = g.V(4).outE();
    Assert.assertTrue(edges.hasNext());
    edge = (HugeEdge) edges.next();
    Assert.assertEquals(Directions.OUT, edge.id().direction());
    Assert.assertEquals("de", edge.value("name"));
    Assert.assertFalse(edges.hasNext());
    vertices = g.V(4).in();
    Assert.assertTrue(vertices.hasNext());
    vertex = (HugeVertex) vertices.next();
    Assert.assertEquals(2L, vertex.id().asObject());
    Assert.assertEquals("B", vertex.value("name"));
    Assert.assertTrue(vertices.hasNext());
    vertex = (HugeVertex) vertices.next();
    Assert.assertEquals(3L, vertex.id().asObject());
    Assert.assertEquals("C", vertex.value("name"));
    Assert.assertTrue(vertices.hasNext());
    vertex = (HugeVertex) vertices.next();
    Assert.assertEquals(6L, vertex.id().asObject());
    Assert.assertEquals("F", vertex.value("name"));
    Assert.assertFalse(vertices.hasNext());
    edges = g.V(4).inE();
    Assert.assertTrue(edges.hasNext());
    edge = (HugeEdge) edges.next();
    Assert.assertEquals(Directions.IN, edge.id().direction());
    Assert.assertEquals("bd", edge.value("name"));
    Assert.assertTrue(edges.hasNext());
    edge = (HugeEdge) edges.next();
    Assert.assertEquals(Directions.IN, edge.id().direction());
    Assert.assertEquals("cd", edge.value("name"));
    Assert.assertTrue(edges.hasNext());
    edge = (HugeEdge) edges.next();
    Assert.assertEquals(Directions.IN, edge.id().direction());
    Assert.assertEquals("fd", edge.value("name"));
    Assert.assertFalse(edges.hasNext());
    vertices = g.V(4).both();
    Assert.assertTrue(vertices.hasNext());
    vertex = (HugeVertex) vertices.next();
    Assert.assertEquals(5L, vertex.id().asObject());
    Assert.assertEquals("E", vertex.value("name"));
    Assert.assertTrue(vertices.hasNext());
    vertex = (HugeVertex) vertices.next();
    Assert.assertEquals(2L, vertex.id().asObject());
    Assert.assertEquals("B", vertex.value("name"));
    Assert.assertTrue(vertices.hasNext());
    vertex = (HugeVertex) vertices.next();
    Assert.assertEquals(3L, vertex.id().asObject());
    Assert.assertEquals("C", vertex.value("name"));
    Assert.assertTrue(vertices.hasNext());
    vertex = (HugeVertex) vertices.next();
    Assert.assertEquals(6L, vertex.id().asObject());
    Assert.assertEquals("F", vertex.value("name"));
    Assert.assertFalse(vertices.hasNext());
    edges = g.V(4).bothE();
    Assert.assertTrue(edges.hasNext());
    edge = (HugeEdge) edges.next();
    Assert.assertEquals(Directions.OUT, edge.id().direction());
    Assert.assertEquals("de", edge.value("name"));
    Assert.assertTrue(edges.hasNext());
    edge = (HugeEdge) edges.next();
    Assert.assertEquals(Directions.IN, edge.id().direction());
    Assert.assertEquals("bd", edge.value("name"));
    Assert.assertTrue(edges.hasNext());
    edge = (HugeEdge) edges.next();
    Assert.assertEquals(Directions.IN, edge.id().direction());
    Assert.assertEquals("cd", edge.value("name"));
    Assert.assertTrue(edges.hasNext());
    edge = (HugeEdge) edges.next();
    Assert.assertEquals(Directions.IN, edge.id().direction());
    Assert.assertEquals("fd", edge.value("name"));
    Assert.assertFalse(edges.hasNext());
    // E
    vertices = g.V(5).out();
    Assert.assertTrue(vertices.hasNext());
    vertex = (HugeVertex) vertices.next();
    Assert.assertEquals(6L, vertex.id().asObject());
    Assert.assertEquals("F", vertex.value("name"));
    Assert.assertFalse(vertices.hasNext());
    edges = g.V(5).outE();
    Assert.assertTrue(edges.hasNext());
    edge = (HugeEdge) edges.next();
    Assert.assertEquals(Directions.OUT, edge.id().direction());
    Assert.assertEquals("ef", edge.value("name"));
    Assert.assertFalse(edges.hasNext());
    vertices = g.V(5).in();
    Assert.assertTrue(vertices.hasNext());
    vertex = (HugeVertex) vertices.next();
    Assert.assertEquals(3L, vertex.id().asObject());
    Assert.assertEquals("C", vertex.value("name"));
    Assert.assertTrue(vertices.hasNext());
    vertex = (HugeVertex) vertices.next();
    Assert.assertEquals(4L, vertex.id().asObject());
    Assert.assertEquals("D", vertex.value("name"));
    Assert.assertFalse(vertices.hasNext());
    edges = g.V(5).inE();
    Assert.assertTrue(edges.hasNext());
    edge = (HugeEdge) edges.next();
    Assert.assertEquals(Directions.IN, edge.id().direction());
    Assert.assertEquals("ce", edge.value("name"));
    Assert.assertTrue(edges.hasNext());
    edge = (HugeEdge) edges.next();
    Assert.assertEquals(Directions.IN, edge.id().direction());
    Assert.assertEquals("de", edge.value("name"));
    Assert.assertFalse(edges.hasNext());
    vertices = g.V(5).both();
    Assert.assertTrue(vertices.hasNext());
    vertex = (HugeVertex) vertices.next();
    Assert.assertEquals(6L, vertex.id().asObject());
    Assert.assertEquals("F", vertex.value("name"));
    Assert.assertTrue(vertices.hasNext());
    Assert.assertTrue(vertices.hasNext());
    vertex = (HugeVertex) vertices.next();
    Assert.assertEquals(3L, vertex.id().asObject());
    Assert.assertEquals("C", vertex.value("name"));
    Assert.assertTrue(vertices.hasNext());
    vertex = (HugeVertex) vertices.next();
    Assert.assertEquals(4L, vertex.id().asObject());
    Assert.assertEquals("D", vertex.value("name"));
    Assert.assertFalse(vertices.hasNext());
    edges = g.V(5).bothE();
    Assert.assertTrue(edges.hasNext());
    edge = (HugeEdge) edges.next();
    Assert.assertEquals(Directions.OUT, edge.id().direction());
    Assert.assertEquals("ef", edge.value("name"));
    Assert.assertTrue(edges.hasNext());
    edge = (HugeEdge) edges.next();
    Assert.assertEquals(Directions.IN, edge.id().direction());
    Assert.assertEquals("ce", edge.value("name"));
    Assert.assertTrue(edges.hasNext());
    edge = (HugeEdge) edges.next();
    Assert.assertEquals(Directions.IN, edge.id().direction());
    Assert.assertEquals("de", edge.value("name"));
    Assert.assertFalse(edges.hasNext());
    // F
    vertices = g.V(6).out();
    Assert.assertTrue(vertices.hasNext());
    vertex = (HugeVertex) vertices.next();
    Assert.assertEquals(4L, vertex.id().asObject());
    Assert.assertEquals("D", vertex.value("name"));
    Assert.assertFalse(vertices.hasNext());
    edges = g.V(6).outE();
    Assert.assertTrue(edges.hasNext());
    edge = (HugeEdge) edges.next();
    Assert.assertEquals(Directions.OUT, edge.id().direction());
    Assert.assertEquals("fd", edge.value("name"));
    Assert.assertFalse(edges.hasNext());
    vertices = g.V(6).in();
    Assert.assertTrue(vertices.hasNext());
    vertex = (HugeVertex) vertices.next();
    Assert.assertEquals(5L, vertex.id().asObject());
    Assert.assertEquals("E", vertex.value("name"));
    Assert.assertFalse(vertices.hasNext());
    edges = g.V(6).inE();
    Assert.assertTrue(edges.hasNext());
    edge = (HugeEdge) edges.next();
    Assert.assertEquals(Directions.IN, edge.id().direction());
    Assert.assertEquals("ef", edge.value("name"));
    Assert.assertFalse(edges.hasNext());
    vertices = g.V(6).both();
    Assert.assertTrue(vertices.hasNext());
    vertex = (HugeVertex) vertices.next();
    Assert.assertEquals(4L, vertex.id().asObject());
    Assert.assertEquals("D", vertex.value("name"));
    Assert.assertTrue(vertices.hasNext());
    vertex = (HugeVertex) vertices.next();
    Assert.assertEquals(5L, vertex.id().asObject());
    Assert.assertEquals("E", vertex.value("name"));
    Assert.assertFalse(vertices.hasNext());
    edges = g.V(6).bothE();
    Assert.assertTrue(edges.hasNext());
    edge = (HugeEdge) edges.next();
    Assert.assertEquals(Directions.OUT, edge.id().direction());
    Assert.assertEquals("fd", edge.value("name"));
    Assert.assertTrue(edges.hasNext());
    edge = (HugeEdge) edges.next();
    Assert.assertEquals(Directions.IN, edge.id().direction());
    Assert.assertEquals("ef", edge.value("name"));
    Assert.assertFalse(edges.hasNext());
}
Also used : GraphTraversalSource(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource) HugeVertex(com.baidu.hugegraph.structure.HugeVertex) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) HugeGraph(com.baidu.hugegraph.HugeGraph) HugeEdge(com.baidu.hugegraph.structure.HugeEdge) SchemaManager(com.baidu.hugegraph.schema.SchemaManager) HugeVertex(com.baidu.hugegraph.structure.HugeVertex) HugeEdge(com.baidu.hugegraph.structure.HugeEdge) Edge(org.apache.tinkerpop.gremlin.structure.Edge) Test(org.junit.Test)

Example 45 with HugeEdge

use of com.baidu.hugegraph.structure.HugeEdge in project incubator-hugegraph by apache.

the class RamTableTest method testReloadFromFileAndQuery.

@Test
public void testReloadFromFileAndQuery() throws Exception {
    HugeGraph graph = this.graph();
    // insert vertices and edges
    for (int i = 0; i < 100; i++) {
        Vertex v1 = graph.addVertex(T.label, "vl1", T.id, i);
        Vertex v2 = graph.addVertex(T.label, "vl1", T.id, i + 100);
        v1.addEdge("el1", v2);
    }
    graph.tx().commit();
    for (int i = 1000; i < 1100; i++) {
        Vertex v1 = graph.addVertex(T.label, "vl2", T.id, i);
        Vertex v2 = graph.addVertex(T.label, "vl2", T.id, i + 100);
        v1.addEdge("el2", v2);
    }
    graph.tx().commit();
    // reload ramtable
    Whitebox.invoke(graph.getClass(), "reloadRamtable", graph);
    // query edges
    for (int i = 0; i < 100; i++) {
        Iterator<Edge> edges = this.edgesOfVertex(IdGenerator.of(i), Directions.OUT, null);
        Assert.assertTrue(edges.hasNext());
        HugeEdge edge = (HugeEdge) edges.next();
        Assert.assertEquals(i + 100, edge.id().otherVertexId().asLong());
        Assert.assertEquals(Directions.OUT, edge.direction());
        Assert.assertEquals("el1", edge.label());
        Assert.assertFalse(edges.hasNext());
    }
    for (int i = 1000; i < 1100; i++) {
        Iterator<Edge> edges = this.edgesOfVertex(IdGenerator.of(i), Directions.OUT, null);
        Assert.assertTrue(edges.hasNext());
        HugeEdge edge = (HugeEdge) edges.next();
        Assert.assertEquals(i + 100, edge.id().otherVertexId().asLong());
        Assert.assertEquals(Directions.OUT, edge.direction());
        Assert.assertEquals("el2", edge.label());
        Assert.assertFalse(edges.hasNext());
    }
    // reload ramtable from file
    Whitebox.invoke(graph.getClass(), "reloadRamtable", graph, true);
    // query edges again
    for (int i = 0; i < 100; i++) {
        Iterator<Edge> edges = this.edgesOfVertex(IdGenerator.of(i), Directions.OUT, null);
        Assert.assertTrue(edges.hasNext());
        HugeEdge edge = (HugeEdge) edges.next();
        Assert.assertEquals(i + 100, edge.id().otherVertexId().asLong());
        Assert.assertEquals(Directions.OUT, edge.direction());
        Assert.assertEquals("el1", edge.label());
        Assert.assertFalse(edges.hasNext());
    }
    for (int i = 1000; i < 1100; i++) {
        Iterator<Edge> edges = this.edgesOfVertex(IdGenerator.of(i), Directions.OUT, null);
        Assert.assertTrue(edges.hasNext());
        HugeEdge edge = (HugeEdge) edges.next();
        Assert.assertEquals(i + 100, edge.id().otherVertexId().asLong());
        Assert.assertEquals(Directions.OUT, edge.direction());
        Assert.assertEquals("el2", edge.label());
        Assert.assertFalse(edges.hasNext());
    }
}
Also used : HugeVertex(com.baidu.hugegraph.structure.HugeVertex) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) HugeGraph(com.baidu.hugegraph.HugeGraph) HugeEdge(com.baidu.hugegraph.structure.HugeEdge) HugeEdge(com.baidu.hugegraph.structure.HugeEdge) Edge(org.apache.tinkerpop.gremlin.structure.Edge) Test(org.junit.Test)

Aggregations

HugeEdge (com.baidu.hugegraph.structure.HugeEdge)54 HugeVertex (com.baidu.hugegraph.structure.HugeVertex)29 Id (com.baidu.hugegraph.backend.id.Id)26 Edge (org.apache.tinkerpop.gremlin.structure.Edge)22 Test (org.junit.Test)20 HugeGraph (com.baidu.hugegraph.HugeGraph)17 EdgeId (com.baidu.hugegraph.backend.id.EdgeId)12 EdgeLabel (com.baidu.hugegraph.schema.EdgeLabel)11 BaseUnitTest (com.baidu.hugegraph.unit.BaseUnitTest)9 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)9 BackendEntry (com.baidu.hugegraph.backend.store.BackendEntry)8 FakeObjects (com.baidu.hugegraph.unit.FakeObjects)8 PropertyKey (com.baidu.hugegraph.schema.PropertyKey)6 EdgeStep (com.baidu.hugegraph.traversal.algorithm.steps.EdgeStep)6 Iterator (java.util.Iterator)6 List (java.util.List)6 Set (java.util.Set)6 HugeException (com.baidu.hugegraph.HugeException)5 ConditionQuery (com.baidu.hugegraph.backend.query.ConditionQuery)5 HugeConfig (com.baidu.hugegraph.config.HugeConfig)5