Search in sources :

Example 56 with CeQueueDto

use of org.sonar.db.ce.CeQueueDto in project sonarqube by SonarSource.

the class PurgeDaoTest method delete_row_in_ce_task_input_referring_to_a_row_in_ce_queue_when_deleting_project.

@Test
public void delete_row_in_ce_task_input_referring_to_a_row_in_ce_queue_when_deleting_project() {
    ComponentDto project = ComponentTesting.newPrivateProjectDto();
    ComponentDto branch = ComponentTesting.newBranchComponent(project, newBranchDto(project));
    ComponentDto anotherBranch = ComponentTesting.newBranchComponent(project, newBranchDto(project));
    ComponentDto anotherProject = ComponentTesting.newPrivateProjectDto();
    dbClient.componentDao().insert(dbSession, project, branch, anotherBranch, anotherProject);
    CeQueueDto projectTask = insertCeQueue(project);
    insertCeTaskInput(projectTask.getUuid());
    CeQueueDto branchTask = insertCeQueue(branch);
    insertCeTaskInput(branchTask.getUuid());
    CeQueueDto anotherBranchTask = insertCeQueue(anotherBranch);
    insertCeTaskInput(anotherBranchTask.getUuid());
    CeQueueDto anotherProjectTask = insertCeQueue(anotherProject);
    insertCeTaskInput(anotherProjectTask.getUuid());
    insertCeTaskInput("non existing task");
    dbSession.commit();
    underTest.deleteProject(dbSession, branch.uuid(), branch.qualifier(), project.name(), project.getKey());
    dbSession.commit();
    assertThat(uuidsIn("ce_queue")).containsOnly(projectTask.getUuid(), anotherBranchTask.getUuid(), anotherProjectTask.getUuid());
    assertThat(taskUuidsIn("ce_task_input")).containsOnly(projectTask.getUuid(), anotherBranchTask.getUuid(), anotherProjectTask.getUuid(), "non existing task");
    underTest.deleteProject(dbSession, project.uuid(), project.qualifier(), project.name(), project.getKey());
    dbSession.commit();
    assertThat(uuidsIn("ce_queue")).containsOnly(anotherProjectTask.getUuid());
    assertThat(taskUuidsIn("ce_task_input")).containsOnly(anotherProjectTask.getUuid(), "non existing task");
}
Also used : ComponentDto(org.sonar.db.component.ComponentDto) CeQueueDto(org.sonar.db.ce.CeQueueDto) Test(org.junit.Test)

Example 57 with CeQueueDto

use of org.sonar.db.ce.CeQueueDto in project sonarqube by SonarSource.

the class PurgeDaoTest method delete_row_in_ce_scanner_context_referring_to_a_row_in_ce_queue_when_deleting_project.

@Test
public void delete_row_in_ce_scanner_context_referring_to_a_row_in_ce_queue_when_deleting_project() {
    ComponentDto project = ComponentTesting.newPrivateProjectDto();
    ComponentDto branch = ComponentTesting.newBranchComponent(project, newBranchDto(project));
    ComponentDto anotherBranch = ComponentTesting.newBranchComponent(project, newBranchDto(project));
    ComponentDto anotherProject = ComponentTesting.newPrivateProjectDto();
    dbClient.componentDao().insert(dbSession, project, branch, anotherBranch, anotherProject);
    CeQueueDto projectTask = insertCeQueue(project);
    insertCeScannerContext(projectTask.getUuid());
    CeQueueDto branchTask = insertCeQueue(branch);
    insertCeScannerContext(branchTask.getUuid());
    CeQueueDto anotherBranchTask = insertCeQueue(anotherBranch);
    insertCeScannerContext(anotherBranchTask.getUuid());
    CeQueueDto anotherProjectTask = insertCeQueue(anotherProject);
    insertCeScannerContext(anotherProjectTask.getUuid());
    insertCeScannerContext("non existing task");
    dbSession.commit();
    underTest.deleteProject(dbSession, branch.uuid(), branch.qualifier(), project.name(), project.getKey());
    dbSession.commit();
    assertThat(uuidsIn("ce_queue")).containsOnly(projectTask.getUuid(), anotherBranchTask.getUuid(), anotherProjectTask.getUuid());
    assertThat(taskUuidsIn("ce_scanner_context")).containsOnly(projectTask.getUuid(), anotherBranchTask.getUuid(), anotherProjectTask.getUuid(), "non existing task");
    underTest.deleteProject(dbSession, project.uuid(), project.qualifier(), project.name(), project.getKey());
    dbSession.commit();
    assertThat(uuidsIn("ce_queue")).containsOnly(anotherProjectTask.getUuid());
    assertThat(taskUuidsIn("ce_scanner_context")).containsOnly(anotherProjectTask.getUuid(), "non existing task");
}
Also used : ComponentDto(org.sonar.db.component.ComponentDto) CeQueueDto(org.sonar.db.ce.CeQueueDto) Test(org.junit.Test)

