use of org.janusgraph.diskstorage.StaticBuffer in project janusgraph by JanusGraph.
the class ExpirationCacheTest method testGracePeriod.
private void testGracePeriod(Duration graceWait) throws Exception {
final int minCleanupTriggerCalls = 5;
final int numKeys = 100, numCols = 10;
loadStore(numKeys, numCols);
// Replace cache with proper times
cache = getCache(store, Duration.ofDays(200), graceWait);
final StaticBuffer key = BufferUtil.getIntBuffer(81);
final List<StaticBuffer> keys = new ArrayList<>();
keys.add(key);
keys.add(BufferUtil.getIntBuffer(37));
keys.add(BufferUtil.getIntBuffer(2));
SliceQuery query = getQuery(2, 8);
verifyResults(key, keys, query, 6);
// If we modify through cache store...
CacheTransaction tx = getCacheTx();
cache.mutateEntries(key, KeyColumnValueStore.NO_ADDITIONS, Lists.newArrayList(getEntry(4, 4)), tx);
tx.commit();
Instant utime = times.getTime();
store.resetCounter();
// ...invalidation should happen and the result set is updated immediately
verifyResults(key, keys, query, 5);
assertEquals(2, store.getSliceCalls());
// however, the key is expired and hence repeated calls need to go through to the store
verifyResults(key, keys, query, 5);
assertEquals(4, store.getSliceCalls());
// however, when we sleep past the grace wait time and trigger a cleanup...
times.sleepPast(utime.plus(graceWait));
for (int t = 0; t < minCleanupTriggerCalls; t++) {
assertEquals(5, cache.getSlice(new KeySliceQuery(key, query), tx).size());
times.sleepFor(Duration.ofMillis(5));
}
// ...the cache should cache results again
store.resetCounter();
verifyResults(key, keys, query, 5);
assertEquals(0, store.getSliceCalls());
verifyResults(key, keys, query, 5);
assertEquals(0, store.getSliceCalls());
}
use of org.janusgraph.diskstorage.StaticBuffer in project janusgraph by JanusGraph.
the class ExpirationCacheTest method verifyResults.
private void verifyResults(StaticBuffer key, List<StaticBuffer> keys, SliceQuery query, int expectedResults) throws Exception {
CacheTransaction tx = getCacheTx();
assertEquals(expectedResults, cache.getSlice(new KeySliceQuery(key, query), tx).size());
Map<StaticBuffer, EntryList> results = cache.getSlice(keys, query, tx);
assertEquals(keys.size(), results.size());
assertEquals(expectedResults, results.get(key).size());
tx.commit();
}
use of org.janusgraph.diskstorage.StaticBuffer in project janusgraph by JanusGraph.
the class BufferUtilTest method testNextBigger.
@Test
public void testNextBigger() {
int trials = 100000;
for (int t = 0; t < trials; t++) {
long val = random.nextLong() >>> 1;
assert val >= 0;
StaticBuffer b = BufferUtil.getLongBuffer(val);
assertEquals(val, b.getLong(0));
StaticBuffer bn = BufferUtil.nextBiggerBuffer(b);
assertEquals(8, bn.length());
assertEquals(val + 1, bn.getLong(0));
}
try {
StaticBuffer b = BufferUtil.getLongBuffer(-1);
BufferUtil.nextBiggerBuffer(b);
fail();
} catch (IllegalArgumentException ignored) {
}
StaticBuffer b = BufferUtil.getLongBuffer(-1);
StaticBuffer bn = BufferUtil.nextBiggerBufferAllowOverflow(b);
Assert.assertEquals(8, bn.length());
Assert.assertTrue(BufferUtil.zeroBuffer(8).equals(bn));
}
use of org.janusgraph.diskstorage.StaticBuffer in project janusgraph by JanusGraph.
the class IDManagementTest method edgeTypeIDTest.
@Test
public void edgeTypeIDTest() {
int partitionBits = 16;
IDManager eid = new IDManager(partitionBits);
int trails = 1000000;
assertEquals(eid.getPartitionBound(), (1L << partitionBits));
Serializer serializer = new StandardSerializer();
for (int t = 0; t < trails; t++) {
long count = RandomGenerator.randomLong(1, IDManager.getSchemaCountBound());
long id;
IDHandler.DirectionID dirID;
RelationCategory type;
if (Math.random() < 0.5) {
id = IDManager.getSchemaId(IDManager.VertexIDType.UserEdgeLabel, count);
assertTrue(eid.isEdgeLabelId(id));
assertFalse(IDManager.isSystemRelationTypeId(id));
type = RelationCategory.EDGE;
if (Math.random() < 0.5)
dirID = IDHandler.DirectionID.EDGE_IN_DIR;
else
dirID = IDHandler.DirectionID.EDGE_OUT_DIR;
} else {
type = RelationCategory.PROPERTY;
id = IDManager.getSchemaId(IDManager.VertexIDType.UserPropertyKey, count);
assertTrue(eid.isPropertyKeyId(id));
assertFalse(IDManager.isSystemRelationTypeId(id));
dirID = IDHandler.DirectionID.PROPERTY_DIR;
}
assertTrue(eid.isRelationTypeId(id));
StaticBuffer b = IDHandler.getRelationType(id, dirID, false);
// System.out.println(dirID);
// System.out.println(getBinary(id));
// System.out.println(getBuffer(b.asReadBuffer()));
ReadBuffer rb = b.asReadBuffer();
IDHandler.RelationTypeParse parse = IDHandler.readRelationType(rb);
assertEquals(id, parse.typeId);
assertEquals(dirID, parse.dirID);
assertFalse(rb.hasRemaining());
// Inline edge type
WriteBuffer wb = new WriteByteBuffer(9);
IDHandler.writeInlineRelationType(wb, id);
long newId = IDHandler.readInlineRelationType(wb.getStaticBuffer().asReadBuffer());
assertEquals(id, newId);
// Compare to Kryo
DataOutput out = serializer.getDataOutput(10);
IDHandler.writeRelationType(out, id, dirID, false);
assertEquals(b, out.getStaticBuffer());
// Make sure the bounds are right
StaticBuffer[] bounds = IDHandler.getBounds(type, false);
assertTrue(bounds[0].compareTo(b) < 0);
assertTrue(bounds[1].compareTo(b) > 0);
bounds = IDHandler.getBounds(RelationCategory.RELATION, false);
assertTrue(bounds[0].compareTo(b) < 0);
assertTrue(bounds[1].compareTo(b) > 0);
}
}
use of org.janusgraph.diskstorage.StaticBuffer in project janusgraph by JanusGraph.
the class IDManagementTest method testEdgeTypeWriting.
public void testEdgeTypeWriting(long edgeTypeId) {
IDHandler.DirectionID[] dir = IDManager.VertexIDType.EdgeLabel.is(edgeTypeId) ? new IDHandler.DirectionID[] { IDHandler.DirectionID.EDGE_IN_DIR, IDHandler.DirectionID.EDGE_OUT_DIR } : new IDHandler.DirectionID[] { IDHandler.DirectionID.PROPERTY_DIR };
boolean invisible = IDManager.isSystemRelationTypeId(edgeTypeId);
for (IDHandler.DirectionID d : dir) {
StaticBuffer b = IDHandler.getRelationType(edgeTypeId, d, invisible);
IDHandler.RelationTypeParse parse = IDHandler.readRelationType(b.asReadBuffer());
assertEquals(d, parse.dirID);
assertEquals(edgeTypeId, parse.typeId);
}
}
Aggregations