return Optional.fromNullable(mapper(session).selectByUuid(uuid));
}
+ public List<CeQueueDto> selectPendingByMinimumExecutionCount(DbSession dbSession, int minExecutionCount) {
+ return mapper(dbSession).selectPendingByMinimumExecutionCount(minExecutionCount);
+ }
+
public CeQueueDto insert(DbSession session, CeQueueDto dto) {
if (dto.getCreatedAt() == 0L || dto.getUpdatedAt() == 0L) {
long now = system2.now();
@CheckForNull
CeQueueDto selectByUuid(@Param("uuid") String uuid);
+ /**
+ * Select all pending tasks which execution count is greater than or equal to the specified {@code minExecutionCount}.
+ */
+ List<CeQueueDto> selectPendingByMinimumExecutionCount(@Param("minExecutionCount") int minExecutionCount);
+
int countByStatusAndComponentUuid(@Param("status") CeQueueDto.Status status, @Nullable @Param("componentUuid") String componentUuid);
void insert(CeQueueDto dto);
@Param("old") UpdateIf.OldProperties oldProperties);
void deleteByUuid(@Param("uuid") String uuid);
-
}
assertThat(underTest.selectAllInAscOrder(db.getSession())).extracting("uuid").containsOnly(TASK_UUID_1, TASK_UUID_2, TASK_UUID_3);
}
+ @Test
+ public void selectPendingByMinimumExecutionCount_returns_pending_tasks_with_executionCount_greater_or_equal_to_argument() {
+ insert("p1", CeQueueDto.Status.PENDING, 0);
+ insert("p2", CeQueueDto.Status.PENDING, 1);
+ insert("p3", CeQueueDto.Status.PENDING, 2);
+ insert("i1", CeQueueDto.Status.IN_PROGRESS, 0);
+ insert("i2", CeQueueDto.Status.IN_PROGRESS, 1);
+ insert("i3", CeQueueDto.Status.IN_PROGRESS, 2);
+
+ assertThat(underTest.selectPendingByMinimumExecutionCount(db.getSession(), 0))
+ .extracting(CeQueueDto::getUuid)
+ .containsOnly("p1", "p2", "p3");
+ assertThat(underTest.selectPendingByMinimumExecutionCount(db.getSession(), 1))
+ .extracting(CeQueueDto::getUuid)
+ .containsOnly("p2", "p3");
+ assertThat(underTest.selectPendingByMinimumExecutionCount(db.getSession(), 2))
+ .extracting(CeQueueDto::getUuid)
+ .containsOnly("p3");
+ assertThat(underTest.selectPendingByMinimumExecutionCount(db.getSession(), 3))
+ .isEmpty();
+ assertThat(underTest.selectPendingByMinimumExecutionCount(db.getSession(), 3 + Math.abs(new Random().nextInt(20))))
+ .isEmpty();
+ }
+
+ @Test
+ public void selectPendingByMinimumExecutionCount_does_not_return_non_pending_tasks() {
+
+ }
+
@Test
public void test_delete() {
insert(TASK_UUID_1, COMPONENT_UUID_1, PENDING);