Search in sources :

Example 6 with TransactionsLockWatchUpdate

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));
}
Also used : TransactionsLockWatchUpdate(com.palantir.lock.watch.TransactionsLockWatchUpdate) Test(org.junit.Test)

Example 7 with TransactionsLockWatchUpdate

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)));
}
Also used : TransactionsLockWatchUpdate(com.palantir.lock.watch.TransactionsLockWatchUpdate) Test(org.junit.Test)

Example 8 with TransactionsLockWatchUpdate

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)));
}
Also used : TransactionsLockWatchUpdate(com.palantir.lock.watch.TransactionsLockWatchUpdate) LockWatchStateUpdate(com.palantir.lock.watch.LockWatchStateUpdate) Test(org.junit.Test)

Example 9 with TransactionsLockWatchUpdate

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);
}
Also used : TransactionsLockWatchUpdate(com.palantir.lock.watch.TransactionsLockWatchUpdate) Test(org.junit.Test)

Example 10 with TransactionsLockWatchUpdate

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)));
}
Also used : TransactionsLockWatchUpdate(com.palantir.lock.watch.TransactionsLockWatchUpdate) Test(org.junit.Test)

Aggregations

TransactionsLockWatchUpdate (com.palantir.lock.watch.TransactionsLockWatchUpdate)19 Test (org.junit.Test)18 LockWatchVersion (com.palantir.lock.watch.LockWatchVersion)5 OpenTransaction (com.palantir.atlasdb.transaction.api.OpenTransaction)2 LockWatchEvent (com.palantir.lock.watch.LockWatchEvent)1 LockWatchStateUpdate (com.palantir.lock.watch.LockWatchStateUpdate)1 UUID (java.util.UUID)1