aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-db
diff options
context:
space:
mode:
authorJenkins CI <ci@sonarsource.com>2016-04-21 08:01:09 +0200
committerJenkins CI <ci@sonarsource.com>2016-04-21 08:01:09 +0200
commit91584ca578a35442467d075ec42151b409778503 (patch)
tree3e1ea4ea59a2d4e4d05de51affca73172fe65f78 /sonar-db
parent6c65ff90687ebe7d184864b0d665f8a51aecfc7a (diff)
parent9d70ff56e7d45ca6d26ee5725cdea6288585358b (diff)
downloadsonarqube-91584ca578a35442467d075ec42151b409778503.tar.gz
sonarqube-91584ca578a35442467d075ec42151b409778503.zip
Automatic merge from branch-5.5
* origin/branch-5.5: SONAR-7553 use api/ce/activity_status to get number of pending and failing tasks SONAR-7553 WS api/ce/activity_status display background tasks related metrics for UI SONAR-7553 DAO of CE_QUEUE count number of rows by status SONAR-7553 DAO of CE_ACTIVITY count number of tasks still failing SONAR-7187 WS api/ce/activity stop using count(1) on DB table CE_QUEUE SONAR-7553 Create composite DB index CE_ACTIVITY(is_last, status) SONAR-7187 do not usage pagination SONAR-7187 Remove paging from api/ce/activity
Diffstat (limited to 'sonar-db')
-rw-r--r--sonar-db/src/main/java/org/sonar/db/ce/CeActivityDao.java8
-rw-r--r--sonar-db/src/main/java/org/sonar/db/ce/CeActivityMapper.java3
-rw-r--r--sonar-db/src/main/java/org/sonar/db/ce/CeQueueDao.java12
-rw-r--r--sonar-db/src/main/java/org/sonar/db/ce/CeQueueMapper.java4
-rw-r--r--sonar-db/src/main/java/org/sonar/db/version/DatabaseVersion.java2
-rw-r--r--sonar-db/src/main/resources/org/sonar/db/ce/CeActivityMapper.xml15
-rw-r--r--sonar-db/src/main/resources/org/sonar/db/ce/CeQueueMapper.xml9
-rw-r--r--sonar-db/src/main/resources/org/sonar/db/version/rows-h2.sql1
-rw-r--r--sonar-db/src/main/resources/org/sonar/db/version/schema-h2.ddl4
-rw-r--r--sonar-db/src/test/java/org/sonar/db/DbTester.java2
-rw-r--r--sonar-db/src/test/java/org/sonar/db/ce/CeActivityDaoTest.java66
-rw-r--r--sonar-db/src/test/java/org/sonar/db/ce/CeQueueDaoTest.java43
12 files changed, 92 insertions, 77 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 e32a1be1535..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,11 +73,8 @@ public class CeActivityDao implements Dao {
return mapper(dbSession).selectByQuery(query, offset, pageSize);
}
- public int countByQuery(DbSession dbSession, CeTaskQuery query) {
- if (query.isShortCircuitedByComponentUuids()) {
- return 0;
- }
- return mapper(dbSession).countByQuery(query);
+ public int countLastByStatusAndComponentUuid(DbSession dbSession, CeActivityDto.Status status, @Nullable String componentUuid) {
+ return mapper(dbSession).countLastByStatusAndComponentUuid(status, componentUuid);
}
private static CeActivityMapper mapper(DbSession dbSession) {
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/java/org/sonar/db/ce/CeQueueDao.java b/sonar-db/src/main/java/org/sonar/db/ce/CeQueueDao.java
index 9670c8c8068..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,8 +21,8 @@ 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.Paging;
import org.sonar.api.utils.System2;
import org.sonar.db.Dao;
import org.sonar.db.DbSession;
@@ -48,14 +48,14 @@ public class CeQueueDao implements Dao {
return mapper(session).selectAllInAscOrder();
}
- public List<CeQueueDto> selectByQueryInDescOrder(DbSession dbSession, CeTaskQuery query, Paging paging) {
+ public List<CeQueueDto> selectByQueryInDescOrder(DbSession dbSession, CeTaskQuery query, int pageSize) {
if (query.isShortCircuitedByComponentUuids()
|| query.isOnlyCurrents()
|| query.getMaxExecutedAt() != null) {
return emptyList();
}
- return mapper(dbSession).selectByQueryInDescOrder(query, new RowBounds(paging.offset(), paging.pageSize()));
+ return mapper(dbSession).selectByQueryInDescOrder(query, new RowBounds(0, pageSize));
}
public int countByQuery(DbSession dbSession, CeTaskQuery query) {
@@ -101,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/java/org/sonar/db/version/DatabaseVersion.java b/sonar-db/src/main/java/org/sonar/db/version/DatabaseVersion.java
index 4b0508ef27f..8f51cc19382 100644
--- a/sonar-db/src/main/java/org/sonar/db/version/DatabaseVersion.java
+++ b/sonar-db/src/main/java/org/sonar/db/version/DatabaseVersion.java
@@ -29,7 +29,7 @@ import org.sonar.db.MyBatis;
public class DatabaseVersion {
- public static final int LAST_VERSION = 1124;
+ public static final int LAST_VERSION = 1125;
/**
* The minimum supported version which can be upgraded. Lower
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 08247b4faa1..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
@@ -74,11 +74,6 @@
WHERE rn BETWEEN (#{offset} * #{pageSize} + 1) AND ((#{offset} + 1) * #{pageSize})
</select>
- <select id="countByQuery" parameterType="map" resultType="int">
- select count(ca.id)
- <include refid="sqlSelectByQuery" />
- </select>
-
<sql id="sqlSelectByQuery">
from ce_activity ca
<where>
@@ -114,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/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/main/resources/org/sonar/db/version/rows-h2.sql b/sonar-db/src/main/resources/org/sonar/db/version/rows-h2.sql
index 9b36923ad6c..72e8889de26 100644
--- a/sonar-db/src/main/resources/org/sonar/db/version/rows-h2.sql
+++ b/sonar-db/src/main/resources/org/sonar/db/version/rows-h2.sql
@@ -402,6 +402,7 @@ INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('1121');
INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('1122');
INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('1123');
INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('1124');
+INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('1125');
INSERT INTO USERS(ID, LOGIN, NAME, EMAIL, EXTERNAL_IDENTITY, EXTERNAL_IDENTITY_PROVIDER, USER_LOCAL, CRYPTED_PASSWORD, SALT, CREATED_AT, UPDATED_AT, REMEMBER_TOKEN, REMEMBER_TOKEN_EXPIRES_AT) VALUES (1, 'admin', 'Administrator', '', 'admin', 'sonarqube', true, 'a373a0e667abb2604c1fd571eb4ad47fe8cc0878', '48bc4b0d93179b5103fd3885ea9119498e9d161b', '1418215735482', '1418215735482', null, null);
ALTER TABLE USERS ALTER COLUMN ID RESTART WITH 2;
diff --git a/sonar-db/src/main/resources/org/sonar/db/version/schema-h2.ddl b/sonar-db/src/main/resources/org/sonar/db/version/schema-h2.ddl
index 1bbd3df88ce..4b00eea977c 100644
--- a/sonar-db/src/main/resources/org/sonar/db/version/schema-h2.ddl
+++ b/sonar-db/src/main/resources/org/sonar/db/version/schema-h2.ddl
@@ -669,6 +669,8 @@ CREATE UNIQUE INDEX "CE_QUEUE_UUID" ON "CE_QUEUE" ("UUID");
CREATE INDEX "CE_QUEUE_COMPONENT_UUID" ON "CE_QUEUE" ("COMPONENT_UUID");
+CREATE INDEX "CE_QUEUE_STATUS" ON "CE_QUEUE" ("STATUS");
+
CREATE UNIQUE INDEX "CE_ACTIVITY_UUID" ON "CE_ACTIVITY" ("UUID");
CREATE INDEX "CE_ACTIVITY_COMPONENT_UUID" ON "CE_ACTIVITY" ("COMPONENT_UUID");
@@ -678,3 +680,5 @@ CREATE UNIQUE INDEX "USER_TOKENS_TOKEN_HASH" ON "USER_TOKENS" ("TOKEN_HASH");
CREATE UNIQUE INDEX "USER_TOKENS_LOGIN_NAME" ON "USER_TOKENS" ("LOGIN", "NAME");
CREATE INDEX "CE_ACTIVITY_ISLASTKEY" ON "CE_ACTIVITY" ("IS_LAST_KEY");
+
+CREATE INDEX "CE_ACTIVITY_ISLAST_STATUS" ON "CE_ACTIVITY" ("IS_LAST", "STATUS");
diff --git a/sonar-db/src/test/java/org/sonar/db/DbTester.java b/sonar-db/src/test/java/org/sonar/db/DbTester.java
index 64c10150619..d58f519899f 100644
--- a/sonar-db/src/test/java/org/sonar/db/DbTester.java
+++ b/sonar-db/src/test/java/org/sonar/db/DbTester.java
@@ -155,7 +155,7 @@ public class DbTester extends ExternalResource {
/**
* Returns the number of rows in the table. Example:
- * <pre>int issues = countTable("issues")</pre>
+ * <pre>int issues = countRowsOfTable("issues")</pre>
*/
public int countRowsOfTable(String tableName) {
Preconditions.checkArgument(StringUtils.containsNone(tableName, " "), "Parameter must be the name of a table. Got " + tableName);
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 bb92b76097b..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);
@@ -141,36 +145,6 @@ public class CeActivityDaoTest {
}
@Test
- public void test_countByQuery() {
- insert("TASK_1", REPORT, "PROJECT_1", CeActivityDto.Status.SUCCESS);
- insert("TASK_2", REPORT, "PROJECT_1", CeActivityDto.Status.FAILED);
- insert("TASK_3", REPORT, "PROJECT_2", CeActivityDto.Status.SUCCESS);
- insert("TASK_4", "views", null, CeActivityDto.Status.SUCCESS);
-
- // no filters
- CeTaskQuery query = new CeTaskQuery();
- assertThat(underTest.countByQuery(db.getSession(), query)).isEqualTo(4);
-
- // select by component uuid
- query = new CeTaskQuery().setComponentUuid("PROJECT_1");
- assertThat(underTest.countByQuery(db.getSession(), query)).isEqualTo(2);
-
- // select by status
- query = new CeTaskQuery().setStatuses(singletonList(CeActivityDto.Status.SUCCESS.name()));
- assertThat(underTest.countByQuery(db.getSession(), query)).isEqualTo(3);
-
- // select by type
- query = new CeTaskQuery().setType(REPORT);
- assertThat(underTest.countByQuery(db.getSession(), query)).isEqualTo(3);
- query = new CeTaskQuery().setType("views");
- assertThat(underTest.countByQuery(db.getSession(), query)).isEqualTo(1);
-
- // select by multiple conditions
- query = new CeTaskQuery().setType(REPORT).setOnlyCurrents(true).setComponentUuid("PROJECT_1");
- assertThat(underTest.countByQuery(db.getSession(), query)).isEqualTo(1);
- }
-
- @Test
public void selectByQuery_no_results_if_shortcircuited_by_component_uuids() {
insert("TASK_1", REPORT, "PROJECT_1", CeActivityDto.Status.SUCCESS);
@@ -180,15 +154,6 @@ public class CeActivityDaoTest {
}
@Test
- public void countByQuery_no_results_if_shortcircuited_by_component_uuids() {
- insert("TASK_1", REPORT, "PROJECT_1", CeActivityDto.Status.SUCCESS);
-
- CeTaskQuery query = new CeTaskQuery();
- query.setComponentUuids(Collections.<String>emptyList());
- assertThat(underTest.countByQuery(db.getSession(), query)).isEqualTo(0);
- }
-
- @Test
public void select_and_count_by_date() {
insertWithDates("UUID1", 1_450_000_000_000L, 1_470_000_000_000L);
insertWithDates("UUID2", 1_460_000_000_000L, 1_480_000_000_000L);
@@ -196,19 +161,16 @@ public class CeActivityDaoTest {
// search by min submitted date
CeTaskQuery query = new CeTaskQuery().setMinSubmittedAt(1_455_000_000_000L);
assertThat(underTest.selectByQuery(db.getSession(), query, 0, 5)).extracting("uuid").containsOnly("UUID2");
- assertThat(underTest.countByQuery(db.getSession(), query)).isEqualTo(1);
// search by max executed date
query = new CeTaskQuery().setMaxExecutedAt(1_475_000_000_000L);
assertThat(underTest.selectByQuery(db.getSession(), query, 0, 5)).extracting("uuid").containsOnly("UUID1");
- assertThat(underTest.countByQuery(db.getSession(), query)).isEqualTo(1);
// search by both dates
query = new CeTaskQuery()
.setMinSubmittedAt(1_400_000_000_000L)
.setMaxExecutedAt(1_475_000_000_000L);
assertThat(underTest.selectByQuery(db.getSession(), query, 0, 5)).extracting("uuid").containsOnly("UUID1");
- assertThat(underTest.countByQuery(db.getSession(), query)).isEqualTo(1);
}
@@ -253,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);
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 479bd23bf76..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
@@ -29,7 +29,6 @@ import java.util.Map;
import javax.annotation.Nullable;
import org.junit.Rule;
import org.junit.Test;
-import org.sonar.api.utils.Paging;
import org.sonar.api.utils.internal.TestSystem2;
import org.sonar.db.DbTester;
@@ -140,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
@@ -227,7 +226,7 @@ public class CeQueueDaoTest {
.setType(CeTaskTypes.REPORT)
.setMinSubmittedAt(100_000L);
- List<CeQueueDto> result = underTest.selectByQueryInDescOrder(db.getSession(), query, Paging.forPageIndex(1).withPageSize(1_000).andTotal(1_000));
+ List<CeQueueDto> result = underTest.selectByQueryInDescOrder(db.getSession(), query, 1_000);
int total = underTest.countByQuery(db.getSession(), query);
assertThat(result).extracting("uuid").containsExactly("TASK_5", TASK_UUID_2);
@@ -244,7 +243,7 @@ public class CeQueueDaoTest {
CeTaskQuery query = new CeTaskQuery().setOnlyCurrents(true);
- List<CeQueueDto> result = underTest.selectByQueryInDescOrder(db.getSession(), query, Paging.forPageIndex(1).withPageSize(1_000).andTotal(1_000));
+ List<CeQueueDto> result = underTest.selectByQueryInDescOrder(db.getSession(), query, 1_000);
int total = underTest.countByQuery(db.getSession(), query);
assertThat(result).isEmpty();
@@ -261,7 +260,7 @@ public class CeQueueDaoTest {
CeTaskQuery query = new CeTaskQuery().setMaxExecutedAt(1_000_000_000_000L);
- List<CeQueueDto> result = underTest.selectByQueryInDescOrder(db.getSession(), query, Paging.forPageIndex(1).withPageSize(1_000).andTotal(1_000));
+ List<CeQueueDto> result = underTest.selectByQueryInDescOrder(db.getSession(), query, 1_000);
int total = underTest.countByQuery(db.getSession(), query);
assertThat(result).isEmpty();
@@ -278,13 +277,38 @@ public class CeQueueDaoTest {
CeTaskQuery query = new CeTaskQuery().setComponentUuids(Collections.<String>emptyList());
- List<CeQueueDto> result = underTest.selectByQueryInDescOrder(db.getSession(), query, Paging.forPageIndex(1).withPageSize(1_000).andTotal(1_000));
+ List<CeQueueDto> result = underTest.selectByQueryInDescOrder(db.getSession(), query, 1_000);
int total = underTest.countByQuery(db.getSession(), query);
assertThat(result).isEmpty();
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();
@@ -315,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) {