aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-db-dao
diff options
context:
space:
mode:
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>2018-09-11 14:04:57 +0200
committersonartech <sonartech@sonarsource.com>2018-10-10 09:23:02 +0200
commite4364789b5e4347ec6c94fdfc3c14b4e568481f2 (patch)
treed61a3a90aedf5bfb49f6566fd55099c9f1eba2a2 /server/sonar-db-dao
parent516f6e6bd2c8d82ffaac2aa8f73f063618b972c1 (diff)
downloadsonarqube-e4364789b5e4347ec6c94fdfc3c14b4e568481f2.tar.gz
sonarqube-e4364789b5e4347ec6c94fdfc3c14b4e568481f2.zip
SONAR-11238 api/ce/[task|activity|component] return task warnings
all return warnings count, warnings list is only available from api/ce/task on demand
Diffstat (limited to 'server/sonar-db-dao')
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/ce/CeActivityDto.java21
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/ce/CeTaskMessageDao.java8
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/ce/CeTaskMessageMapper.java3
-rw-r--r--server/sonar-db-dao/src/main/resources/org/sonar/db/ce/CeActivityMapper.xml27
-rw-r--r--server/sonar-db-dao/src/main/resources/org/sonar/db/ce/CeTaskMessageMapper.xml18
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/ce/CeActivityDaoTest.java153
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/ce/CeActivityDtoTest.java10
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/ce/CeTaskMessageDaoTest.java48
8 files changed, 249 insertions, 39 deletions
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/ce/CeActivityDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/ce/CeActivityDto.java
index af3e004aa75..a3fcffe471a 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/ce/CeActivityDto.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/ce/CeActivityDto.java
@@ -96,9 +96,14 @@ public class CeActivityDto {
* Flag indicating whether the analysis of the current activity has a scanner context or not.
* <p>
* This property can not be populated when inserting but <strong>is populated when reading</strong>.
- * </p>
*/
private boolean hasScannerContext;
+ /**
+ * Count of warnings attached to the current activity.
+ * <p>
+ * This property can not be populated when inserting but <strong>is populated when retrieving the activity by UUID</strong>.
+ */
+ private int warningCount = 0;
CeActivityDto() {
// required for MyBatis
@@ -311,8 +316,19 @@ public class CeActivityDto {
return hasScannerContext;
}
- protected void setHasScannerContext(boolean hasScannerContext) {
+ protected CeActivityDto setHasScannerContext(boolean hasScannerContext) {
this.hasScannerContext = hasScannerContext;
+ return this;
+ }
+
+ public int getWarningCount() {
+ return warningCount;
+ }
+
+ protected CeActivityDto setWarningCount(int warningCount) {
+ checkArgument(warningCount >= 0);
+ this.warningCount = warningCount;
+ return this;
}
@Override
@@ -339,6 +355,7 @@ public class CeActivityDto {
", errorMessage='" + errorMessage + '\'' +
", errorStacktrace='" + errorStacktrace + '\'' +
", hasScannerContext=" + hasScannerContext +
+ ", warningCount=" + warningCount +
'}';
}
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/ce/CeTaskMessageDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/ce/CeTaskMessageDao.java
index 12af5bf80f0..787d73b1d85 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/ce/CeTaskMessageDao.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/ce/CeTaskMessageDao.java
@@ -19,6 +19,7 @@
*/
package org.sonar.db.ce;
+import java.util.List;
import org.sonar.db.Dao;
import org.sonar.db.DbSession;
@@ -27,6 +28,13 @@ public class CeTaskMessageDao implements Dao {
getMapper(dbSession).insert(dto);
}
+ /**
+ * @return the messages for the specific task, if any, in ascending order of column {@code CREATED_AT}.
+ */
+ public List<CeTaskMessageDto> selectByTask(DbSession dbSession, String taskUuid) {
+ return getMapper(dbSession).selectByTask(taskUuid);
+ }
+
private static CeTaskMessageMapper getMapper(DbSession dbSession) {
return dbSession.getMapper(CeTaskMessageMapper.class);
}
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/ce/CeTaskMessageMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/ce/CeTaskMessageMapper.java
index ad312927f3a..e44c8b61a10 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/ce/CeTaskMessageMapper.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/ce/CeTaskMessageMapper.java
@@ -19,9 +19,12 @@
*/
package org.sonar.db.ce;
+import java.util.List;
import org.apache.ibatis.annotations.Param;
public interface CeTaskMessageMapper {
void insert(@Param("dto") CeTaskMessageDto dto);
+ List<CeTaskMessageDto> selectByTask(@Param("taskUuid") String taskUuid);
+
}
diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/ce/CeActivityMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/ce/CeActivityMapper.xml
index 372c6a04d13..61cc9cded15 100644
--- a/server/sonar-db-dao/src/main/resources/org/sonar/db/ce/CeActivityMapper.xml
+++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/ce/CeActivityMapper.xml
@@ -15,6 +15,10 @@
csc.task_uuid is not null as hasScannerContext
</sql>
+ <sql id="countWarnings">
+ (select count(1) from ce_task_message ctm where ctm.task_uuid = ca.uuid) as warningCount
+ </sql>
+
<sql id="columns">
ca.id,
ca.uuid,
@@ -42,25 +46,31 @@
<select id="selectByUuid" parameterType="String" resultType="org.sonar.db.ce.CeActivityDto">
select
- <include refid="columns"/>,
- ca.error_stacktrace as errorStacktrace
+ <include refid="columns"/>,
+ ca.error_stacktrace as errorStacktrace,
+ <include refid="countWarnings"/>
from ce_activity ca
- left outer join ce_scanner_context csc on ca.uuid = csc.task_uuid
- where ca.uuid=#{uuid,jdbcType=VARCHAR}
+ left outer join ce_scanner_context csc on
+ ca.uuid = csc.task_uuid
+ where
+ ca.uuid=#{uuid,jdbcType=VARCHAR}
</select>
<select id="selectByQuery" parameterType="map" resultType="org.sonar.db.ce.CeActivityDto">
select
- <include refid="columns"/>
+ <include refid="columns"/>,
+ <include refid="countWarnings"/>
<include refid="sqlSelectByQuery" />
- order by ca.id desc
+ order by
+ ca.id desc
limit #{pagination.pageSize,jdbcType=INTEGER} offset #{pagination.offset,jdbcType=INTEGER}
</select>
<select id="selectByQuery" parameterType="map" resultType="org.sonar.db.ce.CeActivityDto" databaseId="mssql">
select * from (
select row_number() over(order by id desc) as number,
- <include refid="columns"/>
+ <include refid="columns"/>,
+ <include refid="countWarnings"/>
<include refid="sqlSelectByQuery" />
) as query
where
@@ -72,7 +82,8 @@
select * from (
select rownum as rn, t.* from (
select
- <include refid="columns"/>
+ <include refid="columns"/>,
+ <include refid="countWarnings"/>
<include refid="sqlSelectByQuery" />
order by ca.id desc
) t
diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/ce/CeTaskMessageMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/ce/CeTaskMessageMapper.xml
index ef9af42a3f3..a3fcf1f92da 100644
--- a/server/sonar-db-dao/src/main/resources/org/sonar/db/ce/CeTaskMessageMapper.xml
+++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/ce/CeTaskMessageMapper.xml
@@ -3,6 +3,24 @@
<mapper namespace="org.sonar.db.ce.CeTaskMessageMapper">
+ <sql id="columns">
+ ctm.uuid,
+ ctm.task_uuid as taskUuid,
+ ctm.message as message,
+ ctm.created_at as createdAt
+ </sql>
+
+ <select id="selectByTask" resultType="org.sonar.db.ce.CeTaskMessageDto">
+ select
+ <include refid="columns"/>
+ from
+ ce_task_message ctm
+ where
+ ctm.task_uuid=#{taskUuid,jdbcType=VARCHAR}
+ order by
+ ctm.created_at asc
+ </select>
+
<insert id="insert" parameterType="org.sonar.db.ce.CeTaskMessageDto" useGeneratedKeys="false">
insert into ce_task_message
(
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/ce/CeActivityDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/ce/CeActivityDaoTest.java
index c38abaec26e..eef82b7b76d 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/ce/CeActivityDaoTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/ce/CeActivityDaoTest.java
@@ -29,6 +29,8 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
+import java.util.Random;
+import java.util.stream.IntStream;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import org.assertj.core.api.AbstractListAssert;
@@ -75,7 +77,7 @@ public class CeActivityDaoTest {
@Test
public void test_insert() {
- CeActivityDto inserted = insert("TASK_1", REPORT, COMPONENT_1, MAINCOMPONENT_1, CeActivityDto.Status.SUCCESS);
+ CeActivityDto inserted = insert("TASK_1", REPORT, COMPONENT_1, MAINCOMPONENT_1, SUCCESS);
Optional<CeActivityDto> saved = underTest.selectByUuid(db.getSession(), "TASK_1");
assertThat(saved).isPresent();
@@ -83,7 +85,7 @@ public class CeActivityDaoTest {
assertThat(dto.getUuid()).isEqualTo("TASK_1");
assertThat(dto.getMainComponentUuid()).isEqualTo(MAINCOMPONENT_1);
assertThat(dto.getComponentUuid()).isEqualTo(COMPONENT_1);
- assertThat(dto.getStatus()).isEqualTo(CeActivityDto.Status.SUCCESS);
+ assertThat(dto.getStatus()).isEqualTo(SUCCESS);
assertThat(dto.getSubmitterUuid()).isEqualTo("submitter uuid");
assertThat(dto.getSubmittedAt()).isEqualTo(1_450_000_000_000L);
assertThat(dto.getWorkerUuid()).isEqualTo("worker uuid");
@@ -101,6 +103,34 @@ public class CeActivityDaoTest {
assertThat(dto.getErrorStacktrace()).isNull();
assertThat(dto.getErrorType()).isNull();
assertThat(dto.isHasScannerContext()).isFalse();
+ assertThat(dto.getWarningCount()).isZero();
+ }
+
+ @Test
+ public void selectByUuid_populates_warning_count() {
+ CeActivityDto[] tasks = {
+ insert("TASK_1", REPORT, "PROJECT_1", SUCCESS),
+ insert("TASK_2", REPORT, "PROJECT_1", SUCCESS),
+ insert("TASK_3", REPORT, "PROJECT_1", SUCCESS)
+ };
+ int moreThan1 = 2 + new Random().nextInt(5);
+ insertWarnings(tasks[0], moreThan1);
+ insertWarnings(tasks[1], 0);
+ insertWarnings(tasks[2], 1);
+
+ assertThat(underTest.selectByUuid(dbSession, tasks[0].getUuid()).get().getWarningCount()).isEqualTo(moreThan1);
+ assertThat(underTest.selectByUuid(dbSession, tasks[1].getUuid()).get().getWarningCount()).isEqualTo(0);
+ assertThat(underTest.selectByUuid(dbSession, tasks[2].getUuid()).get().getWarningCount()).isEqualTo(1);
+ }
+
+ private void insertWarnings(CeActivityDto task, int warningCount) {
+ IntStream.range(0, warningCount).forEach(i -> db.getDbClient().ceTaskMessageDao().insert(dbSession,
+ new CeTaskMessageDto()
+ .setUuid(UuidFactoryFast.getInstance().create())
+ .setTaskUuid(task.getUuid())
+ .setMessage("message_" + task.getUuid() + "_" + i)
+ .setCreatedAt(task.getUuid().hashCode() + i)));
+ db.commit();
}
@Test
@@ -296,7 +326,7 @@ public class CeActivityDaoTest {
@Test
public void test_insert_of_errorMessage_of_1_000_chars() {
- CeActivityDto dto = createActivityDto("TASK_1", REPORT, COMPONENT_1, MAINCOMPONENT_1, CeActivityDto.Status.FAILED)
+ CeActivityDto dto = createActivityDto("TASK_1", REPORT, COMPONENT_1, MAINCOMPONENT_1, FAILED)
.setErrorMessage(Strings.repeat("x", 1_000));
underTest.insert(db.getSession(), dto);
@@ -307,7 +337,7 @@ public class CeActivityDaoTest {
@Test
public void test_insert_of_errorMessage_of_1_001_chars_is_truncated_to_1000() {
String expected = Strings.repeat("x", 1_000);
- CeActivityDto dto = createActivityDto("TASK_1", REPORT, COMPONENT_1, MAINCOMPONENT_1, CeActivityDto.Status.FAILED)
+ CeActivityDto dto = createActivityDto("TASK_1", REPORT, COMPONENT_1, MAINCOMPONENT_1, FAILED)
.setErrorMessage(expected + "y");
underTest.insert(db.getSession(), dto);
@@ -317,7 +347,7 @@ public class CeActivityDaoTest {
@Test
public void test_insert_error_message_and_stacktrace() {
- CeActivityDto dto = createActivityDto("TASK_1", REPORT, COMPONENT_1, MAINCOMPONENT_1, CeActivityDto.Status.FAILED)
+ CeActivityDto dto = createActivityDto("TASK_1", REPORT, COMPONENT_1, MAINCOMPONENT_1, FAILED)
.setErrorStacktrace("error stack");
underTest.insert(db.getSession(), dto);
@@ -330,7 +360,7 @@ public class CeActivityDaoTest {
@Test
public void test_insert_error_message_only() {
- CeActivityDto dto = createActivityDto("TASK_1", REPORT, COMPONENT_1, MAINCOMPONENT_1, CeActivityDto.Status.FAILED);
+ CeActivityDto dto = createActivityDto("TASK_1", REPORT, COMPONENT_1, MAINCOMPONENT_1, FAILED);
underTest.insert(db.getSession(), dto);
Optional<CeActivityDto> saved = underTest.selectByUuid(db.getSession(), "TASK_1");
@@ -342,11 +372,11 @@ public class CeActivityDaoTest {
@Test
public void insert_must_set_relevant_is_last_field() {
// only a single task on MAINCOMPONENT_1 -> is_last=true
- insert("TASK_1", REPORT, MAINCOMPONENT_1, CeActivityDto.Status.SUCCESS);
+ insert("TASK_1", REPORT, MAINCOMPONENT_1, SUCCESS);
assertThat(underTest.selectByUuid(db.getSession(), "TASK_1").get().getIsLast()).isTrue();
// only a single task on MAINCOMPONENT_2 -> is_last=true
- insert("TASK_2", REPORT, MAINCOMPONENT_2, CeActivityDto.Status.SUCCESS);
+ insert("TASK_2", REPORT, MAINCOMPONENT_2, SUCCESS);
assertThat(underTest.selectByUuid(db.getSession(), "TASK_2").get().getIsLast()).isTrue();
// two tasks on MAINCOMPONENT_1, the most recent one is TASK_3
@@ -356,7 +386,7 @@ public class CeActivityDaoTest {
assertThat(underTest.selectByUuid(db.getSession(), "TASK_3").get().getIsLast()).isTrue();
// inserting a cancelled task does not change the last task
- insert("TASK_4", REPORT, MAINCOMPONENT_1, CeActivityDto.Status.CANCELED);
+ insert("TASK_4", REPORT, MAINCOMPONENT_1, CANCELED);
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();
@@ -365,10 +395,10 @@ public class CeActivityDaoTest {
@Test
public void test_selectByQuery() {
- insert("TASK_1", REPORT, MAINCOMPONENT_1, CeActivityDto.Status.SUCCESS);
+ insert("TASK_1", REPORT, MAINCOMPONENT_1, SUCCESS);
insert("TASK_2", REPORT, MAINCOMPONENT_1, FAILED);
- insert("TASK_3", REPORT, MAINCOMPONENT_2, CeActivityDto.Status.SUCCESS);
- insert("TASK_4", "views", null, CeActivityDto.Status.SUCCESS);
+ insert("TASK_3", REPORT, MAINCOMPONENT_2, SUCCESS);
+ insert("TASK_4", "views", null, SUCCESS);
// no filters
CeTaskQuery query = new CeTaskQuery().setStatuses(Collections.emptyList());
@@ -381,7 +411,7 @@ public class CeActivityDaoTest {
assertThat(dtos).extracting("uuid").containsExactly("TASK_2", "TASK_1");
// select by status
- query = new CeTaskQuery().setStatuses(singletonList(CeActivityDto.Status.SUCCESS.name()));
+ query = new CeTaskQuery().setStatuses(singletonList(SUCCESS.name()));
dtos = underTest.selectByQuery(db.getSession(), query, forPage(1).andSize(100));
assertThat(dtos).extracting("uuid").containsExactly("TASK_4", "TASK_3", "TASK_1");
@@ -424,11 +454,61 @@ public class CeActivityDaoTest {
}
@Test
+ public void selectByQuery_populates_warningCount() {
+ CeActivityDto[] tasks = {
+ insert("TASK_1", REPORT, "PROJECT_1", SUCCESS),
+ insert("TASK_2", REPORT, "PROJECT_1", FAILED),
+ insert("TASK_3", REPORT, "PROJECT_2", SUCCESS),
+ insert("TASK_4", "views", null, SUCCESS)
+ };
+ int moreThan1 = 2 + new Random().nextInt(5);
+ insertWarnings(tasks[0], moreThan1);
+ insertWarnings(tasks[1], 3);
+ insertWarnings(tasks[2], 1);
+ insertWarnings(tasks[3], 6);
+
+ // no filters
+ CeTaskQuery query = new CeTaskQuery().setStatuses(Collections.emptyList());
+ assertThat(underTest.selectByQuery(db.getSession(), query, forPage(1).andSize(10)))
+ .extracting(CeActivityDto::getUuid, CeActivityDto::getWarningCount)
+ .containsExactly(tuple("TASK_4", 6), tuple("TASK_3", 1), tuple("TASK_2", 3), tuple("TASK_1", moreThan1));
+
+ // select by component uuid
+ query = new CeTaskQuery().setMainComponentUuid("PROJECT_1");
+ assertThat(underTest.selectByQuery(db.getSession(), query, forPage(1).andSize(100)))
+ .extracting(CeActivityDto::getUuid, CeActivityDto::getWarningCount)
+ .containsExactly(tuple("TASK_2", 3), tuple("TASK_1", moreThan1));
+
+ // select by status
+ query = new CeTaskQuery().setStatuses(singletonList(SUCCESS.name()));
+ assertThat(underTest.selectByQuery(db.getSession(), query, forPage(1).andSize(100)))
+ .extracting(CeActivityDto::getUuid, CeActivityDto::getWarningCount)
+ .containsExactly(tuple("TASK_4", 6), tuple("TASK_3", 1), tuple("TASK_1", moreThan1));
+
+ // select by type
+ query = new CeTaskQuery().setType(REPORT);
+ assertThat(underTest.selectByQuery(db.getSession(), query, forPage(1).andSize(100)))
+ .extracting(CeActivityDto::getUuid, CeActivityDto::getWarningCount)
+ .containsExactly(tuple("TASK_3", 1), tuple("TASK_2", 3), tuple("TASK_1", moreThan1));
+ query = new CeTaskQuery().setType("views");
+ assertThat(underTest.selectByQuery(db.getSession(), query, forPage(1).andSize(100)))
+ .extracting(CeActivityDto::getUuid, CeActivityDto::getWarningCount)
+ .containsExactly(tuple("TASK_4", 6));
+
+ // select by multiple conditions
+ query = new CeTaskQuery().setType(REPORT).setOnlyCurrents(true).setMainComponentUuid("PROJECT_1");
+ assertThat(underTest.selectByQuery(db.getSession(), query, forPage(1).andSize(100)))
+ .extracting(CeActivityDto::getUuid, CeActivityDto::getWarningCount)
+ .containsExactly(tuple("TASK_2", 3));
+
+ }
+
+ @Test
public void selectByQuery_is_paginated_and_return_results_sorted_from_last_to_first() {
- insert("TASK_1", REPORT, MAINCOMPONENT_1, CeActivityDto.Status.SUCCESS);
- insert("TASK_2", REPORT, MAINCOMPONENT_1, CeActivityDto.Status.FAILED);
- insert("TASK_3", REPORT, MAINCOMPONENT_2, CeActivityDto.Status.SUCCESS);
- insert("TASK_4", "views", null, CeActivityDto.Status.SUCCESS);
+ insert("TASK_1", REPORT, MAINCOMPONENT_1, SUCCESS);
+ insert("TASK_2", REPORT, MAINCOMPONENT_1, FAILED);
+ insert("TASK_3", REPORT, MAINCOMPONENT_2, SUCCESS);
+ insert("TASK_4", "views", null, SUCCESS);
assertThat(selectPageOfUuids(forPage(1).andSize(1))).containsExactly("TASK_4");
assertThat(selectPageOfUuids(forPage(2).andSize(1))).containsExactly("TASK_3");
@@ -441,7 +521,7 @@ public class CeActivityDaoTest {
@Test
public void selectByQuery_no_results_if_shortcircuited_by_component_uuids() {
- insert("TASK_1", REPORT, MAINCOMPONENT_1, CeActivityDto.Status.SUCCESS);
+ insert("TASK_1", REPORT, MAINCOMPONENT_1, SUCCESS);
CeTaskQuery query = new CeTaskQuery();
query.setMainComponentUuids(Collections.emptyList());
@@ -474,7 +554,7 @@ public class CeActivityDaoTest {
queueDto.setUuid(uuid);
queueDto.setTaskType("fake");
CeActivityDto dto = new CeActivityDto(queueDto);
- dto.setStatus(CeActivityDto.Status.SUCCESS);
+ dto.setStatus(SUCCESS);
dto.setSubmittedAt(submittedAt);
dto.setExecutedAt(executedAt);
underTest.insert(db.getSession(), dto);
@@ -514,10 +594,25 @@ public class CeActivityDaoTest {
}
@Test
+ public void selectOlderThan_does_not_populate_warningCount() {
+ CeActivityDto activity1 = insert("TASK_1", REPORT, "PROJECT_1", FAILED);
+ insertWarnings(activity1, 10);
+ CeActivityDto activity2 = insert("TASK_2", REPORT, "PROJECT_1", SUCCESS);
+ insertWarnings(activity2, 1);
+
+ List<CeActivityDto> dtos = underTest.selectOlderThan(db.getSession(), system2.now() + 1_000_000L);
+
+ assertThat(dtos)
+ .hasSize(2)
+ .extracting(CeActivityDto::getWarningCount)
+ .containsOnly(0);
+ }
+
+ @Test
public void deleteByUuids() {
- insert("TASK_1", "REPORT", MAINCOMPONENT_1, CeActivityDto.Status.SUCCESS);
- insert("TASK_2", "REPORT", MAINCOMPONENT_1, CeActivityDto.Status.SUCCESS);
- insert("TASK_3", "REPORT", MAINCOMPONENT_1, CeActivityDto.Status.SUCCESS);
+ insert("TASK_1", "REPORT", MAINCOMPONENT_1, SUCCESS);
+ insert("TASK_2", "REPORT", MAINCOMPONENT_1, SUCCESS);
+ insert("TASK_3", "REPORT", MAINCOMPONENT_1, SUCCESS);
underTest.deleteByUuids(db.getSession(), ImmutableSet.of("TASK_1", "TASK_3"));
assertThat(underTest.selectByUuid(db.getSession(), "TASK_1").isPresent()).isFalse();
@@ -527,7 +622,7 @@ public class CeActivityDaoTest {
@Test
public void deleteByUuids_does_nothing_if_uuid_does_not_exist() {
- insert("TASK_1", "REPORT", MAINCOMPONENT_1, CeActivityDto.Status.SUCCESS);
+ insert("TASK_1", "REPORT", MAINCOMPONENT_1, SUCCESS);
// must not fail
underTest.deleteByUuids(db.getSession(), singleton("TASK_2"));
@@ -537,14 +632,14 @@ public class CeActivityDaoTest {
@Test
public void count_last_by_status_and_main_component_uuid() {
- insert("TASK_1", CeTaskTypes.REPORT, MAINCOMPONENT_1, CeActivityDto.Status.SUCCESS);
+ insert("TASK_1", CeTaskTypes.REPORT, MAINCOMPONENT_1, SUCCESS);
// component 2
- insert("TASK_2", CeTaskTypes.REPORT, MAINCOMPONENT_2, CeActivityDto.Status.SUCCESS);
+ insert("TASK_2", CeTaskTypes.REPORT, MAINCOMPONENT_2, SUCCESS);
// status failed
- insert("TASK_3", CeTaskTypes.REPORT, MAINCOMPONENT_1, CeActivityDto.Status.FAILED);
+ insert("TASK_3", CeTaskTypes.REPORT, MAINCOMPONENT_1, FAILED);
// status canceled
- insert("TASK_4", CeTaskTypes.REPORT, MAINCOMPONENT_1, CeActivityDto.Status.CANCELED);
- insert("TASK_5", CeTaskTypes.REPORT, MAINCOMPONENT_1, CeActivityDto.Status.SUCCESS);
+ insert("TASK_4", CeTaskTypes.REPORT, MAINCOMPONENT_1, CANCELED);
+ insert("TASK_5", CeTaskTypes.REPORT, MAINCOMPONENT_1, SUCCESS);
db.commit();
assertThat(underTest.countLastByStatusAndMainComponentUuid(dbSession, SUCCESS, MAINCOMPONENT_1)).isEqualTo(1);
@@ -601,7 +696,7 @@ public class CeActivityDaoTest {
queueDto.setTaskType("fake");
CeActivityDto dto = new CeActivityDto(queueDto);
- dto.setStatus(CeActivityDto.Status.SUCCESS);
+ dto.setStatus(SUCCESS);
dto.setAnalysisUuid(uuid + "_AA");
system2.setNow(date);
underTest.insert(db.getSession(), dto);
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/ce/CeActivityDtoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/ce/CeActivityDtoTest.java
index 1035ea80d9f..c11d17e14db 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/ce/CeActivityDtoTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/ce/CeActivityDtoTest.java
@@ -132,6 +132,16 @@ public class CeActivityDtoTest {
assertThat(underTest.getErrorMessage()).isEqualTo(before + after);
}
+ @Test
+ public void setWarningCount_throws_IAE_if_less_than_0() {
+ underTest.setWarningCount(0);
+ underTest.setWarningCount(1 + new Random().nextInt(10));
+
+ expectedException.expect(IllegalArgumentException.class);
+
+ underTest.setWarningCount(-1 - new Random().nextInt(10));
+ }
+
@DataProvider
public static Object[][] stringsWithChar0() {
return new Object[][] {
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/ce/CeTaskMessageDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/ce/CeTaskMessageDaoTest.java
index f219e8873ab..23db043dc96 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/ce/CeTaskMessageDaoTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/ce/CeTaskMessageDaoTest.java
@@ -19,13 +19,16 @@
*/
package org.sonar.db.ce;
+import java.util.List;
import org.assertj.core.groups.Tuple;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.sonar.api.utils.System2;
+import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
+import static org.apache.commons.lang.RandomStringUtils.randomAlphabetic;
import static org.assertj.core.api.Assertions.assertThat;
public class CeTaskMessageDaoTest {
@@ -49,6 +52,51 @@ public class CeTaskMessageDaoTest {
.hasSize(1)
.extracting(t -> t.get("UUID"), t -> t.get("TASK_UUID"), t -> t.get("MESSAGE"), t -> t.get("CREATED_AT"))
.containsOnly(Tuple.tuple("uuid_1", "task_uuid_1", "message_1", 1_222_333L));
+ }
+
+ @Test
+ public void selectByTask_returns_empty_on_empty_table() {
+ String taskUuid = randomAlphabetic(10);
+
+ List<CeTaskMessageDto> dto = underTest.selectByTask(dbTester.getSession(), taskUuid);
+
+ assertThat(dto).isEmpty();
+ }
+
+ @Test
+ public void selectByTask_returns_message_of_task_ordered_by_CREATED_AT_asc() {
+ String task1 = "task1";
+ String task2 = "task2";
+ CeTaskMessageDto[] messages = {
+ insertMessage(task1, 0, 1_222_333L),
+ insertMessage(task2, 1, 2_222_333L),
+ insertMessage(task2, 2, 1_111_333L),
+ insertMessage(task1, 3, 1_222_111L),
+ insertMessage(task1, 4, 222_111L),
+ insertMessage(task1, 5, 3_222_111L)
+ };
+
+ assertThat(underTest.selectByTask(dbTester.getSession(), task1))
+ .extracting(CeTaskMessageDto::getUuid)
+ .containsExactly(messages[4].getUuid(), messages[3].getUuid(), messages[0].getUuid(), messages[5].getUuid());
+
+ assertThat(underTest.selectByTask(dbTester.getSession(), task2))
+ .extracting(CeTaskMessageDto::getUuid)
+ .containsExactly(messages[2].getUuid(), messages[1].getUuid());
+
+ assertThat(underTest.selectByTask(dbTester.getSession(), randomAlphabetic(5)))
+ .isEmpty();
+ }
+ private CeTaskMessageDto insertMessage(String taskUuid, int i, long createdAt) {
+ CeTaskMessageDto res = new CeTaskMessageDto()
+ .setUuid("message_" + i)
+ .setTaskUuid(taskUuid)
+ .setMessage("test_" + i)
+ .setCreatedAt(createdAt);
+ DbSession dbSession = dbTester.getSession();
+ underTest.insert(dbSession, res);
+ dbSession.commit();
+ return res;
}
}