Search in sources :

Example 11 with CeTask

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

the class CeQueueImplTest method submit_with_UNIQUE_QUEUE_PER_MAIN_COMPONENT_creates_task_without_component_when_there_is_a_pending_task_without_component.

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

Example 12 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_many_pending_task_for_same_main_component.

@Test
public void submit_without_UNIQUE_QUEUE_PER_MAIN_COMPONENT_creates_task_when_there_is_many_pending_task_for_same_main_component() {
    String mainComponentUuid = randomAlphabetic(5);
    CeTaskSubmit taskSubmit = createTaskSubmit("with_component", newComponent(mainComponentUuid), null);
    String[] uuids = IntStream.range(0, 2 + new Random().nextInt(5)).mapToObj(i -> insertPendingInQueue(newComponent(mainComponentUuid))).map(CeQueueDto::getUuid).toArray(String[]::new);
    CeTask task = underTest.submit(taskSubmit);
    assertThat(db.getDbClient().ceQueueDao().selectAllInAscOrder(db.getSession())).extracting(CeQueueDto::getUuid).hasSize(uuids.length + 1).contains(uuids).contains(task.getUuid());
}
Also used : Random(java.util.Random) CeTask(org.sonar.ce.task.CeTask) Test(org.junit.Test)

Example 13 with CeTask

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

the class ProjectExportTaskProcessor method processProjectExport.

private void processProjectExport(CeTask task) {
    CeTask.Component exportComponent = mandatoryComponent(task, PROJECT_EXPORT);
    failIfNotMain(exportComponent, task);
    ProjectDescriptor projectExportDescriptor = new ProjectDescriptor(exportComponent.getUuid(), mandatoryKey(exportComponent), mandatoryName(exportComponent));
    try (TaskContainer taskContainer = new TaskContainerImpl(componentContainer, new ProjectExportContainerPopulator(projectExportDescriptor))) {
        taskContainer.bootup();
        taskContainer.getComponentByType(ProjectExportProcessor.class).process();
    }
}
Also used : TaskContainerImpl(org.sonar.ce.task.container.TaskContainerImpl) TaskContainer(org.sonar.ce.task.container.TaskContainer) ProjectExportContainerPopulator(org.sonar.ce.task.projectexport.ProjectExportContainerPopulator) CeTask(org.sonar.ce.task.CeTask) ProjectExportProcessor(org.sonar.ce.task.projectexport.ProjectExportProcessor)

Example 14 with CeTask

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

the class LoadReportAnalysisMetadataHolderStepTest method createCeTask.

private CeTask createCeTask(String projectKey) {
    CeTask res = mock(CeTask.class);
    Optional<CeTask.Component> component = Optional.of(new CeTask.Component(projectKey + "_uuid", projectKey, projectKey + "_name"));
    when(res.getComponent()).thenReturn(component);
    when(res.getMainComponent()).thenReturn(component);
    return res;
}
Also used : CeTask(org.sonar.ce.task.CeTask)

Example 15 with CeTask

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

the class LoadReportAnalysisMetadataHolderStepTest method execute_fails_with_MessageException_if_main_projectKey_is_null_in_CE_task.

@Test
public void execute_fails_with_MessageException_if_main_projectKey_is_null_in_CE_task() {
    CeTask res = mock(CeTask.class);
    Optional<CeTask.Component> component = Optional.of(new CeTask.Component("main_prj_uuid", null, null));
    when(res.getComponent()).thenReturn(component);
    when(res.getMainComponent()).thenReturn(component);
    reportReader.setMetadata(ScannerReport.Metadata.newBuilder().build());
    ComputationStep underTest = createStep(res);
    assertThatThrownBy(() -> underTest.execute(new TestComputationStepContext())).isInstanceOf(MessageException.class).hasMessage("Compute Engine task main component key is null. Project with UUID main_prj_uuid must have been deleted since report was uploaded. Can not proceed.");
}
Also used : MessageException(org.sonar.api.utils.MessageException) ComputationStep(org.sonar.ce.task.step.ComputationStep) CeTask(org.sonar.ce.task.CeTask) TestComputationStepContext(org.sonar.ce.task.step.TestComputationStepContext) 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