use of com.thinkaurelius.titan.diskstorage.locking.consistentkey.ConsistentKeyLockStatus in project titan by thinkaurelius.
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 StorageException shouldn't happen
*/
@Test
public void testDeleteLocksDeletesUncheckedLocks() throws StorageException {
ConsistentKeyLockStatus defaultLS = makeStatusNow();
assertFalse(defaultLS.isChecked());
currentTimeNS++;
// Expect a call for defaultTx's locks and the checked one
expect(lockState.getLocksForTx(defaultTx)).andReturn(Maps.newLinkedHashMap(ImmutableMap.of(defaultLockID, defaultLS)));
List<StaticBuffer> dels = ImmutableList.of(codec.toLockCol(defaultLS.getWriteTimestamp(TimeUnit.NANOSECONDS), defaultLockRid));
expect(times.getApproxNSSinceEpoch()).andReturn(currentTimeNS);
store.mutate(eq(defaultLockKey), eq(ImmutableList.<Entry>of()), eq(dels), eq(defaultTx));
expect(mediator.unlock(defaultLockID, defaultTx)).andReturn(true);
// lockState.release(defaultTx, defaultLockID);
ctrl.replay();
locker.deleteLocks(defaultTx);
}
use of com.thinkaurelius.titan.diskstorage.locking.consistentkey.ConsistentKeyLockStatus in project titan by thinkaurelius.
the class ConsistentKeyLockerTest method testCheckLocksIgnoresSingleExpiredLock.
/**
* Lock checking should treat columns with timestamps older than the
* expiration period as though they were never read from the store (aside
* from logging them). This tests the checker with a single expired column.
*
* @throws StorageException shouldn't happen
* @throws InterruptedException
*/
@Test
public void testCheckLocksIgnoresSingleExpiredLock() throws StorageException, 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 += TimeUnit.NANOSECONDS.convert(100, TimeUnit.DAYS);
// Checker should compare the fake lock's timestamp to the current time
expect(times.sleepUntil(expired.getWriteTimestamp(TimeUnit.NANOSECONDS) + defaultWaitNS)).andReturn(currentTimeNS);
// Checker must slice the store; we return the single expired lock column
recordLockGetSliceAndReturnSingleEntry(new StaticBufferEntry(codec.toLockCol(expired.getWriteTimestamp(TimeUnit.NANOSECONDS), defaultLockRid), defaultLockVal));
ctrl.replay();
TemporaryLockingException ple = null;
try {
locker.checkLocks(defaultTx);
} catch (TemporaryLockingException e) {
ple = e;
}
assertNotNull(ple);
}
Aggregations