Search in sources :

Example 11 with CeTask

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

the class InternalCeQueueImplTest method remove_sets_snapshotId_in_CeActivity_when_CeTaskResult_has_no_snapshot_id.

@Test
public void remove_sets_snapshotId_in_CeActivity_when_CeTaskResult_has_no_snapshot_id() {
    CeTask task = submit(CeTaskTypes.REPORT, "PROJECT_1");
    Optional<CeTask> peek = underTest.peek();
    underTest.remove(peek.get(), CeActivityDto.Status.SUCCESS, newTaskResult(AN_ANALYSIS_UUID), null);
    // available in history
    Optional<CeActivityDto> history = dbTester.getDbClient().ceActivityDao().selectByUuid(dbTester.getSession(), task.getUuid());
    assertThat(history.isPresent()).isTrue();
    assertThat(history.get().getAnalysisUuid()).isEqualTo("U1");
}
Also used : CeActivityDto(org.sonar.db.ce.CeActivityDto) CeTask(org.sonar.ce.queue.CeTask) Test(org.junit.Test)

Example 12 with CeTask

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

the class InternalCeQueueImplTest method cancelAll_pendings_but_not_in_progress.

@Test
public void cancelAll_pendings_but_not_in_progress() throws Exception {
    CeTask inProgressTask = submit(CeTaskTypes.REPORT, "PROJECT_1");
    CeTask pendingTask1 = submit(CeTaskTypes.REPORT, "PROJECT_2");
    CeTask pendingTask2 = submit(CeTaskTypes.REPORT, "PROJECT_3");
    underTest.peek();
    int canceledCount = underTest.cancelAll();
    assertThat(canceledCount).isEqualTo(2);
    Optional<CeActivityDto> history = dbTester.getDbClient().ceActivityDao().selectByUuid(dbTester.getSession(), pendingTask1.getUuid());
    assertThat(history.get().getStatus()).isEqualTo(CeActivityDto.Status.CANCELED);
    history = dbTester.getDbClient().ceActivityDao().selectByUuid(dbTester.getSession(), pendingTask2.getUuid());
    assertThat(history.get().getStatus()).isEqualTo(CeActivityDto.Status.CANCELED);
    history = dbTester.getDbClient().ceActivityDao().selectByUuid(dbTester.getSession(), inProgressTask.getUuid());
    assertThat(history.isPresent()).isFalse();
}
Also used : CeActivityDto(org.sonar.db.ce.CeActivityDto) CeTask(org.sonar.ce.queue.CeTask) Test(org.junit.Test)

Example 13 with CeTask

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

the class InternalCeQueueImplTest method fail_to_cancel_if_in_progress.

@Test
public void fail_to_cancel_if_in_progress() throws Exception {
    expectedException.expect(IllegalStateException.class);
    expectedException.expectMessage(startsWith("Task is in progress and can't be canceled"));
    CeTask task = submit(CeTaskTypes.REPORT, "PROJECT_1");
    underTest.peek();
    underTest.cancel(task.getUuid());
}
Also used : CeTask(org.sonar.ce.queue.CeTask) Test(org.junit.Test)

Example 14 with CeTask

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

the class LoadReportAnalysisMetadataHolderStepTest method set_branch.

@Test
public void set_branch() throws Exception {
    reportReader.setMetadata(newBatchReportBuilder().setBranch(BRANCH).build());
    CeTask ceTask = createCeTask(PROJECT_KEY + ":" + BRANCH, dbTester.getDefaultOrganization().getUuid());
    ComputationStep underTest = createStep(ceTask);
    underTest.execute();
    assertThat(analysisMetadataHolder.getBranch()).isEqualTo(BRANCH);
}
Also used : ComputationStep(org.sonar.server.computation.task.step.ComputationStep) CeTask(org.sonar.ce.queue.CeTask) Test(org.junit.Test)

Example 15 with CeTask

use of org.sonar.ce.queue.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);
    when(res.getComponentUuid()).thenReturn("prj_uuid");
    reportReader.setMetadata(ScannerReport.Metadata.newBuilder().build());
    ComputationStep underTest = createStep(res);
    expectedException.expect(MessageException.class);
    expectedException.expectMessage("Compute Engine task component key is null. Project with UUID prj_uuid must have been deleted since report was uploaded. Can not proceed.");
    underTest.execute();
}
Also used : ComputationStep(org.sonar.server.computation.task.step.ComputationStep) CeTask(org.sonar.ce.queue.CeTask) Test(org.junit.Test)

Aggregations

CeTask (org.sonar.ce.queue.CeTask)27 Test (org.junit.Test)22 CeActivityDto (org.sonar.db.ce.CeActivityDto)6 CeTaskSubmit (org.sonar.ce.queue.CeTaskSubmit)5 ComponentDto (org.sonar.db.component.ComponentDto)2 ComputationStep (org.sonar.server.computation.task.step.ComputationStep)2 BufferedInputStream (java.io.BufferedInputStream)1 InputStream (java.io.InputStream)1 Before (org.junit.Before)1 DbSession (org.sonar.db.DbSession)1 CeQueueDto (org.sonar.db.ce.CeQueueDto)1 WsCe (org.sonarqube.ws.WsCe)1