use of com.thinkaurelius.titan.core.schema.RelationTypeIndex in project titan by thinkaurelius.
the class TitanGraphTest 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
TitanVertex v = tx.addVertex("people");
v.property(VertexProperty.Cardinality.single, "time", 5);
v.addEdge("knows", v, "time", 11);
newTx();
v = 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 rindex = mgmt.getRelationIndex(knows, "byTime");
assertEquals("byTime", rindex.name());
mgmt.changeName(rindex, "overTime");
assertEquals("overTime", rindex.name());
assertTrue(mgmt.containsVertexLabel("people"));
VertexLabel vl = mgmt.getVertexLabel("people");
mgmt.changeName(vl, "person");
assertEquals("person", vl.name());
assertTrue(mgmt.containsGraphIndex("timeIndex"));
TitanGraphIndex gindex = mgmt.getGraphIndex("timeIndex");
mgmt.changeName(gindex, "byTime");
assertEquals("byTime", gindex.name());
finishSchema();
//VERIFY UPDATES IN MGMT 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 = 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