Search in sources :

Example 96 with SchemaManager

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

the class EdgeLabelCoreTest method testAddEdgeLabelWithNotExistProperty.

@Test
public void testAddEdgeLabelWithNotExistProperty() {
    super.initPropertyKeys();
    SchemaManager schema = graph().schema();
    schema.vertexLabel("person").properties("name", "age", "city").primaryKeys("name").create();
    schema.vertexLabel("book").properties("id", "name").primaryKeys("id").create();
    Assert.assertThrows(IllegalArgumentException.class, () -> {
        schema.edgeLabel("look").properties("date").link("person", "book").create();
    });
}
Also used : SchemaManager(com.baidu.hugegraph.schema.SchemaManager) Test(org.junit.Test)

Example 97 with SchemaManager

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

the class EdgeLabelCoreTest method testRemoveEdgeLabel.

@Test
public void testRemoveEdgeLabel() {
    super.initPropertyKeys();
    SchemaManager schema = graph().schema();
    schema.vertexLabel("person").properties("name", "age", "city").primaryKeys("name").create();
    schema.vertexLabel("book").properties("name", "contribution").primaryKeys("name").create();
    schema.edgeLabel("look").link("person", "book").properties("time", "city").create();
    Assert.assertNotNull(schema.getEdgeLabel("look"));
    schema.edgeLabel("look").remove();
    Assert.assertThrows(NotFoundException.class, () -> {
        schema.getEdgeLabel("look");
    });
}
Also used : SchemaManager(com.baidu.hugegraph.schema.SchemaManager) Test(org.junit.Test)

Example 98 with SchemaManager

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

the class EdgeLabelCoreTest method testRemoveEdgeLabelWithEdge.

@Test
public void testRemoveEdgeLabelWithEdge() {
    super.initPropertyKeys();
    SchemaManager schema = graph().schema();
    schema.vertexLabel("person").properties("name", "age", "city").primaryKeys("name").nullableKeys("city").create();
    schema.vertexLabel("book").properties("name").primaryKeys("name").create();
    schema.edgeLabel("write").link("person", "book").properties("time", "weight").create();
    Vertex marko = graph().addVertex(T.label, "person", "name", "marko", "age", 22);
    Vertex java = graph().addVertex(T.label, "book", "name", "java in action");
    Vertex hadoop = graph().addVertex(T.label, "book", "name", "hadoop mapreduce");
    marko.addEdge("write", java, "time", "2016-12-12", "weight", 0.3);
    marko.addEdge("write", hadoop, "time", "2014-2-28", "weight", 0.5);
    graph().tx().commit();
    List<Edge> edges = graph().traversal().E().hasLabel("write").toList();
    Assert.assertNotNull(edges);
    Assert.assertEquals(2, edges.size());
    schema.edgeLabel("write").remove();
    Assert.assertThrows(NotFoundException.class, () -> {
        schema.getEdgeLabel("write");
    });
    Assert.assertThrows(IllegalArgumentException.class, () -> {
        graph().traversal().E().hasLabel("write").toList();
    });
}
Also used : Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) SchemaManager(com.baidu.hugegraph.schema.SchemaManager) Edge(org.apache.tinkerpop.gremlin.structure.Edge) Test(org.junit.Test)

Example 99 with SchemaManager

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

the class EdgeLabelCoreTest method testAddEdgeLabelWithUndefinedNullableKeys.

@Test
public void testAddEdgeLabelWithUndefinedNullableKeys() {
    super.initPropertyKeys();
    SchemaManager schema = graph().schema();
    schema.vertexLabel("person").properties("name", "age", "city").primaryKeys("name").create();
    schema.vertexLabel("author").properties("id", "name").primaryKeys("id").create();
    schema.vertexLabel("book").properties("id", "name").primaryKeys("id").create();
    Assert.assertThrows(IllegalArgumentException.class, () -> {
        schema.edgeLabel("look").properties("time", "weight").nullableKeys("undefined").link("person", "book").create();
    });
}
Also used : SchemaManager(com.baidu.hugegraph.schema.SchemaManager) Test(org.junit.Test)

Example 100 with SchemaManager

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

the class EdgeLabelCoreTest method testAddEdgeLabelWithNullableKeys.

@Test
public void testAddEdgeLabelWithNullableKeys() {
    super.initPropertyKeys();
    SchemaManager schema = graph().schema();
    schema.vertexLabel("person").properties("name", "age", "city").primaryKeys("name").create();
    schema.vertexLabel("book").properties("id", "name").primaryKeys("id").create();
    EdgeLabel look = schema.edgeLabel("look").properties("time", "weight").nullableKeys("weight").link("person", "book").create();
    Assert.assertNotNull(look);
    Assert.assertEquals("look", look.name());
    assertVLEqual("person", look.sourceLabel());
    assertVLEqual("book", look.targetLabel());
    Assert.assertEquals(2, look.properties().size());
    assertContainsPk(look.properties(), "time", "weight");
    Assert.assertEquals(1, look.nullableKeys().size());
    assertContainsPk(look.nullableKeys(), "weight");
}
Also used : EdgeLabel(com.baidu.hugegraph.schema.EdgeLabel) SchemaManager(com.baidu.hugegraph.schema.SchemaManager) Test(org.junit.Test)

Aggregations

SchemaManager (com.baidu.hugegraph.schema.SchemaManager)261 Test (org.junit.Test)227 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)90 HugeGraph (com.baidu.hugegraph.HugeGraph)76 FakeVertex (com.baidu.hugegraph.testutil.FakeObjects.FakeVertex)40 Edge (org.apache.tinkerpop.gremlin.structure.Edge)30 VertexLabel (com.baidu.hugegraph.schema.VertexLabel)27 HugeVertex (com.baidu.hugegraph.structure.HugeVertex)22 HugeEdge (com.baidu.hugegraph.structure.HugeEdge)20 EdgeLabel (com.baidu.hugegraph.schema.EdgeLabel)19 FakeEdge (com.baidu.hugegraph.testutil.FakeObjects.FakeEdge)19 PropertyKey (com.baidu.hugegraph.schema.PropertyKey)15 Id (com.baidu.hugegraph.backend.id.Id)12 IndexLabel (com.baidu.hugegraph.schema.IndexLabel)8 Watched (com.baidu.hugegraph.perf.PerfUtil.Watched)7 GraphTraversalSource (org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource)7 Date (java.util.Date)6 Before (org.junit.Before)6 HashSet (java.util.HashSet)3 HugeException (com.baidu.hugegraph.HugeException)2