Search in sources :

Example 16 with Edge

use of com.baidu.hugegraph.structure.graph.Edge in project incubator-hugegraph-toolchain by apache.

the class RestResultTest method testReadGremlinEdgeAndNull.

@Test
public void testReadGremlinEdgeAndNull() {
    String json = "{" + "\"requestId\": \"d95ac131-24b5-4140-a3ff-91b0c020764a\"," + "\"status\": {" + "\"message\": \"\"," + "\"code\": 200," + "\"attributes\": {}" + "}," + "\"result\": {" + "\"data\": [" + "{" + "\"id\": \"person:peter>created>>software:lop\"," + "\"label\": \"created\"," + "\"type\": \"edge\"," + "\"inVLabel\": \"software\"," + "\"outVLabel\": \"person\"," + "\"inV\": \"software:lop\"," + "\"outV\": \"person:peter\"," + "\"properties\": {" + "\"date\": 1490284800000," + "\"weight\": 0.2" + "}" + "}," + "null" + "]," + "\"meta\": {}" + "}" + "}";
    Mockito.when(this.mockResponse.getStatus()).thenReturn(200);
    Mockito.when(this.mockResponse.getHeaders()).thenReturn(null);
    Mockito.when(this.mockResponse.readEntity(String.class)).thenReturn(json);
    RestResult restResult = new RestResult(this.mockResponse);
    Assert.assertEquals(200, restResult.status());
    Assert.assertNull(restResult.headers());
    Response response = restResult.readObject(Response.class);
    response.graphManager(graph());
    Assert.assertEquals(200, response.status().code());
    Iterator<Result> results = response.result().iterator();
    Assert.assertTrue(results.hasNext());
    Result result = results.next();
    Assert.assertEquals(Edge.class, result.getObject().getClass());
    Edge created = new Edge("created");
    created.id("person:peter>created>>software:lop");
    created.sourceId("person:peter");
    created.targetId("software:lop");
    created.sourceLabel("person");
    created.targetLabel("software");
    created.property("date", 1490284800000L);
    created.property("weight", 0.2);
    Assert.assertTrue(Utils.contains(ImmutableList.of(created), result.getEdge()));
    Assert.assertTrue(results.hasNext());
    result = results.next();
    Assert.assertNull(result);
}
Also used : Response(com.baidu.hugegraph.structure.gremlin.Response) RestResult(com.baidu.hugegraph.rest.RestResult) Edge(com.baidu.hugegraph.structure.graph.Edge) Result(com.baidu.hugegraph.structure.gremlin.Result) RestResult(com.baidu.hugegraph.rest.RestResult) Test(org.junit.Test)

Example 17 with Edge

use of com.baidu.hugegraph.structure.graph.Edge in project incubator-hugegraph-toolchain by apache.

the class BatchInsertTest method testBatchInsertInOneLoopButAddEdgesBeforeVertices.

@Test
public void testBatchInsertInOneLoopButAddEdgesBeforeVertices() {
    List<Vertex> vertices = new ArrayList<>(BATCH_SIZE);
    List<Edge> edges = new ArrayList<>(BATCH_SIZE);
    for (int i = 1; i <= BATCH_SIZE; i++) {
        Vertex vertex1 = new Vertex("person").property("name", "P-" + i).property("age", i);
        Vertex vertex2 = new Vertex("software").property("name", "S-" + i).property("lang", "java");
        Edge edge = new Edge("created").source(vertex1).target(vertex2).property("date", "2018-12-25");
        vertices.add(vertex1);
        vertices.add(vertex2);
        edges.add(edge);
        if (vertices.size() >= BATCH_SIZE) {
            // Must add vertices before edges
            Assert.assertThrows(InvalidOperationException.class, () -> {
                graph().addEdges(edges);
            });
            graph().addVertices(vertices);
            vertices.clear();
            edges.clear();
        }
    }
    Assert.assertEquals(2 * BATCH_SIZE, graph().listVertices(-1).size());
    Assert.assertEquals(0, graph().listEdges(-1).size());
}
Also used : Vertex(com.baidu.hugegraph.structure.graph.Vertex) ArrayList(java.util.ArrayList) Edge(com.baidu.hugegraph.structure.graph.Edge) Test(org.junit.Test) BaseClientTest(com.baidu.hugegraph.BaseClientTest)

Example 18 with Edge

use of com.baidu.hugegraph.structure.graph.Edge in project incubator-hugegraph-toolchain by apache.

the class BatchInsertTest method testBatchInsertInOneLoop.

