aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeryk Bellahsene <teryk.bellahsene@sonarsource.com>2016-04-19 16:29:41 +0200
committerTeryk Bellahsene <teryk.bellahsene@sonarsource.com>2016-04-21 01:23:38 +0200
commit7c0c6d16be2988e96fdde256a286043c25b781fc (patch)
tree4d1c556bdfb20961aba11e1aa0136e7d8b05ddbf
parent393fb11209aea9b9180ef04542b45d6dcf3ba69f (diff)
downloadsonarqube-7c0c6d16be2988e96fdde256a286043c25b781fc.tar.gz
sonarqube-7c0c6d16be2988e96fdde256a286043c25b781fc.zip
SONAR-7553 DAO of CE_ACTIVITY count number of tasks still failing
-rw-r--r--sonar-db/src/main/java/org/sonar/db/ce/CeActivityDao.java5
-rw-r--r--sonar-db/src/main/java/org/sonar/db/ce/CeActivityMapper.java3
-rw-r--r--sonar-db/src/main/resources/org/sonar/db/ce/CeActivityMapper.xml10
-rw-r--r--sonar-db/src/test/java/org/sonar/db/ce/CeActivityDaoTest.java24
4 files changed, 39 insertions, 3 deletions
diff --git a/sonar-db/src/main/java/org/sonar/db/ce/CeActivityDao.java b/sonar-db/src/main/java/org/sonar/db/ce/CeActivityDao.java
index 1055de867d5..91f155ee3ca 100644
--- a/sonar-db/src/main/java/org/sonar/db/ce/CeActivityDao.java
+++ b/sonar-db/src/main/java/org/sonar/db/ce/CeActivityDao.java
@@ -22,6 +22,7 @@ package org.sonar.db.ce;
import com.google.common.base.Optional;
import java.util.Collections;
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;
@@ -72,6 +73,10 @@ public class CeActivityDao implements Dao {
return mapper(dbSession).selectByQuery(query, offset, pageSize);
}
+ public int countLastByStatusAndComponentUuid(DbSession dbSession, CeActivityDto.Status status, @Nullable String componentUuid) {
+ return mapper(dbSession).countLastByStatusAndComponentUuid(status, componentUuid);
+ }
+
private static CeActivityMapper mapper(DbSession dbSession) {
return dbSession.getMapper(CeActivityMapper.class);
}
diff --git a/sonar-db/src/main/java/org/sonar/db/ce/CeActivityMapper.java b/sonar-db/src/main/java/org/sonar/db/ce/CeActivityMapper.java
index ea4652d4185..8bdaa57b1af 100644
--- a/sonar-db/src/main/java/org/sonar/db/ce/CeActivityMapper.java
+++ b/sonar-db/src/main/java/org/sonar/db/ce/CeActivityMapper.java
@@ -21,6 +21,7 @@ package org.sonar.db.ce;
import java.util.List;
import javax.annotation.CheckForNull;
+import javax.annotation.Nullable;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.session.RowBounds;
@@ -37,7 +38,7 @@ public interface CeActivityMapper {
List<CeActivityDto> selectOlderThan(@Param("beforeDate") long beforeDate);
- int countByQuery(@Param("query") CeTaskQuery query);
+ int countLastByStatusAndComponentUuid(@Param("status") CeActivityDto.Status status, @Nullable @Param("componentUuid") String componentUuid);
void insert(CeActivityDto dto);
diff --git a/sonar-db/src/main/resources/org/sonar/db/ce/CeActivityMapper.xml b/sonar-db/src/main/resources/org/sonar/db/ce/CeActivityMapper.xml
index 765c5f28a6b..69e58b22989 100644
--- a/sonar-db/src/main/resources/org/sonar/db/ce/CeActivityMapper.xml
+++ b/sonar-db/src/main/resources/org/sonar/db/ce/CeActivityMapper.xml
@@ -109,6 +109,16 @@
from ce_activity ca
where ca.created_at &lt; #{beforeDate,jdbcType=BIGINT}
</select>
+
+ <select id="countLastByStatusAndComponentUuid" resultType="int">
+ select count(1)
+ from ce_activity
+ where status=#{status}
+ and is_last=${_true}
+ <if test="componentUuid!=null">
+ and component_uuid=#{componentUuid}
+ </if>
+ </select>
<insert id="insert" parameterType="org.sonar.db.ce.CeActivityDto" useGeneratedKeys="false">
insert into ce_activity
diff --git a/sonar-db/src/test/java/org/sonar/db/ce/CeActivityDaoTest.java b/sonar-db/src/test/java/org/sonar/db/ce/CeActivityDaoTest.java
index 14f3a2e4c71..c233b42c15d 100644
--- a/sonar-db/src/test/java/org/sonar/db/ce/CeActivityDaoTest.java
+++ b/sonar-db/src/test/java/org/sonar/db/ce/CeActivityDaoTest.java
@@ -28,10 +28,13 @@ import javax.annotation.Nonnull;
import org.junit.Rule;
import org.junit.Test;
import org.sonar.api.utils.internal.TestSystem2;
+import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
import static java.util.Collections.singletonList;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.sonar.db.ce.CeActivityDto.Status.FAILED;
+import static org.sonar.db.ce.CeActivityDto.Status.SUCCESS;
import static org.sonar.db.ce.CeTaskTypes.REPORT;
public class CeActivityDaoTest {
@@ -40,6 +43,7 @@ public class CeActivityDaoTest {
@Rule
public DbTester db = DbTester.create(system2);
+ DbSession dbSession = db.getSession();
CeActivityDao underTest = new CeActivityDao(system2);
@@ -75,7 +79,7 @@ public class CeActivityDaoTest {
assertThat(underTest.selectByUuid(db.getSession(), "TASK_2").get().getIsLast()).isTrue();
// two tasks on PROJECT_1, the most recent one is TASK_3
- insert("TASK_3", REPORT, "PROJECT_1", CeActivityDto.Status.FAILED);
+ insert("TASK_3", REPORT, "PROJECT_1", FAILED);
assertThat(underTest.selectByUuid(db.getSession(), "TASK_1").get().getIsLast()).isFalse();
assertThat(underTest.selectByUuid(db.getSession(), "TASK_2").get().getIsLast()).isTrue();
assertThat(underTest.selectByUuid(db.getSession(), "TASK_3").get().getIsLast()).isTrue();
@@ -91,7 +95,7 @@ public class CeActivityDaoTest {
@Test
public void test_selectByQuery() {
insert("TASK_1", REPORT, "PROJECT_1", CeActivityDto.Status.SUCCESS);
- insert("TASK_2", REPORT, "PROJECT_1", CeActivityDto.Status.FAILED);
+ insert("TASK_2", REPORT, "PROJECT_1", FAILED);
insert("TASK_3", REPORT, "PROJECT_2", CeActivityDto.Status.SUCCESS);
insert("TASK_4", "views", null, CeActivityDto.Status.SUCCESS);
@@ -211,6 +215,22 @@ public class CeActivityDaoTest {
assertThat(underTest.selectByUuid(db.getSession(), "TASK_1").isPresent()).isTrue();
}
+ @Test
+ public void count_last_by_status_and_component_uuid() {
+ insert("TASK_1", CeTaskTypes.REPORT, "COMPONENT1", CeActivityDto.Status.SUCCESS);
+ // component 2
+ insert("TASK_2", CeTaskTypes.REPORT, "COMPONENT2", CeActivityDto.Status.SUCCESS);
+ // status failed
+ insert("TASK_3", CeTaskTypes.REPORT, "COMPONENT1", CeActivityDto.Status.FAILED);
+ // status canceled
+ insert("TASK_4", CeTaskTypes.REPORT, "COMPONENT1", CeActivityDto.Status.CANCELED);
+ insert("TASK_5", CeTaskTypes.REPORT, "COMPONENT1", CeActivityDto.Status.SUCCESS);
+ db.commit();
+
+ assertThat(underTest.countLastByStatusAndComponentUuid(dbSession, SUCCESS, "COMPONENT1")).isEqualTo(1);
+ assertThat(underTest.countLastByStatusAndComponentUuid(dbSession, SUCCESS, null)).isEqualTo(2);
+ }
+
private void insert(String uuid, String type, String componentUuid, CeActivityDto.Status status) {
CeQueueDto queueDto = new CeQueueDto();
queueDto.setUuid(uuid);