@Test public void massSubmit_with_UNIQUE_QUEUE_PER_MAIN_COMPONENT_does_not_create_task_when_there_is_many_pending_task_for_same_main_component() { String mainComponentUuid = randomAlphabetic(5); CeTaskSubmit taskSubmit = createTaskSubmit("with_component", newComponent(mainComponentUuid), null); String[] uuids = IntStream.range(0, 2 + new Random().nextInt(5)) .mapToObj(i -> insertPendingInQueue(newComponent(mainComponentUuid))) .map(CeQueueDto::getUuid) .toArray(String[]::new); List<CeTask> tasks = underTest.massSubmit(of(taskSubmit), UNIQUE_QUEUE_PER_MAIN_COMPONENT); assertThat(tasks).isEmpty(); assertThat(db.getDbClient().ceQueueDao().selectAllInAscOrder(db.getSession())) .extracting(CeQueueDto::getUuid) .containsOnly(uuids); }
@Test public void massSubmit_with_UNIQUE_QUEUE_PER_MAIN_COMPONENT_creates_task_without_component_when_there_is_a_pending_task_without_component() { CeTaskSubmit taskSubmit = createTaskSubmit("no_component"); CeQueueDto dto = insertPendingInQueue(null); List<CeTask> tasks = underTest.massSubmit(of(taskSubmit), UNIQUE_QUEUE_PER_MAIN_COMPONENT); assertThat(tasks).hasSize(1); assertThat(db.getDbClient().ceQueueDao().selectAllInAscOrder(db.getSession())) .extracting(CeQueueDto::getUuid) .containsOnly(dto.getUuid(), tasks.iterator().next().getUuid()); }
@Test public void massSubmit_without_UNIQUE_QUEUE_PER_MAIN_COMPONENT_creates_task_when_there_is_many_pending_task_for_other_main_component() { String mainComponentUuid = randomAlphabetic(5); CeTaskSubmit taskSubmit = createTaskSubmit("with_component", newComponent(mainComponentUuid), null); String[] uuids = IntStream.range(0, 2 + new Random().nextInt(5)) .mapToObj(i -> insertPendingInQueue(newComponent(mainComponentUuid))) .map(CeQueueDto::getUuid) .toArray(String[]::new); List<CeTask> tasks = underTest.massSubmit(of(taskSubmit)); assertThat(tasks).hasSize(1); assertThat(db.getDbClient().ceQueueDao().selectAllInAscOrder(db.getSession())) .extracting(CeQueueDto::getUuid) .hasSize(uuids.length + 1) .contains(uuids) .contains(tasks.iterator().next().getUuid()); }
@Test public void submit_with_UNIQUE_QUEUE_PER_MAIN_COMPONENT_does_not_create_task_when_there_is_many_pending_task_for_same_main_component() { String mainComponentUuid = randomAlphabetic(5); CeTaskSubmit taskSubmit = createTaskSubmit("with_component", newComponent(mainComponentUuid), null); String[] uuids = IntStream.range(0, 2 + new Random().nextInt(5)) .mapToObj(i -> insertPendingInQueue(newComponent(mainComponentUuid))) .map(CeQueueDto::getUuid) .toArray(String[]::new); Optional<CeTask> task = underTest.submit(taskSubmit, UNIQUE_QUEUE_PER_MAIN_COMPONENT); assertThat(task).isEmpty(); assertThat(db.getDbClient().ceQueueDao().selectAllInAscOrder(db.getSession())) .extracting(CeQueueDto::getUuid) .containsOnly(uuids); }
@Test public void massSubmit_without_UNIQUE_QUEUE_PER_MAIN_COMPONENT_creates_task_when_there_is_one_pending_task_for_other_main_component() { String mainComponentUuid = randomAlphabetic(5); CeTaskSubmit taskSubmit = createTaskSubmit("with_component", newComponent(mainComponentUuid), null); CeQueueDto dto = insertPendingInQueue(newComponent(mainComponentUuid)); List<CeTask> tasks = underTest.massSubmit(of(taskSubmit)); assertThat(tasks).hasSize(1); assertThat(db.getDbClient().ceQueueDao().selectAllInAscOrder(db.getSession())) .extracting(CeQueueDto::getUuid) .containsOnly(dto.getUuid(), tasks.iterator().next().getUuid()); }
@Test public void massSubmit_with_UNIQUE_QUEUE_PER_MAIN_COMPONENT_creates_task_when_there_is_a_pending_task_for_another_main_component() { String mainComponentUuid = randomAlphabetic(5); String otherMainComponentUuid = randomAlphabetic(6); CeTaskSubmit taskSubmit = createTaskSubmit("with_component", newComponent(mainComponentUuid), null); CeQueueDto dto = insertPendingInQueue(newComponent(otherMainComponentUuid)); List<CeTask> tasks = underTest.massSubmit(of(taskSubmit), UNIQUE_QUEUE_PER_MAIN_COMPONENT); assertThat(tasks).hasSize(1); assertThat(db.getDbClient().ceQueueDao().selectAllInAscOrder(db.getSession())) .extracting(CeQueueDto::getUuid) .containsOnly(dto.getUuid(), tasks.iterator().next().getUuid()); }
@Test public void submit_without_UNIQUE_QUEUE_PER_MAIN_COMPONENT_creates_task_when_there_is_many_pending_task_for_same_main_component() { String mainComponentUuid = randomAlphabetic(5); CeTaskSubmit taskSubmit = createTaskSubmit("with_component", newComponent(mainComponentUuid), null); String[] uuids = IntStream.range(0, 2 + new Random().nextInt(5)) .mapToObj(i -> insertPendingInQueue(newComponent(mainComponentUuid))) .map(CeQueueDto::getUuid) .toArray(String[]::new); CeTask task = underTest.submit(taskSubmit); assertThat(db.getDbClient().ceQueueDao().selectAllInAscOrder(db.getSession())) .extracting(CeQueueDto::getUuid) .hasSize(uuids.length + 1) .contains(uuids) .contains(task.getUuid()); }
@Test public void massSubmit_with_UNIQUE_QUEUE_PER_MAIN_COMPONENT_does_not_create_task_when_there_is_one_pending_task_for_same_main_component() { String mainComponentUuid = randomAlphabetic(5); CeTaskSubmit taskSubmit = createTaskSubmit("with_component", newComponent(mainComponentUuid), null); CeQueueDto dto = insertPendingInQueue(newComponent(mainComponentUuid)); List<CeTask> tasks = underTest.massSubmit(of(taskSubmit), UNIQUE_QUEUE_PER_MAIN_COMPONENT); assertThat(tasks).isEmpty(); assertThat(db.getDbClient().ceQueueDao().selectAllInAscOrder(db.getSession())) .extracting(CeQueueDto::getUuid) .containsOnly(dto.getUuid()); }
@Test public void submit_with_UNIQUE_QUEUE_PER_MAIN_COMPONENT_creates_task_without_component_when_there_is_a_pending_task_without_component() { CeTaskSubmit taskSubmit = createTaskSubmit("no_component"); CeQueueDto dto = insertPendingInQueue(null); Optional<CeTask> task = underTest.submit(taskSubmit, UNIQUE_QUEUE_PER_MAIN_COMPONENT); assertThat(task).isNotEmpty(); assertThat(db.getDbClient().ceQueueDao().selectAllInAscOrder(db.getSession())) .extracting(CeQueueDto::getUuid) .containsOnly(dto.getUuid(), task.get().getUuid()); }
@Test public void submit_with_UNIQUE_QUEUE_PER_MAIN_COMPONENT_creates_task_when_there_is_a_pending_task_for_another_main_component() { String mainComponentUuid = randomAlphabetic(5); String otherMainComponentUuid = randomAlphabetic(6); CeTaskSubmit taskSubmit = createTaskSubmit("with_component", newComponent(mainComponentUuid), null); CeQueueDto dto = insertPendingInQueue(newComponent(otherMainComponentUuid)); Optional<CeTask> task = underTest.submit(taskSubmit, UNIQUE_QUEUE_PER_MAIN_COMPONENT); assertThat(task).isNotEmpty(); assertThat(db.getDbClient().ceQueueDao().selectAllInAscOrder(db.getSession())) .extracting(CeQueueDto::getUuid) .containsOnly(dto.getUuid(), task.get().getUuid()); }
@Test public void submit_with_UNIQUE_QUEUE_PER_MAIN_COMPONENT_does_not_create_task_when_there_is_one_pending_task_for_same_main_component() { String mainComponentUuid = randomAlphabetic(5); CeTaskSubmit taskSubmit = createTaskSubmit("with_component", newComponent(mainComponentUuid), null); CeQueueDto dto = insertPendingInQueue(newComponent(mainComponentUuid)); Optional<CeTask> task = underTest.submit(taskSubmit, UNIQUE_QUEUE_PER_MAIN_COMPONENT); assertThat(task).isEmpty(); assertThat(db.getDbClient().ceQueueDao().selectAllInAscOrder(db.getSession())) .extracting(CeQueueDto::getUuid) .containsOnly(dto.getUuid()); }
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); CeTaskSubmit taskSubmit4 = createTaskSubmit("no_pending_2", componentForMainComponentUuid4, null); CeTaskSubmit taskSubmit5 = createTaskSubmit("with_pending_2", newComponent(mainComponentUuid5), null); CeQueueDto dto5 = insertPendingInQueue(newComponent(mainComponentUuid5));
@Test public void submit_without_UNIQUE_QUEUE_PER_MAIN_COMPONENT_creates_task_when_there_is_one_pending_task_for_same_main_component() { String mainComponentUuid = randomAlphabetic(5); CeTaskSubmit taskSubmit = createTaskSubmit("with_component", newComponent(mainComponentUuid), null); CeQueueDto dto = insertPendingInQueue(newComponent(mainComponentUuid)); CeTask task = underTest.submit(taskSubmit); assertThat(db.getDbClient().ceQueueDao().selectAllInAscOrder(db.getSession())) .extracting(CeQueueDto::getUuid) .containsOnly(dto.getUuid(), task.getUuid()); }