private List<IdUuidPair> getHugeNumberOfIdUuidPairs() { List<IdUuidPair> hugeNbOfSnapshotIds = newArrayList(); for (long i = 0; i < 4500; i++) { hugeNbOfSnapshotIds.add(new IdUuidPair(i, "uuid_" + i)); } return hugeNbOfSnapshotIds; }
public ProjectCleaner purge(DbSession session, IdUuidPair rootId, Configuration projectConfig, Collection<String> disabledComponentUuids) { long start = System.currentTimeMillis(); profiler.reset(); PurgeConfiguration configuration = newDefaultPurgeConfiguration(projectConfig, rootId, disabledComponentUuids); periodCleaner.clean(session, configuration.rootProjectIdUuid().getUuid(), projectConfig); purgeDao.purge(session, configuration, purgeListener, profiler); session.commit(); logProfiling(start, projectConfig); return this; }
private void verify_call_purge_method_of_the_purge_task(Component project) { treeRootHolder.setRoot(project); when(settingsRepository.getConfiguration()).thenReturn(new MapSettings().asConfig()); dbIdsRepository.setComponentId(project, PROJECT_ID); underTest.execute(new TestComputationStepContext()); ArgumentCaptor<IdUuidPair> argumentCaptor = ArgumentCaptor.forClass(IdUuidPair.class); verify(projectCleaner).purge(any(), argumentCaptor.capture(), any(), any()); assertThat(argumentCaptor.getValue().getId()).isEqualTo(PROJECT_ID); assertThat(argumentCaptor.getValue().getUuid()).isEqualTo(PROJECT_UUID); }
private static IdUuidPair toIdUuidPair(PurgeableAnalysisDto snapshot) { return new IdUuidPair(snapshot.getAnalysisId(), snapshot.getAnalysisUuid()); }
private static void deleteOldClosedIssues(PurgeConfiguration conf, PurgeMapper mapper, PurgeListener listener) { Date toDate = conf.maxLiveDateOfClosedIssues(); String rootUuid = conf.rootProjectIdUuid().getUuid(); List<String> issueKeys = mapper.selectOldClosedIssueKeys(rootUuid, dateToLong(toDate)); executeLargeInputs(issueKeys, input -> { mapper.deleteIssueChangesFromIssueKeys(input); return emptyList(); }); executeLargeInputs(issueKeys, input -> { mapper.deleteIssuesFromKeys(input); return emptyList(); }); listener.onIssuesRemoval(rootUuid, issueKeys); }
private static IdUuidPair toIdUuidPair(ComponentDto dto) { return new IdUuidPair(dto.getId(), dto.uuid()); }
private static void deleteRootComponent(String rootUuid, PurgeMapper mapper, PurgeCommands commands) { List<IdUuidPair> rootAndModulesOrSubviews = mapper.selectRootAndModulesOrSubviewsByProjectUuid(rootUuid); long rootId = rootAndModulesOrSubviews.stream() .filter(pair -> pair.getUuid().equals(rootUuid)) .map(IdUuidPair::getId) .findFirst() .orElseThrow(() -> new IllegalArgumentException("Couldn't find root component with uuid " + rootUuid)); commands.deletePermissions(rootId); commands.deleteLinks(rootUuid); commands.deleteAnalyses(rootUuid); commands.deleteByRootAndModulesOrSubviews(rootAndModulesOrSubviews); commands.deleteComponents(rootUuid); commands.deleteIssues(rootUuid); commands.deleteFileSources(rootUuid); commands.deleteCeActivity(rootUuid); commands.deleteCeQueue(rootUuid); commands.deleteWebhooks(rootUuid); commands.deleteWebhookDeliveries(rootUuid); commands.deleteProjectMappings(rootUuid); commands.deleteProjectAlmBindings(rootUuid); commands.deleteBranch(rootUuid); commands.deleteLiveMeasures(rootUuid); }
private static PurgeConfiguration newConfigurationWith30Days() { return new PurgeConfiguration(new IdUuidPair(THE_PROJECT_ID, THE_PROJECT_UUID), emptyList(), 30, Optional.of(30), System2.INSTANCE, Collections.emptyList()); }
private void purgeDisabledComponents(DbSession session, PurgeConfiguration conf, PurgeListener listener) { PurgeMapper mapper = mapper(session); executeLargeInputs(conf.getDisabledComponentUuids(), input -> { mapper.deleteFileSourcesByFileUuid(input); mapper.resolveComponentIssuesNotAlreadyResolved(input, system2.now()); mapper.deleteLiveMeasuresByComponentUuids(input); return emptyList(); }); listener.onComponentsDisabling(conf.rootProjectIdUuid().getUuid(), conf.getDisabledComponentUuids()); session.commit(); }
private static PurgeConfiguration newConfigurationWith30Days(System2 system2, String rootProjectUuid, String... disabledComponentUuids) { return new PurgeConfiguration(new IdUuidPair(THE_PROJECT_ID, rootProjectUuid), emptyList(), 30, Optional.of(30), system2, asList(disabledComponentUuids)); }
public void purge(DbSession session, PurgeConfiguration conf, PurgeListener listener, PurgeProfiler profiler) { PurgeMapper mapper = session.getMapper(PurgeMapper.class); PurgeCommands commands = new PurgeCommands(session, mapper, profiler); String rootUuid = conf.rootProjectIdUuid().getUuid(); deleteAbortedAnalyses(rootUuid, commands); deleteDataOfComponentsWithoutHistoricalData(session, rootUuid, conf.getScopesWithoutHistoricalData(), commands); purgeAnalyses(commands, rootUuid); purgeDisabledComponents(session, conf, listener); deleteOldClosedIssues(conf, mapper, listener); purgeStaleBranches(commands, conf, mapper, rootUuid); }
@Test public void should_delete_only_old_closed_issues() { Date now = DateUtils.parseDate("2013-05-18"); PurgeConfiguration conf = new PurgeConfiguration(new IdUuidPair(1L, "1"), emptyList(), 30, Optional.empty(), System2.INSTANCE, emptyList()); Date toDate = conf.maxLiveDateOfClosedIssues(now); assertThat(toDate.getYear()).isEqualTo(113);// =2013 assertThat(toDate.getMonth()).isEqualTo(3); // means April assertThat(toDate.getDate()).isEqualTo(18); }
public ProjectCleaner purge(DbSession session, IdUuidPair rootId, Configuration projectConfig, Collection<String> disabledComponentUuids) { long start = System.currentTimeMillis(); profiler.reset(); PurgeConfiguration configuration = newDefaultPurgeConfiguration(projectConfig, rootId, disabledComponentUuids); periodCleaner.clean(session, configuration.rootProjectIdUuid().getUuid(), projectConfig); purgeDao.purge(session, configuration, purgeListener, profiler); session.commit(); logProfiling(start, projectConfig); return this; }
@Test public void extract_ids() { List<IdUuidPair> idUuidPairList = Lists.newArrayList(new IdUuidPair(1L, "ABCD"), new IdUuidPair(2L, "EFGH")); List<Long> ids = IdUuidPairs.ids(idUuidPairList); assertThat(ids).containsOnly(1L, 2L); }
private static void deleteOldClosedIssues(PurgeConfiguration conf, PurgeMapper mapper, PurgeListener listener) { Date toDate = conf.maxLiveDateOfClosedIssues(); String rootUuid = conf.rootProjectIdUuid().getUuid(); List<String> issueKeys = mapper.selectOldClosedIssueKeys(rootUuid, dateToLong(toDate)); executeLargeInputs(issueKeys, input -> { mapper.deleteIssueChangesFromIssueKeys(input); return emptyList(); }); executeLargeInputs(issueKeys, input -> { mapper.deleteIssuesFromKeys(input); return emptyList(); }); listener.onIssuesRemoval(rootUuid, issueKeys); }
@Test public void extract_uuids() { List<IdUuidPair> idUuidPairList = Lists.newArrayList(new IdUuidPair(1L, "ABCD"), new IdUuidPair(2L, "EFGH")); List<String> uuids = IdUuidPairs.uuids(idUuidPairList); assertThat(uuids).containsOnly("ABCD", "EFGH"); } }
public void purge(DbSession session, PurgeConfiguration conf, PurgeListener listener, PurgeProfiler profiler) { PurgeMapper mapper = session.getMapper(PurgeMapper.class); PurgeCommands commands = new PurgeCommands(session, mapper, profiler); String rootUuid = conf.rootProjectIdUuid().getUuid(); deleteAbortedAnalyses(rootUuid, commands); deleteDataOfComponentsWithoutHistoricalData(session, rootUuid, conf.scopesWithoutHistoricalData(), commands); purgeAnalyses(commands, rootUuid); purgeDisabledComponents(session, conf.getDisabledComponentUuids(), listener); deleteOldClosedIssues(conf, mapper, listener); }
@Test public void should_delete_all_closed_issues() { PurgeConfiguration conf = new PurgeConfiguration(new IdUuidPair(1L, "1"), emptyList(), 0, Optional.empty(), System2.INSTANCE, emptyList()); assertThat(conf.maxLiveDateOfClosedIssues()).isNull(); conf = new PurgeConfiguration(new IdUuidPair(1L, "1"), emptyList(), -1, Optional.empty(), System2.INSTANCE, emptyList()); assertThat(conf.maxLiveDateOfClosedIssues()).isNull(); }
@Test public void should_calculate_branch_purge_date() { PurgeConfiguration conf = new PurgeConfiguration(new IdUuidPair(1L, "1"), emptyList(), 30, Optional.empty(), System2.INSTANCE, emptyList()); assertThat(conf.maxLiveDateOfInactiveShortLivingBranches()).isEmpty(); }
@Test public void should_have_empty_branch_purge_date() { PurgeConfiguration conf = new PurgeConfiguration(new IdUuidPair(1L, "1"), emptyList(), 30, Optional.of(10), System2.INSTANCE, emptyList()); assertThat(conf.maxLiveDateOfInactiveShortLivingBranches()).isNotEmpty(); long tenDaysAgo = DateUtils.addDays(new Date(System2.INSTANCE.now()), -10).getTime(); assertThat(conf.maxLiveDateOfInactiveShortLivingBranches().get().getTime()).isBetween(tenDaysAgo - 5000, tenDaysAgo + 5000); }