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_when_there_is_a_pending_task_for_another_main_component.
@Test
public void massSubmit_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));
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 CeQueueImpl method loadTasks.
private List<CeTask> loadTasks(DbSession dbSession, List<CeQueueDto> dtos) {
// load components, if defined
Set<String> componentUuids = dtos.stream().flatMap(dto -> Stream.of(dto.getComponentUuid(), dto.getMainComponentUuid())).filter(Objects::nonNull).collect(Collectors.toSet());
Map<String, ComponentDto> componentsByUuid = dbClient.componentDao().selectByUuids(dbSession, componentUuids).stream().collect(uniqueIndex(ComponentDto::uuid));
// load characteristics
// TODO could be avoided, characteristics are already present in submissions
Set<String> taskUuids = dtos.stream().map(CeQueueDto::getUuid).collect(MoreCollectors.toSet(dtos.size()));
Multimap<String, CeTaskCharacteristicDto> characteristicsByTaskUuid = dbClient.ceTaskCharacteristicsDao().selectByTaskUuids(dbSession, taskUuids).stream().collect(MoreCollectors.index(CeTaskCharacteristicDto::getTaskUuid));
List<CeTask> result = new ArrayList<>();
for (CeQueueDto dto : dtos) {
ComponentDto component = ofNullable(dto.getComponentUuid()).map(componentsByUuid::get).orElse(null);
ComponentDto mainComponent = ofNullable(dto.getMainComponentUuid()).map(componentsByUuid::get).orElse(null);
Map<String, String> characteristics = characteristicsByTaskUuid.get(dto.getUuid()).stream().collect(uniqueIndex(CeTaskCharacteristicDto::getKey, CeTaskCharacteristicDto::getValue));
result.add(convertToTask(dbSession, dto, characteristics, component, mainComponent));
}
return result;
}
use of org.sonar.ce.task.CeTask in project sonarqube by SonarSource.
the class CeQueueImplTest method submit_populates_component_name_and_key_of_CeTask_if_component_exists.
@Test
public void submit_populates_component_name_and_key_of_CeTask_if_component_exists() {
ComponentDto componentDto = insertComponent(ComponentTesting.newPrivateProjectDto("PROJECT_1"));
CeTaskSubmit taskSubmit = createTaskSubmit(CeTaskTypes.REPORT, Component.fromDto(componentDto), null);
CeTask task = underTest.submit(taskSubmit);
verifyCeTask(taskSubmit, task, componentDto, null);
}
use of org.sonar.ce.task.CeTask in project sonarqube by SonarSource.
the class CeQueueImplTest method submit_populates_submitter_login_of_CeTask_if_submitter_exists.
@Test
public void submit_populates_submitter_login_of_CeTask_if_submitter_exists() {
UserDto userDto = insertUser(UserTesting.newUserDto());
CeTaskSubmit taskSubmit = createTaskSubmit(CeTaskTypes.REPORT, null, userDto.getUuid());
CeTask task = underTest.submit(taskSubmit);
verifyCeTask(taskSubmit, task, null, userDto);
}
use of org.sonar.ce.task.CeTask in project sonarqube by SonarSource.
the class CeQueueImplTest method massSubmit_without_UNIQUE_QUEUE_PER_MAIN_COMPONENT_creates_task_when_there_is_one_pending_task_for_other_main_component.
@Test
public void massSubmit_without_UNIQUE_QUEUE_PER_MAIN_COMPONENT_creates_task_when_there_is_one_pending_task_for_other_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));
assertThat(tasks).hasSize(1);
assertThat(db.getDbClient().ceQueueDao().selectAllInAscOrder(db.getSession())).extracting(CeQueueDto::getUuid).containsOnly(dto.getUuid(), tasks.iterator().next().getUuid());
}
Aggregations