Search in sources :

Example 11 with FeatureFlag

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

the class JanusGraphTest method testSettingTTLOnNonStaticVertexLabel.

@Test
@FeatureFlag(feature = JanusGraphFeature.CellTtl)
public void testSettingTTLOnNonStaticVertexLabel() {
    assertThrows(IllegalArgumentException.class, () -> {
        VertexLabel label1 = mgmt.makeVertexLabel("event").make();
        mgmt.setTTL(label1, Duration.ofSeconds(42));
    });
}
Also used : VertexLabel(org.janusgraph.core.VertexLabel) BaseVertexLabel(org.janusgraph.graphdb.types.system.BaseVertexLabel) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test) FeatureFlag(org.janusgraph.testutil.FeatureFlag)

Example 12 with FeatureFlag

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

the class JanusGraphTest method testEdgeTTLImplicitKey.

@Test
@FeatureFlag(feature = JanusGraphFeature.CellTtl)
public void testEdgeTTLImplicitKey() throws Exception {
    Duration d;
    clopen(option(GraphDatabaseConfiguration.STORE_META_TTL, "edgestore"), true);
    assertEquals("~ttl", ImplicitKey.TTL.name());
    int ttl = 24 * 60 * 60;
    EdgeLabel likes = mgmt.makeEdgeLabel("likes").make();
    EdgeLabel hasLiked = mgmt.makeEdgeLabel("hasLiked").make();
    mgmt.setTTL(likes, Duration.ofSeconds(ttl));
    assertEquals(Duration.ofSeconds(ttl), mgmt.getTTL(likes));
    assertEquals(Duration.ZERO, mgmt.getTTL(hasLiked));
    mgmt.commit();
    JanusGraphVertex v1 = graph.addVertex(), v2 = graph.addVertex();
    Edge e1 = v1.addEdge("likes", v2);
    Edge e2 = v1.addEdge("hasLiked", v2);
    graph.tx().commit();
    // read from the edge created in this transaction
    d = e1.value("~ttl");
    assertEquals(Duration.ofDays(1), d);
    // get the edge via a vertex
    e1 = Iterables.getOnlyElement(v1.query().direction(Direction.OUT).labels("likes").edges());
    d = e1.value("~ttl");
    assertEquals(Duration.ofDays(1), d);
    // returned value of ^ttl is the total time to live since commit, not remaining time
    Thread.sleep(1001);
    graph.tx().rollback();
    e1 = Iterables.getOnlyElement(v1.query().direction(Direction.OUT).labels("likes").edges());
    d = e1.value("~ttl");
    assertEquals(Duration.ofDays(1), d);
    // no ttl on edges of this label
    d = e2.value("~ttl");
    assertEquals(Duration.ZERO, d);
}
Also used : JanusGraphVertex(org.janusgraph.core.JanusGraphVertex) EdgeLabel(org.janusgraph.core.EdgeLabel) Duration(java.time.Duration) AbstractEdge(org.janusgraph.graphdb.relations.AbstractEdge) JanusGraphEdge(org.janusgraph.core.JanusGraphEdge) Edge(org.apache.tinkerpop.gremlin.structure.Edge) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test) FeatureFlag(org.janusgraph.testutil.FeatureFlag)

Example 13 with FeatureFlag

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

the class KeyColumnValueStoreTest method scanTest.

/**
 * Loads a block of data where keys are longs on [idOffset, idOffset +
 * numKeys) and the columns are longs on [idOffset, idOffset + numColumns).
 * {@code idOffset} is {@link KeyValueStoreUtil#idOffset}. Note that
 * identical columns appear on every key. The loaded values are randomly
 * generated strings converted to bytes.
 * <p>
 * Calls the store's supported {@code getKeys} method depending on whether
 * it supports ordered or unordered scan. This logic is delegated to
 * {@link KCVSUtil#getKeys(KeyColumnValueStore, StoreFeatures, int, int, StoreTransaction)}
 * . That method uses all-zero and all-one buffers for the key and column
 * limits and retrieves every key.
 * <p>
 * This method does nothing and returns immediately if the store supports no
 * scans.
 */
@Test
@FeatureFlag(feature = JanusGraphFeature.Scan)
public void scanTest() throws BackendException {
    String[][] values = generateValues();
    loadValues(values);
    KeyIterator iterator0 = KCVSUtil.getKeys(store, storeFeatures(), 8, 4, tx);
    verifyIterator(iterator0, numKeys);
    clopen();
    KeyIterator iterator1 = KCVSUtil.getKeys(store, storeFeatures(), 8, 4, tx);
    KeyIterator iterator2 = KCVSUtil.getKeys(store, storeFeatures(), 8, 4, tx);
    // The idea is to open an iterator without using it
    // to make sure that closing a transaction will clean it up.
    // (important for BerkeleyJE where leaving cursors open causes exceptions)
    @SuppressWarnings("unused") KeyIterator iterator3 = KCVSUtil.getKeys(store, storeFeatures(), 8, 4, tx);
    verifyIterator(iterator1, numKeys);
    verifyIterator(iterator2, numKeys);
}
Also used : KeyIterator(org.janusgraph.diskstorage.keycolumnvalue.KeyIterator) Test(org.junit.jupiter.api.Test) JanusGraphBaseStoreFeaturesTest(org.janusgraph.JanusGraphBaseStoreFeaturesTest) FeatureFlag(org.janusgraph.testutil.FeatureFlag)

