Search in sources :

Example 1 with LockWatchStateUpdate

use of com.palantir.lock.watch.LockWatchStateUpdate in project atlasdb by palantir.

the class LockWatchEventCacheImplTest method snapshotClearsPreviousTransactionState.

@Test
public void snapshotClearsPreviousTransactionState() {
    eventCache.processStartTransactionsUpdate(ImmutableSet.of(TIMESTAMP_1), SNAPSHOT_VERSION_1);
    LockWatchStateUpdate newSnapshot = LockWatchStateUpdate.snapshot(DIFFERENT_LEADER, SEQUENCE_3, ImmutableSet.of(), ImmutableSet.of(REFERENCE_2));
    // New snapshot clears all state from before, and thus TIMESTAMP_1 is no longer present, and should throw
    // when attempting to retrieve information about it
    eventCache.processStartTransactionsUpdate(ImmutableSet.of(TIMESTAMP_2, TIMESTAMP_3), newSnapshot);
    verify(eventLog).processUpdate(SNAPSHOT_VERSION_1);
    verify(eventLog).processUpdate(newSnapshot);
    assertThatThrownBy(() -> eventCache.getUpdateForTransactions(ImmutableSet.of(TIMESTAMP_1, TIMESTAMP_2, TIMESTAMP_3), Optional.empty())).isExactlyInstanceOf(TransactionLockWatchFailedException.class).hasMessage("start timestamp missing from map");
    assertThatCode(() -> eventCache.getUpdateForTransactions(ImmutableSet.of(TIMESTAMP_2, TIMESTAMP_3), Optional.empty())).as("contains only timestamps from the new snapshot").doesNotThrowAnyException();
}
Also used : LockWatchStateUpdate(com.palantir.lock.watch.LockWatchStateUpdate) TransactionLockWatchFailedException(com.palantir.atlasdb.transaction.api.TransactionLockWatchFailedException) Test(org.junit.Test)

Example 2 with LockWatchStateUpdate

use of com.palantir.lock.watch.LockWatchStateUpdate in project atlasdb by palantir.

the class LockWatchEventCacheIntegrationTest method successUpdateWithNoEventsButLaterVersionThrowsRetryableException.

@Test
public void successUpdateWithNoEventsButLaterVersionThrowsRetryableException() {
    LockWatchStateUpdate emptySuccess = LockWatchStateUpdate.success(LEADER, 4L, ImmutableList.of());
    setupInitialState();
    assertThatThrownBy(() -> eventCache.processStartTransactionsUpdate(TIMESTAMPS_2, emptySuccess)).isExactlyInstanceOf(TransactionLockWatchFailedException.class).hasMessage("Success event has a later version than the current version, but has no events to bridge the " + "gap. The transaction should be retried, but this should only happen rarely.");
}
Also used : LockWatchStateUpdate(com.palantir.lock.watch.LockWatchStateUpdate) TransactionLockWatchFailedException(com.palantir.atlasdb.transaction.api.TransactionLockWatchFailedException) Test(org.junit.Test)

Example 3 with LockWatchStateUpdate

use of com.palantir.lock.watch.LockWatchStateUpdate in project atlasdb by palantir.

the class LockWatchEventCacheIntegrationTest method emptySuccessesFollowingSnapshotsDoNotCauseAdditionalCacheClearance.

