Search in sources :

Example 21 with FeatureFlag

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());
}
Also used : JanusGraphVertex(org.janusgraph.core.JanusGraphVertex) EdgeLabel(org.janusgraph.core.EdgeLabel) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test) FeatureFlag(org.janusgraph.testutil.FeatureFlag)

Example 22 with FeatureFlag

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));
}
Also used : Field(java.lang.reflect.Field) KeyRangeQuery(org.janusgraph.diskstorage.keycolumnvalue.KeyRangeQuery) BackendException(org.janusgraph.diskstorage.BackendException) PermanentBackendException(org.janusgraph.diskstorage.PermanentBackendException) SliceQuery(org.janusgraph.diskstorage.keycolumnvalue.SliceQuery) KeyColumnValueStoreTest(org.janusgraph.diskstorage.KeyColumnValueStoreTest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) FeatureFlag(org.janusgraph.testutil.FeatureFlag)

Aggregations

FeatureFlag (org.janusgraph.testutil.FeatureFlag)22 Test (org.junit.jupiter.api.Test)22 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)16 JanusGraphVertex (org.janusgraph.core.JanusGraphVertex)9 JanusGraphBaseStoreFeaturesTest (org.janusgraph.JanusGraphBaseStoreFeaturesTest)6 EdgeLabel (org.janusgraph.core.EdgeLabel)6 VertexLabel (org.janusgraph.core.VertexLabel)5 KeyIterator (org.janusgraph.diskstorage.keycolumnvalue.KeyIterator)5 KeyRangeQuery (org.janusgraph.diskstorage.keycolumnvalue.KeyRangeQuery)5 SliceQuery (org.janusgraph.diskstorage.keycolumnvalue.SliceQuery)5 BaseVertexLabel (org.janusgraph.graphdb.types.system.BaseVertexLabel)5 KeyColumnValueStoreTest (org.janusgraph.diskstorage.KeyColumnValueStoreTest)4 KeySliceQuery (org.janusgraph.diskstorage.keycolumnvalue.KeySliceQuery)4 Tag (org.junit.jupiter.api.Tag)4 PropertyKey (org.janusgraph.core.PropertyKey)3 Field (java.lang.reflect.Field)2 Duration (java.time.Duration)2 Edge (org.apache.tinkerpop.gremlin.structure.Edge)2 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)2 JanusGraphEdge (org.janusgraph.core.JanusGraphEdge)2