Search in sources :

Example 61 with CeQueueDto

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();
}
Also used : LocalDateTime(java.time.LocalDateTime) AlmSettingDto(org.sonar.db.alm.setting.AlmSettingDto) CeTaskTypes(org.sonar.db.ce.CeTaskTypes) Arrays(java.util.Arrays) STATUS_PROCESSED(org.sonar.db.component.SnapshotDto.STATUS_PROCESSED) PortfolioProjectDto(org.sonar.db.portfolio.PortfolioProjectDto) Date(java.util.Date) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Random(java.util.Random) DbSession(org.sonar.db.DbSession) MeasureDto(org.sonar.db.measure.MeasureDto) UserDismissedMessageDto(org.sonar.db.user.UserDismissedMessageDto) Collections.singletonList(java.util.Collections.singletonList) RandomUtils(org.apache.commons.lang.math.RandomUtils) ByteArrayInputStream(java.io.ByteArrayInputStream) Arrays.asList(java.util.Arrays.asList) ComponentTesting(org.sonar.db.component.ComponentTesting) UuidFactoryFast(org.sonar.core.util.UuidFactoryFast) ZoneOffset(java.time.ZoneOffset) NewCodePeriodType(org.sonar.db.newcodeperiod.NewCodePeriodType) DbTester(org.sonar.db.DbTester) IssueChangeDto(org.sonar.db.issue.IssueChangeDto) CeTaskMessageType(org.sonar.db.ce.CeTaskMessageType) ImmutableSet(com.google.common.collect.ImmutableSet) WebhookDto(org.sonar.db.webhook.WebhookDto) System2(org.sonar.api.utils.System2) CloseableIterator(org.sonar.core.util.CloseableIterator) Collection(java.util.Collection) Set(java.util.Set) Collectors(java.util.stream.Collectors) ComponentDbTester(org.sonar.db.component.ComponentDbTester) DbClient(org.sonar.db.DbClient) NewCodePeriodDto(org.sonar.db.newcodeperiod.NewCodePeriodDto) List(java.util.List) ComponentDto(org.sonar.db.component.ComponentDto) ComponentTesting.newSubPortfolio(org.sonar.db.component.ComponentTesting.newSubPortfolio) Stream(java.util.stream.Stream) ProjectDto(org.sonar.db.project.ProjectDto) UTC(java.time.ZoneOffset.UTC) CATEGORY_VERSION(org.sonar.db.event.EventDto.CATEGORY_VERSION) Optional(java.util.Optional) WebhookDeliveryLiteDto(org.sonar.db.webhook.WebhookDeliveryLiteDto) MoreObjects.firstNonNull(com.google.common.base.MoreObjects.firstNonNull) IssueTesting.newCodeReferenceIssue(org.sonar.db.issue.IssueTesting.newCodeReferenceIssue) PropertyDto(org.sonar.db.property.PropertyDto) EventDto(org.sonar.db.event.EventDto) ComponentTesting.newDirectory(org.sonar.db.component.ComponentTesting.newDirectory) Mockito.mock(org.mockito.Mockito.mock) IntStream(java.util.stream.IntStream) BranchDto(org.sonar.db.component.BranchDto) ComponentTesting.newBranchDto(org.sonar.db.component.ComponentTesting.newBranchDto) IssueDto(org.sonar.db.issue.IssueDto) RuleDefinitionDto(org.sonar.db.rule.RuleDefinitionDto) UserDto(org.sonar.db.user.UserDto) REPORT(org.sonar.db.ce.CeTaskTypes.REPORT) ComponentTesting.newFileDto(org.sonar.db.component.ComponentTesting.newFileDto) LocalDateTime(java.time.LocalDateTime) EventComponentChangeDto(org.sonar.db.event.EventComponentChangeDto) Mockito.verifyZeroInteractions(org.mockito.Mockito.verifyZeroInteractions) CeTaskInputDao(org.sonar.db.ce.CeTaskInputDao) Uuids(org.sonar.core.util.Uuids) CeActivityDto(org.sonar.db.ce.CeActivityDto) SnapshotTesting.newSnapshot(org.sonar.db.component.SnapshotTesting.newSnapshot) DateUtils(org.apache.commons.lang.time.DateUtils) EventTesting(org.sonar.db.event.EventTesting) Status(org.sonar.db.ce.CeQueueDto.Status) ComponentTesting.newProjectCopy(org.sonar.db.component.ComponentTesting.newProjectCopy) CeTaskCharacteristicDto(org.sonar.db.ce.CeTaskCharacteristicDto) WebhookDeliveryTesting.newDto(org.sonar.db.webhook.WebhookDeliveryTesting.newDto) BranchType(org.sonar.db.component.BranchType) Collections.emptySet(java.util.Collections.emptySet) FileSourceDto(org.sonar.db.source.FileSourceDto) RandomStringUtils.randomAlphabetic(org.apache.commons.lang.RandomStringUtils.randomAlphabetic) WebhookDeliveryTesting.selectAllDeliveryUuids(org.sonar.db.webhook.WebhookDeliveryTesting.selectAllDeliveryUuids) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) STATUS_UNPROCESSED(org.sonar.db.component.SnapshotDto.STATUS_UNPROCESSED) Mockito.verify(org.mockito.Mockito.verify) Consumer(java.util.function.Consumer) Rule(org.junit.Rule) MetricDto(org.sonar.db.metric.MetricDto) Issue(org.sonar.api.issue.Issue) LiveMeasureDto(org.sonar.db.measure.LiveMeasureDto) CeQueueDto(org.sonar.db.ce.CeQueueDto) Tuple.tuple(org.assertj.core.groups.Tuple.tuple) SnapshotDto(org.sonar.db.component.SnapshotDto) Collections(java.util.Collections) CeTaskMessageDto(org.sonar.db.ce.CeTaskMessageDto) ComponentTesting.newModuleDto(org.sonar.db.component.ComponentTesting.newModuleDto) ComponentDto(org.sonar.db.component.ComponentDto) CeQueueDto(org.sonar.db.ce.CeQueueDto) Test(org.junit.Test)

