use of com.thinkaurelius.titan.diskstorage.StaticBuffer in project titan by thinkaurelius.
the class ConsistentKeyLockerTest method testDeleteLocksOnTwoLocks.
/**
* Delete two locks without any timeouts, errors, etc.
*
* @throws StorageException shouldn't happen
*/
@Test
public void testDeleteLocksOnTwoLocks() throws StorageException {
ConsistentKeyLockStatus defaultLS = makeStatusNow();
currentTimeNS++;
ConsistentKeyLockStatus otherLS = makeStatusNow();
currentTimeNS++;
// 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);
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);
dels = ImmutableList.of(codec.toLockCol(otherLS.getWriteTimestamp(TimeUnit.NANOSECONDS), defaultLockRid));
expect(times.getApproxNSSinceEpoch()).andReturn(currentTimeNS);
store.mutate(eq(otherLockKey), eq(ImmutableList.<Entry>of()), eq(dels), eq(defaultTx));
expect(mediator.unlock(otherLockID, defaultTx)).andReturn(true);
ctrl.replay();
locker.deleteLocks(defaultTx);
}
use of com.thinkaurelius.titan.diskstorage.StaticBuffer in project titan by thinkaurelius.
the class ConsistentKeyLockerTest method recordExceptionLockWrite.
private StaticBuffer recordExceptionLockWrite(long duration, TimeUnit tu, StaticBuffer del, Throwable t) throws StorageException {
expect(times.getApproxNSSinceEpoch()).andReturn(++currentTimeNS);
StaticBuffer lockCol = codec.toLockCol(currentTimeNS, defaultLockRid);
Entry add = new StaticBufferEntry(lockCol, defaultLockVal);
StaticBuffer k = eq(defaultLockKey);
// assert null != add;
final List<Entry> adds = eq(Arrays.<Entry>asList(add));
// assert null != adds;
final List<StaticBuffer> dels;
if (null != del) {
dels = eq(Arrays.<StaticBuffer>asList(del));
} else {
dels = eq(ImmutableList.<StaticBuffer>of());
}
store.mutate(k, adds, dels, eq(defaultTx));
expectLastCall().andThrow(t);
currentTimeNS += TimeUnit.NANOSECONDS.convert(duration, tu);
expect(times.getApproxNSSinceEpoch()).andReturn(currentTimeNS);
return lockCol;
}
use of com.thinkaurelius.titan.diskstorage.StaticBuffer in project titan by thinkaurelius.
the class ConsistentKeyLockerTest method recordLockGetSlice.
private void recordLockGetSlice(List<Entry> returnedEntries) throws StorageException {
final StaticBuffer lower = ByteBufferUtil.zeroBuffer(9);
final StaticBuffer upper = ByteBufferUtil.oneBuffer(9);
final KeySliceQuery ksq = new KeySliceQuery(defaultLockKey, lower, upper);
expect(store.getSlice(eq(ksq), eq(defaultTx))).andReturn(returnedEntries);
}
use of com.thinkaurelius.titan.diskstorage.StaticBuffer in project titan by thinkaurelius.
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 StorageException shouldn't happen
*/
@Test
public void testDeleteLocksIdempotence() throws StorageException {
// Setup a LockStatus for defaultLockID
ConsistentKeyLockStatus lockStatus = makeStatusNow();
currentTimeNS += TimeUnit.NANOSECONDS.convert(1, TimeUnit.NANOSECONDS);
expect(lockState.getLocksForTx(defaultTx)).andReturn(Maps.newLinkedHashMap(ImmutableMap.of(defaultLockID, lockStatus)));
StaticBuffer del = codec.toLockCol(lockStatus.getWriteTimestamp(TimeUnit.NANOSECONDS), defaultLockRid);
expect(times.getApproxNSSinceEpoch()).andReturn(currentTimeNS);
store.mutate(eq(defaultLockKey), eq(ImmutableList.<Entry>of()), eq(Arrays.asList(del)), eq(defaultTx));
expect(mediator.unlock(defaultLockID, defaultTx)).andReturn(true);
// lockState.release(defaultTx, defaultLockID);
ctrl.replay();
locker.deleteLocks(defaultTx);
ctrl.verify();
ctrl.reset();
expect(lockState.getLocksForTx(defaultTx)).andReturn(Maps.newLinkedHashMap(ImmutableMap.<KeyColumn, ConsistentKeyLockStatus>of()));
ctrl.replay();
locker.deleteLocks(defaultTx);
}
use of com.thinkaurelius.titan.diskstorage.StaticBuffer in project titan by thinkaurelius.
the class ConsistentKeyLockerTest method testCheckLocksIdempotence.
/**
* Each written lock should be checked at most once. Test this by faking a
* single previously written lock using mocks and stubs and then calling
* checkLocks() twice. The second call should have no effect.
*
* @throws InterruptedException shouldn't happen
* @throws StorageException shouldn't happen
*/
@Test
public void testCheckLocksIdempotence() throws InterruptedException, StorageException {
// Fake a pre-existing valid lock
final ConsistentKeyLockStatus ls = makeStatusNow();
expect(lockState.getLocksForTx(defaultTx)).andReturn(ImmutableMap.of(defaultLockID, ls));
currentTimeNS += TimeUnit.NANOSECONDS.convert(10, TimeUnit.SECONDS);
expect(times.sleepUntil(ls.getWriteTimestamp(TimeUnit.NANOSECONDS) + defaultWaitNS)).andReturn(currentTimeNS);
final StaticBuffer lc = codec.toLockCol(ls.getWriteTimestamp(TimeUnit.NANOSECONDS), defaultLockRid);
recordLockGetSliceAndReturnSingleEntry(new StaticBufferEntry(lc, defaultLockVal));
ctrl.replay();
locker.checkLocks(defaultTx);
ctrl.verify();
ctrl.reset();
// Return the faked lock in a map of size 1
expect(lockState.getLocksForTx(defaultTx)).andReturn(ImmutableMap.of(defaultLockID, ls));
ctrl.replay();
// At this point, checkLocks() should see that the single lock in the
// map returned above has already been checked and return immediately
locker.checkLocks(defaultTx);
}
Aggregations