Search in sources :

Example 16 with EdgeLabel

use of com.thinkaurelius.titan.core.EdgeLabel in project titan by thinkaurelius.

the class TitanGraphTest method testEdgeTTLTiming.

/* ==================================================================================
                            TIME TO LIVE
     ==================================================================================*/
@Test
public void testEdgeTTLTiming() throws Exception {
    if (!features.hasCellTTL()) {
        return;
    }
    EdgeLabel label1 = mgmt.makeEdgeLabel("likes").make();
    int ttl1 = 1;
    int ttl2 = 4;
    mgmt.setTTL(label1, Duration.ofSeconds(ttl1));
    EdgeLabel label2 = mgmt.makeEdgeLabel("dislikes").make();
    mgmt.setTTL(label2, Duration.ofSeconds(ttl2));
    EdgeLabel label3 = mgmt.makeEdgeLabel("indifferentTo").make();
    assertEquals(Duration.ofSeconds(ttl1), mgmt.getTTL(label1));
    assertEquals(Duration.ofSeconds(ttl2), mgmt.getTTL(label2));
    assertEquals(Duration.ZERO, mgmt.getTTL(label3));
    mgmt.commit();
    TitanVertex v1 = graph.addVertex(), v2 = graph.addVertex(), v3 = graph.addVertex();
    v1.addEdge("likes", v2);
    v2.addEdge("dislikes", v1);
    v3.addEdge("indifferentTo", v1);
    // initial, pre-commit state of the edges.  They are not yet subject to TTL
    assertNotEmpty(v1.query().direction(Direction.OUT).vertices());
    assertNotEmpty(v2.query().direction(Direction.OUT).vertices());
    assertNotEmpty(v3.query().direction(Direction.OUT).vertices());
    long commitTime = System.currentTimeMillis();
    graph.tx().commit();
    // edges are now subject to TTL, although we must commit() or rollback() to see it
    assertNotEmpty(v1.query().direction(Direction.OUT).vertices());
    assertNotEmpty(v2.query().direction(Direction.OUT).vertices());
    assertNotEmpty(v3.query().direction(Direction.OUT).vertices());
    Thread.sleep(commitTime + (ttl1 * 1000L + 200) - System.currentTimeMillis());
    graph.tx().rollback();
    // e1 has dropped out
    assertEmpty(v1.query().direction(Direction.OUT).vertices());
    assertNotEmpty(v2.query().direction(Direction.OUT).vertices());
    assertNotEmpty(v3.query().direction(Direction.OUT).vertices());
    Thread.sleep(commitTime + (ttl2 * 1000L + 500) - System.currentTimeMillis());
    graph.tx().rollback();
    // both e1 and e2 have dropped out.  e3 has no TTL, and so remains
    assertEmpty(v1.query().direction(Direction.OUT).vertices());
    assertEmpty(v2.query().direction(Direction.OUT).vertices());
    assertNotEmpty(v3.query().direction(Direction.OUT).vertices());
}
Also used : TitanVertex(com.thinkaurelius.titan.core.TitanVertex) EdgeLabel(com.thinkaurelius.titan.core.EdgeLabel) Test(org.junit.Test)

Example 17 with EdgeLabel

use of com.thinkaurelius.titan.core.EdgeLabel in project titan by thinkaurelius.

the class TitanGraphTest method testVertexCentricIndexWithNull.

