Search in sources :

Example 6 with CheckAndSetException

use of com.palantir.atlasdb.keyvalue.api.CheckAndSetException 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 7 with CheckAndSetException

use of com.palantir.atlasdb.keyvalue.api.CheckAndSetException 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)

Example 8 with CheckAndSetException

use of com.palantir.atlasdb.keyvalue.api.CheckAndSetException in project atlasdb by palantir.

the class AbstractKeyValueServiceTest method testCheckAndSetFromWrongValue.

@Test(expected = CheckAndSetException.class)
public void testCheckAndSetFromWrongValue() {
    Assume.assumeTrue(checkAndSetSupported());
    CheckAndSetRequest request = CheckAndSetRequest.newCell(TEST_TABLE, TEST_CELL, value00);
    keyValueService.checkAndSet(request);
    try {
        CheckAndSetRequest secondRequest = CheckAndSetRequest.singleCell(TEST_TABLE, TEST_CELL, value01, value00);
        keyValueService.checkAndSet(secondRequest);
    } catch (CheckAndSetException ex) {
        assertThat(ex.getActualValues(), contains(value00));
        throw ex;
    }
}
Also used : CheckAndSetRequest(com.palantir.atlasdb.keyvalue.api.CheckAndSetRequest) CheckAndSetException(com.palantir.atlasdb.keyvalue.api.CheckAndSetException) Test(org.junit.Test)

Aggregations

CheckAndSetException (com.palantir.atlasdb.keyvalue.api.CheckAndSetException)8 Test (org.junit.Test)4 Cell (com.palantir.atlasdb.keyvalue.api.Cell)2 CheckAndSetRequest (com.palantir.atlasdb.keyvalue.api.CheckAndSetRequest)2 ImmutableLockEntry (com.palantir.atlasdb.persistentlock.ImmutableLockEntry)2 LockEntry (com.palantir.atlasdb.persistentlock.LockEntry)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableMultimap (com.google.common.collect.ImmutableMultimap)1 Iterables (com.google.common.collect.Iterables)1 AsyncInitializer (com.palantir.async.initializer.AsyncInitializer)1 AtlasDbConstants (com.palantir.atlasdb.AtlasDbConstants)1 PtBytes (com.palantir.atlasdb.encoding.PtBytes)1 KeyAlreadyExistsException (com.palantir.atlasdb.keyvalue.api.KeyAlreadyExistsException)1 KeyValueService (com.palantir.atlasdb.keyvalue.api.KeyValueService)1 RangeRequest (com.palantir.atlasdb.keyvalue.api.RangeRequest)1 Value (com.palantir.atlasdb.keyvalue.api.Value)1 SchemaMetadata (com.palantir.atlasdb.schema.SchemaMetadata)1 UnsafeArg (com.palantir.logsafe.UnsafeArg)1 PalantirSqlConnection (com.palantir.nexus.db.sql.PalantirSqlConnection)1