use of org.sonar.ce.task.CeTaskResult 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.CeTaskResult in project sonarqube by SonarSource.
the class MutableTaskResultHolderImplTest method getResult_returns_object_set_with_setResult.
@Test
public void getResult_returns_object_set_with_setResult() {
CeTaskResult taskResult = mock(CeTaskResult.class);
underTest.setResult(taskResult);
Assertions.assertThat(underTest.getResult()).isSameAs(taskResult);
}
use of org.sonar.ce.task.CeTaskResult 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();
}
use of org.sonar.ce.task.CeTaskResult in project sonarqube by SonarSource.
the class InternalCeQueueImplTest method newTaskResult.
private CeTaskResult newTaskResult(@Nullable String analysisUuid) {
CeTaskResult taskResult = mock(CeTaskResult.class);
when(taskResult.getAnalysisUuid()).thenReturn(java.util.Optional.ofNullable(analysisUuid));
return taskResult;
}
Aggregations