@Test
public void testVertexCentricIndexWithNull() {
    EdgeLabel bought = makeLabel("bought");
    PropertyKey time = makeKey("time", Long.class);
    mgmt.buildEdgeIndex(bought, "byTimeDesc", BOTH, decr, time);
    mgmt.buildEdgeIndex(bought, "byTimeIncr", BOTH, incr, time);
    finishSchema();
    TitanVertex v1 = tx.addVertex(), v2 = tx.addVertex();
    v1.addEdge("bought", v2).property("time", 1);
    v1.addEdge("bought", v2).property("time", 2);
    v1.addEdge("bought", v2).property("time", 3);
    v1.addEdge("bought", v2);
    v1.addEdge("bought", v2);
    assertEquals(5, v1.query().direction(OUT).labels("bought").edgeCount());
    assertEquals(1, v1.query().direction(OUT).labels("bought").has("time", 1).edgeCount());
    assertEquals(1, v1.query().direction(OUT).labels("bought").has("time", Cmp.LESS_THAN, 3).has("time", Cmp.GREATER_THAN, 1).edgeCount());
    assertEquals(3, v1.query().direction(OUT).labels("bought").has("time", Cmp.LESS_THAN, 5).edgeCount());
    assertEquals(3, v1.query().direction(OUT).labels("bought").has("time", Cmp.GREATER_THAN, 0).edgeCount());
    assertEquals(2, v1.query().direction(OUT).labels("bought").has("time", Cmp.LESS_THAN, 3).edgeCount());
    assertEquals(1, v1.query().direction(OUT).labels("bought").has("time", Cmp.GREATER_THAN, 2).edgeCount());
    assertEquals(2, v1.query().direction(OUT).labels("bought").hasNot("time").edgeCount());
    assertEquals(5, v1.query().direction(OUT).labels("bought").edgeCount());
    newTx();
    v1 = tx.getVertex(v1.longId());
    //Queries copied from above
    assertEquals(5, v1.query().direction(OUT).labels("bought").edgeCount());
    assertEquals(1, v1.query().direction(OUT).labels("bought").has("time", 1).edgeCount());
    assertEquals(1, v1.query().direction(OUT).labels("bought").has("time", Cmp.LESS_THAN, 3).has("time", Cmp.GREATER_THAN, 1).edgeCount());
    assertEquals(3, v1.query().direction(OUT).labels("bought").has("time", Cmp.LESS_THAN, 5).edgeCount());
    assertEquals(3, v1.query().direction(OUT).labels("bought").has("time", Cmp.GREATER_THAN, 0).edgeCount());
    assertEquals(2, v1.query().direction(OUT).labels("bought").has("time", Cmp.LESS_THAN, 3).edgeCount());
    assertEquals(1, v1.query().direction(OUT).labels("bought").has("time", Cmp.GREATER_THAN, 2).edgeCount());
    assertEquals(2, v1.query().direction(OUT).labels("bought").hasNot("time").edgeCount());
    assertEquals(5, v1.query().direction(OUT).labels("bought").edgeCount());
}
Also used : TitanVertex(com.thinkaurelius.titan.core.TitanVertex) EdgeLabel(com.thinkaurelius.titan.core.EdgeLabel) PropertyKey(com.thinkaurelius.titan.core.PropertyKey) Test(org.junit.Test)

Example 18 with EdgeLabel

use of com.thinkaurelius.titan.core.EdgeLabel 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)

Example 19 with EdgeLabel

use of com.thinkaurelius.titan.core.EdgeLabel in project titan by thinkaurelius.

the class TitanGraphTest method testEdgeTTLWithTransactions.

@Test
public void testEdgeTTLWithTransactions() throws Exception {
    if (!features.hasCellTTL()) {
        return;
    }
    EdgeLabel label1 = mgmt.makeEdgeLabel("likes").make();
    mgmt.setTTL(label1, Duration.ofSeconds(1));
    assertEquals(Duration.ofSeconds(1), mgmt.getTTL(label1));
    mgmt.commit();
    TitanVertex v1 = graph.addVertex(), v2 = graph.addVertex();
    v1.addEdge("likes", v2);
    // pre-commit state of the edge.  It is not yet subject to TTL
    assertNotEmpty(v1.query().direction(Direction.OUT).vertices());
    Thread.sleep(1001);
    // the edge should have expired by now, but only if it had been committed
    assertNotEmpty(v1.query().direction(Direction.OUT).vertices());
    graph.tx().commit();
    // still here, because we have just committed the edge.  Its countdown starts at the commit
    assertNotEmpty(v1.query().direction(Direction.OUT).vertices());
    Thread.sleep(1001);
    // the edge has expired in Cassandra, but still appears alive in this transaction
    assertNotEmpty(v1.query().direction(Direction.OUT).vertices());
    // syncing with the data store, we see that the edge has expired
    graph.tx().rollback();
    assertEmpty(v1.query().direction(Direction.OUT).vertices());
}
Also used : TitanVertex(com.thinkaurelius.titan.core.TitanVertex) EdgeLabel(com.thinkaurelius.titan.core.EdgeLabel) Test(org.junit.Test)

Example 20 with EdgeLabel

