use of com.palantir.lock.watch.TransactionsLockWatchUpdate in project atlasdb by palantir.
the class LockWatchEventCacheImplTest method getUpdateForTransactionsCondensesSnapshotWherePossible.
@Test
public void getUpdateForTransactionsCondensesSnapshotWherePossible() {
eventCache.processStartTransactionsUpdate(ImmutableSet.of(TIMESTAMP_1), SNAPSHOT_VERSION_1);
eventCache.processStartTransactionsUpdate(ImmutableSet.of(TIMESTAMP_2), SUCCESS_VERSION_2);
eventCache.processStartTransactionsUpdate(ImmutableSet.of(TIMESTAMP_3), SUCCESS_VERSION_3);
verify(eventLog).processUpdate(SNAPSHOT_VERSION_1);
verify(eventLog).processUpdate(SUCCESS_VERSION_2);
verify(eventLog).processUpdate(SUCCESS_VERSION_3);
TransactionsLockWatchUpdate update = eventCache.getUpdateForTransactions(ImmutableSet.of(TIMESTAMP_2, TIMESTAMP_3), Optional.of(VERSION_0));
verify(eventLog).getEventsBetweenVersions(VersionBounds.builder().startVersion(VERSION_0).endVersion(VERSION_3).earliestSnapshotVersion(VERSION_2.version()).build());
assertThat(update.clearCache()).as("provided version is too far behind").isTrue();
assertThat(update.events()).as("events condensed up to version 2").containsExactly(LockWatchCreatedEvent.builder(ImmutableSet.of(REFERENCE_1), ImmutableSet.of(DESCRIPTOR_1, DESCRIPTOR_2)).build(SEQUENCE_2), UNLOCK_DESCRIPTOR_1_VERSION_3);
assertThat(update.startTsToSequence()).containsExactlyInAnyOrderEntriesOf(ImmutableMap.of(TIMESTAMP_2, VERSION_2, TIMESTAMP_3, VERSION_3));
}
use of com.palantir.lock.watch.TransactionsLockWatchUpdate in project atlasdb by palantir.
the class LockWatchEventCacheIntegrationTest method eventsExceedingMaximumCacheSizeAreRetentionedAnyway.
@Test
public void eventsExceedingMaximumCacheSizeAreRetentionedAnyway() {
createEventCache(1, 1);
setupInitialState();
eventCache.processStartTransactionsUpdate(TIMESTAMPS_2, SUCCESS);
TransactionsLockWatchUpdate laterUpdate = eventCache.getUpdateForTransactions(TIMESTAMPS_2, Optional.of(LockWatchVersion.of(LEADER, 3L)));
assertThat(laterUpdate.clearCache()).as("Verify update is a snapshot").isTrue();
assertThat(laterUpdate.events()).as("Verify events are condensed into a snapshot").containsExactly(LockWatchCreatedEvent.builder(ImmutableSet.of(REFERENCE), ImmutableSet.of(DESCRIPTOR, DESCRIPTOR_3)).build(6L));
assertThat(laterUpdate.startTsToSequence()).as("Verify transaction present in timestamp map").containsExactlyEntriesOf(ImmutableMap.of(START_TS_2, LockWatchVersion.of(LEADER, SUCCESS_VERSION)));
}
use of com.palantir.lock.watch.TransactionsLockWatchUpdate in project atlasdb by palantir.
the class LockWatchEventCacheIntegrationTest method veryFarBehindClientDoesNotCauseEncloseCheckToThrow.
@Test
public void veryFarBehindClientDoesNotCauseEncloseCheckToThrow() {
LockWatchStateUpdate.Snapshot snapshot = LockWatchStateUpdate.snapshot(LEADER, 5000L, ImmutableSet.of(DESCRIPTOR_2), ImmutableSet.of());
eventCache.processStartTransactionsUpdate(TIMESTAMPS, snapshot);
TransactionsLockWatchUpdate update = eventCache.getUpdateForTransactions(TIMESTAMPS, Optional.of(LockWatchVersion.of(LEADER, 0L)));
assertThat(update.clearCache()).isTrue();
assertThat(update.events()).containsExactly(LockWatchCreatedEvent.builder(ImmutableSet.of(), ImmutableSet.of(DESCRIPTOR_2)).build(5000L));
assertThat(update.startTsToSequence()).containsExactlyInAnyOrderEntriesOf(ImmutableMap.of(START_TS_1, LockWatchVersion.of(LEADER, 5000L)));
}
use of com.palantir.lock.watch.TransactionsLockWatchUpdate in project atlasdb by palantir.
the class LockWatchEventCacheIntegrationTest method getEventsForTransactionsSomeCondensing.
@Test
public void getEventsForTransactionsSomeCondensing() {
setupInitialState();
eventCache.processStartTransactionsUpdate(TIMESTAMPS_2, SUCCESS);
verifyStage();
eventCache.processStartTransactionsUpdate(ImmutableSet.of(START_TS_3), SUCCESS_2);
verifyStage();
// Client is behind and needs a snapshot, and some but not all events will be condensed
TransactionsLockWatchUpdate results = eventCache.getUpdateForTransactions(ImmutableSet.of(START_TS_2, START_TS_3), Optional.empty());
assertThat(results.clearCache()).isTrue();
assertThat(results.startTsToSequence()).containsExactlyInAnyOrderEntriesOf(ImmutableMap.of(START_TS_2, LockWatchVersion.of(LEADER, 6L), START_TS_3, LockWatchVersion.of(LEADER, 7L)));
assertThat(results.events()).containsExactly(LockWatchCreatedEvent.builder(ImmutableSet.of(REFERENCE), ImmutableSet.of(DESCRIPTOR, DESCRIPTOR_3)).build(6L), LOCK_EVENT_2);
}
use of com.palantir.lock.watch.TransactionsLockWatchUpdate in project atlasdb by palantir.
the class LockWatchEventCacheIntegrationTest method eventsExceedingMinimumCacheSizeAreNotRetentionedForActiveTransactions.
@Test
public void eventsExceedingMinimumCacheSizeAreNotRetentionedForActiveTransactions() {
createEventCache(1);
setupInitialState();
eventCache.processStartTransactionsUpdate(TIMESTAMPS_2, SUCCESS);
TransactionsLockWatchUpdate update = eventCache.getUpdateForTransactions(TIMESTAMPS_2, Optional.of(LockWatchVersion.of(LEADER, 3L)));
assertThat(update.clearCache()).as("Verify update is not a snapshot").isFalse();
assertThat(update.events()).as("Verify events are not condensed into a snapshot").containsExactly(WATCH_EVENT, UNLOCK_EVENT, LOCK_EVENT);
assertThat(update.startTsToSequence()).as("Verify transaction present in timestamp map").containsExactlyEntriesOf(ImmutableMap.of(START_TS_2, LockWatchVersion.of(LEADER, SUCCESS_VERSION)));
}
Aggregations