use of com.palantir.atlasdb.transaction.api.OpenTransaction in project atlasdb by palantir.
the class LockWatchEventIntegrationTest method upToDateVersionReturnsOnlyNecessaryEvents.
@Test
public void upToDateVersionReturnsOnlyNecessaryEvents() {
LockWatchVersion baseVersion = getCurrentVersion();
performWriteTransactionLockingAndUnlockingCells(ImmutableMap.of(CELL_1, DATA_1));
OpenTransaction secondTxn = startSingleTransaction();
performWriteTransactionLockingAndUnlockingCells(ImmutableMap.of(CELL_2, DATA_2));
LockWatchVersion currentVersion = getCurrentVersion();
performWriteTransactionLockingAndUnlockingCells(ImmutableMap.of(CELL_3, DATA_3));
OpenTransaction fifthTxn = startSingleTransaction();
TransactionsLockWatchUpdate update = getUpdateForTransactions(Optional.of(currentVersion), secondTxn, fifthTxn);
assertThat(update.clearCache()).isFalse();
assertThat(update.startTsToSequence().get(secondTxn.getTimestamp()).version()).isEqualTo(baseVersion.version() + 2);
assertThat(update.startTsToSequence().get(fifthTxn.getTimestamp()).version()).isEqualTo(currentVersion.version() + 2);
// Note that the lock/unlock events for CELL_2 are not present because a more up-to-date version was passed in
assertThat(lockedDescriptors(update.events())).containsExactlyInAnyOrderElementsOf(getDescriptors(CELL_3));
assertThat(unlockedDescriptors(update.events())).containsExactlyInAnyOrderElementsOf(getDescriptors(CELL_3));
assertThat(watchDescriptors(update.events())).isEmpty();
}
use of com.palantir.atlasdb.transaction.api.OpenTransaction in project atlasdb by palantir.
the class LockWatchEventIntegrationTest method multipleTransactionVersionsReturnsSnapshotAndOnlyRelevantRecentEvents.
@Test
public void multipleTransactionVersionsReturnsSnapshotAndOnlyRelevantRecentEvents() {
LockWatchVersion baseVersion = getCurrentVersion();
performWriteTransactionLockingAndUnlockingCells(ImmutableMap.of(CELL_1, DATA_1, CELL_2, DATA_2));
OpenTransaction secondTxn = startSingleTransaction();
performWriteTransactionLockingAndUnlockingCells(ImmutableMap.of(CELL_3, DATA_3));
// The purpose of this transaction is to test when we can guarantee that there are some locks taken out
// without the subsequent unlock event.
Runnable cleanup = performWriteTransactionThatBlocksAfterLockingCells();
OpenTransaction fifthTxn = startSingleTransaction();
TransactionsLockWatchUpdate update = getUpdateForTransactions(Optional.empty(), secondTxn, fifthTxn);
/*
There are five transactions in this test, with the following events:
Transaction 1: lock C1, C2; unlock C1, C2.
Transaction 2: uncommitted, no events
Transaction 3: lock C3; unlock C3
Transaction 4: lock C1, C4; no unlocks (as stuck in commit stage)
Transaction 5: uncommitted, no events
From the above, Transactions 1 and 3 should increment the version by 2 each; Transaction 4 by 1. Thus,
Transaction 2 should be at base + 2, and Transaction 5 at base + 5.
*/
assertThat(update.clearCache()).isTrue();
assertThat(update.startTsToSequence().get(secondTxn.getTimestamp()).version()).isEqualTo(baseVersion.version() + 2);
assertThat(update.startTsToSequence().get(fifthTxn.getTimestamp()).version()).isEqualTo(baseVersion.version() + 5);
assertThat(lockedDescriptors(update.events())).containsExactlyInAnyOrderElementsOf(getDescriptors(CELL_1, CELL_3, CELL_4));
assertThat(unlockedDescriptors(update.events())).containsExactlyInAnyOrderElementsOf(getDescriptors(CELL_3));
assertThat(watchDescriptors(update.events())).isEmpty();
secondTxn.finish(_unused -> null);
fifthTxn.finish(_unused -> null);
cleanup.run();
}
Aggregations