Search in sources :

Example 11 with RelationTypeIndex

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());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TitanVertex(com.thinkaurelius.titan.core.TitanVertex) BaseVertexLabel(com.thinkaurelius.titan.graphdb.types.system.BaseVertexLabel) VertexLabel(com.thinkaurelius.titan.core.VertexLabel) EdgeLabel(com.thinkaurelius.titan.core.EdgeLabel) RelationTypeIndex(com.thinkaurelius.titan.core.schema.RelationTypeIndex) TitanGraphIndex(com.thinkaurelius.titan.core.schema.TitanGraphIndex) PropertyKey(com.thinkaurelius.titan.core.PropertyKey) Test(org.junit.Test)

Aggregations

RelationTypeIndex (com.thinkaurelius.titan.core.schema.RelationTypeIndex)11 TitanGraphIndex (com.thinkaurelius.titan.core.schema.TitanGraphIndex)7 PropertyKey (com.thinkaurelius.titan.core.PropertyKey)6 Test (org.junit.Test)5 EdgeLabel (com.thinkaurelius.titan.core.EdgeLabel)4 TitanManagement (com.thinkaurelius.titan.core.schema.TitanManagement)4 TitanVertex (com.thinkaurelius.titan.core.TitanVertex)3 ScanMetrics (com.thinkaurelius.titan.diskstorage.keycolumnvalue.scan.ScanMetrics)3 TitanSchemaVertex (com.thinkaurelius.titan.graphdb.types.vertices.TitanSchemaVertex)3 RelationType (com.thinkaurelius.titan.core.RelationType)2 TitanException (com.thinkaurelius.titan.core.TitanException)2 VertexLabel (com.thinkaurelius.titan.core.VertexLabel)2 SchemaStatus (com.thinkaurelius.titan.core.schema.SchemaStatus)2 BackendException (com.thinkaurelius.titan.diskstorage.BackendException)2 TitanGraphBaseTest (com.thinkaurelius.titan.graphdb.TitanGraphBaseTest)2 IndexRemoveJob (com.thinkaurelius.titan.graphdb.olap.job.IndexRemoveJob)2 CompositeIndexType (com.thinkaurelius.titan.graphdb.types.CompositeIndexType)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 ImmutableSet (com.google.common.collect.ImmutableSet)1 SchemaViolationException (com.thinkaurelius.titan.core.SchemaViolationException)1