use of org.sonar.api.utils.log.LogAndArguments 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.api.utils.log.LogAndArguments 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.api.utils.log.LogAndArguments in project sonarqube by SonarSource.
the class GitScmProviderTest method branchChangedFiles_should_return_null_if_repo_exactref_is_null.
@Test
public void branchChangedFiles_should_return_null_if_repo_exactref_is_null() throws IOException {
Repository repository = mock(Repository.class);
RefDatabase refDatabase = mock(RefDatabase.class);
when(repository.getRefDatabase()).thenReturn(refDatabase);
when(refDatabase.findRef(BRANCH_NAME)).thenReturn(null);
GitScmProvider provider = new GitScmProvider(mockCommand(), analysisWarnings, gitIgnoreCommand, system2) {
@Override
Repository buildRepo(Path basedir) {
return repository;
}
};
assertThat(provider.branchChangedFiles(BRANCH_NAME, worktree)).isNull();
String refNotFound = "Could not find ref 'branch' in refs/heads, refs/remotes, refs/remotes/upstream or refs/remotes/origin";
LogAndArguments warnLog = logs.getLogs(WARN).get(0);
assertThat(warnLog.getRawMsg()).isEqualTo(refNotFound);
String warning = refNotFound + ". You may see unexpected issues and changes. Please make sure to fetch this ref before pull request analysis" + " and refer to <a href=\"/documentation/analysis/scm-integration/\" target=\"_blank\">the documentation</a>.";
verify(analysisWarnings).addUnique(warning);
}
Aggregations