use of org.janusgraph.testutil.FeatureFlag in project janusgraph by JanusGraph.
the class JanusGraphTest method testEdgeTTLTiming.
/* ==================================================================================
TIME TO LIVE
==================================================================================*/
@Test
@FeatureFlag(feature = JanusGraphFeature.CellTtl)
public void testEdgeTTLTiming() throws Exception {
EdgeLabel label1 = mgmt.makeEdgeLabel("likes").make();
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));
assertEquals(Duration.ofSeconds(ttl2), mgmt.getTTL(label2));
assertEquals(Duration.ZERO, mgmt.getTTL(label3));
mgmt.commit();
JanusGraphVertex v1 = graph.addVertex(), v2 = graph.addVertex(), v3 = graph.addVertex();
v1.addEdge("likes", v2);
v2.addEdge("dislikes", v1);
v3.addEdge("indifferentTo", v1);
// initial, pre-commit state of the edges. They are not yet subject to TTL
assertNotEmpty(v1.query().direction(Direction.OUT).vertices());
assertNotEmpty(v2.query().direction(Direction.OUT).vertices());
assertNotEmpty(v3.query().direction(Direction.OUT).vertices());
long commitTime = System.currentTimeMillis();
graph.tx().commit();
// edges are now subject to TTL, although we must commit() or rollback() to see it
assertNotEmpty(v1.query().direction(Direction.OUT).vertices());
assertNotEmpty(v2.query().direction(Direction.OUT).vertices());
assertNotEmpty(v3.query().direction(Direction.OUT).vertices());
Thread.sleep(commitTime + (ttl1 * 1000L + 200) - System.currentTimeMillis());
graph.tx().rollback();
// e1 has dropped out
assertEmpty(v1.query().direction(Direction.OUT).vertices());
assertNotEmpty(v2.query().direction(Direction.OUT).vertices());
assertNotEmpty(v3.query().direction(Direction.OUT).vertices());
Thread.sleep(commitTime + (ttl2 * 1000L + 500) - System.currentTimeMillis());
graph.tx().rollback();
// both e1 and e2 have dropped out. e3 has no TTL, and so remains
assertEmpty(v1.query().direction(Direction.OUT).vertices());
assertEmpty(v2.query().direction(Direction.OUT).vertices());
assertNotEmpty(v3.query().direction(Direction.OUT).vertices());
}
use of org.janusgraph.testutil.FeatureFlag in project janusgraph by JanusGraph.
the class CQLStoreTest method testGetKeysWithoutUnorderedScan.
@Test
@FeatureFlag(feature = JanusGraphFeature.OrderedScan)
public void testGetKeysWithoutUnorderedScan() throws BackendException, NoSuchFieldException, IllegalAccessException {
// support ordered scan but not unordered scan
Field field = StandardStoreFeatures.class.getDeclaredField("unorderedScan");
field.setAccessible(true);
Field modifiersField = Field.class.getDeclaredField("modifiers");
modifiersField.setAccessible(true);
modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL);
field.set(manager.getFeatures(), false);
Exception ex = assertThrows(PermanentBackendException.class, () -> store.getKeys(new SliceQuery(BufferUtil.zeroBuffer(1), BufferUtil.oneBuffer(4)), tx));
assertEquals("This operation is only allowed when partitioner supports unordered scan", ex.getMessage());
assertDoesNotThrow(() -> store.getKeys(new KeyRangeQuery(BufferUtil.getLongBuffer(1), BufferUtil.getLongBuffer(1000), BufferUtil.getLongBuffer(1), BufferUtil.getLongBuffer(1000)), tx));
}
Aggregations