Example 58 with CeQueueDto

use of org.sonar.db.ce.CeQueueDto in project sonarqube by SonarSource.

the class PurgeDaoTest method insertCeQueue.

private CeQueueDto insertCeQueue(ComponentDto component) {
    CeQueueDto res = new CeQueueDto().setUuid(UuidFactoryFast.getInstance().create()).setTaskType("foo").setComponentUuid(component.uuid()).setMainComponentUuid(firstNonNull(component.getMainBranchProjectUuid(), component.uuid())).setStatus(Status.PENDING).setCreatedAt(1_2323_222L).setUpdatedAt(1_2323_222L);
    dbClient.ceQueueDao().insert(dbSession, res);
    dbSession.commit();
    return res;
}
Also used : CeQueueDto(org.sonar.db.ce.CeQueueDto)

Example 59 with CeQueueDto

use of org.sonar.db.ce.CeQueueDto in project sonarqube by SonarSource.

the class PurgeDaoTest method createCeQueue.

private CeQueueDto createCeQueue(ComponentDto component, Status status) {
    CeQueueDto queueDto = new CeQueueDto();
    queueDto.setUuid(Uuids.create());
    queueDto.setTaskType(REPORT);
    queueDto.setComponentUuid(component.uuid());
    queueDto.setMainComponentUuid(firstNonNull(component.getMainBranchProjectUuid(), component.uuid()));
    queueDto.setSubmitterUuid("submitter uuid");
    queueDto.setCreatedAt(1_300_000_000_000L);
    queueDto.setStatus(status);
    return queueDto;
}
Also used : CeQueueDto(org.sonar.db.ce.CeQueueDto)

Example 60 with CeQueueDto

use of org.sonar.db.ce.CeQueueDto in project sonarqube by SonarSource.

the class PurgeDaoTest method insertCeActivityAndChildDataWithDate.

@SafeVarargs
private final void insertCeActivityAndChildDataWithDate(String ceActivityUuid, LocalDateTime dateTime, Consumer<CeQueueDto>... queueDtoConsumers) {
    long date = dateTime.toInstant(UTC).toEpochMilli();
    CeQueueDto queueDto = new CeQueueDto();
    queueDto.setUuid(ceActivityUuid);
    queueDto.setTaskType(CeTaskTypes.REPORT);
    Arrays.stream(queueDtoConsumers).forEach(t -> t.accept(queueDto));
    CeActivityDto dto = new CeActivityDto(queueDto);
    dto.setStatus(CeActivityDto.Status.SUCCESS);
    when(system2.now()).thenReturn(date);
    insertCeTaskInput(dto.getUuid());
    insertCeTaskCharacteristics(dto.getUuid(), 1);
    insertCeScannerContext(dto.getUuid());
    insertCeTaskMessages(dto.getUuid(), 2);
    db.getDbClient().ceActivityDao().insert(db.getSession(), dto);
    db.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