Search in sources :

Example 6 with OpenTransaction

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

Example 7 with OpenTransaction

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

Aggregations

OpenTransaction (com.palantir.atlasdb.transaction.api.OpenTransaction)7 ImmutableList (com.google.common.collect.ImmutableList)3 ImmutableSet (com.google.common.collect.ImmutableSet)3 Iterables (com.google.common.collect.Iterables)3 TransactionToken (com.palantir.atlasdb.api.TransactionToken)3 KeyValueService (com.palantir.atlasdb.keyvalue.api.KeyValueService)3 Transaction (com.palantir.atlasdb.transaction.api.Transaction)3 Preconditions (com.palantir.logsafe.Preconditions)3 Duration (java.time.Duration)3 List (java.util.List)3 Collectors (java.util.stream.Collectors)3 Test (org.junit.Test)3 Cache (com.google.common.cache.Cache)2 CacheBuilder (com.google.common.cache.CacheBuilder)2 AtlasDbService (com.palantir.atlasdb.api.AtlasDbService)2 RangeToken (com.palantir.atlasdb.api.RangeToken)2 TableCell (com.palantir.atlasdb.api.TableCell)2 TableCellVal (com.palantir.atlasdb.api.TableCellVal)2 TableRange (com.palantir.atlasdb.api.TableRange)2 TableRowResult (com.palantir.atlasdb.api.TableRowResult)2