@Test
public void testBatchInsertInOneLoop() {
    List<Vertex> vertices = new ArrayList<>(BATCH_SIZE);
    List<Edge> edges = new ArrayList<>(BATCH_SIZE);
    for (int i = 1; i <= BATCH_SIZE; i++) {
        Vertex vertex1 = new Vertex("person").property("name", "P-" + i).property("age", i);
        Vertex vertex2 = new Vertex("software").property("name", "S-" + i).property("lang", "java");
        Edge edge = new Edge("created").source(vertex1).target(vertex2).property("date", "2018-12-25");
        vertices.add(vertex1);
        vertices.add(vertex2);
        edges.add(edge);
        if (vertices.size() >= BATCH_SIZE) {
            graph().addVertices(vertices);
            graph().addEdges(edges);
            vertices.clear();
            edges.clear();
        }
    }
    Assert.assertEquals(2 * BATCH_SIZE, graph().listVertices(-1).size());
    Assert.assertEquals(BATCH_SIZE, graph().listEdges(-1).size());
}
Also used : Vertex(com.baidu.hugegraph.structure.graph.Vertex) ArrayList(java.util.ArrayList) Edge(com.baidu.hugegraph.structure.graph.Edge) Test(org.junit.Test) BaseClientTest(com.baidu.hugegraph.BaseClientTest)

Example 19 with Edge

use of com.baidu.hugegraph.structure.graph.Edge in project incubator-hugegraph-toolchain by apache.

the class BatchInsertTest method testBatchInsertInTwoLoops.

@Test
public void testBatchInsertInTwoLoops() {
    int vertexCount = BATCH_SIZE;
    List<Vertex> persons = new ArrayList<>(BATCH_SIZE);
    List<Vertex> softwares = new ArrayList<>(BATCH_SIZE);
    List<Edge> edges = new ArrayList<>(BATCH_SIZE);
    for (int i = 1; i <= vertexCount; i++) {
        Vertex person = new Vertex("person").property("name", "P-" + i).property("age", i);
        Vertex software = new Vertex("software").property("name", "S-" + i).property("lang", "java");
        persons.add(person);
        softwares.add(software);
    }
    graph().addVertices(persons);
    graph().addVertices(softwares);
    for (int i = 0; i < vertexCount; i++) {
        Vertex person = persons.get(i);
        Vertex software = softwares.get(i);
        Edge edge = new Edge("created").source(person).target(software).property("date", "2018-12-25");
        edges.add(edge);
    }
    graph().addEdges(edges);
    Assert.assertEquals(2 * BATCH_SIZE, graph().listVertices(-1).size());
    Assert.assertEquals(BATCH_SIZE, graph().listEdges(-1).size());
}
Also used : Vertex(com.baidu.hugegraph.structure.graph.Vertex) ArrayList(java.util.ArrayList) Edge(com.baidu.hugegraph.structure.graph.Edge) Test(org.junit.Test) BaseClientTest(com.baidu.hugegraph.BaseClientTest)

Example 20 with Edge

use of com.baidu.hugegraph.structure.graph.Edge in project incubator-hugegraph-toolchain by apache.

the class TraverserManagerTest method testIterateEdgesByShard.

@Test
public void testIterateEdgesByShard() {
    List<Shard> shards = traverser().edgeShards(1 * 1024 * 1024);
    List<Edge> edges = new LinkedList<>();
    for (Shard shard : shards) {
        Iterator<Edge> iter = traverser().iteratorEdges(shard, 1);
        while (iter.hasNext()) {
            edges.add(iter.next());
        }
    }
    Assert.assertEquals(6, edges.size());
}
Also used : Shard(com.baidu.hugegraph.structure.graph.Shard) Edge(com.baidu.hugegraph.structure.graph.Edge) LinkedList(java.util.LinkedList) Test(org.junit.Test) BaseClientTest(com.baidu.hugegraph.BaseClientTest)

Aggregations

Edge (com.baidu.hugegraph.structure.graph.Edge)103 Test (org.junit.Test)73 Vertex (com.baidu.hugegraph.structure.graph.Vertex)33 ArrayList (java.util.ArrayList)22 BaseClientTest (com.baidu.hugegraph.BaseClientTest)20 BatchEdgeRequest (com.baidu.hugegraph.structure.graph.BatchEdgeRequest)12 HugeClient (com.baidu.hugegraph.driver.HugeClient)10 Path (com.baidu.hugegraph.structure.graph.Path)9 Result (com.baidu.hugegraph.structure.gremlin.Result)8 ResultSet (com.baidu.hugegraph.structure.gremlin.ResultSet)7 RestResult (com.baidu.hugegraph.rest.RestResult)5 VertexLabel (com.baidu.hugegraph.structure.schema.VertexLabel)5 GraphManager (com.baidu.hugegraph.driver.GraphManager)4 SchemaManager (com.baidu.hugegraph.driver.SchemaManager)4 GraphView (com.baidu.hugegraph.entity.query.GraphView)4 Edges (com.baidu.hugegraph.structure.graph.Edges)4 Date (java.util.Date)4 HashMap (java.util.HashMap)4 GremlinResult (com.baidu.hugegraph.entity.query.GremlinResult)3 TypedResult (com.baidu.hugegraph.entity.query.TypedResult)3