use of org.janusgraph.diskstorage.locking.consistentkey.ConsistentKeyLockStatus in project janusgraph by JanusGraph.
the class ConsistentKeyLockerTest method testDeleteLocksInSimplestCase.
/**
* Delete a single lock without any timeouts, errors, etc.
*
* @throws org.janusgraph.diskstorage.BackendException shouldn't happen
*/
@Test
public void testDeleteLocksInSimplestCase() throws BackendException {
// Setup a LockStatus for defaultLockID
final ConsistentKeyLockStatus lockStatus = makeStatusNow();
currentTimeNS = currentTimeNS.plusNanos(1);
@SuppressWarnings("serial") Map<KeyColumn, ConsistentKeyLockStatus> expectedMap = new HashMap<KeyColumn, ConsistentKeyLockStatus>() {
{
put(defaultLockID, lockStatus);
}
};
expect(lockState.getLocksForTx(defaultTx)).andReturn(expectedMap);
List<StaticBuffer> deletions = ImmutableList.of(codec.toLockCol(lockStatus.getWriteTimestamp(), defaultLockRid, times));
expect(times.getTime()).andReturn(currentTimeNS);
store.mutate(eq(defaultLockKey), eq(ImmutableList.of()), eq(deletions), eq(defaultTx));
expect(mediator.unlock(defaultLockID, defaultTx)).andReturn(true);
ctrl.replay();
locker.deleteLocks(defaultTx);
}
use of org.janusgraph.diskstorage.locking.consistentkey.ConsistentKeyLockStatus in project janusgraph by JanusGraph.
the class ConsistentKeyLockerTest method testDeleteLocksIdempotence.
/**
* When delete is called multiple times with no intervening write or check
* calls, all calls after the first should have no effect.
*
* @throws org.janusgraph.diskstorage.BackendException shouldn't happen
*/
@Test
public void testDeleteLocksIdempotence() throws BackendException {
// Setup a LockStatus for defaultLockID
ConsistentKeyLockStatus lockStatus = makeStatusNow();
currentTimeNS = currentTimeNS.plusNanos(1);
expect(lockState.getLocksForTx(defaultTx)).andReturn(Maps.newLinkedHashMap(ImmutableMap.of(defaultLockID, lockStatus)));
expectLockDeleteSuccessfully(defaultLockID, defaultLockKey, lockStatus);
ctrl.replay();
locker.deleteLocks(defaultTx);
ctrl.verify();
ctrl.reset();
expect(lockState.getLocksForTx(defaultTx)).andReturn(Maps.newLinkedHashMap(ImmutableMap.of()));
ctrl.replay();
locker.deleteLocks(defaultTx);
}
use of org.janusgraph.diskstorage.locking.consistentkey.ConsistentKeyLockStatus in project janusgraph by JanusGraph.
the class ConsistentKeyLockerTest method testCheckOwnExpiredLockThrowsException.
/**
* A transaction that writes a lock, waits past expiration, and attempts
* to check locks should receive an {@code ExpiredLockException} during
* the check stage.
*
* @throws org.janusgraph.diskstorage.BackendException shouldn't happen
* @throws InterruptedException
*/
@Test
public void testCheckOwnExpiredLockThrowsException() throws BackendException, InterruptedException {
// Fake a pre-existing lock that's long since expired
final ConsistentKeyLockStatus expired = makeStatusNow();
expect(lockState.getLocksForTx(defaultTx)).andReturn(ImmutableMap.of(defaultLockID, expired));
// pretend a huge multiple of the expiration time has passed
currentTimeNS = currentTimeNS.plus(100, ChronoUnit.DAYS);
// Checker should compare the fake lock's timestamp to the current time
expectSleepAfterWritingLock(expired);
// Checker must slice the store; we return the single expired lock column
recordLockGetSliceAndReturnSingleEntry(StaticArrayEntry.of(codec.toLockCol(expired.getWriteTimestamp(), defaultLockRid, times), defaultLockVal));
ctrl.replay();
ExpiredLockException ele = null;
try {
locker.checkLocks(defaultTx);
} catch (ExpiredLockException e) {
ele = e;
}
assertNotNull(ele);
}
use of org.janusgraph.diskstorage.locking.consistentkey.ConsistentKeyLockStatus in project janusgraph by JanusGraph.
the class ConsistentKeyLockerTest method testDeleteLocksOnTwoLocks.
/**
* Delete two locks without any timeouts, errors, etc.
*
* @throws org.janusgraph.diskstorage.BackendException shouldn't happen
*/
@Test
public void testDeleteLocksOnTwoLocks() throws BackendException {
ConsistentKeyLockStatus defaultLS = makeStatusNow();
currentTimeNS = currentTimeNS.plusNanos(1);
ConsistentKeyLockStatus otherLS = makeStatusNow();
currentTimeNS = currentTimeNS.plusNanos(1);
// Expect a call for defaultTx's locks and return two
Map<KeyColumn, ConsistentKeyLockStatus> expectedMap = Maps.newLinkedHashMap();
expectedMap.put(defaultLockID, defaultLS);
expectedMap.put(otherLockID, otherLS);
expect(lockState.getLocksForTx(defaultTx)).andReturn(expectedMap);
expectLockDeleteSuccessfully(defaultLockID, defaultLockKey, defaultLS);
expectLockDeleteSuccessfully(otherLockID, otherLockKey, otherLS);
ctrl.replay();
locker.deleteLocks(defaultTx);
}
use of org.janusgraph.diskstorage.locking.consistentkey.ConsistentKeyLockStatus in project janusgraph by JanusGraph.
the class ConsistentKeyLockerTest method testDeleteLocksRetriesOnTemporaryStorageException.
/**
* Lock deletion should retry if the first store mutation throws a temporary
* exception.
*
* @throws org.janusgraph.diskstorage.BackendException shouldn't happen
*/
@Test
public void testDeleteLocksRetriesOnTemporaryStorageException() throws BackendException {
ConsistentKeyLockStatus defaultLS = makeStatusNow();
currentTimeNS = currentTimeNS.plusNanos(1);
expect(lockState.getLocksForTx(defaultTx)).andReturn(Maps.newLinkedHashMap(ImmutableMap.of(defaultLockID, defaultLS)));
expectDeleteLock(defaultLockID, defaultLockKey, defaultLS, new TemporaryBackendException("Storage cluster is backlogged"));
ctrl.replay();
locker.deleteLocks(defaultTx);
}
Aggregations