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();
}
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.");
}
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();
}
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();
}
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();
}
Aggregations