Search in sources :

Example 1 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_exists.

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

Example 2 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_without_component_when_there_is_a_pending_task_without_component.

@Test
public void massSubmit_with_UNIQUE_QUEUE_PER_MAIN_COMPONENT_creates_task_without_component_when_there_is_a_pending_task_without_component() {
    CeTaskSubmit taskSubmit = createTaskSubmit("no_component");
    CeQueueDto dto = insertPendingInQueue(null);
    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 3 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_tasks_depending_on_whether_there_is_pending_task_for_same_main_component.

@Test
public void massSubmit_with_UNIQUE_QUEUE_PER_MAIN_COMPONENT_creates_tasks_depending_on_whether_there_is_pending_task_for_same_main_component() {
    String mainComponentUuid1 = randomAlphabetic(5);
    String mainComponentUuid2 = randomAlphabetic(6);
    String mainComponentUuid3 = randomAlphabetic(7);
    String mainComponentUuid4 = randomAlphabetic(8);
    String mainComponentUuid5 = randomAlphabetic(9);
    CeTaskSubmit taskSubmit1 = createTaskSubmit("with_one_pending", newComponent(mainComponentUuid1), null);
    CeQueueDto dto1 = insertPendingInQueue(newComponent(mainComponentUuid1));
    Component componentForMainComponentUuid2 = newComponent(mainComponentUuid2);
    CeTaskSubmit taskSubmit2 = createTaskSubmit("no_pending", componentForMainComponentUuid2, null);
    CeTaskSubmit taskSubmit3 = createTaskSubmit("with_many_pending", newComponent(mainComponentUuid3), null);
    String[] uuids3 = IntStream.range(0, 2 + new Random().nextInt(5)).mapToObj(i -> insertPendingInQueue(newComponent(mainComponentUuid3))).map(CeQueueDto::getUuid).toArray(String[]::new);
    Component componentForMainComponentUuid4 = newComponent(mainComponentUuid4);
    CeTaskSubmit taskSubmit4 = createTaskSubmit("no_pending_2", componentForMainComponentUuid4, null);
    CeTaskSubmit taskSubmit5 = createTaskSubmit("with_pending_2", newComponent(mainComponentUuid5), null);
    CeQueueDto dto5 = insertPendingInQueue(newComponent(mainComponentUuid5));
    List<CeTask> tasks = underTest.massSubmit(of(taskSubmit1, taskSubmit2, taskSubmit3, taskSubmit4, taskSubmit5), UNIQUE_QUEUE_PER_MAIN_COMPONENT);
    assertThat(tasks).hasSize(2).extracting(task -> task.getComponent().get().getUuid(), task -> task.getMainComponent().get().getUuid()).containsOnly(tuple(componentForMainComponentUuid2.getUuid(), componentForMainComponentUuid2.getMainComponentUuid()), tuple(componentForMainComponentUuid4.getUuid(), componentForMainComponentUuid4.getMainComponentUuid()));
    assertThat(db.getDbClient().ceQueueDao().selectAllInAscOrder(db.getSession())).extracting(CeQueueDto::getUuid).hasSize(1 + uuids3.length + 1 + tasks.size()).contains(dto1.getUuid()).contains(uuids3).contains(dto5.getUuid()).containsAll(tasks.stream().map(CeTask::getUuid).collect(Collectors.toList()));
}
Also used : IntStream(java.util.stream.IntStream) Component(org.sonar.ce.queue.CeTaskSubmit.Component) CeTaskTypes(org.sonar.db.ce.CeTaskTypes) UserDto(org.sonar.db.user.UserDto) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Random(java.util.Random) DbSession(org.sonar.db.DbSession) TestSystem2(org.sonar.api.impl.utils.TestSystem2) CeActivityDto(org.sonar.db.ce.CeActivityDto) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) CeTask(org.sonar.ce.task.CeTask) Arrays.asList(java.util.Arrays.asList) ComponentTesting(org.sonar.db.component.ComponentTesting) UuidFactoryFast(org.sonar.core.util.UuidFactoryFast) Assertions.catchThrowable(org.assertj.core.api.Assertions.catchThrowable) Nullable(javax.annotation.Nullable) ImmutableList.of(com.google.common.collect.ImmutableList.of) DbTester(org.sonar.db.DbTester) Collections.emptyMap(java.util.Collections.emptyMap) System2(org.sonar.api.utils.System2) RandomStringUtils.randomAlphabetic(org.apache.commons.lang.RandomStringUtils.randomAlphabetic) Assertions.tuple(org.assertj.core.api.Assertions.tuple) UuidFactory(org.sonar.core.util.UuidFactory) Test(org.junit.Test) Collectors(java.util.stream.Collectors) SequenceUuidFactory(org.sonar.core.util.SequenceUuidFactory) List(java.util.List) ComponentDto(org.sonar.db.component.ComponentDto) Rule(org.junit.Rule) CeQueueDto(org.sonar.db.ce.CeQueueDto) Optional(java.util.Optional) UNIQUE_QUEUE_PER_MAIN_COMPONENT(org.sonar.ce.queue.CeQueue.SubmitOption.UNIQUE_QUEUE_PER_MAIN_COMPONENT) UserTesting(org.sonar.db.user.UserTesting) Random(java.util.Random) CeQueueDto(org.sonar.db.ce.CeQueueDto) Component(org.sonar.ce.queue.CeTaskSubmit.Component) CeTask(org.sonar.ce.task.CeTask) Test(org.junit.Test)

Example 4 with CeTask

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

the class CeQueueImplTest method cancel_pending.

@Test
public void cancel_pending() {
    CeTask task = submit(CeTaskTypes.REPORT, newComponent(randomAlphabetic(12)));
    CeQueueDto queueDto = db.getDbClient().ceQueueDao().selectByUuid(db.getSession(), task.getUuid()).get();
    underTest.cancel(db.getSession(), queueDto);
    Optional<CeActivityDto> activity = db.getDbClient().ceActivityDao().selectByUuid(db.getSession(), task.getUuid());
    assertThat(activity).isPresent();
    assertThat(activity.get().getStatus()).isEqualTo(CeActivityDto.Status.CANCELED);
}
Also used : CeActivityDto(org.sonar.db.ce.CeActivityDto) CeQueueDto(org.sonar.db.ce.CeQueueDto) CeTask(org.sonar.ce.task.CeTask) Test(org.junit.Test)

Example 5 with CeTask

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

the class CeQueueImplTest method fail_in_progress_task.

@Test
public void fail_in_progress_task() {
    CeTask task = submit(CeTaskTypes.REPORT, newComponent(randomAlphabetic(12)));
    CeQueueDto queueDto = db.getDbClient().ceQueueDao().peek(db.getSession(), WORKER_UUID, false, false).get();
    underTest.fail(db.getSession(), queueDto, "TIMEOUT", "Failed on timeout");
    Optional<CeActivityDto> activity = db.getDbClient().ceActivityDao().selectByUuid(db.getSession(), task.getUuid());
    assertThat(activity).isPresent();
    assertThat(activity.get().getStatus()).isEqualTo(CeActivityDto.Status.FAILED);
    assertThat(activity.get().getErrorType()).isEqualTo("TIMEOUT");
    assertThat(activity.get().getErrorMessage()).isEqualTo("Failed on timeout");
    assertThat(activity.get().getExecutedAt()).isEqualTo(NOW);
    assertThat(activity.get().getWorkerUuid()).isEqualTo(WORKER_UUID);
}
Also used : CeActivityDto(org.sonar.db.ce.CeActivityDto) 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