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);
}
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());
}
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()));
}
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);
}
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);
}
Aggregations