use of org.sonar.ce.task.CeTask in project sonarqube by SonarSource.
the class IssueSyncTaskProcessorTest method newContainerPopulator.
@Test
public void newContainerPopulator() {
CeTask task = new CeTask.Builder().setUuid("TASK_UUID").setType("Type").build();
IssueSyncTaskProcessor.newContainerPopulator(task).populateContainer(container);
Mockito.verify(container, Mockito.times(5)).add(any());
}
use of org.sonar.ce.task.CeTask in project sonarqube by SonarSource.
the class CeWorkerImplTest method display_start_at_debug_level_stop_at_error_level_for_console_if_DEBUG_is_enabled_and_task_failed.
@Test
public void display_start_at_debug_level_stop_at_error_level_for_console_if_DEBUG_is_enabled_and_task_failed() throws Exception {
logTester.setLevel(LoggerLevel.DEBUG);
CeTask ceTask = createCeTask(submitter);
when(queue.peek(anyString(), anyBoolean())).thenReturn(Optional.of(ceTask));
taskProcessorRepository.setProcessorForTask(CeTaskTypes.REPORT, taskProcessor);
makeTaskProcessorFail(ceTask);
underTest.call();
verifyWorkerUuid();
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());
assertThat(logTester.logs(LoggerLevel.DEBUG)).isEmpty();
}
use of org.sonar.ce.task.CeTask in project sonarqube by SonarSource.
the class CeWorkerImplTest method isExecutedBy_returns_false_unless_a_thread_is_currently_calling_call.
@Test
public void isExecutedBy_returns_false_unless_a_thread_is_currently_calling_call() throws InterruptedException {
CountDownLatch inCallLatch = new CountDownLatch(1);
CountDownLatch assertionsDoneLatch = new CountDownLatch(1);
// mock long running peek(String) call => Thread is executing call() but not running a task
when(queue.peek(anyString(), anyBoolean())).thenAnswer((Answer<Optional<CeTask>>) invocation -> {
inCallLatch.countDown();
try {
assertionsDoneLatch.await(10, TimeUnit.SECONDS);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
return Optional.empty();
});
Thread t = callCallInNewThread(underTest);
try {
t.start();
inCallLatch.await(10, TimeUnit.SECONDS);
assertThat(underTest.isExecutedBy(Thread.currentThread())).isFalse();
assertThat(underTest.isExecutedBy(new Thread())).isFalse();
assertThat(underTest.isExecutedBy(t)).isTrue();
} finally {
assertionsDoneLatch.countDown();
t.join();
}
assertThat(underTest.isExecutedBy(Thread.currentThread())).isFalse();
assertThat(underTest.isExecutedBy(new Thread())).isFalse();
assertThat(underTest.isExecutedBy(t)).isFalse();
}
use of org.sonar.ce.task.CeTask in project sonarqube by SonarSource.
the class CeWorkerImplTest method do_no_log_error_when_task_fails_with_MessageException.
@Test
public void do_no_log_error_when_task_fails_with_MessageException() throws Exception {
CeTask ceTask = createCeTask(submitter);
when(queue.peek(anyString(), anyBoolean())).thenReturn(Optional.of(ceTask));
taskProcessorRepository.setProcessorForTask(CeTaskTypes.REPORT, taskProcessor);
makeTaskProcessorFail(ceTask, MessageException.of("simulate MessageException thrown by TaskProcessor#process"));
underTest.call();
List<String> logs = logTester.logs(LoggerLevel.INFO);
assertThat(logs).hasSize(2);
assertThat(logs.get(1)).contains(" | submitter=" + submitter.getLogin());
assertThat(logs.get(1)).contains(String.format(" | submitter=%s | status=FAILED | time=", submitter.getLogin()));
assertThat(logTester.logs(LoggerLevel.ERROR)).isEmpty();
}
use of org.sonar.ce.task.CeTask in project sonarqube by SonarSource.
the class CeWorkerImplTest method getCurrentTask_returns_empty_when_a_thread_is_currently_calling_call_but_not_executing_a_task.
@Test
public void getCurrentTask_returns_empty_when_a_thread_is_currently_calling_call_but_not_executing_a_task() throws InterruptedException {
CountDownLatch inCallLatch = new CountDownLatch(1);
CountDownLatch assertionsDoneLatch = new CountDownLatch(1);
// mock long running peek(String) call => Thread is executing call() but not running a task
when(queue.peek(anyString(), anyBoolean())).thenAnswer((Answer<Optional<CeTask>>) invocation -> {
inCallLatch.countDown();
try {
assertionsDoneLatch.await(10, TimeUnit.SECONDS);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
return Optional.empty();
});
Thread t = callCallInNewThread(underTest);
try {
t.start();
inCallLatch.await(10, TimeUnit.SECONDS);
assertThat(underTest.getCurrentTask()).isEmpty();
} finally {
assertionsDoneLatch.countDown();
t.join();
}
assertThat(underTest.getCurrentTask()).isEmpty();
}
Aggregations