use of com.thinkaurelius.titan.core.EdgeLabel in project titan by thinkaurelius.

the class AbstractIndexManagementIT method testRepairRelationIndex.

@Test
public void testRepairRelationIndex() throws InterruptedException, BackendException, ExecutionException {
    tx.commit();
    mgmt.commit();
    // Load the "Graph of the Gods" sample data (WITHOUT mixed index coverage)
    GraphOfTheGodsFactory.loadWithoutMixedIndex(graph, true);
    // Create and enable a relation index on lives edges by reason
    TitanManagement m = graph.openManagement();
    PropertyKey reason = m.getPropertyKey("reason");
    EdgeLabel lives = m.getEdgeLabel("lives");
    m.buildEdgeIndex(lives, "livesByReason", Direction.BOTH, Order.decr, reason);
    m.commit();
    graph.tx().commit();
    // Block until the SchemaStatus transitions to REGISTERED
    assertTrue(ManagementSystem.awaitRelationIndexStatus(graph, "livesByReason", "lives").status(SchemaStatus.REGISTERED).call().getSucceeded());
    m = graph.openManagement();
    RelationTypeIndex index = m.getRelationIndex(m.getRelationType("lives"), "livesByReason");
    m.updateIndex(index, SchemaAction.ENABLE_INDEX);
    m.commit();
    graph.tx().commit();
    // Block until the SchemaStatus transitions to ENABLED
    assertTrue(ManagementSystem.awaitRelationIndexStatus(graph, "livesByReason", "lives").status(SchemaStatus.ENABLED).call().getSucceeded());
    // Run a query that hits the index but erroneously returns nothing because we haven't repaired yet
    //assertFalse(graph.query().has("reason", "no fear of death").edges().iterator().hasNext());
    // Repair
    MapReduceIndexManagement mri = new MapReduceIndexManagement(graph);
    m = graph.openManagement();
    index = m.getRelationIndex(m.getRelationType("lives"), "livesByReason");
    ScanMetrics metrics = mri.updateIndex(index, SchemaAction.REINDEX).get();
    assertEquals(8, metrics.getCustom(IndexRepairJob.ADDED_RECORDS_COUNT));
}
Also used : EdgeLabel(com.thinkaurelius.titan.core.EdgeLabel) ScanMetrics(com.thinkaurelius.titan.diskstorage.keycolumnvalue.scan.ScanMetrics) TitanManagement(com.thinkaurelius.titan.core.schema.TitanManagement) RelationTypeIndex(com.thinkaurelius.titan.core.schema.RelationTypeIndex) PropertyKey(com.thinkaurelius.titan.core.PropertyKey) Test(org.junit.Test) TitanGraphBaseTest(com.thinkaurelius.titan.graphdb.TitanGraphBaseTest)

Aggregations

EdgeLabel (com.thinkaurelius.titan.core.EdgeLabel)23 PropertyKey (com.thinkaurelius.titan.core.PropertyKey)18 TitanVertex (com.thinkaurelius.titan.core.TitanVertex)18 Test (org.junit.Test)18 TitanEdge (com.thinkaurelius.titan.core.TitanEdge)8 Edge (org.apache.tinkerpop.gremlin.structure.Edge)8 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)6 TitanTransaction (com.thinkaurelius.titan.core.TitanTransaction)5 TitanVertexProperty (com.thinkaurelius.titan.core.TitanVertexProperty)5 TitanGraphIndex (com.thinkaurelius.titan.core.schema.TitanGraphIndex)5 VertexLabel (com.thinkaurelius.titan.core.VertexLabel)4 RelationTypeIndex (com.thinkaurelius.titan.core.schema.RelationTypeIndex)4 BaseVertexLabel (com.thinkaurelius.titan.graphdb.types.system.BaseVertexLabel)4 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)4 VertexProperty (org.apache.tinkerpop.gremlin.structure.VertexProperty)4 InternalRelationType (com.thinkaurelius.titan.graphdb.internal.InternalRelationType)3 StandardEdgeLabelMaker (com.thinkaurelius.titan.graphdb.types.StandardEdgeLabelMaker)3 SchemaViolationException (com.thinkaurelius.titan.core.SchemaViolationException)2 VertexList (com.thinkaurelius.titan.core.VertexList)2 Change (com.thinkaurelius.titan.core.log.Change)2