Search in sources :

Example 76 with VertexLabel

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

the class VertexLabelCoreTest method testAddVertexLabelWithIdStrategy.

@Test
public void testAddVertexLabelWithIdStrategy() {
    super.initPropertyKeys();
    SchemaManager schema = graph().schema();
    VertexLabel person = schema.vertexLabel("person").properties("name", "age", "city").create();
    Assert.assertEquals(IdStrategy.AUTOMATIC, person.idStrategy());
    VertexLabel person1 = schema.vertexLabel("person1").useAutomaticId().properties("name", "age", "city").create();
    Assert.assertEquals(IdStrategy.AUTOMATIC, person1.idStrategy());
    VertexLabel person2 = schema.vertexLabel("person2").useCustomizeStringId().properties("name", "age", "city").create();
    Assert.assertEquals(IdStrategy.CUSTOMIZE_STRING, person2.idStrategy());
    VertexLabel person3 = schema.vertexLabel("person3").useCustomizeNumberId().properties("name", "age", "city").create();
    Assert.assertEquals(IdStrategy.CUSTOMIZE_NUMBER, person3.idStrategy());
    VertexLabel person4 = schema.vertexLabel("person4").useCustomizeUuidId().properties("name", "age", "city").create();
    Assert.assertEquals(IdStrategy.CUSTOMIZE_UUID, person4.idStrategy());
    VertexLabel person5 = schema.vertexLabel("person5").properties("name", "age", "city").primaryKeys("name").create();
    Assert.assertEquals(IdStrategy.PRIMARY_KEY, person5.idStrategy());
    VertexLabel person6 = schema.vertexLabel("person6").usePrimaryKeyId().properties("name", "age", "city").primaryKeys("name").create();
    Assert.assertEquals(IdStrategy.PRIMARY_KEY, person6.idStrategy());
}
Also used : VertexLabel(com.baidu.hugegraph.schema.VertexLabel) SchemaManager(com.baidu.hugegraph.schema.SchemaManager) Test(org.junit.Test)

Example 77 with VertexLabel

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

the class VertexLabelCoreTest method testAddVertexLabelWithUserdata.

@Test
public void testAddVertexLabelWithUserdata() {
    super.initPropertyKeys();
    SchemaManager schema = graph().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"));
    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"));
}
Also used : VertexLabel(com.baidu.hugegraph.schema.VertexLabel) SchemaManager(com.baidu.hugegraph.schema.SchemaManager) Test(org.junit.Test)

Example 78 with VertexLabel

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

the class VertexLabelCoreTest method testAddVertexLabelWithTtl.

@Test
public void testAddVertexLabelWithTtl() {
    super.initPropertyKeys();
    SchemaManager schema = graph().schema();
    schema.propertyKey("born").asDate().ifNotExist().create();
    Assert.assertThrows(IllegalArgumentException.class, () -> {
        schema.vertexLabel("person").properties("name", "age", "city", "born").ttl(-86400L).create();
    });
    Assert.assertThrows(IllegalArgumentException.class, () -> {
        schema.vertexLabel("person").properties("name", "age", "city", "born").ttlStartTime("born").create();
    });
    Assert.assertThrows(IllegalArgumentException.class, () -> {
        schema.vertexLabel("person").properties("name", "age", "city", "born").ttlStartTime("name").create();
    });
    Assert.assertThrows(IllegalArgumentException.class, () -> {
        schema.vertexLabel("person").properties("name", "age", "city", "born").ttlStartTime("age").create();
    });
    VertexLabel person = schema.vertexLabel("person").properties("name", "age", "city", "born").ttl(86400L).create();
    Assert.assertNotNull(person);
    Assert.assertEquals("person", person.name());
    Assert.assertEquals(4, person.properties().size());
    assertContainsPk(person.properties(), "name", "age", "city", "born");
    Assert.assertEquals(0, person.primaryKeys().size());
    Assert.assertEquals(IdStrategy.AUTOMATIC, person.idStrategy());
    Assert.assertEquals(86400L, person.ttl());
    Assert.assertEquals(IdGenerator.ZERO, person.ttlStartTime());
    VertexLabel student = schema.vertexLabel("student").properties("name", "age", "city", "born").ttl(86400L).ttlStartTime("born").create();
    Assert.assertNotNull(student);
    Assert.assertEquals("student", student.name());
    Assert.assertEquals(4, student.properties().size());
    assertContainsPk(student.properties(), "name", "age", "city", "born");
    Assert.assertEquals(0, student.primaryKeys().size());
    Assert.assertEquals(IdStrategy.AUTOMATIC, student.idStrategy());
    Assert.assertEquals(86400L, student.ttl());
    Assert.assertNotNull(student.ttlStartTime());
    assertContainsPk(ImmutableSet.of(student.ttlStartTime()), "born");
}
Also used : VertexLabel(com.baidu.hugegraph.schema.VertexLabel) SchemaManager(com.baidu.hugegraph.schema.SchemaManager) Test(org.junit.Test)

