Search in sources :

Example 56 with CeTask

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

the class IndexIssuesStepTest method fail_if_missing_component_in_task.

@Test
public void fail_if_missing_component_in_task() {
    CeTask ceTask = new CeTask.Builder().setType("type").setUuid("uuid").setComponent(null).setMainComponent(null).build();
    IndexIssuesStep underTest = new IndexIssuesStep(ceTask, dbClient, issueIndexer);
    assertThatThrownBy(() -> underTest.execute(() -> null)).isInstanceOf(UnsupportedOperationException.class).hasMessage("component not found in task");
}
Also used : CeTask(org.sonar.ce.task.CeTask) Test(org.junit.Test)

Example 57 with CeTask

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

the class LoadReportAnalysisMetadataHolderStepTest method execute_fails_with_MessageException_if_projectKey_is_null_in_CE_task.

@Test
public void execute_fails_with_MessageException_if_projectKey_is_null_in_CE_task() {
    CeTask res = mock(CeTask.class);
    Optional<CeTask.Component> component = Optional.of(new CeTask.Component("prj_uuid", null, null));
    when(res.getComponent()).thenReturn(component);
    when(res.getMainComponent()).thenReturn(Optional.of(new CeTask.Component("main_prj_uuid", "main_prj_key", null)));
    reportReader.setMetadata(ScannerReport.Metadata.newBuilder().build());
    ComputationStep underTest = createStep(res);
    assertThatThrownBy(() -> underTest.execute(new TestComputationStepContext())).isInstanceOf(MessageException.class).hasMessage("Compute Engine task component key is null. Project with UUID 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)

Example 58 with CeTask

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

the class SubmitAction method handle.

@Override
public void handle(Request wsRequest, Response wsResponse) throws Exception {
    String projectKey = wsRequest.mandatoryParam(PARAM_PROJECT_KEY);
    String projectName = abbreviate(defaultIfBlank(wsRequest.param(PARAM_PROJECT_NAME), projectKey), MAX_COMPONENT_NAME_LENGTH);
    Map<String, String> characteristics = parseTaskCharacteristics(wsRequest);
    try (InputStream report = new BufferedInputStream(wsRequest.mandatoryParamAsPart(PARAM_REPORT_DATA).getInputStream())) {
        CeTask task = reportSubmitter.submit(projectKey, projectName, characteristics, report);
        Ce.SubmitResponse submitResponse = Ce.SubmitResponse.newBuilder().setTaskId(task.getUuid()).setProjectId(task.getComponent().get().getUuid()).build();
        WsUtils.writeProtobuf(submitResponse, wsRequest, wsResponse);
    }
}
Also used : Ce(org.sonarqube.ws.Ce) BufferedInputStream(java.io.BufferedInputStream) BufferedInputStream(java.io.BufferedInputStream) InputStream(java.io.InputStream) CeTask(org.sonar.ce.task.CeTask)

Example 59 with CeTask

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

the class CeTaskLoggingTest method createCeTask.

private CeTask createCeTask(String uuid) {
    CeTask ceTask = Mockito.mock(CeTask.class);
    when(ceTask.getUuid()).thenReturn(uuid);
    return ceTask;
}
Also used : CeTask(org.sonar.ce.task.CeTask)

Example 60 with CeTask

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

the class CeTaskMessagesImplTest method addAll_has_no_effect_if_arg_is_empty.

@Test
public void addAll_has_no_effect_if_arg_is_empty() {
    DbClient dbClientMock = mock(DbClient.class);
    UuidFactory uuidFactoryMock = mock(UuidFactory.class);
    CeTask ceTaskMock = mock(CeTask.class);
    CeTaskMessagesImpl underTest = new CeTaskMessagesImpl(dbClientMock, uuidFactoryMock, ceTaskMock);
    underTest.addAll(Collections.emptyList());
    verifyZeroInteractions(dbClientMock, uuidFactoryMock, ceTaskMock);
}
Also used : DbClient(org.sonar.db.DbClient) UuidFactory(org.sonar.core.util.UuidFactory) 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