Search in sources :

Example 16 with CeActivityDto

use of org.sonar.db.ce.CeActivityDto in project sonarqube by SonarSource.

the class InternalCeQueueImplTest method remove_does_not_set_analysisUuid_in_CeActivity_when_CeTaskResult_has_no_analysis_uuid.

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

Example 17 with CeActivityDto

use of org.sonar.db.ce.CeActivityDto in project sonarqube by SonarSource.

the class InternalCeQueueImplTest method test_remove.

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

Example 18 with CeActivityDto

use of org.sonar.db.ce.CeActivityDto 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 19 with CeActivityDto

use of org.sonar.db.ce.CeActivityDto 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 20 with CeActivityDto

use of org.sonar.db.ce.CeActivityDto in project sonarqube by SonarSource.

the class ComponentActionTest method insertActivity.

private CeActivityDto insertActivity(String taskUuid, String componentUuid, CeActivityDto.Status status) {
    CeQueueDto queueDto = new CeQueueDto();
    queueDto.setTaskType(CeTaskTypes.REPORT);
    queueDto.setComponentUuid(componentUuid);
    queueDto.setUuid(taskUuid);
    CeActivityDto activityDto = new CeActivityDto(queueDto);
    activityDto.setStatus(status);
    activityDto.setExecutionTimeMs(500L);
    activityDto.setAnalysisUuid("U1");
    dbTester.getDbClient().ceActivityDao().insert(dbTester.getSession(), activityDto);
    dbTester.getSession().commit();
    return activityDto;
}
Also used : CeActivityDto(org.sonar.db.ce.CeActivityDto) CeQueueDto(org.sonar.db.ce.CeQueueDto)

Aggregations

CeActivityDto (org.sonar.db.ce.CeActivityDto)33 Test (org.junit.Test)21 CeQueueDto (org.sonar.db.ce.CeQueueDto)11 WsCe (org.sonarqube.ws.WsCe)9 CeTask (org.sonar.ce.queue.CeTask)6 TestResponse (org.sonar.server.ws.TestResponse)4 DbSession (org.sonar.db.DbSession)3 ComponentDto (org.sonar.db.component.ComponentDto)2 Date (java.util.Date)1 StringUtils.defaultString (org.apache.commons.lang.StringUtils.defaultString)1 Status (org.sonar.db.ce.CeQueueDto.Status)1 CeTaskQuery (org.sonar.db.ce.CeTaskQuery)1 ProjectResponse (org.sonarqube.ws.WsCe.ProjectResponse)1