use of org.sonar.ce.task.CeTask in project sonarqube by SonarSource.
the class CeWorkerImplTest method isExecutedBy_returns_false_unless_a_thread_is_currently_executing_a_task.
@Test
public void isExecutedBy_returns_false_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.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 peek_and_process_task_without_listeners.
@Test
public void peek_and_process_task_without_listeners() throws Exception {
CeTask task = createCeTask(null);
taskProcessorRepository.setProcessorForTask(task.getType(), taskProcessor);
when(queue.peek(anyString(), anyBoolean())).thenReturn(Optional.of(task));
assertThat(underTestNoListener.call()).isEqualTo(TASK_PROCESSED);
verifyWorkerUuid();
inOrder.verify(taskProcessor).process(task);
inOrder.verify(queue).remove(task, CeActivityDto.Status.SUCCESS, null, null);
inOrder.verifyNoMoreInteractions();
}
use of org.sonar.ce.task.CeTask in project sonarqube by SonarSource.
the class CeWorkerImplTest method display_submitterLogin_in_logs_when_set_in_case_of_error.
@Test
public void display_submitterLogin_in_logs_when_set_in_case_of_error() throws Exception {
UserDto userDto = insertRandomUser();
CeTask ceTask = createCeTask(toTaskSubmitter(userDto));
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)).contains(String.format("submitter=%s", userDto.getLogin()));
assertThat(logs.get(1)).contains(String.format("submitter=%s | status=FAILED | time=", userDto.getLogin()));
logs = logTester.logs(LoggerLevel.ERROR);
assertThat(logs).hasSize(1);
assertThat(logs.get(0)).isEqualTo("Failed to execute task " + ceTask.getUuid());
}
use of org.sonar.ce.task.CeTask in project sonarqube by SonarSource.
the class InternalCeQueueImplTest method peek_populates_name_and_key_for_existing_component_and_main_component.
@Test
public void peek_populates_name_and_key_for_existing_component_and_main_component() {
ComponentDto project = db.components().insertPrivateProject();
ComponentDto branch = db.components().insertProjectBranch(project);
CeTask task = submit(CeTaskTypes.REPORT, branch);
Optional<CeTask> peek = underTest.peek(WORKER_UUID_1, true);
assertThat(peek).isPresent();
assertThat(peek.get().getUuid()).isEqualTo(task.getUuid());
assertThat(peek.get().getType()).isEqualTo(CeTaskTypes.REPORT);
assertThat(peek.get().getComponent()).contains(new CeTask.Component(branch.uuid(), branch.getDbKey(), branch.name()));
assertThat(peek.get().getMainComponent()).contains(new CeTask.Component(project.uuid(), project.getDbKey(), project.name()));
// no more pending tasks
peek = underTest.peek(WORKER_UUID_2, true);
assertThat(peek).isEmpty();
}
use of org.sonar.ce.task.CeTask in project sonarqube by SonarSource.
the class InternalCeQueueImplTest method remove_does_not_set_analysisUuid_in_CeActivity_when_CeTaskResult_has_no_analysis_uuid.
@Test
public void remove_does_not_set_analysisUuid_in_CeActivity_when_CeTaskResult_has_no_analysis_uuid() {
CeTask task = submit(CeTaskTypes.REPORT, newProjectDto("PROJECT_1"));
Optional<CeTask> peek = underTest.peek(WORKER_UUID_1, true);
underTest.remove(peek.get(), CeActivityDto.Status.SUCCESS, newTaskResult(null), null);
// available in history
Optional<CeActivityDto> history = db.getDbClient().ceActivityDao().selectByUuid(db.getSession(), task.getUuid());
assertThat(history).isPresent();
assertThat(history.get().getAnalysisUuid()).isNull();
}
Aggregations