@Test(expected = IllegalArgumentException.class) public void testGetTTLFromUnsupportedType() throws Exception { if (!features.hasCellTTL()) { throw new IllegalArgumentException(); } TitanSchemaType type = ImplicitKey.ID; mgmt.getTTL(type); }
@Test public void testGettingUndefinedVertexLabelTTL() { if (!features.hasCellTTL()) { return; } // getTTL should return a null duration on an extant type without a TTL mgmt.makeVertexLabel("foo").make(); mgmt.commit(); graph.tx().rollback(); // Check getTTL on vertex label mgmt = graph.openManagement(); assertEquals(Duration.ZERO, mgmt.getTTL(mgmt.getVertexLabel("foo"))); mgmt.rollback(); }
@Test public void testGettingUndefinedEdgeLabelTTL() { if (!features.hasCellTTL()) { return; } // getTTL should return a null duration on an extant type without a TTL mgmt.makeEdgeLabel("likes").make(); mgmt.commit(); graph.tx().rollback(); // Check getTTL on edge label mgmt = graph.openManagement(); assertEquals(Duration.ZERO, mgmt.getTTL(mgmt.getEdgeLabel("likes"))); mgmt.rollback(); }
@Test public void testVertexTTLWithCompositeIndex() throws Exception { if (!features.hasCellTTL()) { return; } PropertyKey name = mgmt.makePropertyKey("name").dataType(String.class).make(); PropertyKey time = mgmt.makePropertyKey("time").dataType(Long.class).make(); TitanGraphIndex index1 = mgmt.buildIndex("index1", Vertex.class).addKey(name).buildCompositeIndex(); TitanGraphIndex index2 = mgmt.buildIndex("index2", Vertex.class).addKey(name).addKey(time).buildCompositeIndex(); VertexLabel label1 = mgmt.makeVertexLabel("event").setStatic().make(); mgmt.setTTL(label1, Duration.ofSeconds(1)); assertEquals(Duration.ZERO, mgmt.getTTL(name)); assertEquals(Duration.ZERO, mgmt.getTTL(time)); assertEquals(Duration.ofSeconds(1), mgmt.getTTL(label1)); mgmt.commit(); TitanVertex v1 = tx.addVertex(T.label, "event", "name", "some event", "time", System.currentTimeMillis()); tx.commit(); Object id = v1.id(); v1 = getV(graph, id); assertNotNull(v1); assertNotEmpty(graph.query().has("name", "some event").vertices()); Thread.sleep(1001); graph.tx().rollback(); v1 = getV(graph, id); assertNull(v1); assertEmpty(graph.query().has("name", "some event").vertices()); }
VertexLabel label1 = mgmt.makeVertexLabel("event").setStatic().make(); mgmt.setTTL(label1, Duration.ofSeconds(ttl1)); assertEquals(Duration.ofSeconds(ttl1), mgmt.getTTL(label1)); mgmt.commit();
VertexLabel label1 = mgmt.makeVertexLabel("event").setStatic().make(); mgmt.setTTL(label1, Duration.ofSeconds(2)); assertEquals(Duration.ofSeconds(42), mgmt.getTTL(name)); assertEquals(Duration.ofSeconds(1), mgmt.getTTL(place)); assertEquals(Duration.ofSeconds(2), mgmt.getTTL(label1)); mgmt.commit();
@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()); }
VertexLabel label1 = mgmt.makeVertexLabel("person").setStatic().make(); mgmt.setTTL(label1, Duration.ofSeconds(2)); assertEquals(Duration.ofSeconds(42), mgmt.getTTL(likes)); assertEquals(Duration.ofSeconds(1), mgmt.getTTL(dislikes)); assertEquals(Duration.ZERO, mgmt.getTTL(indifferentTo)); assertEquals(Duration.ofSeconds(2), mgmt.getTTL(label1)); mgmt.commit();
@Test(expected = IllegalArgumentException.class) public void testGetTTLFromUnsupportedType() throws Exception { if (!features.hasCellTTL()) { throw new IllegalArgumentException(); } TitanSchemaType type = ImplicitKey.ID; mgmt.getTTL(type); }
@Test public void testEdgeTTLWithTransactions() throws Exception { if (!features.hasCellTTL()) { return; } EdgeLabel label1 = mgmt.makeEdgeLabel("likes").make(); mgmt.setTTL(label1, 1, TimeUnit.SECONDS); assertEquals(1, mgmt.getTTL(label1).getLength(TimeUnit.SECONDS)); mgmt.commit(); Vertex v1 = graph.addVertex(null), v2 = graph.addVertex(null); graph.addEdge(null, v1, v2, "likes"); // pre-commit state of the edge. It is not yet subject to TTL assertTrue(v1.getVertices(Direction.OUT).iterator().hasNext()); Thread.sleep(1001); // the edge should have expired by now, but only if it had been committed assertTrue(v1.getVertices(Direction.OUT).iterator().hasNext()); graph.commit(); // still here, because we have just committed the edge. Its countdown starts at the commit assertTrue(v1.getVertices(Direction.OUT).iterator().hasNext()); Thread.sleep(1001); // the edge has expired in Cassandra, but still appears alive in this transaction assertTrue(v1.getVertices(Direction.OUT).iterator().hasNext()); // syncing with the data store, we see that the edge has expired graph.rollback(); assertFalse(v1.getVertices(Direction.OUT).iterator().hasNext()); }
@Test public void testEdgeTTLWithCompositeIndex() throws Exception { if (!features.hasCellTTL()) { return; } PropertyKey edgeName = mgmt.makePropertyKey("edge-name").dataType(String.class).make(); mgmt.buildIndex("edge-name", Edge.class).addKey(edgeName).buildCompositeIndex(); EdgeLabel label = mgmt.makeEdgeLabel("likes").make(); mgmt.setTTL(label, 1, TimeUnit.SECONDS); assertEquals(0, mgmt.getTTL(edgeName).getLength(TimeUnit.SECONDS)); assertEquals(1, mgmt.getTTL(label).getLength(TimeUnit.SECONDS)); mgmt.commit(); Vertex v1 = graph.addVertex(null), v2 = graph.addVertex(null); Edge e = graph.addEdge(null, v1, v2, "likes"); e.setProperty("edge-name", "v1-likes-v2"); graph.commit(); assertTrue(v1.getEdges(Direction.OUT).iterator().hasNext()); assertTrue(graph.getEdges("edge-name", "v1-likes-v2").iterator().hasNext()); Thread.sleep(1001); graph.rollback(); // the edge is gone not only from its previous endpoints, but also from key indices assertFalse(graph.getEdges("edge-name", "v1-likes-v2").iterator().hasNext()); assertFalse(v1.getEdges(Direction.OUT).iterator().hasNext()); }
@Category({ BrittleTests.class }) @Test public void testEdgeTTLWithVertexCentricIndex() throws Exception { if (!features.hasCellTTL()) { return; } int ttl = 1; // artificially low TTL for test final PropertyKey time = mgmt.makePropertyKey("time").dataType(Integer.class).make(); EdgeLabel wavedAt = mgmt.makeEdgeLabel("wavedAt").signature(time).make(); mgmt.buildEdgeIndex(wavedAt, "timeindex", Direction.BOTH, Order.DESC, time); mgmt.setTTL(wavedAt, ttl, TimeUnit.SECONDS); assertEquals(0, mgmt.getTTL(time).getLength(TimeUnit.SECONDS)); assertEquals(ttl, mgmt.getTTL(wavedAt).getLength(TimeUnit.SECONDS)); mgmt.commit(); Vertex v1 = graph.addVertex(null), v2 = graph.addVertex(null); Edge e1 = graph.addEdge(null, v1, v2, "wavedAt"); e1.setProperty("time", 42); assertTrue(v1.getEdges(Direction.OUT).iterator().hasNext()); assertTrue(v1.query().direction(Direction.OUT).interval("time", 0, 100).edges().iterator().hasNext()); graph.commit(); long commitTime = System.currentTimeMillis(); assertTrue(v1.getEdges(Direction.OUT).iterator().hasNext()); assertTrue(v1.query().direction(Direction.OUT).interval("time", 0, 100).edges().iterator().hasNext()); Thread.sleep(commitTime + (ttl * 1000L + 100) - System.currentTimeMillis()); graph.rollback(); assertFalse(v1.getEdges(Direction.OUT).iterator().hasNext()); assertFalse(v1.query().direction(Direction.OUT).interval("time", 0, 100).edges().iterator().hasNext()); }
@Test public void testVertexTTLWithCompositeIndex() throws Exception { if (!features.hasCellTTL()) { return; } PropertyKey name = mgmt.makePropertyKey("name").dataType(String.class).make(); PropertyKey time = mgmt.makePropertyKey("time").dataType(Long.class).make(); TitanGraphIndex index1 = mgmt.buildIndex("index1", Vertex.class).addKey(name).buildCompositeIndex(); TitanGraphIndex index2 = mgmt.buildIndex("index2", Vertex.class).addKey(name).addKey(time).buildCompositeIndex(); VertexLabel label1 = mgmt.makeVertexLabel("event").setStatic().make(); mgmt.setTTL(label1, 1, TimeUnit.SECONDS); assertEquals(0, mgmt.getTTL(name).getLength(TimeUnit.SECONDS)); assertEquals(0, mgmt.getTTL(time).getLength(TimeUnit.SECONDS)); assertEquals(1, mgmt.getTTL(label1).getLength(TimeUnit.SECONDS)); mgmt.commit(); Vertex v1 = tx.addVertexWithLabel("event"); v1.setProperty("name", "some event"); v1.setProperty("time", System.currentTimeMillis()); tx.commit(); Object id = v1.getId(); v1 = graph.getVertex(id); assertNotNull(v1); assertTrue(graph.getVertices("name", "some event").iterator().hasNext()); Thread.sleep(1001); graph.rollback(); v1 = graph.getVertex(id); assertNull(v1); assertFalse(graph.getVertices("name", "some event").iterator().hasNext()); }
VertexLabel label1 = mgmt.makeVertexLabel("event").setStatic().make(); mgmt.setTTL(label1, ttl1, TimeUnit.SECONDS); assertEquals(ttl1, mgmt.getTTL(label1).getLength(TimeUnit.SECONDS)); mgmt.commit();