use of org.sonar.ce.task.CeTask in project sonarqube by SonarSource.
the class CeWorkerImplTest method log_error_when_task_failed_and_ending_state_can_not_be_persisted_to_db.
@Test
public void log_error_when_task_failed_and_ending_state_can_not_be_persisted_to_db() throws Exception {
CeTask ceTask = createCeTask(submitter);
when(queue.peek(anyString(), anyBoolean())).thenReturn(Optional.of(ceTask));
taskProcessorRepository.setProcessorForTask(CeTaskTypes.REPORT, taskProcessor);
IllegalStateException ex = makeTaskProcessorFail(ceTask);
RuntimeException runtimeException = new RuntimeException("Simulate queue#remove failing");
doThrow(runtimeException).when(queue).remove(ceTask, CeActivityDto.Status.FAILED, null, ex);
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()));
List<LogAndArguments> logAndArguments = logTester.getLogs(LoggerLevel.ERROR);
assertThat(logAndArguments).hasSize(2);
LogAndArguments executionErrorLog = logAndArguments.get(0);
assertThat(executionErrorLog.getFormattedMsg()).isEqualTo("Failed to execute task " + ceTask.getUuid());
assertThat(executionErrorLog.getArgs().get()).containsOnly(ceTask.getUuid(), ex);
LogAndArguments finalizingErrorLog = logAndArguments.get(1);
assertThat(finalizingErrorLog.getFormattedMsg()).isEqualTo("Failed to finalize task with uuid '" + ceTask.getUuid() + "' and persist its state to db");
Object arg1 = finalizingErrorLog.getArgs().get()[0];
assertThat(arg1).isSameAs(runtimeException);
assertThat(((Exception) arg1).getSuppressed()).containsOnly(ex);
}
use of org.sonar.ce.task.CeTask in project sonarqube by SonarSource.
the class CeWorkerImplTest method call_sets_and_restores_thread_name_with_information_of_worker_when_an_error_occurs.
@Test
public void call_sets_and_restores_thread_name_with_information_of_worker_when_an_error_occurs() throws Exception {
String threadName = randomAlphabetic(3);
CeTask ceTask = createCeTask(submitter);
when(queue.peek(anyString(), anyBoolean())).thenAnswer(invocation -> {
assertThat(Thread.currentThread().getName()).isEqualTo("Worker " + randomOrdinal + " (UUID=" + workerUuid + ") on " + threadName);
return Optional.of(ceTask);
});
taskProcessorRepository.setProcessorForTask(CeTaskTypes.REPORT, taskProcessor);
makeTaskProcessorFail(ceTask);
Thread newThread = createThreadNameVerifyingThread(threadName);
newThread.start();
newThread.join();
}
use of org.sonar.ce.task.CeTask in project sonarqube by SonarSource.
the class SimpleCeTaskInterrupterTest method onStart_has_no_effect.
@Test
public void onStart_has_no_effect() {
CeTask ceTask = mock(CeTask.class);
underTest.onStart(ceTask);
verifyZeroInteractions(ceTask);
}
use of org.sonar.ce.task.CeTask in project sonarqube by SonarSource.
the class SimpleCeTaskInterrupterTest method onEnd_has_no_effect.
@Test
public void onEnd_has_no_effect() {
CeTask ceTask = mock(CeTask.class);
underTest.onEnd(ceTask);
verifyZeroInteractions(ceTask);
}
use of org.sonar.ce.task.CeTask in project sonarqube by SonarSource.
the class CeWorkerImplTest method peek_and_process_task.
@Test
public void peek_and_process_task() throws Exception {
CeTask task = createCeTask(null);
taskProcessorRepository.setProcessorForTask(task.getType(), taskProcessor);
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(taskProcessor).process(task);
inOrder.verify(queue).remove(task, CeActivityDto.Status.SUCCESS, null, null);
inOrder.verify(executionListener1).onEnd(eq(task), eq(CeActivityDto.Status.SUCCESS), any(), isNull(), isNull());
inOrder.verify(executionListener2).onEnd(eq(task), eq(CeActivityDto.Status.SUCCESS), any(), isNull(), isNull());
}
Aggregations