@Test
public void emptySuccessesFollowingSnapshotsDoNotCauseAdditionalCacheClearance() {
    LockWatchStateUpdate snapshot = LockWatchStateUpdate.snapshot(LEADER, 3L, ImmutableSet.of(DESCRIPTOR_2), ImmutableSet.of());
    LockWatchStateUpdate emptySuccess = LockWatchStateUpdate.success(LEADER, 3L, ImmutableList.of());
    LockWatchEvent lockEvent = LockEvent.builder(ImmutableSet.of(DESCRIPTOR_3), COMMIT_TOKEN).build(4L);
    LockWatchStateUpdate success = LockWatchStateUpdate.success(LEADER, 4L, ImmutableList.of(lockEvent));
    setupInitialState();
    verifyStage();
    eventCache.processStartTransactionsUpdate(ImmutableSet.of(1L), snapshot);
    verifyStage();
    assertThat(eventCache.getUpdateForTransactions(ImmutableSet.of(1L), Optional.of(LockWatchVersion.of(LEADER, 2L))).clearCache()).isTrue();
    assertThat(eventCache.getUpdateForTransactions(ImmutableSet.of(1L), Optional.of(LockWatchVersion.of(LEADER, 3L))).clearCache()).isFalse();
    eventCache.processStartTransactionsUpdate(ImmutableSet.of(2L), emptySuccess);
    verifyStage();
    assertThat(eventCache.getUpdateForTransactions(ImmutableSet.of(2L), Optional.of(LockWatchVersion.of(LEADER, 3L))).clearCache()).isFalse();
    eventCache.processStartTransactionsUpdate(ImmutableSet.of(3L), emptySuccess);
    verifyStage();
    assertThat(eventCache.getUpdateForTransactions(ImmutableSet.of(3L), Optional.of(LockWatchVersion.of(LEADER, 3L))).clearCache()).isFalse();
    eventCache.processStartTransactionsUpdate(ImmutableSet.of(99L), success);
    verifyStage();
    assertThat(eventCache.getUpdateForTransactions(ImmutableSet.of(99L), Optional.of(LockWatchVersion.of(LEADER, 3L))).events()).containsExactly(lockEvent);
    assertThat(eventCache.getUpdateForTransactions(ImmutableSet.of(99L), Optional.of(LockWatchVersion.of(LEADER, 4L))).events()).isEmpty();
}
Also used : LockWatchStateUpdate(com.palantir.lock.watch.LockWatchStateUpdate) LockWatchEvent(com.palantir.lock.watch.LockWatchEvent) Test(org.junit.Test)

Example 4 with LockWatchStateUpdate

use of com.palantir.lock.watch.LockWatchStateUpdate in project atlasdb by palantir.

the class LockWatchEventCacheIntegrationTest method cacheClearedOnSnapshotUpdate.

@Test
public void cacheClearedOnSnapshotUpdate() {
    setupInitialState();
    eventCache.processStartTransactionsUpdate(TIMESTAMPS_2, SUCCESS);
    verifyStage();
    LockWatchStateUpdate snapshot2 = LockWatchStateUpdate.snapshot(LEADER, 7L, ImmutableSet.of(DESCRIPTOR), ImmutableSet.of());
    Set<Long> timestamps3 = ImmutableSet.of(123L, 1255L);
    eventCache.processStartTransactionsUpdate(timestamps3, snapshot2);
    verifyStage();
}
Also used : LockWatchStateUpdate(com.palantir.lock.watch.LockWatchStateUpdate) Test(org.junit.Test)

Example 5 with LockWatchStateUpdate

use of com.palantir.lock.watch.LockWatchStateUpdate in project atlasdb by palantir.

the class LockEventLogImplTest method emptyLogTest.

@Test
public void emptyLogTest() {
    LockWatchStateUpdate update = log.getLogDiff(NEGATIVE_VERSION_CURRENT_LOG_ID);
    LockWatchStateUpdate.Success success = UpdateVisitors.assertSuccess(update);
    assertThat(success.lastKnownVersion()).isEqualTo(-1L);
    assertThat(success.events()).isEmpty();
}
Also used : LockWatchStateUpdate(com.palantir.lock.watch.LockWatchStateUpdate) Test(org.junit.Test)

Aggregations

LockWatchStateUpdate (com.palantir.lock.watch.LockWatchStateUpdate)18 Test (org.junit.Test)15 LockWatchReference (com.palantir.lock.watch.LockWatchReferences.LockWatchReference)5 LockWatchEvent (com.palantir.lock.watch.LockWatchEvent)3 TransactionLockWatchFailedException (com.palantir.atlasdb.transaction.api.TransactionLockWatchFailedException)2 AtlasRowLockDescriptor (com.palantir.lock.AtlasRowLockDescriptor)2 LockDescriptor (com.palantir.lock.LockDescriptor)2 Timer (com.codahale.metrics.Timer)1 LeaderTime (com.palantir.lock.v2.LeaderTime)1 TaggedMetricRegistry (com.palantir.tritium.metrics.registry.TaggedMetricRegistry)1 UUID (java.util.UUID)1