Search in sources :

Example 26 with CeTask

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

the class CeWorkerImplTest method log_error_when_task_fails_with_not_MessageException.

@Test
public void log_error_when_task_fails_with_not_MessageException() throws Exception {
    CeTask ceTask = createCeTask(submitter);
    when(queue.peek(anyString(), anyBoolean())).thenReturn(Optional.of(ceTask));
    taskProcessorRepository.setProcessorForTask(CeTaskTypes.REPORT, taskProcessor);
    makeTaskProcessorFail(ceTask);
    underTest.call();
    List<String> logs = logTester.logs(LoggerLevel.INFO);
    assertThat(logs).hasSize(2);
    assertThat(logs.get(0)).contains(" | submitter=" + submitter.getLogin());
    assertThat(logs.get(1)).contains(String.format(" | submitter=%s | status=FAILED | time=", submitter.getLogin()));
    logs = logTester.logs(LoggerLevel.ERROR);
    assertThat(logs).hasSize(1);
    assertThat(logs.iterator().next()).isEqualTo("Failed to execute task " + ceTask.getUuid());
}
Also used : ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) CeTask(org.sonar.ce.task.CeTask) Test(org.junit.Test)

Example 27 with CeTask

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

the class CeWorkerImplTest method fail_when_no_CeTaskProcessor_is_found_in_repository.

@Test
public void fail_when_no_CeTaskProcessor_is_found_in_repository() throws Exception {
    CeTask task = createCeTask(null);
    taskProcessorRepository.setNoProcessorForTask(CeTaskTypes.REPORT);
    when(queue.peek(anyString(), anyBoolean())).thenReturn(Optional.of(task));
    assertThat(underTest.call()).isEqualTo(TASK_PROCESSED);
    verifyWorkerUuid();
    inOrder.verify(executionListener1).onStart(task);
    inOrder.verify(executionListener2).onStart(task);
    inOrder.verify(queue).remove(task, CeActivityDto.Status.FAILED, null, null);
    inOrder.verify(executionListener1).onEnd(eq(task), eq(CeActivityDto.Status.FAILED), any(), isNull(), isNull());
    inOrder.verify(executionListener2).onEnd(eq(task), eq(CeActivityDto.Status.FAILED), any(), isNull(), isNull());
}
Also used : CeTask(org.sonar.ce.task.CeTask) Test(org.junit.Test)

Example 28 with CeTask

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

the class CeWorkerImplTest method do_not_log_submitter_param_if_anonymous_and_error.

@Test
public void do_not_log_submitter_param_if_anonymous_and_error() throws Exception {
    CeTask ceTask = createCeTask(null);
    when(queue.peek(anyString(), anyBoolean())).thenReturn(Optional.of(ceTask));
    taskProcessorRepository.setProcessorForTask(ceTask.getType(), taskProcessor);
    makeTaskProcessorFail(ceTask);
    underTest.call();
    verifyWorkerUuid();
    List<String> logs = logTester.logs(LoggerLevel.INFO);
    assertThat(logs).hasSize(2);
    assertThat(logs.get(0)).doesNotContain("submitter=");
    assertThat(logs.get(1)).doesNotContain("submitter=");
    logs = logTester.logs(LoggerLevel.ERROR);
    assertThat(logs).hasSize(1);
    assertThat(logs.iterator().next()).doesNotContain("submitter=");
    assertThat(logTester.logs(LoggerLevel.DEBUG)).isEmpty();
}
Also used : ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) CeTask(org.sonar.ce.task.CeTask) Test(org.junit.Test)

Example 29 with CeTask

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

the class CeWorkerImplTest method fail_when_no_CeTaskProcessor_is_found_in_repository_without_listener.

@Test
public void fail_when_no_CeTaskProcessor_is_found_in_repository_without_listener() throws Exception {
    CeTask task = createCeTask(null);
    taskProcessorRepository.setNoProcessorForTask(CeTaskTypes.REPORT);
    when(queue.peek(anyString(), anyBoolean())).thenReturn(Optional.of(task));
    assertThat(underTestNoListener.call()).isEqualTo(TASK_PROCESSED);
    verifyWorkerUuid();
    inOrder.verify(queue).remove(task, CeActivityDto.Status.FAILED, null, null);
    inOrder.verifyNoMoreInteractions();
}
Also used : CeTask(org.sonar.ce.task.CeTask) Test(org.junit.Test)

Example 30 with CeTask

use of org.sonar.ce.task.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() {
    CeTask inProgressTask = submit(CeTaskTypes.REPORT, newProjectDto("PROJECT_1"));
    CeTask pendingTask1 = submit(CeTaskTypes.REPORT, newProjectDto("PROJECT_2"));
    CeTask pendingTask2 = submit(CeTaskTypes.REPORT, newProjectDto("PROJECT_3"));
    underTest.peek(WORKER_UUID_2, true);
    int canceledCount = underTest.cancelAll();
    assertThat(canceledCount).isEqualTo(2);
    Optional<CeActivityDto> history = db.getDbClient().ceActivityDao().selectByUuid(db.getSession(), pendingTask1.getUuid());
    assertThat(history.get().getStatus()).isEqualTo(CeActivityDto.Status.CANCELED);
    history = db.getDbClient().ceActivityDao().selectByUuid(db.getSession(), pendingTask2.getUuid());
    assertThat(history.get().getStatus()).isEqualTo(CeActivityDto.Status.CANCELED);
    history = db.getDbClient().ceActivityDao().selectByUuid(db.getSession(), inProgressTask.getUuid());
    assertThat(history).isEmpty();
}
Also used : CeActivityDto(org.sonar.db.ce.CeActivityDto) 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