use of org.sonar.ce.queue.CeQueue.SubmitOption.UNIQUE_QUEUE_PER_MAIN_COMPONENT 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()));
}
Aggregations