@Test public void canMarkVariousOutcomes() { Map<Integer, Runnable> tasks = ImmutableMap.<Integer, Runnable>builderWithExpectedSize(6) .put(1, transactionOutcomeMetrics::markAbort) .put(2, transactionOutcomeMetrics::markSuccessfulCommit) .put(3, transactionOutcomeMetrics::markLocksExpired) .put(4, transactionOutcomeMetrics::markPutUnlessExistsFailed) .put(5, transactionOutcomeMetrics::markRollbackOtherTransaction) .put(6, transactionOutcomeMetrics::markPreCommitCheckFailed) .build(); tasks.entrySet().forEach(entry -> IntStream.range(0, entry.getKey()).forEach(unused -> entry.getValue().run())); assertThat(transactionOutcomeMetrics) .hasAborts(1) .hasSuccessfulCommits(2) .hasLocksExpired(3) .hasPutUnlessExistsFailures(4) .hasRollbackOther(5) .hasPreCommitCheckFailures(6); }
@Test public void canMarkOneSuccessfulCommit() { transactionOutcomeMetrics.markSuccessfulCommit(); assertThat(transactionOutcomeMetrics).hasSuccessfulCommits(1); }
@Test public void readTransactionSucceedsIfConditionSucceeds() { serializableTxManager.runTaskWithConditionReadOnly(PreCommitConditions.NO_OP, (tx, condition) -> tx.get(TABLE, ImmutableSet.of(TEST_CELL))); TransactionOutcomeMetricsAssert.assertThat(transactionOutcomeMetrics) .hasSuccessfulCommits(1); }
@Test public void transactionDeletesAsyncOnRollback() { DeterministicScheduler executor = new DeterministicScheduler(); TestTransactionManager deleteTxManager = new TestTransactionManagerImpl( metricsManager, keyValueService, timestampService, timestampService, lockClient, lockService, transactionService, conflictDetectionManager, sweepStrategyManager, sweepQueue, executor); Supplier<PreCommitCondition> conditionSupplier = mock(Supplier.class); when(conditionSupplier.get()).thenReturn(ALWAYS_FAILS_CONDITION) .thenReturn(PreCommitConditions.NO_OP); deleteTxManager.runTaskWithConditionWithRetry(conditionSupplier, (tx, condition) -> { tx.put(TABLE, ImmutableMap.of(TEST_CELL, PtBytes.toBytes("value"))); return null; }); verify(keyValueService, times(0)).delete(any(), any()); executor.runUntilIdle(); verify(keyValueService, times(1)).delete(any(), any()); TransactionOutcomeMetricsAssert.assertThat(transactionOutcomeMetrics) .hasSuccessfulCommits(1) .hasFailedCommits(1); }
@Test public void canMarkMultipleSuccessfulCommits() { transactionOutcomeMetrics.markSuccessfulCommit(); transactionOutcomeMetrics.markSuccessfulCommit(); transactionOutcomeMetrics.markSuccessfulCommit(); transactionOutcomeMetrics.markSuccessfulCommit(); assertThat(transactionOutcomeMetrics).hasSuccessfulCommits(4); }