Search in sources :

Example 36 with VertexLabel

use of com.baidu.hugegraph.structure.schema.VertexLabel in project incubator-hugegraph-toolchain by apache.

the class VertexLabelTest method testAddVertexLabelWithUserData.

@Test
public void testAddVertexLabelWithUserData() {
    SchemaManager schema = schema();
    VertexLabel player = schema.vertexLabel("player").properties("name").userdata("super_vl", "person").create();
    Assert.assertEquals(2, player.userdata().size());
    Assert.assertEquals("person", player.userdata().get("super_vl"));
    String time = (String) player.userdata().get("~create_time");
    Date createTime = DateUtil.parse(time);
    Assert.assertTrue(createTime.before(DateUtil.now()));
    VertexLabel runner = schema.vertexLabel("runner").properties("name").userdata("super_vl", "person").userdata("super_vl", "player").create();
    // The same key user data will be overwritten
    Assert.assertEquals(2, runner.userdata().size());
    Assert.assertEquals("player", runner.userdata().get("super_vl"));
    time = (String) runner.userdata().get("~create_time");
    createTime = DateUtil.parse(time);
    Assert.assertTrue(createTime.before(DateUtil.now()));
}
Also used : VertexLabel(com.baidu.hugegraph.structure.schema.VertexLabel) SchemaManager(com.baidu.hugegraph.driver.SchemaManager) Date(java.util.Date) Test(org.junit.Test)

Example 37 with VertexLabel

use of com.baidu.hugegraph.structure.schema.VertexLabel in project incubator-hugegraph-toolchain by apache.

the class VertexLabelTest method testListByNames.

@Test
public void testListByNames() {
    SchemaManager schema = schema();
    VertexLabel player = schema.vertexLabel("player").create();
    VertexLabel runner = schema.vertexLabel("runner").create();
    List<VertexLabel> vertexLabels;
    vertexLabels = schema.getVertexLabels(ImmutableList.of("player"));
    Assert.assertEquals(1, vertexLabels.size());
    assertContains(vertexLabels, player);
    vertexLabels = schema.getVertexLabels(ImmutableList.of("runner"));
    Assert.assertEquals(1, vertexLabels.size());
    assertContains(vertexLabels, runner);
    vertexLabels = schema.getVertexLabels(ImmutableList.of("player", "runner"));
    Assert.assertEquals(2, vertexLabels.size());
    assertContains(vertexLabels, player);
    assertContains(vertexLabels, runner);
}
Also used : VertexLabel(com.baidu.hugegraph.structure.schema.VertexLabel) SchemaManager(com.baidu.hugegraph.driver.SchemaManager) Test(org.junit.Test)

Example 38 with VertexLabel

use of com.baidu.hugegraph.structure.schema.VertexLabel in project incubator-hugegraph-toolchain by apache.

the class EdgeApiTest method testBatchCreateWithValidVertexAndNotCheck.

@Test
public void testBatchCreateWithValidVertexAndNotCheck() {
    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, false);
    List<String> knowsIds = edgeAPI.create(knows, false);
    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 39 with VertexLabel

use of com.baidu.hugegraph.structure.schema.VertexLabel in project incubator-hugegraph-toolchain by apache.

the class BaseClientTest method create50KnowsBatch.

protected List<Edge> create50KnowsBatch() {
    VertexLabel person = schema().getVertexLabel("person");
    List<Edge> edges = new ArrayList<>(50);
    for (int i = 0; i < 50; i++) {
        Edge edge = new Edge("knows");
        edge.sourceLabel("person");
        edge.targetLabel("person");
        edge.sourceId(person.id() + ":Person-" + i);
        edge.targetId(person.id() + ":Person-" + (i + 50));
        edge.property("date", "2017-03-24");
        edges.add(edge);
    }
    return edges;
}
Also used : VertexLabel(com.baidu.hugegraph.structure.schema.VertexLabel) ArrayList(java.util.ArrayList) Edge(com.baidu.hugegraph.structure.graph.Edge)

Example 40 with VertexLabel

use of com.baidu.hugegraph.structure.schema.VertexLabel in project incubator-hugegraph-toolchain by apache.

the class JobApiTest method testRebuildVertexLabel.

@Test
public void testRebuildVertexLabel() {
    VertexLabel person = schema().getVertexLabel("person");
    long taskId = rebuildAPI.rebuild(person);
    Task task = taskAPI.get(taskId);
    Assert.assertNotNull(task);
    Assert.assertEquals(taskId, task.id());
    waitUntilTaskCompleted(taskId);
}
Also used : Task(com.baidu.hugegraph.structure.Task) VertexLabel(com.baidu.hugegraph.structure.schema.VertexLabel) Test(org.junit.Test)

Aggregations

VertexLabel (com.baidu.hugegraph.structure.schema.VertexLabel)46 Test (org.junit.Test)31 HugeClient (com.baidu.hugegraph.driver.HugeClient)7 IndexLabel (com.baidu.hugegraph.structure.schema.IndexLabel)7 SchemaManager (com.baidu.hugegraph.driver.SchemaManager)6 ExternalException (com.baidu.hugegraph.exception.ExternalException)5 ServerException (com.baidu.hugegraph.exception.ServerException)5 Edge (com.baidu.hugegraph.structure.graph.Edge)5 ArrayList (java.util.ArrayList)5 Date (java.util.Date)5 RestResult (com.baidu.hugegraph.rest.RestResult)3 Vertex (com.baidu.hugegraph.structure.graph.Vertex)3 EdgeLabel (com.baidu.hugegraph.structure.schema.EdgeLabel)3 PropertyKey (com.baidu.hugegraph.structure.schema.PropertyKey)2 VertexLabelEntity (com.baidu.hugegraph.entity.schema.VertexLabelEntity)1 VertexLabelStyle (com.baidu.hugegraph.entity.schema.VertexLabelStyle)1 Record (com.baidu.hugegraph.loader.builder.Record)1 VertexBuilder (com.baidu.hugegraph.loader.builder.VertexBuilder)1 ParseException (com.baidu.hugegraph.loader.exception.ParseException)1 ElementMapping (com.baidu.hugegraph.loader.mapping.ElementMapping)1