Search in sources :

Example 71 with Vertex

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

the class BaseClientTest method create50SoftwareBatch.

protected List<Vertex> create50SoftwareBatch() {
    List<Vertex> vertices = new ArrayList<>(50);
    for (int i = 0; i < 50; i++) {
        Vertex vertex = new Vertex("software");
        vertex.property("name", "Software" + "-" + i);
        vertex.property("lang", "java");
        vertex.property("price", 328);
        vertices.add(vertex);
    }
    return vertices;
}
Also used : Vertex(com.baidu.hugegraph.structure.graph.Vertex) ArrayList(java.util.ArrayList)

Example 72 with Vertex

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

the class BatchUpdateElementApiTest method testVertexBatchUpdateWithNullValues.

@Test
public void testVertexBatchUpdateWithNullValues() {
    BatchVertexRequest req = batchVertexRequest("price", 1, null, UpdateStrategy.OVERRIDE);
    List<Vertex> vertices = vertexAPI.update(req);
    assertBatchResponse(vertices, "price", 1);
}
Also used : Vertex(com.baidu.hugegraph.structure.graph.Vertex) BatchVertexRequest(com.baidu.hugegraph.structure.graph.BatchVertexRequest) Test(org.junit.Test)

Example 73 with Vertex

use of com.baidu.hugegraph.structure.graph.Vertex 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 74 with Vertex

use of com.baidu.hugegraph.structure.graph.Vertex 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 75 with Vertex

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

the class TraverserManager method vertices.

public Vertices vertices(Shard shard, String page, long pageLimit) {
    E.checkArgument(page == null || pageLimit >= 0, "Page limit must be >= 0 when page is not null");
    Vertices vertices = this.verticesAPI.scan(shard, page, pageLimit);
    for (Vertex vertex : vertices.results()) {
        vertex.attachManager(this.graphManager);
    }
    return vertices;
}
Also used : Vertex(com.baidu.hugegraph.structure.graph.Vertex) Vertices(com.baidu.hugegraph.structure.graph.Vertices) PathsWithVertices(com.baidu.hugegraph.structure.traverser.PathsWithVertices)

Aggregations

Vertex (com.baidu.hugegraph.structure.graph.Vertex)165 Test (org.junit.Test)110 Edge (com.baidu.hugegraph.structure.graph.Edge)33 HugeClient (com.baidu.hugegraph.driver.HugeClient)22 ArrayList (java.util.ArrayList)21 SchemaManager (com.baidu.hugegraph.driver.SchemaManager)18 BaseClientTest (com.baidu.hugegraph.BaseClientTest)17 BeforeClass (org.junit.BeforeClass)17 GraphManager (com.baidu.hugegraph.driver.GraphManager)14 BatchVertexRequest (com.baidu.hugegraph.structure.graph.BatchVertexRequest)13 Path (com.baidu.hugegraph.structure.graph.Path)11 Result (com.baidu.hugegraph.structure.gremlin.Result)10 ResultSet (com.baidu.hugegraph.structure.gremlin.ResultSet)10 List (java.util.List)10 BaseApiTest (com.baidu.hugegraph.api.BaseApiTest)9 ImmutableList (com.google.common.collect.ImmutableList)6 ImmutableMap (com.google.common.collect.ImmutableMap)6 Map (java.util.Map)6 RestResult (com.baidu.hugegraph.rest.RestResult)5 PathsWithVertices (com.baidu.hugegraph.structure.traverser.PathsWithVertices)5