Search in sources :

Example 41 with Edge

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

the class BatchUpdateElementApiTest method testEdgeBatchUpdateStrategyBigger.

@Test
public void testEdgeBatchUpdateStrategyBigger() {
    // TODO: Add date comparison after fixing the date serialization bug
    BatchEdgeRequest req = batchEdgeRequest("price", -3, 1, UpdateStrategy.BIGGER);
    List<Edge> edges = edgeAPI.update(req);
    assertBatchResponse(edges, "price", 1);
    req = batchEdgeRequest("price", 7, 3, UpdateStrategy.BIGGER);
    edges = edgeAPI.update(req);
    assertBatchResponse(edges, "price", 7);
}
Also used : BatchEdgeRequest(com.baidu.hugegraph.structure.graph.BatchEdgeRequest) Edge(com.baidu.hugegraph.structure.graph.Edge) Test(org.junit.Test)

Example 42 with Edge

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

the class BatchUpdateElementApiTest method testEdgeBatchUpdateStrategySmaller.

@Test
public void testEdgeBatchUpdateStrategySmaller() {
    BatchEdgeRequest req = batchEdgeRequest("price", -3, 1, UpdateStrategy.SMALLER);
    List<Edge> edges = edgeAPI.update(req);
    assertBatchResponse(edges, "price", -3);
    req = batchEdgeRequest("price", 7, 3, UpdateStrategy.SMALLER);
    edges = edgeAPI.update(req);
    assertBatchResponse(edges, "price", 3);
}
Also used : BatchEdgeRequest(com.baidu.hugegraph.structure.graph.BatchEdgeRequest) Edge(com.baidu.hugegraph.structure.graph.Edge) Test(org.junit.Test)

Example 43 with Edge

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

the class EdgeApiTest method testBatchCreateWithMoreThanBatchSize.

@Test
public void testBatchCreateWithMoreThanBatchSize() {
    List<Vertex> persons = super.create100PersonBatch();
    List<Vertex> softwares = super.create50SoftwareBatch();
    vertexAPI.create(persons);
    vertexAPI.create(softwares);
    List<Edge> edges = new ArrayList<>(1000);
    for (int i = 0; i < 1000; i++) {
        Edge edge = new Edge("created");
        edge.sourceLabel("person");
        edge.targetLabel("software");
        edge.sourceId("person:Person-" + i);
        edge.targetId("software:Software-" + i);
        edge.property("date", "2017-08-24");
        edge.property("city", "Hongkong");
        edges.add(edge);
    }
    Utils.assertResponseError(400, () -> {
        edgeAPI.create(edges, true);
    });
}
Also used : Vertex(com.baidu.hugegraph.structure.graph.Vertex) ArrayList(java.util.ArrayList) Edge(com.baidu.hugegraph.structure.graph.Edge) Test(org.junit.Test)

Example 44 with Edge

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

the class EdgeApiTest method testBatchCreateWithValidVertexAndCheck.

@Test
public void testBatchCreateWithValidVertexAndCheck() {
    VertexLabel person = schema().getVertexLabel("person");
    VertexLabel software = schema().getVertexLabel("software");
    List<Vertex> persons = super.create100PersonBatch();
    List<Vertex> softwares = super.create50SoftwareBatch();
    vertexAPI.create(persons);
    vertexAPI.create(softwares);
    List<Edge> createds = super.create50CreatedBatch();
    List<Edge> knows = super.create50KnowsBatch();
    List<String> createdIds = edgeAPI.create(createds, true);
    List<String> knowsIds = edgeAPI.create(knows, true);
    Assert.assertEquals(50, createdIds.size());
    Assert.assertEquals(50, knowsIds.size());
    for (int i = 0; i < 50; i++) {
        Edge created = edgeAPI.get(createdIds.get(i));
        Assert.assertEquals("created", created.label());
        Assert.assertEquals("person", created.sourceLabel());
        Assert.assertEquals("software", created.targetLabel());
        Assert.assertEquals(person.id() + ":Person-" + i, created.sourceId());
        Assert.assertEquals(software.id() + ":Software-" + i, created.targetId());
        String date = Utils.formatDate("2017-03-24");
        Map<String, Object> props = ImmutableMap.of("date", date, "city", "Hongkong");
        Assert.assertEquals(props, created.properties());
    }
    for (int i = 0; i < 50; i++) {
        Edge know = edgeAPI.get(knowsIds.get(i));
        Assert.assertEquals("knows", know.label());
        Assert.assertEquals("person", know.sourceLabel());
        Assert.assertEquals("person", know.targetLabel());
        Assert.assertEquals(person.id() + ":Person-" + i, know.sourceId());
        Assert.assertEquals(person.id() + ":Person-" + (i + 50), know.targetId());
        String date = Utils.formatDate("2017-03-24");
        Map<String, Object> props = ImmutableMap.of("date", date);
        Assert.assertEquals(props, know.properties());
    }
}
Also used : Vertex(com.baidu.hugegraph.structure.graph.Vertex) VertexLabel(com.baidu.hugegraph.structure.schema.VertexLabel) Edge(com.baidu.hugegraph.structure.graph.Edge) Test(org.junit.Test)

Example 45 with Edge

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

the class TraverserManager method edges.

public Edges edges(Shard shard, String page, long pageLimit) {
    E.checkArgument(page == null || pageLimit >= 0, "Page limit must be >= 0 when page is not null");
    Edges edges = this.edgesAPI.scan(shard, page, pageLimit);
    for (Edge edge : edges.results()) {
        edge.attachManager(this.graphManager);
    }
    return edges;
}
Also used : Edges(com.baidu.hugegraph.structure.graph.Edges) Edge(com.baidu.hugegraph.structure.graph.Edge)

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