use of org.janusgraph.diskstorage.Entry in project janusgraph by JanusGraph.
the class StaticArrayEntryTest method testInversion.
@Test
public void testInversion() {
WriteBuffer wb = new WriteByteBuffer(20);
wb.putInt(1).putInt(2).putInt(3).putInt(4);
Entry entry = new StaticArrayEntry(wb.getStaticBufferFlipBytes(4, 2 * 4), 3 * 4);
ReadBuffer rb = entry.asReadBuffer();
assertEquals(1, rb.getInt());
assertEquals(2, rb.subrange(4, true).getInt());
assertEquals(~2, rb.getInt());
assertEquals(3, rb.getInt());
assertEquals(4, rb.getInt());
rb.movePositionTo(entry.getValuePosition());
assertEquals(4, rb.getInt());
}
use of org.janusgraph.diskstorage.Entry in project janusgraph by JanusGraph.
the class StaticArrayEntryTest method testArrayBuffer.
@Test
public void testArrayBuffer() {
WriteBuffer wb = new WriteByteBuffer(128);
wb.putInt(1).putInt(2).putInt(3).putInt(4);
int valuePos = wb.getPosition();
wb.putInt(5).putInt(6);
Entry entry = new StaticArrayEntry(wb.getStaticBuffer(), valuePos);
assertEquals(4 * 4, entry.getValuePosition());
assertEquals(6 * 4, entry.length());
assertTrue(entry.hasValue());
for (int i = 1; i <= 6; i++) assertEquals(i, entry.getInt((i - 1) * 4));
ReadBuffer rb = entry.asReadBuffer();
for (int i = 1; i <= 6; i++) assertEquals(i, rb.getInt());
assertFalse(rb.hasRemaining());
assertNull(entry.getCache());
entry.setCache(cache);
assertEquals(cache, entry.getCache());
rb = entry.getColumnAs(StaticBuffer.STATIC_FACTORY).asReadBuffer();
for (int i = 1; i <= 4; i++) assertEquals(i, rb.getInt());
assertFalse(rb.hasRemaining());
rb = entry.getValueAs(StaticBuffer.STATIC_FACTORY).asReadBuffer();
for (int i = 5; i <= 6; i++) assertEquals(i, rb.getInt());
assertFalse(rb.hasRemaining());
}
use of org.janusgraph.diskstorage.Entry in project janusgraph by JanusGraph.
the class ConsistentKeyLockerTest method recordExceptionLockWrite.
private StaticBuffer recordExceptionLockWrite(Throwable t) throws BackendException {
currentTimeNS = currentTimeNS.plusNanos(1);
expect(times.getTime()).andReturn(currentTimeNS);
StaticBuffer lockCol = codec.toLockCol(currentTimeNS, defaultLockRid, times);
Entry add = StaticArrayEntry.of(lockCol, defaultLockVal);
StaticBuffer k = eq(defaultLockKey);
final List<Entry> adds = eq(Collections.singletonList(add));
final List<StaticBuffer> deletions;
deletions = eq(ImmutableList.of());
store.mutate(k, adds, deletions, eq(defaultTx));
expectLastCall().andThrow(t);
currentTimeNS = currentTimeNS.plus(1, ChronoUnit.NANOS);
expect(times.getTime()).andReturn(currentTimeNS);
return lockCol;
}
use of org.janusgraph.diskstorage.Entry in project janusgraph by JanusGraph.
the class KCVSCacheTest method testSmallCache.
@Test
public void testSmallCache() throws Exception {
// numCols must be greater than or equal to 10 as it is assumed below
final int numKeys = 100, numCols = 10;
final int repeats = 100, clearEvery = 20, numMulti = 10;
loadStore(numKeys, numCols);
// Repeatedly read from cache and clear in between
int calls = 0;
assertEquals(calls, store.getSliceCalls());
for (int t = 0; t < repeats; t++) {
if (t % clearEvery == 0) {
cache.clearCache();
calls += numKeys * 2 + 1;
}
CacheTransaction tx = getCacheTx();
for (int i = 1; i <= numKeys; i++) {
assertEquals(10, cache.getSlice(getQuery(i, 0, numCols + 1).setLimit(10), tx).size());
assertEquals(3, cache.getSlice(getQuery(i, 2, 5), tx).size());
}
// Multi-query
final List<StaticBuffer> keys = new ArrayList<>();
for (int i = 10; i < 10 + numMulti; i++) keys.add(BufferUtil.getIntBuffer(i));
Map<StaticBuffer, EntryList> result = cache.getSlice(keys, getQuery(4, 9), tx);
assertEquals(keys.size(), result.size());
for (StaticBuffer key : keys) assertTrue(result.containsKey(key));
for (EntryList r : result.values()) {
assertEquals(5, r.size());
}
tx.commit();
assertEquals(calls, store.getSliceCalls());
}
store.resetCounter();
// Check invalidation
StaticBuffer key = BufferUtil.getIntBuffer(23);
final List<StaticBuffer> keys = new ArrayList<>();
keys.add(key);
keys.add(BufferUtil.getIntBuffer(12));
keys.add(BufferUtil.getIntBuffer(5));
// Read
CacheTransaction tx = getCacheTx();
assertEquals(numCols, cache.getSlice(new KeySliceQuery(key, getQuery(0, numCols + 1)), tx).size());
Map<StaticBuffer, EntryList> result = cache.getSlice(keys, getQuery(2, 8), tx);
assertEquals(keys.size(), result.size());
assertEquals(6, result.get(key).size());
// Update
final List<Entry> deletions = new ArrayList<>(numCols / 2);
for (int j = 1; j <= numCols; j = j + 2) deletions.add(getEntry(j, j));
cache.mutateEntries(key, KeyColumnValueStore.NO_ADDITIONS, deletions, tx);
tx.commit();
assertEquals(2, store.getSliceCalls());
// Ensure updates are correctly read
tx = getCacheTx();
assertEquals(numCols / 2, cache.getSlice(new KeySliceQuery(key, getQuery(0, numCols + 1)), tx).size());
result = cache.getSlice(keys, getQuery(2, 8), tx);
assertEquals(keys.size(), result.size());
assertEquals(3, result.get(key).size());
tx.commit();
assertEquals(4, store.getSliceCalls());
}
use of org.janusgraph.diskstorage.Entry in project janusgraph by JanusGraph.
the class LockCleanerRunnableTest method testDeleteSingleLock.
/**
* Simplest case test of the lock cleaner.
*/
@Test
public void testDeleteSingleLock() throws BackendException {
Instant now = Instant.ofEpochMilli(1L);
Entry expiredLockCol = StaticArrayEntry.of(codec.toLockCol(now, defaultLockRid, TimestampProviders.MILLI), BufferUtil.getIntBuffer(0));
EntryList expiredSingleton = StaticArrayEntryList.of(expiredLockCol);
now = now.plusMillis(1);
del = new StandardLockCleanerRunnable(store, kc, tx, codec, now, TimestampProviders.MILLI);
expect(store.getSlice(eq(ksq), eq(tx))).andReturn(expiredSingleton);
store.mutate(eq(key), eq(ImmutableList.of()), eq(ImmutableList.of(expiredLockCol.getColumn())), anyObject(StoreTransaction.class));
ctrl.replay();
del.run();
}
Aggregations