private List<IdUuidPair> getHugeNumberOfIdUuidPairs() { List<IdUuidPair> hugeNbOfSnapshotIds = newArrayList(); for (long i = 0; i < 4500; i++) { hugeNbOfSnapshotIds.add(new IdUuidPair(i, "uuid_" + i)); } return hugeNbOfSnapshotIds; }
private static IdUuidPair toIdUuidPair(ComponentDto dto) { return new IdUuidPair(dto.getId(), dto.uuid()); }
private static IdUuidPair toIdUuidPair(PurgeableAnalysisDto snapshot) { return new IdUuidPair(snapshot.getAnalysisId(), snapshot.getAnalysisUuid()); }
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 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)); }
@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); }
@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); }
@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 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"); } }
@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 shouldDeleteHistoricalDataOfDirectoriesAndFiles() { db.prepareDbUnit(getClass(), "shouldDeleteHistoricalDataOfDirectoriesAndFiles.xml"); PurgeConfiguration conf = new PurgeConfiguration(new IdUuidPair(THE_PROJECT_ID, "PROJECT_UUID"), asList(Scopes.DIRECTORY, Scopes.FILE), 30, Optional.of(30), System2.INSTANCE, Collections.emptyList()); underTest.purge(dbSession, conf, PurgeListener.EMPTY, new PurgeProfiler()); dbSession.commit(); db.assertDbUnit(getClass(), "shouldDeleteHistoricalDataOfDirectoriesAndFiles-result.xml", "projects", "snapshots", "project_measures"); }
@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); }
@Test public void shouldDeleteAnalyses() { db.prepareDbUnit(getClass(), "shouldDeleteAnalyses.xml"); underTest.deleteAnalyses(dbSession, new PurgeProfiler(), ImmutableList.of(new IdUuidPair(3, "u3"))); db.assertDbUnit(getClass(), "shouldDeleteAnalyses-result.xml", "snapshots"); }
private void execute(Component root) { try (DbSession dbSession = dbClient.openSession(true)) { IdUuidPair idUuidPair = new IdUuidPair(dbIdsRepository.getComponentId(root), root.getUuid()); projectCleaner.purge(dbSession, idUuidPair, configRepository.getConfiguration(), disabledComponentsHolder.getUuids()); dbSession.commit(); } }
/** * Test that all related data is purged. */ @Test public void shouldPurgeAnalysis() { dbTester.prepareDbUnit(getClass(), "shouldPurgeAnalysis.xml"); new PurgeCommands(dbTester.getSession(), profiler).purgeAnalyses(singletonList(new IdUuidPair(1, "u1"))); dbTester.assertDbUnit(getClass(), "shouldPurgeAnalysis-result.xml", "snapshots", "analysis_properties", "project_measures", "duplications_index", "events"); }
@Test public void delete_wasted_measures_when_purging_analysis() { dbTester.prepareDbUnit(getClass(), "shouldDeleteWastedMeasuresWhenPurgingAnalysis.xml"); new PurgeCommands(dbTester.getSession(), profiler).purgeAnalyses(singletonList(new IdUuidPair(1, "u1"))); dbTester.assertDbUnit(getClass(), "shouldDeleteWastedMeasuresWhenPurgingAnalysis-result.xml", "project_measures"); }
@Test public void doClean() { PurgeDao dao = mock(PurgeDao.class); DbSession session = mock(DbSession.class); when(dao.selectPurgeableAnalyses("uuid_123", session)).thenReturn(Arrays.asList( new PurgeableAnalysisDto().setAnalysisId(999).setAnalysisUuid("u999").setDate(System2.INSTANCE.now()), new PurgeableAnalysisDto().setAnalysisId(456).setAnalysisUuid("u456").setDate(System2.INSTANCE.now()) )); Filter filter1 = newFirstSnapshotInListFilter(); Filter filter2 = newFirstSnapshotInListFilter(); PurgeProfiler profiler = new PurgeProfiler(); DefaultPeriodCleaner cleaner = new DefaultPeriodCleaner(dao, profiler); cleaner.doClean("uuid_123", Arrays.asList(filter1, filter2), session); InOrder inOrder = Mockito.inOrder(dao, filter1, filter2); inOrder.verify(filter1).log(); inOrder.verify(dao, times(1)).deleteAnalyses(eq(session), eq(profiler), eq(ImmutableList.of(new IdUuidPair(999, "u999")))); inOrder.verify(filter2).log(); inOrder.verify(dao, times(1)).deleteAnalyses(eq(session), eq(profiler), eq(ImmutableList.of(new IdUuidPair(456, "u456")))); inOrder.verifyNoMoreInteractions(); }
@Test public void delete_files_and_directories() { MapSettings settings = new MapSettings(new PropertyDefinitions(PurgeProperties.all())); settings.setProperty(PurgeConstants.DAYS_BEFORE_DELETING_CLOSED_ISSUES, 5); Date now = new Date(); PurgeConfiguration underTest = PurgeConfiguration.newDefaultPurgeConfiguration(settings.asConfig(), new IdUuidPair(42L, "any-uuid"), emptyList()); assertThat(underTest.getScopesWithoutHistoricalData()) .containsExactlyInAnyOrder(Scopes.DIRECTORY, Scopes.FILE); assertThat(underTest.maxLiveDateOfClosedIssues(now)).isEqualTo(DateUtils.addDays(now, -5)); } }
underTest.deleteAnalyses(dbSession, new PurgeProfiler(), ImmutableList.of(new IdUuidPair(3, "foo"))); assertThat(uuidsIn("event_component_changes", "event_analysis_uuid")) .containsOnly(projectAnalysis1.getUuid(), projectAnalysis2.getUuid()); .containsOnly(projectEvent1.getUuid(), projectEvent2.getUuid(), projectEvent3.getUuid()); underTest.deleteAnalyses(dbSession, new PurgeProfiler(), ImmutableList.of(new IdUuidPair(projectAnalysis1.getId(), projectAnalysis1.getUuid()))); assertThat(uuidsIn("event_component_changes", "event_analysis_uuid")) .containsOnly(projectAnalysis2.getUuid()); .containsOnly(projectEvent2.getUuid(), projectEvent3.getUuid()); underTest.deleteAnalyses(dbSession, new PurgeProfiler(), ImmutableList.of(new IdUuidPair(projectAnalysis4.getId(), projectAnalysis4.getUuid()))); assertThat(uuidsIn("event_component_changes", "event_analysis_uuid")) .containsOnly(projectAnalysis2.getUuid()); .containsOnly(projectEvent2.getUuid(), projectEvent3.getUuid()); underTest.deleteAnalyses(dbSession, new PurgeProfiler(), ImmutableList.of(new IdUuidPair(projectAnalysis3.getId(), projectAnalysis3.getUuid()))); assertThat(uuidsIn("event_component_changes", "event_analysis_uuid")) .containsOnly(projectAnalysis2.getUuid()); .containsOnly(projectEvent2.getUuid()); underTest.deleteAnalyses(dbSession, new PurgeProfiler(), ImmutableList.of(new IdUuidPair(projectAnalysis2.getId(), projectAnalysis2.getUuid()))); assertThat(db.countRowsOfTable("event_component_changes")) .isZero();
private void execute(Component root) { try (DbSession dbSession = dbClient.openSession(true)) { IdUuidPair idUuidPair = new IdUuidPair(dbIdsRepository.getComponentId(root), root.getUuid()); projectCleaner.purge(dbSession, idUuidPair, configRepository.getConfiguration(), disabledComponentsHolder.getUuids()); dbSession.commit(); } }