Search in sources :

Example 51 with CeTask

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

the class CeQueueImplTest method submit_returns_task_populated_from_CeTaskSubmit_and_creates_CeQueue_row.

@Test
public void submit_returns_task_populated_from_CeTaskSubmit_and_creates_CeQueue_row() {
    String componentUuid = randomAlphabetic(3);
    String mainComponentUuid = randomAlphabetic(4);
    CeTaskSubmit taskSubmit = createTaskSubmit(CeTaskTypes.REPORT, new Component(componentUuid, mainComponentUuid), "submitter uuid");
    UserDto userDto = db.getDbClient().userDao().selectByUuid(db.getSession(), taskSubmit.getSubmitterUuid());
    CeTask task = underTest.submit(taskSubmit);
    verifyCeTask(taskSubmit, task, null, userDto);
    verifyCeQueueDtoForTaskSubmit(taskSubmit);
}
Also used : UserDto(org.sonar.db.user.UserDto) Component(org.sonar.ce.queue.CeTaskSubmit.Component) CeTask(org.sonar.ce.task.CeTask) Test(org.junit.Test)

Example 52 with CeTask

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

the class CeQueueImplTest method submit_without_UNIQUE_QUEUE_PER_MAIN_COMPONENT_creates_task_when_there_is_one_pending_task_for_same_main_component.

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

Example 53 with CeTask

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

the class CeQueueImplTest method cancelAll_pendings_but_not_in_progress.

@Test
public void cancelAll_pendings_but_not_in_progress() {
    CeTask inProgressTask = submit(CeTaskTypes.REPORT, newComponent(randomAlphabetic(12)));
    CeTask pendingTask1 = submit(CeTaskTypes.REPORT, newComponent(randomAlphabetic(12)));
    CeTask pendingTask2 = submit(CeTaskTypes.REPORT, newComponent(randomAlphabetic(12)));
    db.getDbClient().ceQueueDao().peek(session, WORKER_UUID, false, false);
    int canceledCount = underTest.cancelAll();
    assertThat(canceledCount).isEqualTo(2);
    Optional<CeActivityDto> ceActivityInProgress = db.getDbClient().ceActivityDao().selectByUuid(db.getSession(), pendingTask1.getUuid());
    assertThat(ceActivityInProgress.get().getStatus()).isEqualTo(CeActivityDto.Status.CANCELED);
    Optional<CeActivityDto> ceActivityPending1 = db.getDbClient().ceActivityDao().selectByUuid(db.getSession(), pendingTask2.getUuid());
    assertThat(ceActivityPending1.get().getStatus()).isEqualTo(CeActivityDto.Status.CANCELED);
    Optional<CeActivityDto> ceActivityPending2 = db.getDbClient().ceActivityDao().selectByUuid(db.getSession(), inProgressTask.getUuid());
    assertThat(ceActivityPending2).isNotPresent();
}
Also used : CeActivityDto(org.sonar.db.ce.CeActivityDto) CeTask(org.sonar.ce.task.CeTask) Test(org.junit.Test)

Example 54 with CeTask

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

the class CeQueueImplTest method fail_throws_exception_if_task_is_pending.

@Test
public void fail_throws_exception_if_task_is_pending() {
    CeTask task = submit(CeTaskTypes.REPORT, newComponent(randomAlphabetic(12)));
    CeQueueDto queueDto = db.getDbClient().ceQueueDao().selectByUuid(db.getSession(), task.getUuid()).get();
    Throwable thrown = catchThrowable(() -> underTest.fail(db.getSession(), queueDto, "TIMEOUT", "Failed on timeout"));
    assertThat(thrown).isInstanceOf(IllegalStateException.class).hasMessage("Task is not in-progress and can't be marked as failed [uuid=" + task.getUuid() + "]");
}
Also used : CeQueueDto(org.sonar.db.ce.CeQueueDto) Assertions.catchThrowable(org.assertj.core.api.Assertions.catchThrowable) CeTask(org.sonar.ce.task.CeTask) Test(org.junit.Test)

Example 55 with CeTask

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

the class IgnoreOrphanBranchStepTest method fail_if_missing_main_component_in_task.

@Test
public void fail_if_missing_main_component_in_task() {
    CeTask ceTask = new CeTask.Builder().setType("type").setUuid("uuid").setComponent(null).setMainComponent(null).build();
    IgnoreOrphanBranchStep underTest = new IgnoreOrphanBranchStep(ceTask, dbClient);
    assertThatThrownBy(() -> underTest.execute(() -> null)).isInstanceOf(UnsupportedOperationException.class).hasMessage("main component not found in task");
}
Also used : 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