aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-db
diff options
context:
space:
mode:
authorTeryk Bellahsene <teryk.bellahsene@sonarsource.com>2016-04-19 16:30:22 +0200
committerTeryk Bellahsene <teryk.bellahsene@sonarsource.com>2016-04-21 01:23:38 +0200
commitb53cc3cb38c77de88c1d55377968a13c7ab4df66 (patch)
tree9412731b32d1d06158a62ba66cfc834ca837cb4f /sonar-db
parent7c0c6d16be2988e96fdde256a286043c25b781fc (diff)
downloadsonarqube-b53cc3cb38c77de88c1d55377968a13c7ab4df66.tar.gz
sonarqube-b53cc3cb38c77de88c1d55377968a13c7ab4df66.zip
SONAR-7553 DAO of CE_QUEUE count number of rows by status
Diffstat (limited to 'sonar-db')
-rw-r--r--sonar-db/src/main/java/org/sonar/db/ce/CeQueueDao.java7
-rw-r--r--sonar-db/src/main/java/org/sonar/db/ce/CeQueueMapper.java4
-rw-r--r--sonar-db/src/main/resources/org/sonar/db/ce/CeQueueMapper.xml9
-rw-r--r--sonar-db/src/test/java/org/sonar/db/ce/CeQueueDaoTest.java34
4 files changed, 42 insertions, 12 deletions
diff --git a/sonar-db/src/main/java/org/sonar/db/ce/CeQueueDao.java b/sonar-db/src/main/java/org/sonar/db/ce/CeQueueDao.java
index 779f7372bbf..283b3823443 100644
--- a/sonar-db/src/main/java/org/sonar/db/ce/CeQueueDao.java
+++ b/sonar-db/src/main/java/org/sonar/db/ce/CeQueueDao.java
@@ -21,6 +21,7 @@ package org.sonar.db.ce;
import com.google.common.base.Optional;
import java.util.List;
+import javax.annotation.Nullable;
import org.apache.ibatis.session.RowBounds;
import org.sonar.api.utils.System2;
import org.sonar.db.Dao;
@@ -100,11 +101,11 @@ public class CeQueueDao implements Dao {
}
public int countByStatus(DbSession dbSession, CeQueueDto.Status status) {
- return mapper(dbSession).countByStatus(status);
+ return mapper(dbSession).countByStatusAndComponentUuid(status, null);
}
- public int countAll(DbSession dbSession) {
- return mapper(dbSession).countAll();
+ public int countByStatusAndComponentUuid(DbSession dbSession, CeQueueDto.Status status, @Nullable String componentUuid) {
+ return mapper(dbSession).countByStatusAndComponentUuid(status, componentUuid);
}
public Optional<CeQueueDto> peek(DbSession session) {
diff --git a/sonar-db/src/main/java/org/sonar/db/ce/CeQueueMapper.java b/sonar-db/src/main/java/org/sonar/db/ce/CeQueueMapper.java
index 62fca4a7ff1..aa0645987dd 100644
--- a/sonar-db/src/main/java/org/sonar/db/ce/CeQueueMapper.java
+++ b/sonar-db/src/main/java/org/sonar/db/ce/CeQueueMapper.java
@@ -40,9 +40,7 @@ public interface CeQueueMapper {
@CheckForNull
CeQueueDto selectByUuid(@Param("uuid") String uuid);
- int countByStatus(@Param("status") CeQueueDto.Status status);
-
- int countAll();
+ int countByStatusAndComponentUuid(@Param("status") CeQueueDto.Status status, @Nullable @Param("componentUuid") String componentUuid);
void insert(CeQueueDto dto);
diff --git a/sonar-db/src/main/resources/org/sonar/db/ce/CeQueueMapper.xml b/sonar-db/src/main/resources/org/sonar/db/ce/CeQueueMapper.xml
index c9924353c1a..e3d71cc85ac 100644
--- a/sonar-db/src/main/resources/org/sonar/db/ce/CeQueueMapper.xml
+++ b/sonar-db/src/main/resources/org/sonar/db/ce/CeQueueMapper.xml
@@ -29,8 +29,13 @@
where cq.uuid=#{uuid}
</select>
- <select id="countByStatus" parameterType="org.sonar.db.ce.CeQueueDto$Status" resultType="int">
- select count(1) from ce_queue where status=#{status}
+ <select id="countByStatusAndComponentUuid" parameterType="map" resultType="int">
+ select count(1)
+ from ce_queue
+ where status=#{status}
+ <if test="componentUuid!=null">
+ and component_uuid=#{componentUuid}
+ </if>
</select>
<select id="countAll" resultType="int">
diff --git a/sonar-db/src/test/java/org/sonar/db/ce/CeQueueDaoTest.java b/sonar-db/src/test/java/org/sonar/db/ce/CeQueueDaoTest.java
index 70fc652ad83..30c4694047b 100644
--- a/sonar-db/src/test/java/org/sonar/db/ce/CeQueueDaoTest.java
+++ b/sonar-db/src/test/java/org/sonar/db/ce/CeQueueDaoTest.java
@@ -139,7 +139,7 @@ public class CeQueueDaoTest {
system2.setNow(INIT_TIME + 3_000_000);
insert(TASK_UUID_2, COMPONENT_UUID_2, PENDING);
- assertThat(underTest.countAll(db.getSession())).isEqualTo(2);
+ assertThat(db.countRowsOfTable("ce_queue")).isEqualTo(2);
verifyCeQueueStatuses(TASK_UUID_1, PENDING, TASK_UUID_2, PENDING);
// peek first one
@@ -284,6 +284,31 @@ public class CeQueueDaoTest {
assertThat(total).isEqualTo(0);
}
+ @Test
+ public void count_by_status_and_component_uuid() {
+ // task retrieved in the queue
+ insert(newCeQueueDto(TASK_UUID_1)
+ .setComponentUuid(COMPONENT_UUID_1)
+ .setStatus(IN_PROGRESS)
+ .setTaskType(CeTaskTypes.REPORT)
+ .setCreatedAt(100_000L));
+ // on component uuid 2, not returned
+ insert(newCeQueueDto(TASK_UUID_2)
+ .setComponentUuid(COMPONENT_UUID_2)
+ .setStatus(IN_PROGRESS)
+ .setTaskType(CeTaskTypes.REPORT)
+ .setCreatedAt(100_000L));
+ // pending status, not returned
+ insert(newCeQueueDto(TASK_UUID_3)
+ .setComponentUuid(COMPONENT_UUID_1)
+ .setStatus(PENDING)
+ .setTaskType(CeTaskTypes.REPORT)
+ .setCreatedAt(100_000L));
+
+ assertThat(underTest.countByStatusAndComponentUuid(db.getSession(), IN_PROGRESS, COMPONENT_UUID_1)).isEqualTo(1);
+ assertThat(underTest.countByStatus(db.getSession(), IN_PROGRESS)).isEqualTo(2);
+ }
+
private void insert(CeQueueDto dto) {
underTest.insert(db.getSession(), dto);
db.commit();
@@ -314,12 +339,13 @@ public class CeQueueDaoTest {
});
}
- private void verifyCeQueueStatuses(String taskUuid1, CeQueueDto.Status taskStatus1, String taskUuid2, CeQueueDto.Status taskStatus2, String taskUuid3, CeQueueDto.Status taskStatus3) {
- verifyCeQueueStatuses(new String[]{taskUuid1, taskUuid2, taskUuid3}, new CeQueueDto.Status[]{taskStatus1, taskStatus2, taskStatus3});
+ private void verifyCeQueueStatuses(String taskUuid1, CeQueueDto.Status taskStatus1, String taskUuid2, CeQueueDto.Status taskStatus2, String taskUuid3,
+ CeQueueDto.Status taskStatus3) {
+ verifyCeQueueStatuses(new String[] {taskUuid1, taskUuid2, taskUuid3}, new CeQueueDto.Status[] {taskStatus1, taskStatus2, taskStatus3});
}
private void verifyCeQueueStatuses(String taskUuid1, CeQueueDto.Status taskStatus1, String taskUuid2, CeQueueDto.Status taskStatus2) {
- verifyCeQueueStatuses(new String[]{taskUuid1, taskUuid2}, new CeQueueDto.Status[]{taskStatus1, taskStatus2});
+ verifyCeQueueStatuses(new String[] {taskUuid1, taskUuid2}, new CeQueueDto.Status[] {taskStatus1, taskStatus2});
}
private void verifyCeQueueStatuses(String[] taskUuids, CeQueueDto.Status[] statuses) {