@Test(expected = IllegalArgumentException.class) public void testSettingTTLOnUnsupportedType() { if (!features.hasCellTTL()) { throw new IllegalArgumentException(); } JanusGraphSchemaType type = ImplicitKey.ID; mgmt.setTTL(type, Duration.ZERO); }
@Test(expected = IllegalArgumentException.class) public void testSettingTTLOnNonStaticVertexLabel() { if (!features.hasCellTTL()) { throw new IllegalArgumentException(); } VertexLabel label1 = mgmt.makeVertexLabel("event").make(); mgmt.setTTL(label1, Duration.ofSeconds(42)); }
@Test public void testVertexTTLImplicitKey() throws Exception { Duration d; if (!features.hasCellTTL()) { return; } clopen(option(GraphDatabaseConfiguration.STORE_META_TTL, "edgestore"), true); int ttl1 = 1; VertexLabel label1 = mgmt.makeVertexLabel("event").setStatic().make(); mgmt.setTTL(label1, Duration.ofSeconds(ttl1)); assertEquals(Duration.ofSeconds(ttl1), mgmt.getTTL(label1)); mgmt.commit(); JanusGraphVertex v1 = tx.addVertex("event"); JanusGraphVertex v2 = tx.addVertex(); tx.commit(); /* TODO: this fails d = v1.getProperty("~ttl"); assertEquals(1, d); d = v2.getProperty("~ttl"); assertEquals(0, d); */ Object v1id = v1.id(); Object v2id = v2.id(); v1 = getV(graph, v1id); v2 = getV(graph, v2id); d = v1.value("~ttl"); assertEquals(Duration.ofSeconds(1), d); d = v2.value("~ttl"); assertEquals(Duration.ZERO, d); }
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));
mgmt.setTTL(name, Duration.ofSeconds(42)); mgmt.setTTL(place, Duration.ofSeconds(1)); final JanusGraphIndex index1 = mgmt.buildIndex("index1", Vertex.class).addKey(name) .buildCompositeIndex(); .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));
@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(); JanusGraphVertex 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()); }
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));
@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(); final JanusGraphIndex index1 = mgmt.buildIndex("index1", Vertex.class).addKey(name) .buildCompositeIndex(); final JanusGraphIndex 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(); JanusGraphVertex 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()); }
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));
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));
mgmt.setTTL(label, Duration.ofSeconds(likesTTLSeconds));