]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-9041 add CeQueueDao#selectPendingByMinimumExecutionCount
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Thu, 30 Mar 2017 15:13:01 +0000 (17:13 +0200)
committerEric Hartmann <hartmann.eric@gmail.Com>
Thu, 27 Apr 2017 07:23:18 +0000 (09:23 +0200)
server/sonar-db-dao/src/main/java/org/sonar/db/ce/CeQueueDao.java
server/sonar-db-dao/src/main/java/org/sonar/db/ce/CeQueueMapper.java
server/sonar-db-dao/src/main/resources/org/sonar/db/ce/CeQueueMapper.xml
server/sonar-db-dao/src/test/java/org/sonar/db/ce/CeQueueDaoTest.java

index 3c630e3f0349ce91ca31674a4fda8953527ef268..90714f6ebdf463557f158c9135c2535d2f5e1cec 100644 (file)
@@ -80,6 +80,10 @@ public class CeQueueDao implements Dao {
     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();
index 1f7161b7fad6016154565f445bf5696b36ac5a98..2d82fb11ea41095ba94aa66f9ee797970de8e66b 100644 (file)
@@ -41,6 +41,11 @@ public interface CeQueueMapper {
   @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);
@@ -52,5 +57,4 @@ public interface CeQueueMapper {
     @Param("old") UpdateIf.OldProperties oldProperties);
 
   void deleteByUuid(@Param("uuid") String uuid);
-
 }
index 383fc06394db663148e15cace4ea4b311cd98d6b..df76f8c561efaacf03c8b8cfc6735d3ff0efa693 100644 (file)
       id asc
   </sql>
 
+  <select id="selectPendingByMinimumExecutionCount" resultType="org.sonar.db.ce.CeQueueDto">
+    select
+      <include refid="columns"/>
+    from
+      ce_queue cq
+    where
+      cq.status = 'PENDING'
+      and cq.execution_count >= #{minExecutionCount,jdbcType=INTEGER}
+  </select>
+
   <insert id="insert" parameterType="org.sonar.db.ce.CeQueueDto" useGeneratedKeys="false">
     insert into ce_queue
     (
index 925d8c61e3fb0777ecd46c2b70737f071d55a7ff..1ff894d6d39cc0658db55f8ba673741f73da70f4 100644 (file)
@@ -159,6 +159,35 @@ public class CeQueueDaoTest {
     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);