@Test public void testCleanupOldAssetExtractionsMultipleBranch() throws Exception { String assetPath = "path/to/asset.xliff"; Repository repository = createRepoWithThreeAssetExtractions(assetPath); Asset asset = assetRepository.findByPathAndRepositoryId(assetPath, repository.getId()); List<AssetExtraction> originalAssetExtractions = assetExtractionRepository.findByAsset(asset); AssetExtraction lastSuccessfulAssetExtraction = asset.getLastSuccessfulAssetExtraction(); assertEquals("There should be 3 asset extractions", 3, originalAssetExtractions.size()); List<String> branches = Arrays.asList("branch1", "branch2"); branches.forEach(branch -> createOrUpdateAssetAndWaitUntilProcessingEnds(repository, assetPath, 1, branch)); branches.forEach(branch -> createOrUpdateAssetAndWaitUntilProcessingEnds(repository, assetPath, 2, branch)); List<AssetExtraction> afterBranches = assetExtractionRepository.findByAsset(asset); assertEquals("There should be 7 asset extractions (3 orginal + 4 x per branch)", 11, afterBranches.size()); assetExtractionCleanupService.cleanupOldAssetExtractions(); List<AssetExtraction> assetExtractionsAfterCleanup = assetExtractionRepository.findByAsset(asset); assertEquals("There should be 1 assets extraction per branch (3) and one merged asset extraction", 4, assetExtractionsAfterCleanup.size()); }
public void cleanupOldAssetExtractions() { logger.debug("cleanupOldAssetExtractions"); List<Long> assetExtractionIdsToDelete; do { PageRequest pageable = PageRequest.of(0, 5); assetExtractionIdsToDelete = assetExtractionRepository.findFinishedAndOldAssetExtractions(pageable); for (Long assetExtractionIdToDelete : assetExtractionIdsToDelete) { deleteAssetExtractionAndRelatedEntities(assetExtractionIdToDelete); } } while (!assetExtractionIdsToDelete.isEmpty()); }
AssetExtractionCleanupService { public void cleanupOldAssetExtractions() { logger.debug("cleanupOldAssetExtractions"); List<Long> assetExtractionIdsToDelete; do { PageRequest pageable = PageRequest.of(0, 5); assetExtractionIdsToDelete = assetExtractionRepository.findFinishedAndOldAssetExtractions(pageable); for (Long assetExtractionIdToDelete : assetExtractionIdsToDelete) { deleteAssetExtractionAndRelatedEntities(assetExtractionIdToDelete); } } while (!assetExtractionIdsToDelete.isEmpty()); } }
AssetExtractionCleanupService { public void cleanupOldAssetExtractions() { logger.debug("cleanupOldAssetExtractions"); List<Long> assetExtractionIdsToDelete; do { PageRequest pageable = PageRequest.of(0, 5); assetExtractionIdsToDelete = assetExtractionRepository.findFinishedAndOldAssetExtractions(pageable); for (Long assetExtractionIdToDelete : assetExtractionIdsToDelete) { deleteAssetExtractionAndRelatedEntities(assetExtractionIdToDelete); } } while (!assetExtractionIdsToDelete.isEmpty()); }  }
AssetExtractionCleanupService { public void cleanupOldAssetExtractions() { logger.debug("cleanupOldAssetExtractions"); List<Long> assetExtractionIdsToDelete; do { PageRequest pageable = PageRequest.of(0, 5); assetExtractionIdsToDelete = assetExtractionRepository.findFinishedAndOldAssetExtractions(pageable); for (Long assetExtractionIdToDelete : assetExtractionIdsToDelete) { deleteAssetExtractionAndRelatedEntities(assetExtractionIdToDelete); } } while (!assetExtractionIdsToDelete.isEmpty()); }  void cleanupOldAssetExtractions(); }
AssetExtractionCleanupService { public void cleanupOldAssetExtractions() { logger.debug("cleanupOldAssetExtractions"); List<Long> assetExtractionIdsToDelete; do { PageRequest pageable = PageRequest.of(0, 5); assetExtractionIdsToDelete = assetExtractionRepository.findFinishedAndOldAssetExtractions(pageable); for (Long assetExtractionIdToDelete : assetExtractionIdsToDelete) { deleteAssetExtractionAndRelatedEntities(assetExtractionIdToDelete); } } while (!assetExtractionIdsToDelete.isEmpty()); }  void cleanupOldAssetExtractions();  }