Search in sources :

Example 1 with CeTask

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

the class InternalCeQueueImpl method peek.

@Override
public Optional<CeTask> peek() {
    if (peekPaused.get()) {
        return Optional.absent();
    }
    try (DbSession dbSession = dbClient.openSession(false)) {
        Optional<CeQueueDto> dto = dbClient.ceQueueDao().peek(dbSession);
        CeTask task = null;
        if (dto.isPresent()) {
            task = loadTask(dbSession, dto.get());
            queueStatus.addInProgress();
        }
        return Optional.fromNullable(task);
    }
}
Also used : DbSession(org.sonar.db.DbSession) CeQueueDto(org.sonar.db.ce.CeQueueDto) CeTask(org.sonar.ce.queue.CeTask)

Example 2 with CeTask

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

the class CeLoggingTest 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.queue.CeTask)

Example 3 with CeTask

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

the class InternalCeQueueImplTest method submit_returns_task_populated_from_CeTaskSubmit_and_creates_CeQueue_row.

@Test
public void submit_returns_task_populated_from_CeTaskSubmit_and_creates_CeQueue_row() {
    CeTaskSubmit taskSubmit = createTaskSubmit(CeTaskTypes.REPORT, "PROJECT_1", "rob");
    CeTask task = underTest.submit(taskSubmit);
    verifyCeTask(taskSubmit, task, null);
    verifyCeQueueDtoForTaskSubmit(taskSubmit);
}
Also used : CeTaskSubmit(org.sonar.ce.queue.CeTaskSubmit) CeTask(org.sonar.ce.queue.CeTask) Test(org.junit.Test)

Example 4 with CeTask

use of org.sonar.ce.queue.CeTask 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 5 with CeTask

use of org.sonar.ce.queue.CeTask 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

CeTask (org.sonar.ce.queue.CeTask)26 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 Before (org.junit.Before)1 DbSession (org.sonar.db.DbSession)1 CeQueueDto (org.sonar.db.ce.CeQueueDto)1