Search in sources :

Example 1 with FeatureFlag

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();
}
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 2 with FeatureFlag

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);
}
Also used : CacheVertex(org.janusgraph.graphdb.vertices.CacheVertex) JanusGraphVertex(org.janusgraph.core.JanusGraphVertex) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) VertexLabel(org.janusgraph.core.VertexLabel) BaseVertexLabel(org.janusgraph.graphdb.types.system.BaseVertexLabel) JanusGraphVertex(org.janusgraph.core.JanusGraphVertex) JanusGraphIndex(org.janusgraph.core.schema.JanusGraphIndex) PropertyKey(org.janusgraph.core.PropertyKey) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test) FeatureFlag(org.janusgraph.testutil.FeatureFlag) Tag(org.junit.jupiter.api.Tag)

Example 3 with FeatureFlag

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());
}
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 4 with FeatureFlag

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

Example 5 with FeatureFlag

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());
}
Also used : StandardStoreFeatures(org.janusgraph.diskstorage.keycolumnvalue.StandardStoreFeatures) StoreFeatures(org.janusgraph.diskstorage.keycolumnvalue.StoreFeatures) 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