Search in sources :

Example 6 with CeTask

use of org.sonar.ce.task.CeTask in project sonarqube by SonarSource.

the class CeQueueImplTest method massSubmit_with_UNIQUE_QUEUE_PER_MAIN_COMPONENT_creates_task_when_there_is_a_pending_task_for_another_main_component.

@Test
public void massSubmit_with_UNIQUE_QUEUE_PER_MAIN_COMPONENT_creates_task_when_there_is_a_pending_task_for_another_main_component() {
    String mainComponentUuid = randomAlphabetic(5);
    String otherMainComponentUuid = randomAlphabetic(6);
    CeTaskSubmit taskSubmit = createTaskSubmit("with_component", newComponent(mainComponentUuid), null);
    CeQueueDto dto = insertPendingInQueue(newComponent(otherMainComponentUuid));
    List<CeTask> tasks = underTest.massSubmit(of(taskSubmit), UNIQUE_QUEUE_PER_MAIN_COMPONENT);
    assertThat(tasks).hasSize(1);
    assertThat(db.getDbClient().ceQueueDao().selectAllInAscOrder(db.getSession())).extracting(CeQueueDto::getUuid).containsOnly(dto.getUuid(), tasks.iterator().next().getUuid());
}
Also used : CeQueueDto(org.sonar.db.ce.CeQueueDto) CeTask(org.sonar.ce.task.CeTask) Test(org.junit.Test)

Example 7 with CeTask

use of org.sonar.ce.task.CeTask in project sonarqube by SonarSource.

the class CeQueueImpl method loadTasks.

private List<CeTask> loadTasks(DbSession dbSession, List<CeQueueDto> dtos) {
    // load components, if defined
    Set<String> componentUuids = dtos.stream().flatMap(dto -> Stream.of(dto.getComponentUuid(), dto.getMainComponentUuid())).filter(Objects::nonNull).collect(Collectors.toSet());
    Map<String, ComponentDto> componentsByUuid = dbClient.componentDao().selectByUuids(dbSession, componentUuids).stream().collect(uniqueIndex(ComponentDto::uuid));
    // load characteristics
    // TODO could be avoided, characteristics are already present in submissions
    Set<String> taskUuids = dtos.stream().map(CeQueueDto::getUuid).collect(MoreCollectors.toSet(dtos.size()));
    Multimap<String, CeTaskCharacteristicDto> characteristicsByTaskUuid = dbClient.ceTaskCharacteristicsDao().selectByTaskUuids(dbSession, taskUuids).stream().collect(MoreCollectors.index(CeTaskCharacteristicDto::getTaskUuid));
    List<CeTask> result = new ArrayList<>();
    for (CeQueueDto dto : dtos) {
        ComponentDto component = ofNullable(dto.getComponentUuid()).map(componentsByUuid::get).orElse(null);
        ComponentDto mainComponent = ofNullable(dto.getMainComponentUuid()).map(componentsByUuid::get).orElse(null);
        Map<String, String> characteristics = characteristicsByTaskUuid.get(dto.getUuid()).stream().collect(uniqueIndex(CeTaskCharacteristicDto::getKey, CeTaskCharacteristicDto::getValue));
        result.add(convertToTask(dbSession, dto, characteristics, component, mainComponent));
    }
    return result;
}
Also used : CeTaskCharacteristicDto(org.sonar.db.ce.CeTaskCharacteristicDto) ComponentDto(org.sonar.db.component.ComponentDto) ArrayList(java.util.ArrayList) CeQueueDto(org.sonar.db.ce.CeQueueDto) CeTask(org.sonar.ce.task.CeTask)

Example 8 with CeTask

use of org.sonar.ce.task.CeTask in project sonarqube by SonarSource.

the class CeQueueImplTest method submit_populates_component_name_and_key_of_CeTask_if_component_exists.

@Test
public void submit_populates_component_name_and_key_of_CeTask_if_component_exists() {
    ComponentDto componentDto = insertComponent(ComponentTesting.newPrivateProjectDto("PROJECT_1"));
    CeTaskSubmit taskSubmit = createTaskSubmit(CeTaskTypes.REPORT, Component.fromDto(componentDto), null);
    CeTask task = underTest.submit(taskSubmit);
    verifyCeTask(taskSubmit, task, componentDto, null);
}
Also used : ComponentDto(org.sonar.db.component.ComponentDto) CeTask(org.sonar.ce.task.CeTask) Test(org.junit.Test)

Example 9 with CeTask

use of org.sonar.ce.task.CeTask in project sonarqube by SonarSource.

the class CeQueueImplTest method submit_populates_submitter_login_of_CeTask_if_submitter_exists.

@Test
public void submit_populates_submitter_login_of_CeTask_if_submitter_exists() {
    UserDto userDto = insertUser(UserTesting.newUserDto());
    CeTaskSubmit taskSubmit = createTaskSubmit(CeTaskTypes.REPORT, null, userDto.getUuid());
    CeTask task = underTest.submit(taskSubmit);
    verifyCeTask(taskSubmit, task, null, userDto);
}
Also used : UserDto(org.sonar.db.user.UserDto) CeTask(org.sonar.ce.task.CeTask) Test(org.junit.Test)

Example 10 with CeTask

use of org.sonar.ce.task.CeTask in project sonarqube by SonarSource.

the class CeQueueImplTest method massSubmit_without_UNIQUE_QUEUE_PER_MAIN_COMPONENT_creates_task_when_there_is_one_pending_task_for_other_main_component.

@Test
public void massSubmit_without_UNIQUE_QUEUE_PER_MAIN_COMPONENT_creates_task_when_there_is_one_pending_task_for_other_main_component() {
    String mainComponentUuid = randomAlphabetic(5);
    CeTaskSubmit taskSubmit = createTaskSubmit("with_component", newComponent(mainComponentUuid), null);
    CeQueueDto dto = insertPendingInQueue(newComponent(mainComponentUuid));
    List<CeTask> tasks = underTest.massSubmit(of(taskSubmit));
    assertThat(tasks).hasSize(1);
    assertThat(db.getDbClient().ceQueueDao().selectAllInAscOrder(db.getSession())).extracting(CeQueueDto::getUuid).containsOnly(dto.getUuid(), tasks.iterator().next().getUuid());
}
Also used : CeQueueDto(org.sonar.db.ce.CeQueueDto) CeTask(org.sonar.ce.task.CeTask) Test(org.junit.Test)

Aggregations

CeTask (org.sonar.ce.task.CeTask)85 Test (org.junit.Test)75 CeQueueDto (org.sonar.db.ce.CeQueueDto)17 CeActivityDto (org.sonar.db.ce.CeActivityDto)16 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)12 ComponentDto (org.sonar.db.component.ComponentDto)12 UserDto (org.sonar.db.user.UserDto)10 MessageException (org.sonar.api.utils.MessageException)7 Optional (java.util.Optional)5 Random (java.util.Random)5 CheckForNull (javax.annotation.CheckForNull)5 System2 (org.sonar.api.utils.System2)5 DbSession (org.sonar.db.DbSession)5 List (java.util.List)4 Map (java.util.Map)4 CountDownLatch (java.util.concurrent.CountDownLatch)4 Nullable (javax.annotation.Nullable)4 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)4 Assertions.assertThatThrownBy (org.assertj.core.api.Assertions.assertThatThrownBy)4 Rule (org.junit.Rule)4