use of org.janusgraph.testutil.FeatureFlag in project janusgraph by JanusGraph.
the class JanusGraphTest method testUnsettingTTL.
@Test
@FeatureFlag(feature = JanusGraphFeature.CellTtl)
public void testUnsettingTTL() throws InterruptedException {
int initialTTLMillis = 2000;
// Define schema: one edge label with a short ttl
EdgeLabel likes = mgmt.makeEdgeLabel("likes").make();
mgmt.setTTL(likes, Duration.ofMillis(initialTTLMillis));
mgmt.commit();
graph.tx().rollback();
// Insert two vertices with a TTLed edge
JanusGraphVertex v1 = graph.addVertex();
JanusGraphVertex v2 = graph.addVertex();
v1.addEdge("likes", v2);
graph.tx().commit();
// Let the edge die
Thread.sleep((long) Math.ceil(initialTTLMillis * 1.25));
// Edge should be gone
assertEquals(2, Iterators.size(graph.vertices()));
assertEquals(0, Iterators.size(graph.edges()));
graph.tx().rollback();
// Remove the TTL on the edge label
mgmt = graph.openManagement();
mgmt.setTTL(mgmt.getEdgeLabel("likes"), Duration.ZERO);
mgmt.commit();
Thread.sleep(1L);
// Check that the edge is still gone, add a new edge
assertEquals(2, Iterators.size(graph.vertices()));
assertEquals(0, Iterators.size(graph.edges()));
v1 = graph.addVertex();
v2 = graph.addVertex();
v1.addEdge("likes", v2);
graph.tx().commit();
// Sleep past when it would have expired under the original config
Thread.sleep((long) Math.ceil(initialTTLMillis * 1.25));
// Edge must not be dead
assertEquals(4, Iterators.size(graph.vertices()));
assertEquals(1, Iterators.size(graph.edges()));
graph.tx().rollback();
}
use of org.janusgraph.testutil.FeatureFlag in project janusgraph by JanusGraph.
the class JanusGraphTest method testPropertyTTLTiming.
@Test
@Tag(TestCategory.BRITTLE_TESTS)
@FeatureFlag(feature = JanusGraphFeature.CellTtl)
public void testPropertyTTLTiming() throws Exception {
PropertyKey name = mgmt.makePropertyKey("name").dataType(String.class).make();
PropertyKey place = mgmt.makePropertyKey("place").dataType(String.class).make();
mgmt.setTTL(name, Duration.ofSeconds(42));
mgmt.setTTL(place, Duration.ofSeconds(1));
final JanusGraphIndex index1 = mgmt.buildIndex("index1", Vertex.class).addKey(name).buildCompositeIndex();
final JanusGraphIndex 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));
assertEquals(Duration.ofSeconds(2), mgmt.getTTL(label1));
mgmt.commit();
JanusGraphVertex v1 = tx.addVertex(T.label, "event", "name", "some event", "place", "somewhere");
tx.commit();
Object id = v1.id();
v1 = getV(graph, id);
assertNotNull(v1);
assertNotEmpty(graph.query().has("name", "some event").has("place", "somewhere").vertices());
assertNotEmpty(graph.query().has("name", "some event").vertices());
Thread.sleep(1001);
graph.tx().rollback();
// short-lived property expires first
v1 = getV(graph, id);
assertNotNull(v1);
assertEmpty(graph.query().has("name", "some event").has("place", "somewhere").vertices());
assertNotEmpty(graph.query().has("name", "some event").vertices());
Thread.sleep(1001);
graph.tx().rollback();
// vertex expires before defined TTL of the long-lived property
assertEmpty(graph.query().has("name", "some event").has("place", "somewhere").vertices());
assertEmpty(graph.query().has("name", "some event").vertices());
v1 = getV(graph, id);
assertNull(v1);
}
use of org.janusgraph.testutil.FeatureFlag in project janusgraph by JanusGraph.
the class JanusGraphTest method testEdgeTTLWithTransactions.
@Test
@FeatureFlag(feature = JanusGraphFeature.CellTtl)
public void testEdgeTTLWithTransactions() throws Exception {
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());
}
use of org.janusgraph.testutil.FeatureFlag in project janusgraph by JanusGraph.
the class JanusGraphTest method testEdgeTTLWithIndex.
@Test
@Tag(TestCategory.BRITTLE_TESTS)
@FeatureFlag(feature = JanusGraphFeature.CellTtl)
public void testEdgeTTLWithIndex() throws Exception {
// artificially low TTL for test
int ttl = 1;
final PropertyKey time = mgmt.makePropertyKey("time").dataType(Integer.class).make();
EdgeLabel wavedAt = mgmt.makeEdgeLabel("wavedAt").signature(time).make();
mgmt.buildEdgeIndex(wavedAt, "timeindex", Direction.BOTH, desc, 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.commit();
JanusGraphVertex v1 = graph.addVertex(), v2 = graph.addVertex();
v1.addEdge("wavedAt", v2, "time", 42);
assertTrue(v1.query().direction(Direction.OUT).interval("time", 0, 100).edges().iterator().hasNext());
assertNotEmpty(v1.query().direction(Direction.OUT).edges());
assertNotEmpty(graph.query().has("time", 42).edges());
graph.tx().commit();
long commitTime = System.currentTimeMillis();
assertTrue(v1.query().direction(Direction.OUT).interval("time", 0, 100).edges().iterator().hasNext());
assertNotEmpty(v1.query().direction(Direction.OUT).edges());
assertNotEmpty(graph.query().has("time", 42).edges());
Thread.sleep(commitTime + (ttl * 1000L + 100) - System.currentTimeMillis());
graph.tx().rollback();
assertFalse(v1.query().direction(Direction.OUT).interval("time", 0, 100).edges().iterator().hasNext());
assertEmpty(v1.query().direction(Direction.OUT).edges());
assertEmpty(graph.query().has("time", 42).edges());
}
use of org.janusgraph.testutil.FeatureFlag in project janusgraph by JanusGraph.
the class CQLStoreTest method testUnorderedConfiguration.
@Test
@FeatureFlag(feature = JanusGraphFeature.UnorderedScan)
public void testUnorderedConfiguration(TestInfo testInfo) {
final StoreFeatures features = this.manager.getFeatures();
assertFalse(features.hasLocalKeyPartition());
}
Aggregations