Search in sources :

Example 11 with CeActivityDto

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

the class TaskFormatterTest method formatActivity_with_both_error_message_and_stacktrace.

@Test
public void formatActivity_with_both_error_message_and_stacktrace() {
    CeActivityDto dto = newActivity("UUID", "COMPONENT_UUID", CeActivityDto.Status.FAILED).setErrorMessage("error msg").setErrorStacktrace("error stacktrace");
    WsCe.Task task = underTest.formatActivity(db.getSession(), Collections.singletonList(dto)).iterator().next();
    assertThat(task.getErrorMessage()).isEqualTo(dto.getErrorMessage());
    assertThat(task.getErrorStacktrace()).isEqualTo(dto.getErrorStacktrace());
}
Also used : CeActivityDto(org.sonar.db.ce.CeActivityDto) WsCe(org.sonarqube.ws.WsCe) Test(org.junit.Test)

Example 12 with CeActivityDto

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

the class TaskFormatterTest method formatActivity.

@Test
public void formatActivity() {
    CeActivityDto dto = newActivity("UUID", "COMPONENT_UUID", CeActivityDto.Status.FAILED);
    WsCe.Task wsTask = underTest.formatActivity(db.getSession(), dto);
    assertThat(wsTask.getType()).isEqualTo(CeTaskTypes.REPORT);
    assertThat(wsTask.getId()).isEqualTo("UUID");
    assertThat(wsTask.getStatus()).isEqualTo(WsCe.TaskStatus.FAILED);
    assertThat(wsTask.getSubmittedAt()).isEqualTo(DateUtils.formatDateTime(new Date(1_450_000_000_000L)));
    assertThat(wsTask.getExecutionTimeMs()).isEqualTo(500L);
    assertThat(wsTask.getAnalysisId()).isEqualTo("U1");
    assertThat(wsTask.getLogs()).isFalse();
    assertThat(wsTask.hasScannerContext()).isFalse();
}
Also used : CeActivityDto(org.sonar.db.ce.CeActivityDto) WsCe(org.sonarqube.ws.WsCe) Date(java.util.Date) Test(org.junit.Test)

Example 13 with CeActivityDto

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

the class TaskFormatterTest method formatActivities.

@Test
public void formatActivities() {
    CeActivityDto dto1 = newActivity("UUID1", "COMPONENT_UUID", CeActivityDto.Status.FAILED);
    CeActivityDto dto2 = newActivity("UUID2", "COMPONENT_UUID", CeActivityDto.Status.SUCCESS);
    Iterable<WsCe.Task> wsTasks = underTest.formatActivity(db.getSession(), asList(dto1, dto2));
    assertThat(wsTasks).extracting("id").containsExactly("UUID1", "UUID2");
}
Also used : CeActivityDto(org.sonar.db.ce.CeActivityDto) Test(org.junit.Test)

Example 14 with CeActivityDto

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

the class InternalCeQueueImplTest method cancel_pending.

@Test
public void cancel_pending() throws Exception {
    CeTask task = submit(CeTaskTypes.REPORT, "PROJECT_1");
    // ignore
    boolean canceled = underTest.cancel("UNKNOWN");
    assertThat(canceled).isFalse();
    canceled = underTest.cancel(task.getUuid());
    assertThat(canceled).isTrue();
    Optional<CeActivityDto> activity = dbTester.getDbClient().ceActivityDao().selectByUuid(dbTester.getSession(), task.getUuid());
    assertThat(activity.isPresent()).isTrue();
    assertThat(activity.get().getStatus()).isEqualTo(CeActivityDto.Status.CANCELED);
}
Also used : CeActivityDto(org.sonar.db.ce.CeActivityDto) CeTask(org.sonar.ce.queue.CeTask) Test(org.junit.Test)

Example 15 with CeActivityDto

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

the class InternalCeQueueImplTest method remove_saves_error_message_and_stacktrace_when_exception_is_provided.

@Test
public void remove_saves_error_message_and_stacktrace_when_exception_is_provided() {
    Throwable error = new NullPointerException("Fake NPE to test persistence to DB");
    CeTask task = submit(CeTaskTypes.REPORT, "PROJECT_1");
    Optional<CeTask> peek = underTest.peek();
    underTest.remove(peek.get(), CeActivityDto.Status.FAILED, null, error);
    Optional<CeActivityDto> activityDto = dbTester.getDbClient().ceActivityDao().selectByUuid(session, task.getUuid());
    assertThat(activityDto).isPresent();
    assertThat(activityDto.get().getErrorMessage()).isEqualTo(error.getMessage());
    assertThat(activityDto.get().getErrorStacktrace()).isEqualToIgnoringWhitespace(stacktraceToString(error));
}
Also used : CeActivityDto(org.sonar.db.ce.CeActivityDto) CeTask(org.sonar.ce.queue.CeTask) Test(org.junit.Test)

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