use of com.palantir.atlasdb.transaction.impl.metrics.TransactionOutcomeMetrics in project atlasdb by palantir.
the class SnapshotTransactionTest method commitThrowsIfRolledBackAtCommitTime_expiredLocks.
@Test
public void commitThrowsIfRolledBackAtCommitTime_expiredLocks() {
final Cell cell = Cell.create(PtBytes.toBytes("row1"), PtBytes.toBytes("column1"));
TimelockService timelockService = spy(inMemoryTimeLockRule.getLegacyTimelockService());
// expire the locks when the pre-commit check happens - this is guaranteed to be after we've written the data
PreCommitCondition condition = unused -> doReturn(ImmutableSet.of()).when(timelockService).refreshLockLeases(any());
ConjureStartTransactionsResponse conjureResponse = startTransactionWithWatches();
LockImmutableTimestampResponse res = conjureResponse.getImmutableTimestamp();
long transactionTs = conjureResponse.getTimestamps().start();
Transaction snapshot = getSnapshotTransactionWith(timelockService, () -> transactionTs, res, condition);
// simulate roll back at commit time
transactionService.putUnlessExists(snapshot.getTimestamp(), TransactionConstants.FAILED_COMMIT_TS);
snapshot.put(TABLE, ImmutableMap.of(cell, PtBytes.toBytes("value")));
assertThatExceptionOfType(TransactionLockTimeoutException.class).isThrownBy(snapshot::commit);
timelockService.unlock(ImmutableSet.of(res.getLock()));
TransactionOutcomeMetricsAssert.assertThat(transactionOutcomeMetrics).hasFailedCommits(1).hasLocksExpired(1);
}
Aggregations