Search in sources :

Example 1 with LockCleanerService

use of org.janusgraph.diskstorage.locking.consistentkey.LockCleanerService in project janusgraph by JanusGraph.

the class ConsistentKeyLockerTest method testCleanExpiredLock.

/**
 * Checking locks when the expired lock cleaner is enabled should trigger
 * one call to the LockCleanerService.
 *
 * @throws org.janusgraph.diskstorage.BackendException shouldn't happen
 */
@Test
public void testCleanExpiredLock() throws BackendException, InterruptedException {
    LockCleanerService mockCleaner = ctrl.createMock(LockCleanerService.class);
    ctrl.replay();
    Locker altLocker = getDefaultBuilder().customCleaner(mockCleaner).build();
    ctrl.verify();
    ctrl.reset();
    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
    expect(times.sleepPast(expired.getWriteTimestamp().plus(defaultWaitNS))).andReturn(currentTimeNS);
    // Checker must slice the store; we return the single expired lock column
    recordLockGetSliceAndReturnSingleEntry(StaticArrayEntry.of(codec.toLockCol(expired.getWriteTimestamp(), defaultLockRid, times), defaultLockVal));
    // Checker must attempt to cleanup expired lock
    mockCleaner.clean(eq(defaultLockID), eq(currentTimeNS.minus(defaultExpireNS)), eq(defaultTx));
    expectLastCall().once();
    ctrl.replay();
    TemporaryLockingException ple = null;
    try {
        altLocker.checkLocks(defaultTx);
    } catch (TemporaryLockingException e) {
        ple = e;
    }
    assertNotNull(ple);
}
Also used : ConsistentKeyLocker(org.janusgraph.diskstorage.locking.consistentkey.ConsistentKeyLocker) ConsistentKeyLockStatus(org.janusgraph.diskstorage.locking.consistentkey.ConsistentKeyLockStatus) LockCleanerService(org.janusgraph.diskstorage.locking.consistentkey.LockCleanerService) Test(org.junit.jupiter.api.Test)

Aggregations

ConsistentKeyLockStatus (org.janusgraph.diskstorage.locking.consistentkey.ConsistentKeyLockStatus)1 ConsistentKeyLocker (org.janusgraph.diskstorage.locking.consistentkey.ConsistentKeyLocker)1 LockCleanerService (org.janusgraph.diskstorage.locking.consistentkey.LockCleanerService)1 Test (org.junit.jupiter.api.Test)1