use of org.janusgraph.diskstorage.StaticBuffer in project janusgraph by JanusGraph.
the class ConsistentKeyLockerTest method testWriteLockRetriesOnTemporaryStorageException.
/**
* Test the locker retries a lock write after the initial store mutation
* fails with a {@link org.janusgraph.diskstorage.TemporaryBackendException}. The retry should both
* attempt to write the and delete the failed mutation column.
*
* @throws org.janusgraph.diskstorage.BackendException shouldn't happen
*/
@Test
public void testWriteLockRetriesOnTemporaryStorageException() throws BackendException {
TemporaryBackendException tse = new TemporaryBackendException("Storage cluster is waking up");
expect(lockState.has(defaultTx, defaultLockID)).andReturn(false);
recordSuccessfulLocalLock();
StaticBuffer firstCol = recordExceptionLockWrite(tse);
LockInfo secondLI = recordSuccessfulLockWrite(1, ChronoUnit.NANOS, firstCol);
recordSuccessfulLocalLock(secondLI.tsNS);
lockState.take(eq(defaultTx), eq(defaultLockID), eq(secondLI.stat));
ctrl.replay();
// SUT
locker.writeLock(defaultLockID, defaultTx);
}
use of org.janusgraph.diskstorage.StaticBuffer in project janusgraph by JanusGraph.
the class ConsistentKeyLockerTest method testWriteLockDiesOnPermanentStorageException.
/**
* Test that the first {@link org.janusgraph.diskstorage.PermanentBackendException} thrown by the
* locker's store causes it to attempt to delete outstanding lock writes and
* then emit the exception without retrying.
*
* @throws org.janusgraph.diskstorage.BackendException shouldn't happen
*/
@Test
public void testWriteLockDiesOnPermanentStorageException() throws BackendException {
PermanentBackendException errOnFire = new PermanentBackendException("Storage cluster is on fire");
expect(lockState.has(defaultTx, defaultLockID)).andReturn(false);
recordSuccessfulLocalLock();
StaticBuffer lockCol = recordExceptionLockWrite(errOnFire);
recordSuccessfulLockDelete(lockCol);
recordSuccessfulLocalUnlock();
ctrl.replay();
BackendException expected = null;
try {
// SUT
locker.writeLock(defaultLockID, defaultTx);
} catch (PermanentLockingException e) {
expected = e;
}
assertNotNull(expected);
assertEquals(errOnFire, expected.getCause());
}
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;
assertTrue(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);
assertEquals(8, bn.length());
assertEquals(BufferUtil.zeroBuffer(8), bn);
}
Aggregations