Search in sources :

Example 1 with UNIQUE_QUEUE_PER_MAIN_COMPONENT

use of org.sonar.ce.queue.CeQueue.SubmitOption.UNIQUE_QUEUE_PER_MAIN_COMPONENT in project sonarqube by SonarSource.

the class CeQueueImplTest method massSubmit_with_UNIQUE_QUEUE_PER_MAIN_COMPONENT_creates_tasks_depending_on_whether_there_is_pending_task_for_same_main_component.

@Test
public void massSubmit_with_UNIQUE_QUEUE_PER_MAIN_COMPONENT_creates_tasks_depending_on_whether_there_is_pending_task_for_same_main_component() {
    String mainComponentUuid1 = randomAlphabetic(5);
    String mainComponentUuid2 = randomAlphabetic(6);
    String mainComponentUuid3 = randomAlphabetic(7);
    String mainComponentUuid4 = randomAlphabetic(8);
    String mainComponentUuid5 = randomAlphabetic(9);
    CeTaskSubmit taskSubmit1 = createTaskSubmit("with_one_pending", newComponent(mainComponentUuid1), null);
    CeQueueDto dto1 = insertPendingInQueue(newComponent(mainComponentUuid1));
    Component componentForMainComponentUuid2 = newComponent(mainComponentUuid2);
    CeTaskSubmit taskSubmit2 = createTaskSubmit("no_pending", componentForMainComponentUuid2, null);
    CeTaskSubmit taskSubmit3 = createTaskSubmit("with_many_pending", newComponent(mainComponentUuid3), null);
    String[] uuids3 = IntStream.range(0, 2 + new Random().nextInt(5)).mapToObj(i -> insertPendingInQueue(newComponent(mainComponentUuid3))).map(CeQueueDto::getUuid).toArray(String[]::new);
    Component componentForMainComponentUuid4 = newComponent(mainComponentUuid4);
    CeTaskSubmit taskSubmit4 = createTaskSubmit("no_pending_2", componentForMainComponentUuid4, null);
    CeTaskSubmit taskSubmit5 = createTaskSubmit("with_pending_2", newComponent(mainComponentUuid5), null);
    CeQueueDto dto5 = insertPendingInQueue(newComponent(mainComponentUuid5));
    List<CeTask> tasks = underTest.massSubmit(of(taskSubmit1, taskSubmit2, taskSubmit3, taskSubmit4, taskSubmit5), UNIQUE_QUEUE_PER_MAIN_COMPONENT);
    assertThat(tasks).hasSize(2).extracting(task -> task.getComponent().get().getUuid(), task -> task.getMainComponent().get().getUuid()).containsOnly(tuple(componentForMainComponentUuid2.getUuid(), componentForMainComponentUuid2.getMainComponentUuid()), tuple(componentForMainComponentUuid4.getUuid(), componentForMainComponentUuid4.getMainComponentUuid()));
    assertThat(db.getDbClient().ceQueueDao().selectAllInAscOrder(db.getSession())).extracting(CeQueueDto::getUuid).hasSize(1 + uuids3.length + 1 + tasks.size()).contains(dto1.getUuid()).contains(uuids3).contains(dto5.getUuid()).containsAll(tasks.stream().map(CeTask::getUuid).collect(Collectors.toList()));
}
Also used : IntStream(java.util.stream.IntStream) Component(org.sonar.ce.queue.CeTaskSubmit.Component) CeTaskTypes(org.sonar.db.ce.CeTaskTypes) UserDto(org.sonar.db.user.UserDto) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Random(java.util.Random) DbSession(org.sonar.db.DbSession) TestSystem2(org.sonar.api.impl.utils.TestSystem2) CeActivityDto(org.sonar.db.ce.CeActivityDto) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) CeTask(org.sonar.ce.task.CeTask) Arrays.asList(java.util.Arrays.asList) ComponentTesting(org.sonar.db.component.ComponentTesting) UuidFactoryFast(org.sonar.core.util.UuidFactoryFast) Assertions.catchThrowable(org.assertj.core.api.Assertions.catchThrowable) Nullable(javax.annotation.Nullable) ImmutableList.of(com.google.common.collect.ImmutableList.of) DbTester(org.sonar.db.DbTester) Collections.emptyMap(java.util.Collections.emptyMap) System2(org.sonar.api.utils.System2) RandomStringUtils.randomAlphabetic(org.apache.commons.lang.RandomStringUtils.randomAlphabetic) Assertions.tuple(org.assertj.core.api.Assertions.tuple) UuidFactory(org.sonar.core.util.UuidFactory) Test(org.junit.Test) Collectors(java.util.stream.Collectors) SequenceUuidFactory(org.sonar.core.util.SequenceUuidFactory) List(java.util.List) ComponentDto(org.sonar.db.component.ComponentDto) Rule(org.junit.Rule) CeQueueDto(org.sonar.db.ce.CeQueueDto) Optional(java.util.Optional) UNIQUE_QUEUE_PER_MAIN_COMPONENT(org.sonar.ce.queue.CeQueue.SubmitOption.UNIQUE_QUEUE_PER_MAIN_COMPONENT) UserTesting(org.sonar.db.user.UserTesting) Random(java.util.Random) CeQueueDto(org.sonar.db.ce.CeQueueDto) Component(org.sonar.ce.queue.CeTaskSubmit.Component) CeTask(org.sonar.ce.task.CeTask) Test(org.junit.Test)

Aggregations

ImmutableList.of (com.google.common.collect.ImmutableList.of)1 Arrays.asList (java.util.Arrays.asList)1 Collections.emptyMap (java.util.Collections.emptyMap)1 List (java.util.List)1 Optional (java.util.Optional)1 Random (java.util.Random)1 Collectors (java.util.stream.Collectors)1 IntStream (java.util.stream.IntStream)1 Nullable (javax.annotation.Nullable)1 RandomStringUtils.randomAlphabetic (org.apache.commons.lang.RandomStringUtils.randomAlphabetic)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 Assertions.assertThatThrownBy (org.assertj.core.api.Assertions.assertThatThrownBy)1 Assertions.catchThrowable (org.assertj.core.api.Assertions.catchThrowable)1 Assertions.tuple (org.assertj.core.api.Assertions.tuple)1 Rule (org.junit.Rule)1 Test (org.junit.Test)1 TestSystem2 (org.sonar.api.impl.utils.TestSystem2)1 System2 (org.sonar.api.utils.System2)1 UNIQUE_QUEUE_PER_MAIN_COMPONENT (org.sonar.ce.queue.CeQueue.SubmitOption.UNIQUE_QUEUE_PER_MAIN_COMPONENT)1 Component (org.sonar.ce.queue.CeTaskSubmit.Component)1