use of org.sonar.db.ce.CeQueueDto in project sonarqube by SonarSource.
the class PurgeDaoTest method delete_ce_analysis_older_than_180_and_scanner_context_older_than_40_days_of_project_and_branches_when_purging_project.
@Test
public void delete_ce_analysis_older_than_180_and_scanner_context_older_than_40_days_of_project_and_branches_when_purging_project() {
LocalDateTime now = LocalDateTime.now();
ComponentDto project1 = db.components().insertPublicProject();
ComponentDto branch1 = db.components().insertProjectBranch(project1, b -> b.setExcludeFromPurge(true));
Consumer<CeQueueDto> belongsToProject1 = t -> t.setMainComponentUuid(project1.uuid()).setComponentUuid(project1.uuid());
Consumer<CeQueueDto> belongsToBranch1 = t -> t.setMainComponentUuid(project1.uuid()).setComponentUuid(branch1.uuid());
insertCeActivityAndChildDataWithDate("VERY_OLD_1", now.minusDays(180).minusMonths(10), belongsToProject1);
insertCeActivityAndChildDataWithDate("JUST_OLD_ENOUGH_1", now.minusDays(180).minusDays(1), belongsToProject1);
insertCeActivityAndChildDataWithDate("NOT_OLD_ENOUGH_1", now.minusDays(180), belongsToProject1);
insertCeActivityAndChildDataWithDate("RECENT_1", now.minusDays(1), belongsToProject1);
insertCeActivityAndChildDataWithDate("VERY_OLD_2", now.minusDays(180).minusMonths(10), belongsToBranch1);
insertCeActivityAndChildDataWithDate("JUST_OLD_ENOUGH_2", now.minusDays(180).minusDays(1), belongsToBranch1);
insertCeActivityAndChildDataWithDate("NOT_OLD_ENOUGH_2", now.minusDays(180), belongsToBranch1);
insertCeActivityAndChildDataWithDate("RECENT_2", now.minusDays(1), belongsToBranch1);
when(system2.now()).thenReturn(now.toInstant(ZoneOffset.UTC).toEpochMilli());
underTest.purge(db.getSession(), newConfigurationWith30Days(System2.INSTANCE, project1.uuid(), project1.uuid()), PurgeListener.EMPTY, new PurgeProfiler());
assertThat(selectActivity("VERY_OLD_1")).isEmpty();
assertThat(selectTaskInput("VERY_OLD_1")).isEmpty();
assertThat(selectTaskCharacteristic("VERY_OLD_1")).isEmpty();
assertThat(scannerContextExists("VERY_OLD_1")).isFalse();
assertThat(selectActivity("VERY_OLD_2")).isEmpty();
assertThat(selectTaskInput("VERY_OLD_2")).isEmpty();
assertThat(selectTaskCharacteristic("VERY_OLD_2")).isEmpty();
assertThat(scannerContextExists("VERY_OLD_2")).isFalse();
assertThat(selectActivity("JUST_OLD_ENOUGH_1")).isEmpty();
assertThat(selectTaskInput("JUST_OLD_ENOUGH_1")).isEmpty();
assertThat(selectTaskCharacteristic("JUST_OLD_ENOUGH_1")).isEmpty();
assertThat(scannerContextExists("JUST_OLD_ENOUGH_1")).isFalse();
assertThat(selectActivity("JUST_OLD_ENOUGH_2")).isEmpty();
assertThat(selectTaskInput("JUST_OLD_ENOUGH_2")).isEmpty();
assertThat(selectTaskCharacteristic("JUST_OLD_ENOUGH_2")).isEmpty();
assertThat(scannerContextExists("JUST_OLD_ENOUGH_2")).isFalse();
assertThat(selectActivity("NOT_OLD_ENOUGH_1")).isNotEmpty();
assertThat(selectTaskInput("NOT_OLD_ENOUGH_1")).isNotEmpty();
assertThat(selectTaskCharacteristic("NOT_OLD_ENOUGH_1")).hasSize(1);
// because more than 4 weeks old
assertThat(scannerContextExists("NOT_OLD_ENOUGH_1")).isFalse();
assertThat(selectActivity("NOT_OLD_ENOUGH_2")).isNotEmpty();
assertThat(selectTaskInput("NOT_OLD_ENOUGH_2")).isNotEmpty();
assertThat(selectTaskCharacteristic("NOT_OLD_ENOUGH_2")).hasSize(1);
// because more than 4 weeks old
assertThat(scannerContextExists("NOT_OLD_ENOUGH_2")).isFalse();
assertThat(selectActivity("RECENT_1")).isNotEmpty();
assertThat(selectTaskInput("RECENT_1")).isNotEmpty();
assertThat(selectTaskCharacteristic("RECENT_1")).hasSize(1);
assertThat(scannerContextExists("RECENT_1")).isTrue();
assertThat(selectActivity("RECENT_2")).isNotEmpty();
assertThat(selectTaskInput("RECENT_2")).isNotEmpty();
assertThat(selectTaskCharacteristic("RECENT_2")).hasSize(1);
assertThat(scannerContextExists("RECENT_2")).isTrue();
}
use of org.sonar.db.ce.CeQueueDto in project sonarqube by SonarSource.
the class ComponentActionTest method insertActivity.
private CeActivityDto insertActivity(String taskUuid, String componentUuid, CeActivityDto.Status status) {
CeQueueDto queueDto = new CeQueueDto();
queueDto.setTaskType(CeTaskTypes.REPORT);
queueDto.setComponentUuid(componentUuid);
queueDto.setUuid(taskUuid);
CeActivityDto activityDto = new CeActivityDto(queueDto);
activityDto.setStatus(status);
activityDto.setExecutionTimeMs(500L);
activityDto.setAnalysisUuid("U1");
dbTester.getDbClient().ceActivityDao().insert(dbTester.getSession(), activityDto);
dbTester.getSession().commit();
return activityDto;
}
use of org.sonar.db.ce.CeQueueDto in project sonarqube by SonarSource.
the class TaskActionTest method createAndPersistQueueTask.
private CeQueueDto createAndPersistQueueTask(@Nullable ComponentDto component) {
CeQueueDto dto = new CeQueueDto();
dto.setTaskType(CeTaskTypes.REPORT);
dto.setUuid(SOME_TASK_UUID);
dto.setStatus(CeQueueDto.Status.PENDING);
dto.setSubmitterLogin("john");
if (component != null) {
dto.setComponentUuid(component.uuid());
}
persist(dto);
return dto;
}
use of org.sonar.db.ce.CeQueueDto in project sonarqube by SonarSource.
the class ActivityActionTest method insertQueue.
private CeQueueDto insertQueue(String taskUuid, String componentUuid, CeQueueDto.Status status) {
CeQueueDto queueDto = new CeQueueDto();
queueDto.setTaskType(CeTaskTypes.REPORT);
queueDto.setComponentUuid(componentUuid);
queueDto.setUuid(taskUuid);
queueDto.setStatus(status);
dbTester.getDbClient().ceQueueDao().insert(dbTester.getSession(), queueDto);
dbTester.commit();
return queueDto;
}
use of org.sonar.db.ce.CeQueueDto in project sonarqube by SonarSource.
the class PurgeCeActivitiesTest method insertWithDate.
private void insertWithDate(String uuid, long date) {
CeQueueDto queueDto = new CeQueueDto();
queueDto.setUuid(uuid);
queueDto.setTaskType(CeTaskTypes.REPORT);
CeActivityDto dto = new CeActivityDto(queueDto);
dto.setStatus(CeActivityDto.Status.SUCCESS);
when(system2.now()).thenReturn(date);
dbTester.getDbClient().ceActivityDao().insert(dbTester.getSession(), dto);
dbTester.getSession().commit();
}
Aggregations