use of org.sonar.ce.task.CeTask in project sonarqube by SonarSource.
the class CeTaskLoggingWorkerExecutionListenerTest method onStart_calls_initForTask_with_method_argument.
@Test
public void onStart_calls_initForTask_with_method_argument() {
CeTask ceTask = Mockito.mock(CeTask.class);
underTest.onStart(ceTask);
verify(ceTaskLogging).initForTask(ceTask);
verifyNoMoreInteractions(ceTaskLogging);
}
use of org.sonar.ce.task.CeTask in project sonarqube by SonarSource.
the class CeWorkerImplTest method log_error_when_task_was_successful_but_ending_state_can_not_be_persisted_to_db.
@Test
public void log_error_when_task_was_successful_but_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);
doThrow(new RuntimeException("Simulate queue#remove failing")).when(queue).remove(ceTask, CeActivityDto.Status.SUCCESS, null, null);
underTest.call();
assertThat(logTester.logs(LoggerLevel.ERROR)).containsOnly("Failed to finalize task with uuid '" + ceTask.getUuid() + "' and persist its state to db");
}
use of org.sonar.ce.task.CeTask in project sonarqube by SonarSource.
the class CeWorkerImplTest method fail_to_process_task_without_listeners.
@Test
public void fail_to_process_task_without_listeners() throws Exception {
CeTask task = createCeTask(null);
when(queue.peek(anyString(), anyBoolean())).thenReturn(Optional.of(task));
taskProcessorRepository.setProcessorForTask(task.getType(), taskProcessor);
Throwable error = makeTaskProcessorFail(task);
assertThat(underTestNoListener.call()).isEqualTo(TASK_PROCESSED);
verifyWorkerUuid();
inOrder.verify(taskProcessor).process(task);
inOrder.verify(queue).remove(task, CeActivityDto.Status.FAILED, null, error);
inOrder.verifyNoMoreInteractions();
}
use of org.sonar.ce.task.CeTask in project sonarqube by SonarSource.
the class CeWorkerImplTest method log_error_as_suppressed_when_task_failed_with_MessageException_and_ending_state_can_not_be_persisted_to_db.
@Test
public void log_error_as_suppressed_when_task_failed_with_MessageException_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);
MessageException ex = makeTaskProcessorFail(ceTask, MessageException.of("simulate MessageException thrown by TaskProcessor#process"));
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(1);
assertThat(logAndArguments.get(0).getFormattedMsg()).isEqualTo("Failed to finalize task with uuid '" + ceTask.getUuid() + "' and persist its state to db");
Object arg1 = logAndArguments.get(0).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 getCurrentTask_returns_empty_unless_a_thread_is_currently_executing_a_task.
@Test
public void getCurrentTask_returns_empty_unless_a_thread_is_currently_executing_a_task() throws InterruptedException {
CountDownLatch inCallLatch = new CountDownLatch(1);
CountDownLatch assertionsDoneLatch = new CountDownLatch(1);
String taskType = randomAlphabetic(12);
CeTask ceTask = mock(CeTask.class);
when(ceTask.getType()).thenReturn(taskType);
when(queue.peek(anyString(), anyBoolean())).thenReturn(Optional.of(ceTask));
taskProcessorRepository.setProcessorForTask(taskType, new SimpleCeTaskProcessor() {
@CheckForNull
@Override
public CeTaskResult process(CeTask task) {
inCallLatch.countDown();
try {
assertionsDoneLatch.await(10, TimeUnit.SECONDS);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
return null;
}
});
Thread t = callCallInNewThread(underTest);
try {
t.start();
inCallLatch.await(10, TimeUnit.SECONDS);
assertThat(underTest.getCurrentTask()).contains(ceTask);
} finally {
assertionsDoneLatch.countDown();
t.join();
}
assertThat(underTest.getCurrentTask()).isEmpty();
}
Aggregations