Search in sources :

Example 71 with StaticBuffer

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);
}
Also used : StaticBufferEntry(com.thinkaurelius.titan.diskstorage.keycolumnvalue.StaticBufferEntry) Entry(com.thinkaurelius.titan.diskstorage.keycolumnvalue.Entry) StaticBuffer(com.thinkaurelius.titan.diskstorage.StaticBuffer) ConsistentKeyLockStatus(com.thinkaurelius.titan.diskstorage.locking.consistentkey.ConsistentKeyLockStatus) KeyColumn(com.thinkaurelius.titan.diskstorage.util.KeyColumn) Test(org.junit.Test)

Example 72 with StaticBuffer

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;
}
Also used : StaticBufferEntry(com.thinkaurelius.titan.diskstorage.keycolumnvalue.StaticBufferEntry) Entry(com.thinkaurelius.titan.diskstorage.keycolumnvalue.Entry) StaticBuffer(com.thinkaurelius.titan.diskstorage.StaticBuffer) StaticBufferEntry(com.thinkaurelius.titan.diskstorage.keycolumnvalue.StaticBufferEntry)

Example 73 with StaticBuffer

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);
}
Also used : StaticBuffer(com.thinkaurelius.titan.diskstorage.StaticBuffer) KeySliceQuery(com.thinkaurelius.titan.diskstorage.keycolumnvalue.KeySliceQuery)

Example 74 with StaticBuffer

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);
}
Also used : StaticBufferEntry(com.thinkaurelius.titan.diskstorage.keycolumnvalue.StaticBufferEntry) Entry(com.thinkaurelius.titan.diskstorage.keycolumnvalue.Entry) StaticBuffer(com.thinkaurelius.titan.diskstorage.StaticBuffer) ConsistentKeyLockStatus(com.thinkaurelius.titan.diskstorage.locking.consistentkey.ConsistentKeyLockStatus) KeyColumn(com.thinkaurelius.titan.diskstorage.util.KeyColumn) Test(org.junit.Test)

Example 75 with StaticBuffer

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);
}
Also used : StaticBuffer(com.thinkaurelius.titan.diskstorage.StaticBuffer) StaticBufferEntry(com.thinkaurelius.titan.diskstorage.keycolumnvalue.StaticBufferEntry) ConsistentKeyLockStatus(com.thinkaurelius.titan.diskstorage.locking.consistentkey.ConsistentKeyLockStatus) Test(org.junit.Test)

Aggregations

StaticBuffer (com.thinkaurelius.titan.diskstorage.StaticBuffer)92 Test (org.junit.Test)30 ArrayList (java.util.ArrayList)16 StaticBufferEntry (com.thinkaurelius.titan.diskstorage.keycolumnvalue.StaticBufferEntry)15 Entry (com.thinkaurelius.titan.diskstorage.keycolumnvalue.Entry)14 TemporaryStorageException (com.thinkaurelius.titan.diskstorage.TemporaryStorageException)13 ConsistentKeyLockStatus (com.thinkaurelius.titan.diskstorage.locking.consistentkey.ConsistentKeyLockStatus)13 DataOutput (com.thinkaurelius.titan.graphdb.database.serialize.DataOutput)12 HashMap (java.util.HashMap)12 ImmutableMap (com.google.common.collect.ImmutableMap)11 Map (java.util.Map)11 Entry (com.thinkaurelius.titan.diskstorage.Entry)10 ReadBuffer (com.thinkaurelius.titan.diskstorage.ReadBuffer)10 StorageException (com.thinkaurelius.titan.diskstorage.StorageException)9 PermanentStorageException (com.thinkaurelius.titan.diskstorage.PermanentStorageException)8 KeySliceQuery (com.thinkaurelius.titan.diskstorage.keycolumnvalue.KeySliceQuery)7 KCVMutation (com.thinkaurelius.titan.diskstorage.keycolumnvalue.KCVMutation)6 KeyRange (com.thinkaurelius.titan.diskstorage.keycolumnvalue.KeyRange)6 SliceQuery (com.thinkaurelius.titan.diskstorage.keycolumnvalue.SliceQuery)6 Instant (java.time.Instant)6