Search in sources :

Example 46 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_does_not_create_task_when_there_is_one_pending_task_for_same_main_component.

@Test
public void massSubmit_with_UNIQUE_QUEUE_PER_MAIN_COMPONENT_does_not_create_task_when_there_is_one_pending_task_for_same_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), UNIQUE_QUEUE_PER_MAIN_COMPONENT);
    assertThat(tasks).isEmpty();
    assertThat(db.getDbClient().ceQueueDao().selectAllInAscOrder(db.getSession())).extracting(CeQueueDto::getUuid).containsOnly(dto.getUuid());
}
Also used : CeQueueDto(org.sonar.db.ce.CeQueueDto) CeTask(org.sonar.ce.task.CeTask) Test(org.junit.Test)

Example 47 with CeTask

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

the class CeQueueImplTest method massSubmit_populates_component_name_and_key_of_CeTask_if_project_and_branch_exists.

@Test
public void massSubmit_populates_component_name_and_key_of_CeTask_if_project_and_branch_exists() {
    ComponentDto project = insertComponent(ComponentTesting.newPrivateProjectDto("PROJECT_1"));
    ComponentDto branch1 = db.components().insertProjectBranch(project);
    ComponentDto branch2 = db.components().insertProjectBranch(project);
    CeTaskSubmit taskSubmit1 = createTaskSubmit(CeTaskTypes.REPORT, Component.fromDto(branch1), null);
    CeTaskSubmit taskSubmit2 = createTaskSubmit("something", Component.fromDto(branch2), null);
    List<CeTask> tasks = underTest.massSubmit(asList(taskSubmit1, taskSubmit2));
    assertThat(tasks).hasSize(2);
    verifyCeTask(taskSubmit1, tasks.get(0), branch1, project, null);
    verifyCeTask(taskSubmit2, tasks.get(1), branch2, project, null);
}
Also used : ComponentDto(org.sonar.db.component.ComponentDto) CeTask(org.sonar.ce.task.CeTask) Test(org.junit.Test)

Example 48 with CeTask

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

the class CeQueueImplTest method submit_with_UNIQUE_QUEUE_PER_MAIN_COMPONENT_creates_task_when_there_is_a_pending_task_for_another_main_component.

@Test
public void submit_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));
    Optional<CeTask> task = underTest.submit(taskSubmit, UNIQUE_QUEUE_PER_MAIN_COMPONENT);
    assertThat(task).isNotEmpty();
    assertThat(db.getDbClient().ceQueueDao().selectAllInAscOrder(db.getSession())).extracting(CeQueueDto::getUuid).containsOnly(dto.getUuid(), task.get().getUuid());
}
Also used : CeQueueDto(org.sonar.db.ce.CeQueueDto) CeTask(org.sonar.ce.task.CeTask) Test(org.junit.Test)

Example 49 with CeTask

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

the class CeQueueImplTest method submit_returns_task_without_component_info_when_submit_has_none.

@Test
public void submit_returns_task_without_component_info_when_submit_has_none() {
    CeTaskSubmit taskSubmit = createTaskSubmit("not cpt related");
    CeTask task = underTest.submit(taskSubmit);
    verifyCeTask(taskSubmit, task, null, null);
}
Also used : CeTask(org.sonar.ce.task.CeTask) Test(org.junit.Test)

Example 50 with CeTask

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

the class CeQueueImplTest method massSubmit_returns_tasks_for_each_CeTaskSubmit_populated_from_CeTaskSubmit_and_creates_CeQueue_row_for_each.

@Test
public void massSubmit_returns_tasks_for_each_CeTaskSubmit_populated_from_CeTaskSubmit_and_creates_CeQueue_row_for_each() {
    String mainComponentUuid = randomAlphabetic(10);
    CeTaskSubmit taskSubmit1 = createTaskSubmit(CeTaskTypes.REPORT, newComponent(mainComponentUuid), "submitter uuid");
    CeTaskSubmit taskSubmit2 = createTaskSubmit("some type");
    UserDto userDto1 = db.getDbClient().userDao().selectByUuid(db.getSession(), taskSubmit1.getSubmitterUuid());
    List<CeTask> tasks = underTest.massSubmit(asList(taskSubmit1, taskSubmit2));
    assertThat(tasks).hasSize(2);
    verifyCeTask(taskSubmit1, tasks.get(0), null, userDto1);
    verifyCeTask(taskSubmit2, tasks.get(1), null, null);
    verifyCeQueueDtoForTaskSubmit(taskSubmit1);
    verifyCeQueueDtoForTaskSubmit(taskSubmit2);
}
Also used : UserDto(org.sonar.db.user.UserDto) 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