@Override protected TransactionManager getManager() { // create new transaction manager every time because some tests close it return createAndRegisterManager(); }
@Test public void shouldNotConflictIfImmutableTimestampLockExpiresEvenIfNoWritesOnNonThoroughSweptTable() { TransactionManager txnManagerWithMocks = setupTransactionManager(); txnManagerWithMocks.runTaskThrowOnConflict(txn -> { get(txn, TEST_TABLE, "row1", "col1"); return null; }); }
@Test public void shouldNotRunTaskReadOnlyWithClosedTransactionManager() { txMgr.close(); assertThatThrownBy(() -> txMgr.runTaskReadOnly((TransactionTask<Void, RuntimeException>) txn -> { put(txn, "row1", "col1", "v1"); return null; })) .isInstanceOf(IllegalStateException.class) .hasMessage("Operations cannot be performed on closed TransactionManager."); }
@Test public void shouldNotConflictIfImmutableTimestampLockExpiresIfNoReadsOrWrites() { TransactionManager txnManagerWithMocks = setupTransactionManager(); txnManagerWithMocks.runTaskThrowOnConflict(txn -> null); }
@Test public void shouldNotMakeRemoteCallsInAReadonlyTransactionIfNoWorkIsDone() { TimestampService mockTimestampService = mock(TimestampService.class); TimestampManagementService mockTimestampManagementService = mock(TimestampManagementService.class); LockService mockLockService = mock(LockService.class); TransactionManager txnManagerWithMocks = SerializableTransactionManager.createForTest( metricsManager, getKeyValueService(), mockTimestampService, mockTimestampManagementService, LockClient.of("foo"), mockLockService, transactionService, () -> AtlasDbConstraintCheckingMode.FULL_CONSTRAINT_CHECKING_THROWS_EXCEPTIONS, conflictDetectionManager, sweepStrategyManager, NoOpCleaner.INSTANCE, AbstractTransactionTest.GET_RANGES_THREAD_POOL_SIZE, AbstractTransactionTest.DEFAULT_GET_RANGES_CONCURRENCY, MultiTableSweepQueueWriter.NO_OP); // fetch an immutable timestamp once so it's cached when(mockTimestampService.getFreshTimestamp()).thenReturn(1L); when(mockLockService.getMinLockedInVersionId("foo")).thenReturn(1L); txnManagerWithMocks.getImmutableTimestamp(); verify(mockTimestampService).getFreshTimestamp(); verify(mockLockService).getMinLockedInVersionId("foo"); // now execute a read transaction txnManagerWithMocks.runTaskReadOnly(txn -> null); verifyNoMoreInteractions(mockLockService); verifyNoMoreInteractions(mockTimestampService); verifyNoMoreInteractions(mockTimestampManagementService); }
@Test public void shouldNotRunTaskWithRetryWithClosedTransactionManager() { txMgr.close(); assertThatThrownBy(() -> txMgr.runTaskWithRetry((TransactionTask<Void, RuntimeException>) txn -> { put(txn, "row1", "col1", "v1"); return null; })) .isInstanceOf(IllegalStateException.class) .hasMessage("Operations cannot be performed on closed TransactionManager."); }
@Test public void shouldConflictIfImmutableTimestampLockExpiresEvenIfNoWritesOnThoroughSweptTable() { TransactionManager txnManagerWithMocks = setupTransactionManager(); assertThatThrownBy(() -> txnManagerWithMocks.runTaskThrowOnConflict(txn -> { get(txn, TEST_TABLE_THOROUGH, "row1", "col1"); return null; })) .isInstanceOf(TransactionFailedRetriableException.class); }
@Test public void shouldNotRunTaskThrowOnConflictWithClosedTransactionManager() { txMgr.close(); assertThatThrownBy(() -> txMgr.runTaskThrowOnConflict((TransactionTask<Void, RuntimeException>) txn -> { put(txn, "row1", "col1", "v1"); return null; })) .isInstanceOf(IllegalStateException.class) .hasMessage("Operations cannot be performed on closed TransactionManager."); }