Search in sources :

Example 6 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 7 with FeatureFlag

use of org.janusgraph.testutil.FeatureFlag in project janusgraph by JanusGraph.

the class KeyColumnValueStoreTest method testOrderedGetKeysRespectsKeyLimit.

/**
 * Verify that
 * {@link KeyColumnValueStore#getKeys(KeyRangeQuery, StoreTransaction)}
 * treats the lower key bound as inclusive and the upper key bound as
 * exclusive. Verify that keys less than the start and greater than or equal
 * to the end containing matching columns are not returned.
 *
 * @throws BackendException
 */
@Test
@FeatureFlag(feature = JanusGraphFeature.OrderedScan)
public void testOrderedGetKeysRespectsKeyLimit(TestInfo testInfo) throws BackendException {
    Preconditions.checkState(4 <= numKeys && 4 <= numColumns);
    final long minKey = KeyValueStoreUtil.idOffset + 1;
    final long maxKey = KeyValueStoreUtil.idOffset + numKeys - 2;
    final long expectedKeyCount = maxKey - minKey;
    String[][] values = generateValues();
    loadValues(values);
    final SliceQuery columnSlice = new SliceQuery(BufferUtil.zeroBuffer(8), BufferUtil.oneBuffer(8)).setLimit(1);
    KeyIterator keys;
    keys = store.getKeys(new KeyRangeQuery(BufferUtil.getLongBuffer(minKey), BufferUtil.getLongBuffer(maxKey), columnSlice), tx);
    assertEquals(expectedKeyCount, KeyValueStoreUtil.count(keys));
    clopen();
    keys = store.getKeys(new KeyRangeQuery(BufferUtil.getLongBuffer(minKey), BufferUtil.getLongBuffer(maxKey), columnSlice), tx);
    assertEquals(expectedKeyCount, KeyValueStoreUtil.count(keys));
}
Also used : KeyRangeQuery(org.janusgraph.diskstorage.keycolumnvalue.KeyRangeQuery) KeyIterator(org.janusgraph.diskstorage.keycolumnvalue.KeyIterator) SliceQuery(org.janusgraph.diskstorage.keycolumnvalue.SliceQuery) KeySliceQuery(org.janusgraph.diskstorage.keycolumnvalue.KeySliceQuery) Test(org.junit.jupiter.api.Test) JanusGraphBaseStoreFeaturesTest(org.janusgraph.JanusGraphBaseStoreFeaturesTest) FeatureFlag(org.janusgraph.testutil.FeatureFlag)

Example 8 with FeatureFlag

use of org.janusgraph.testutil.FeatureFlag in project janusgraph by JanusGraph.

the class KeyColumnValueStoreTest method testGetKeysWithSliceQuery.

@Test
@FeatureFlag(feature = JanusGraphFeature.UnorderedScan)
public void testGetKeysWithSliceQuery(TestInfo testInfo) throws Exception {
    populateDBWith100Keys();
    tx.commit();
    tx = startTx();
    KeyIterator keyIterator = store.getKeys(new SliceQuery(new ReadArrayBuffer("b".getBytes()), new ReadArrayBuffer("c".getBytes())), tx);
    examineGetKeysResults(keyIterator, 0, 100);
}
Also used : KeyIterator(org.janusgraph.diskstorage.keycolumnvalue.KeyIterator) ReadArrayBuffer(org.janusgraph.diskstorage.util.ReadArrayBuffer) SliceQuery(org.janusgraph.diskstorage.keycolumnvalue.SliceQuery) KeySliceQuery(org.janusgraph.diskstorage.keycolumnvalue.KeySliceQuery) Test(org.junit.jupiter.api.Test) JanusGraphBaseStoreFeaturesTest(org.janusgraph.JanusGraphBaseStoreFeaturesTest) FeatureFlag(org.janusgraph.testutil.FeatureFlag)

Example 9 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 10 with FeatureFlag

use of org.janusgraph.testutil.FeatureFlag in project janusgraph by JanusGraph.

the class JanusGraphTest method testVertexTTLWithCompositeIndex.

@Test
@FeatureFlag(feature = JanusGraphFeature.CellTtl)
public void testVertexTTLWithCompositeIndex() throws Exception {
    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());
}
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)

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