@Test(expected = IllegalArgumentException.class) public void testSettingTTLOnUnsupportedType() throws Exception { if (!features.hasCellTTL()) { throw new IllegalArgumentException(); } TitanSchemaType type = ImplicitKey.ID; mgmt.setTTL(type, Duration.ZERO); }
@Test(expected = IllegalArgumentException.class) public void testSettingTTLOnNonStaticVertexLabel() throws Exception { if (!features.hasCellTTL()) { throw new IllegalArgumentException(); } VertexLabel label1 = mgmt.makeVertexLabel("event").make(); mgmt.setTTL(label1, Duration.ofSeconds(42)); }
mgmt.setTTL(label1, Duration.ofSeconds(ttl1)); assertEquals(Duration.ofSeconds(ttl1), mgmt.getTTL(label1)); mgmt.commit();
mgmt.buildEdgeIndex(wavedAt, "timeindex", Direction.BOTH, decr, time); mgmt.buildIndex("edge-time", Edge.class).addKey(time).buildCompositeIndex(); mgmt.setTTL(wavedAt, Duration.ofSeconds(ttl)); assertEquals(Duration.ZERO, mgmt.getTTL(time)); assertEquals(Duration.ofSeconds(ttl), mgmt.getTTL(wavedAt));
@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()); }
mgmt.setTTL(name, Duration.ofSeconds(42)); mgmt.setTTL(place, Duration.ofSeconds(1)); TitanGraphIndex index1 = mgmt.buildIndex("index1", Vertex.class).addKey(name).buildCompositeIndex(); TitanGraphIndex index2 = mgmt.buildIndex("index2", Vertex.class).addKey(name).addKey(place).buildCompositeIndex(); 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));
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));
@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()); }
mgmt.setTTL(event, Duration.ofSeconds(eventTTLSeconds));
mgmt.setTTL(likes, Duration.ofSeconds(42)); // long edge TTL will be overridden by short vertex TTL EdgeLabel dislikes = mgmt.makeEdgeLabel("dislikes").make(); mgmt.setTTL(dislikes, Duration.ofSeconds(1)); EdgeLabel indifferentTo = mgmt.makeEdgeLabel("indifferentTo").make(); 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));
EdgeLabel likes = mgmt.makeEdgeLabel("likes").make(); EdgeLabel hasLiked = mgmt.makeEdgeLabel("hasLiked").make(); mgmt.setTTL(likes, Duration.ofSeconds(ttl)); assertEquals(Duration.ofSeconds(ttl), mgmt.getTTL(likes)); assertEquals(Duration.ZERO, mgmt.getTTL(hasLiked));
mgmt.setTTL(label, Duration.ofSeconds(likesTTLSeconds));
@Test(expected = IllegalArgumentException.class) public void testSettingTTLOnUnsupportedType() throws Exception { if (!features.hasCellTTL()) { throw new IllegalArgumentException(); } TitanSchemaType type = ImplicitKey.ID; mgmt.setTTL(type, 0, TimeUnit.SECONDS); }
@Test(expected = IllegalArgumentException.class) public void testSettingTTLOnNonStaticVertexLabel() throws Exception { if (!features.hasCellTTL()) { throw new IllegalArgumentException(); } VertexLabel label1 = mgmt.makeVertexLabel("event").make(); mgmt.setTTL(label1, 42, TimeUnit.SECONDS); }
@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()); }
@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 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()); }
@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()); }
mgmt.setTTL(label1, ttl1, TimeUnit.SECONDS); assertEquals(ttl1, mgmt.getTTL(label1).getLength(TimeUnit.SECONDS)); mgmt.commit();