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));
});
}
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);
}
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);
}
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());
}
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);
}
Aggregations