Example 79 with VertexLabel

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

the class VertexLabelCoreTest method testAddVertexLabelWithoutPropertyKey.

@Test
public void testAddVertexLabelWithoutPropertyKey() {
    super.initPropertyKeys();
    SchemaManager schema = graph().schema();
    VertexLabel person = schema.vertexLabel("person").create();
    Assert.assertTrue(person.properties().isEmpty());
}
Also used : VertexLabel(com.baidu.hugegraph.schema.VertexLabel) SchemaManager(com.baidu.hugegraph.schema.SchemaManager) Test(org.junit.Test)

Example 80 with VertexLabel

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

the class VertexLabelCoreTest method testListVertexLabels.

@Test
public void testListVertexLabels() {
    super.initPropertyKeys();
    SchemaManager schema = graph().schema();
    VertexLabel person = schema.vertexLabel("person").properties("name", "age", "city").primaryKeys("name").create();
    VertexLabel author = schema.vertexLabel("author").properties("id", "name").primaryKeys("id").create();
    VertexLabel book = schema.vertexLabel("book").properties("id", "name").primaryKeys("id").create();
    List<VertexLabel> vertexLabels = schema.getVertexLabels();
    Assert.assertEquals(3, vertexLabels.size());
    Assert.assertTrue(vertexLabels.contains(person));
    Assert.assertTrue(vertexLabels.contains(author));
    Assert.assertTrue(vertexLabels.contains(book));
    // clear cache
    params().schemaEventHub().call(Events.CACHE, "clear", null);
    Assert.assertEquals(person, schema.getVertexLabel("person"));
    vertexLabels = schema.getVertexLabels();
    Assert.assertEquals(3, vertexLabels.size());
    Assert.assertTrue(vertexLabels.contains(person));
    Assert.assertTrue(vertexLabels.contains(author));
    Assert.assertTrue(vertexLabels.contains(book));
}
Also used : VertexLabel(com.baidu.hugegraph.schema.VertexLabel) SchemaManager(com.baidu.hugegraph.schema.SchemaManager) Test(org.junit.Test)

Aggregations

VertexLabel (com.baidu.hugegraph.schema.VertexLabel)86 Test (org.junit.Test)35 SchemaManager (com.baidu.hugegraph.schema.SchemaManager)27 Id (com.baidu.hugegraph.backend.id.Id)23 PropertyKey (com.baidu.hugegraph.schema.PropertyKey)20 HugeGraph (com.baidu.hugegraph.HugeGraph)19 HugeVertex (com.baidu.hugegraph.structure.HugeVertex)19 EdgeId (com.baidu.hugegraph.backend.id.EdgeId)12 EdgeLabel (com.baidu.hugegraph.schema.EdgeLabel)12 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)11 FakeObjects (com.baidu.hugegraph.unit.FakeObjects)7 ConditionQuery (com.baidu.hugegraph.backend.query.ConditionQuery)6 BaseUnitTest (com.baidu.hugegraph.unit.BaseUnitTest)5 Timed (com.codahale.metrics.annotation.Timed)5 RolesAllowed (jakarta.annotation.security.RolesAllowed)5 Produces (jakarta.ws.rs.Produces)5 Watched (com.baidu.hugegraph.perf.PerfUtil.Watched)4 IndexLabel (com.baidu.hugegraph.schema.IndexLabel)4 HugeEdge (com.baidu.hugegraph.structure.HugeEdge)4 Date (java.util.Date)4