Source:
<code>public void testDeleteDontMarkPreviouslyMarkedSearchesAsDeleted() { DatabaseSearchCacheSvcImpl.setMaximumResultsToDeleteInOnePassForUnitTest(5); DatabaseSearchCacheSvcImpl.setMaximumSearchesToCheckForDeletionCandidacyForUnitTest(10); runInTransaction(()->{ for (int i = 0; i < 20; i++) { Search search = new Search(); search.setCreated(DateUtils.addDays(new Date(), -1)); search.setLastUpdated(DateUtils.addDays(new Date(), -1), DateUtils.addDays(new Date(), -1)); search.setUuid(UUID.randomUUID().toString()); search.setSearchType(SearchTypeEnum.SEARCH); search.setStatus(SearchStatusEnum.FINISHED); mySearchDao.save(search); if (i < 3) { for (int j = 0; j < 10; j++) { SearchResult sr = new SearchResult(search); sr.setOrder(j); sr.setResourcePid((long) j); mySearchResultDao.save(sr); } } } }); runInTransaction(()->{ assertEquals(20, mySearchDao.count()); assertEquals(30, mySearchResultDao.count()); }); myCaptureQueriesListener.clear(); myDataaseCacheSvc.pollForStaleSearchesAndDeleteThem(); runInTransaction(()->{ assertEquals(13, mySearchDao.count()); assertEquals(3, mySearchDao.countDeleted()); assertEquals(15, mySearchResultDao.count()); }); <START> myCaptureQueriesListener.clear(); <END> myDataaseCacheSvc.pollForStaleSearchesAndDeleteThem(); runInTransaction(()->{ assertEquals(6, mySearchDao.count()); assertEquals(6, mySearchDao.countDeleted()); assertEquals(0, mySearchResultDao.count()); }); myCaptureQueriesListener.clear(); myDataaseCacheSvc.pollForStaleSearchesAndDeleteThem(); runInTransaction(()->{ assertEquals(0, mySearchDao.count()); assertEquals(0, mySearchDao.countDeleted()); assertEquals(0, mySearchResultDao.count()); }); }</code><technical_language>this</technical_language>

Target:
public void testDeleteDontMarkPreviouslyMarkedSearchesAsDeleted() { DatabaseSearchCacheSvcImpl.setMaximumResultsToDeleteInOnePassForUnitTest(5); DatabaseSearchCacheSvcImpl.setMaximumSearchesToCheckForDeletionCandidacyForUnitTest(10); runInTransaction(()->{ for (int i = 0; i < 20; i++) { Search search = new Search(); search.setCreated(DateUtils.addDays(new Date(), -1)); search.setLastUpdated(DateUtils.addDays(new Date(), -1), DateUtils.addDays(new Date(), -1)); search.setUuid(UUID.randomUUID().toString()); search.setSearchType(SearchTypeEnum.SEARCH); search.setStatus(SearchStatusEnum.FINISHED); mySearchDao.save(search); if (i < 3) { for (int j = 0; j < 10; j++) { SearchResult sr = new SearchResult(search); sr.setOrder(j); sr.setResourcePid((long) j); mySearchResultDao.save(sr); } } } }); runInTransaction(()->{ assertEquals(20, mySearchDao.count()); assertEquals(30, mySearchResultDao.count()); }); myDataaseCacheSvc.pollForStaleSearchesAndDeleteThem(); runInTransaction(()->{ assertEquals(13, mySearchDao.count()); assertEquals(3, mySearchDao.countDeleted()); assertEquals(15, mySearchResultDao.count()); }); myDataaseCacheSvc.pollForStaleSearchesAndDeleteThem(); runInTransaction(()->{ assertEquals(6, mySearchDao.count()); assertEquals(6, mySearchDao.countDeleted()); assertEquals(0, mySearchResultDao.count()); }); myDataaseCacheSvc.pollForStaleSearchesAndDeleteThem(); runInTransaction(()->{ assertEquals(0, mySearchDao.count()); assertEquals(0, mySearchDao.countDeleted()); assertEquals(0, mySearchResultDao.count()); }); }