Example 62 with CeQueueDto

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;
}
Also used : CeActivityDto(org.sonar.db.ce.CeActivityDto) CeQueueDto(org.sonar.db.ce.CeQueueDto)

Example 63 with CeQueueDto

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;
}
Also used : CeQueueDto(org.sonar.db.ce.CeQueueDto)

Example 64 with CeQueueDto

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;
}
Also used : CeQueueDto(org.sonar.db.ce.CeQueueDto)

Example 65 with CeQueueDto

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();
}
Also used : CeActivityDto(org.sonar.db.ce.CeActivityDto) CeQueueDto(org.sonar.db.ce.CeQueueDto)

Aggregations

CeQueueDto (org.sonar.db.ce.CeQueueDto)120 Test (org.junit.Test)58 CeActivityDto (org.sonar.db.ce.CeActivityDto)36 ComponentDto (org.sonar.db.component.ComponentDto)20 DbSession (org.sonar.db.DbSession)18 CeTask (org.sonar.ce.task.CeTask)17 UserDto (org.sonar.db.user.UserDto)17 Ce (org.sonarqube.ws.Ce)11 CeTaskCharacteristicDto (org.sonar.db.ce.CeTaskCharacteristicDto)6 List (java.util.List)5 Optional (java.util.Optional)5 Random (java.util.Random)5 Collectors (java.util.stream.Collectors)5 System2 (org.sonar.api.utils.System2)5 Arrays (java.util.Arrays)4 Arrays.asList (java.util.Arrays.asList)4 Collection (java.util.Collection)4 Collections (java.util.Collections)4 Date (java.util.Date)4 IntStream (java.util.stream.IntStream)4