@Test(expected = IllegalArgumentException.class) public void testGetTTLFromUnsupportedType() { if (!features.hasCellTTL()) { throw new IllegalArgumentException(); } JanusGraphSchemaType type = ImplicitKey.ID; mgmt.getTTL(type); }
@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(); 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()); }
@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 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); }
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(); 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()); }
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();