use of org.janusgraph.core.schema.RelationTypeIndex in project janusgraph by JanusGraph.
the class JanusGraphTest method testSchemaNameChange.
@Test
public void testSchemaNameChange() {
PropertyKey time = mgmt.makePropertyKey("time").dataType(Integer.class).cardinality(Cardinality.SINGLE).make();
EdgeLabel knows = mgmt.makeEdgeLabel("knows").multiplicity(Multiplicity.MULTI).make();
mgmt.buildEdgeIndex(knows, "byTime", Direction.BOTH, time);
mgmt.buildIndex("timeIndex", Vertex.class).addKey(time).buildCompositeIndex();
mgmt.makeVertexLabel("people").make();
finishSchema();
// CREATE SMALL GRAPH
JanusGraphVertex v = tx.addVertex("people");
v.property(VertexProperty.Cardinality.single, "time", 5);
v.addEdge("knows", v, "time", 11);
newTx();
v = Iterables.getOnlyElement(tx.query().has("time", 5).vertices());
assertNotNull(v);
assertEquals("people", v.label());
assertEquals(5, v.<Integer>value("time").intValue());
assertCount(1, v.query().direction(Direction.IN).labels("knows").edges());
assertCount(1, v.query().direction(Direction.OUT).labels("knows").has("time", 11).edges());
newTx();
// UPDATE SCHEMA NAMES
assertTrue(mgmt.containsRelationType("knows"));
knows = mgmt.getEdgeLabel("knows");
mgmt.changeName(knows, "know");
assertEquals("know", knows.name());
assertTrue(mgmt.containsRelationIndex(knows, "byTime"));
RelationTypeIndex byTimeIndex = mgmt.getRelationIndex(knows, "byTime");
assertEquals("byTime", byTimeIndex.name());
mgmt.changeName(byTimeIndex, "overTime");
assertEquals("overTime", byTimeIndex.name());
assertTrue(mgmt.containsVertexLabel("people"));
VertexLabel vl = mgmt.getVertexLabel("people");
mgmt.changeName(vl, "person");
assertEquals("person", vl.name());
assertTrue(mgmt.containsGraphIndex("timeIndex"));
JanusGraphIndex graphIndex = mgmt.getGraphIndex("timeIndex");
mgmt.changeName(graphIndex, "byTime");
assertEquals("byTime", graphIndex.name());
finishSchema();
// VERIFY UPDATES IN MANAGEMENT SYSTEM
assertTrue(mgmt.containsRelationType("know"));
assertFalse(mgmt.containsRelationType("knows"));
knows = mgmt.getEdgeLabel("know");
assertTrue(mgmt.containsRelationIndex(knows, "overTime"));
assertFalse(mgmt.containsRelationIndex(knows, "byTime"));
assertTrue(mgmt.containsVertexLabel("person"));
assertFalse(mgmt.containsVertexLabel("people"));
assertTrue(mgmt.containsGraphIndex("byTime"));
assertFalse(mgmt.containsGraphIndex("timeIndex"));
// VERIFY UPDATES IN TRANSACTION
newTx();
v = Iterables.getOnlyElement(tx.query().has("time", 5).vertices());
assertNotNull(v);
assertEquals("person", v.label());
assertEquals(5, v.<Integer>value("time").intValue());
assertCount(1, v.query().direction(Direction.IN).labels("know").edges());
assertCount(0, v.query().direction(Direction.IN).labels("knows").edges());
assertCount(1, v.query().direction(Direction.OUT).labels("know").has("time", 11).edges());
}
Aggregations