### Question:
TrimService { @Transactional private int doTrimDerivedTablesOnHeight(int height, boolean isSharding) { log.debug("TRIM: doTrimDerivedTablesOnHeight on height={}, isSharding={}", height, isSharding); long start = System.currentTimeMillis(); TransactionalDataSource dataSource = dbManager.getDataSource(); boolean inTransaction = dataSource.isInTransaction(); log.debug("doTrimDerivedTablesOnHeight height = '{}', inTransaction = '{}'", height, inTransaction); if (!inTransaction) { dataSource.begin(); } long onlyTrimTime = 0; int epochTime = timeService.getEpochTime(); int pruningTime = epochTime - epochTime % DEFAULT_PRUNABLE_UPDATE_PERIOD; for (DerivedTableInterface table : dbTablesRegistry.getDerivedTables()) { log.trace("Try to acquire lock..."); globalSync.readLock(); log.trace("Got it."); try { long startTime = System.currentTimeMillis(); table.prune(pruningTime); table.trim(height, isSharding); dataSource.commit(false); long duration = System.currentTimeMillis() - startTime; onlyTrimTime += duration; } finally { globalSync.readUnlock(); } } log.info("Trim time onlyTrim/full: {} / {} ms, pruning='{}' on height='{}'", onlyTrimTime, System.currentTimeMillis() - start, pruningTime, height); return pruningTime; } @Inject  TrimService(DatabaseManager databaseManager,
                       DerivedTablesRegistry derivedDbTablesRegistry,
                       GlobalSync globalSync,
                       TimeService timeService,
                       Event<TrimData> trimEvent,
                       Event<TrimConfig> trimConfigEvent,
                       TrimDao trimDao,
                       @Property(value = "apl.maxRollback", defaultValue = "720") int maxRollback
    ); int getLastTrimHeight(); void init(int height, int shardInitialBlockHeight); void trimDerivedTables(int height, boolean async); void doTrimDerivedTablesOnBlockchainHeight(int blockchainHeight, boolean async); void resetTrim(); void resetTrim(int height); int doTrimDerivedTablesOnHeightLocked(int height, boolean isSharding); void updateTrimConfig(boolean enableTrim, boolean clearQueue); boolean isTrimming(); void waitTrimming();  }### Answer:
@Test void testDoTrimDerivedTablesOnHeight() { doReturn(List.of(derivedTable, derivedTable)).when(registry).getDerivedTables(); TransactionalDataSource dataSource = spy(databaseManager.getDataSource()); doReturn(dataSource).when(databaseManager).getDataSource(); DbUtils.inTransaction(extension, con -> trimService.doTrimDerivedTablesOnHeightLocked(2000, false)); verify(dataSource, times(2)).commit(false); verify(derivedTable, times(2)).trim(2000, false); }