Search in sources :

Example 1 with IdUuidPair

use of org.sonar.db.purge.IdUuidPair in project sonarqube by SonarSource.

the class DefaultPeriodCleanerTest method doClean.

@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();
}
Also used : DbSession(org.sonar.db.DbSession) PurgeableAnalysisDto(org.sonar.db.purge.PurgeableAnalysisDto) InOrder(org.mockito.InOrder) PurgeProfiler(org.sonar.db.purge.PurgeProfiler) IdUuidPair(org.sonar.db.purge.IdUuidPair) PurgeDao(org.sonar.db.purge.PurgeDao) Test(org.junit.Test)

Example 2 with IdUuidPair

use of org.sonar.db.purge.IdUuidPair in project sonarqube by SonarSource.

the class PurgeDatastoresStep method execute.

private void execute(Component root) {
    try (DbSession dbSession = dbClient.openSession(true)) {
        IdUuidPair idUuidPair = new IdUuidPair(dbIdsRepository.getComponentId(root), root.getUuid());
        projectCleaner.purge(dbSession, idUuidPair, settingsRepository.getSettings(root), disabledComponentsHolder.getUuids());
        dbSession.commit();
    }
}
Also used : DbSession(org.sonar.db.DbSession) IdUuidPair(org.sonar.db.purge.IdUuidPair)

Example 3 with IdUuidPair

use of org.sonar.db.purge.IdUuidPair in project sonarqube by SonarSource.

the class PurgeDatastoresStepTest method verify_call_purge_method_of_the_purge_task.

private void verify_call_purge_method_of_the_purge_task(Component project) {
    treeRootHolder.setRoot(project);
    when(settingsRepository.getSettings(project)).thenReturn(new MapSettings());
    dbIdsRepository.setComponentId(project, PROJECT_ID);
    underTest.execute();
    ArgumentCaptor<IdUuidPair> argumentCaptor = ArgumentCaptor.forClass(IdUuidPair.class);
    verify(projectCleaner).purge(any(DbSession.class), argumentCaptor.capture(), any(Settings.class), anyList());
    assertThat(argumentCaptor.getValue().getId()).isEqualTo(PROJECT_ID);
    assertThat(argumentCaptor.getValue().getUuid()).isEqualTo(PROJECT_UUID);
}
Also used : DbSession(org.sonar.db.DbSession) MapSettings(org.sonar.api.config.MapSettings) IdUuidPair(org.sonar.db.purge.IdUuidPair) Settings(org.sonar.api.config.Settings) MapSettings(org.sonar.api.config.MapSettings)

Aggregations

DbSession (org.sonar.db.DbSession)3 IdUuidPair (org.sonar.db.purge.IdUuidPair)3 Test (org.junit.Test)1 InOrder (org.mockito.InOrder)1 MapSettings (org.sonar.api.config.MapSettings)1 Settings (org.sonar.api.config.Settings)1 PurgeDao (org.sonar.db.purge.PurgeDao)1 PurgeProfiler (org.sonar.db.purge.PurgeProfiler)1 PurgeableAnalysisDto (org.sonar.db.purge.PurgeableAnalysisDto)1