Search in sources :

Example 16 with ConsistentKeyLockStatus

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);
}
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) Test(org.junit.Test)

Example 17 with ConsistentKeyLockStatus

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

Aggregations

ConsistentKeyLockStatus (com.thinkaurelius.titan.diskstorage.locking.consistentkey.ConsistentKeyLockStatus)17 Test (org.junit.Test)16 StaticBufferEntry (com.thinkaurelius.titan.diskstorage.keycolumnvalue.StaticBufferEntry)15 StaticBuffer (com.thinkaurelius.titan.diskstorage.StaticBuffer)13 Entry (com.thinkaurelius.titan.diskstorage.keycolumnvalue.Entry)8 TemporaryStorageException (com.thinkaurelius.titan.diskstorage.TemporaryStorageException)4 KeyColumn (com.thinkaurelius.titan.diskstorage.util.KeyColumn)3 PermanentStorageException (com.thinkaurelius.titan.diskstorage.PermanentStorageException)2 HashMap (java.util.HashMap)1