Search in sources :

Example 1 with LockEntry

use of com.palantir.atlasdb.persistentlock.LockEntry in project atlasdb by palantir.

the class PersistentLockManagerTest method whenWeGetTheLockFirstTimeAndThenHoldItForever.

private void whenWeGetTheLockFirstTimeAndThenHoldItForever() {
    LockEntry oldEntry = ImmutableLockEntry.builder().lockName("BackupLock").instanceId(FIRST_LOCK_ID.value()).reason("Sweep").build();
    CheckAndSetException casException = new CheckAndSetException(Cell.create(PtBytes.toBytes("unu"), PtBytes.toBytes("sed")), TableReference.createFromFullyQualifiedName("unu.sed"), PtBytes.toBytes("unused"), ImmutableList.of(oldEntry.value()));
    when(mockPls.acquireBackupLock(anyString())).thenReturn(FIRST_LOCK_ID).thenThrow(casException);
}
Also used : LockEntry(com.palantir.atlasdb.persistentlock.LockEntry) ImmutableLockEntry(com.palantir.atlasdb.persistentlock.ImmutableLockEntry) CheckAndSetException(com.palantir.atlasdb.keyvalue.api.CheckAndSetException)

Example 2 with LockEntry

use of com.palantir.atlasdb.persistentlock.LockEntry in project atlasdb by palantir.

the class PersistentLockManagerTest method cannotAcquireAfterReleaseSeemsToFailButSecretlySucceedsAndThenSomeoneElseTakesTheLock.

@Test
@GuardedBy("manager")
public void cannotAcquireAfterReleaseSeemsToFailButSecretlySucceedsAndThenSomeoneElseTakesTheLock() {
    doThrow(RuntimeException.class).when(mockPls).releaseBackupLock(any());
    manager.acquirePersistentLockWithRetry();
    try {
        manager.releasePersistentLock();
    } catch (RuntimeException e) {
    // Expected
    }
    LockEntry usurper = ImmutableLockEntry.builder().lockName("BackupLock").instanceId(UUID.randomUUID()).reason("backup").build();
    CheckAndSetException casException = new CheckAndSetException(Cell.create(PtBytes.toBytes("unu"), PtBytes.toBytes("sed")), TableReference.createFromFullyQualifiedName("unu.sed"), PtBytes.toBytes("unused"), ImmutableList.of(usurper.value()));
    when(mockPls.acquireBackupLock(anyString())).thenThrow(casException);
    // We call the non-retrying version here, because we:
    // (a) don't want the test to hang
    // (b) want to verify that we adjusted our view of the lockId.
    manager.tryAcquirePersistentLock();
    verify(mockPls, times(2)).acquireBackupLock("Sweep");
    assertNull(manager.lockId);
}
Also used : LockEntry(com.palantir.atlasdb.persistentlock.LockEntry) ImmutableLockEntry(com.palantir.atlasdb.persistentlock.ImmutableLockEntry) CheckAndSetException(com.palantir.atlasdb.keyvalue.api.CheckAndSetException) GuardedBy(net.jcip.annotations.GuardedBy) Test(org.junit.Test)

Aggregations

CheckAndSetException (com.palantir.atlasdb.keyvalue.api.CheckAndSetException)2 ImmutableLockEntry (com.palantir.atlasdb.persistentlock.ImmutableLockEntry)2 LockEntry (com.palantir.atlasdb.persistentlock.LockEntry)2 GuardedBy (net.jcip.annotations.GuardedBy)1 Test (org.junit.Test)1