Example 14 with FeatureFlag

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

the class KeyColumnValueStoreTest method testTtl.

@Tag(TestCategory.BRITTLE_TESTS)
@Test
@FeatureFlag(feature = JanusGraphFeature.CellTtl)
public void testTtl() throws Exception {
    StaticBuffer key = KeyColumnValueStoreUtil.longToByteBuffer(0);
    int[] ttls = new int[] { 0, 1, 2 };
    final List<Entry> additions = new LinkedList<>();
    for (int i = 0; i < ttls.length; i++) {
        StaticBuffer col = KeyColumnValueStoreUtil.longToByteBuffer(i);
        StaticArrayEntry entry = (StaticArrayEntry) StaticArrayEntry.of(col, col);
        entry.setMetaData(EntryMetaData.TTL, ttls[i]);
        additions.add(entry);
    }
    store.mutate(key, additions, KeyColumnValueStore.NO_DELETIONS, tx);
    tx.commit();
    // commitTime starts just after the commit, so we won't check for expiration too early
    long commitTime = System.currentTimeMillis();
    tx = startTx();
    StaticBuffer columnStart = KeyColumnValueStoreUtil.longToByteBuffer(0);
    StaticBuffer columnEnd = KeyColumnValueStoreUtil.longToByteBuffer(ttls.length);
    List<Entry> result = store.getSlice(new KeySliceQuery(key, columnStart, columnEnd).setLimit(ttls.length), tx);
    assertEquals(ttls.length, result.size());
    // wait for one cell to expire
    Thread.sleep(commitTime + 1001 - System.currentTimeMillis());
    // cells immediately expire upon TTL, even before rollback()
    result = store.getSlice(new KeySliceQuery(key, columnStart, columnEnd).setLimit(ttls.length), tx);
    assertEquals(ttls.length - 1, result.size());
    tx.rollback();
    result = store.getSlice(new KeySliceQuery(key, columnStart, columnEnd).setLimit(ttls.length), tx);
    assertEquals(ttls.length - 1, result.size());
    Thread.sleep(commitTime + 2001 - System.currentTimeMillis());
    tx.rollback();
    result = store.getSlice(new KeySliceQuery(key, columnStart, columnEnd).setLimit(ttls.length), tx);
    assertEquals(ttls.length - 2, result.size());
    // cell 0 doesn't expire due to TTL of 0 (infinite)
    Thread.sleep(commitTime + 4001 - System.currentTimeMillis());
    tx.rollback();
    result = store.getSlice(new KeySliceQuery(key, columnStart, columnEnd).setLimit(ttls.length), tx);
    assertEquals(ttls.length - 2, result.size());
}
Also used : StaticArrayEntry(org.janusgraph.diskstorage.util.StaticArrayEntry) LinkedList(java.util.LinkedList) StaticArrayEntry(org.janusgraph.diskstorage.util.StaticArrayEntry) KeySliceQuery(org.janusgraph.diskstorage.keycolumnvalue.KeySliceQuery) Test(org.junit.jupiter.api.Test) JanusGraphBaseStoreFeaturesTest(org.janusgraph.JanusGraphBaseStoreFeaturesTest) FeatureFlag(org.janusgraph.testutil.FeatureFlag) Tag(org.junit.jupiter.api.Tag)

Example 15 with FeatureFlag

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

the class KeyColumnValueStoreTest method testGetKeysWithKeyRange.

@Test
@FeatureFlag(feature = JanusGraphFeature.OrderedScan)
public void testGetKeysWithKeyRange(TestInfo testInfo) throws Exception {
    populateDBWith100Keys();
    tx.commit();
    tx = startTx();
    KeyIterator keyIterator = store.getKeys(new KeyRangeQuery(// key start
    KeyColumnValueStoreUtil.longToByteBuffer(10), // key end
    KeyColumnValueStoreUtil.longToByteBuffer(40), // column start
    new ReadArrayBuffer("b".getBytes()), new ReadArrayBuffer("c".getBytes())), tx);
    examineGetKeysResults(keyIterator, 10, 40);
}
Also used : KeyRangeQuery(org.janusgraph.diskstorage.keycolumnvalue.KeyRangeQuery) KeyIterator(org.janusgraph.diskstorage.keycolumnvalue.KeyIterator) ReadArrayBuffer(org.janusgraph.diskstorage.util.ReadArrayBuffer) Test(org.junit.jupiter.api.Test) JanusGraphBaseStoreFeaturesTest(org.janusgraph.JanusGraphBaseStoreFeaturesTest) 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