use of org.janusgraph.diskstorage.locking.consistentkey.ConsistentKeyLockStatus in project janusgraph by JanusGraph.
the class ConsistentKeyLockerTest method testCheckLocksInSimplestCase.
/**
* Test a single checking a single lock under optimal conditions (no
* timeouts, no errors)
*
* @throws org.janusgraph.diskstorage.BackendException shouldn't happen
* @throws InterruptedException shouldn't happen
*/
@Test
public void testCheckLocksInSimplestCase() throws BackendException, InterruptedException {
// Fake a pre-existing lock
final ConsistentKeyLockStatus ls = makeStatusNow();
expect(lockState.getLocksForTx(defaultTx)).andReturn(ImmutableMap.of(defaultLockID, ls));
currentTimeNS = currentTimeNS.plusSeconds(10);
// Checker should compare the fake lock's timestamp to the current time
expectSleepAfterWritingLock(ls);
// Expect a store getSlice() and return the fake lock's column and value
recordLockGetSliceAndReturnSingleEntry(StaticArrayEntry.of(codec.toLockCol(ls.getWriteTimestamp(), defaultLockRid, times), defaultLockVal));
ctrl.replay();
locker.checkLocks(defaultTx);
}
use of org.janusgraph.diskstorage.locking.consistentkey.ConsistentKeyLockStatus in project janusgraph by JanusGraph.
the class ConsistentKeyLockerTest method testDeleteLocksDeletesUncheckedLocks.
/**
* Deletion should remove previously written locks regardless of whether
* they were ever checked; this method fakes and verifies deletion on a
* single unchecked lock
*
* @throws org.janusgraph.diskstorage.BackendException shouldn't happen
*/
@Test
public void testDeleteLocksDeletesUncheckedLocks() throws BackendException {
ConsistentKeyLockStatus defaultLS = makeStatusNow();
assertFalse(defaultLS.isChecked());
currentTimeNS = currentTimeNS.plusNanos(1);
// Expect a call for defaultTx's locks and the checked one
expect(lockState.getLocksForTx(defaultTx)).andReturn(Maps.newLinkedHashMap(ImmutableMap.of(defaultLockID, defaultLS)));
expectLockDeleteSuccessfully(defaultLockID, defaultLockKey, defaultLS);
ctrl.replay();
locker.deleteLocks(defaultTx);
}
use of org.janusgraph.diskstorage.locking.consistentkey.ConsistentKeyLockStatus in project janusgraph by JanusGraph.
the class ConsistentKeyLockerTest method testCheckLocksThrowsExceptionAfterMaxTemporaryStorageExceptions.
/**
* The checker will throw a TemporaryStorageException if getSlice() throws
* fails with a TemporaryStorageException as many times as there are
* configured lock retries.
*
* @throws InterruptedException shouldn't happen
* @throws org.janusgraph.diskstorage.BackendException shouldn't happen
*/
@Test
public void testCheckLocksThrowsExceptionAfterMaxTemporaryStorageExceptions() throws InterruptedException, BackendException {
// Setup a LockStatus for defaultLockID
ConsistentKeyLockStatus lockStatus = makeStatusNow();
currentTimeNS = currentTimeNS.plusNanos(1);
expect(lockState.getLocksForTx(defaultTx)).andReturn(ImmutableMap.of(defaultLockID, lockStatus));
expectSleepAfterWritingLock(lockStatus);
// Three successive getSlice calls, each throwing a distinct TSE
recordExceptionalLockGetSlice(new TemporaryBackendException("Storage cluster is having me-time"));
recordExceptionalLockGetSlice(new TemporaryBackendException("Storage cluster is in a dissociative fugue state"));
recordExceptionalLockGetSlice(new TemporaryBackendException("Storage cluster has gone to Prague to find itself"));
ctrl.replay();
TemporaryBackendException tse = null;
try {
locker.checkLocks(defaultTx);
} catch (TemporaryBackendException e) {
tse = e;
}
assertNotNull(tse);
}
use of org.janusgraph.diskstorage.locking.consistentkey.ConsistentKeyLockStatus in project janusgraph by JanusGraph.
the class ConsistentKeyLockerTest method recordSuccessfulLockWrite.
private LockInfo recordSuccessfulLockWrite(StoreTransaction tx, long duration, TemporalUnit tu, StaticBuffer del) throws BackendException {
currentTimeNS = currentTimeNS.plusNanos(1);
expect(times.getTime()).andReturn(currentTimeNS);
final Instant lockNS = currentTimeNS;
StaticBuffer lockCol = codec.toLockCol(lockNS, defaultLockRid, times);
Entry add = StaticArrayEntry.of(lockCol, defaultLockVal);
StaticBuffer k = eq(defaultLockKey);
final List<Entry> adds = eq(Collections.singletonList(add));
final List<StaticBuffer> deletions;
if (null != del) {
deletions = eq(Collections.singletonList(del));
} else {
deletions = eq(ImmutableList.of());
}
store.mutate(k, adds, deletions, eq(tx));
expectLastCall().once();
currentTimeNS = currentTimeNS.plus(duration, tu);
expect(times.getTime()).andReturn(currentTimeNS);
ConsistentKeyLockStatus status = new ConsistentKeyLockStatus(lockNS, lockNS.plus(defaultExpireNS));
return new LockInfo(lockNS, status, lockCol);
}
Aggregations