diff options
author | Simon Brandhof <simon.brandhof@sonarsource.com> | 2015-09-28 23:28:06 +0200 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@sonarsource.com> | 2015-09-29 11:31:42 +0200 |
commit | 96ab2f7679e5c904a942f5256969ddff07ca788d (patch) | |
tree | 0e4f9fb10434db64ac5c830f350cf897e5efc699 /sonar-db/src | |
parent | 1067fc0a3adb177489c261b955b7ef3fe623a1be (diff) | |
download | sonarqube-96ab2f7679e5c904a942f5256969ddff07ca788d.tar.gz sonarqube-96ab2f7679e5c904a942f5256969ddff07ca788d.zip |
SONAR-6630 delete logs related to old reports
Diffstat (limited to 'sonar-db/src')
5 files changed, 42 insertions, 15 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 58214c0c0ad..f54d80f566d 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 @@ -52,8 +52,12 @@ public class CeActivityDao implements Dao { } } - public void deleteOlderThan(DbSession dbSession, long beforeDate) { - mapper(dbSession).deleteOlderThan(beforeDate); + public List<CeActivityDto> selectOlderThan(DbSession dbSession, long beforeDate) { + return mapper(dbSession).selectOlderThan(beforeDate); + } + + public void deleteByUuid(DbSession dbSession, String uuid) { + mapper(dbSession).deleteByUuid(uuid); } /** 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 7c019b25eb4..7d9ada5c11e 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 @@ -35,6 +35,8 @@ public interface CeActivityMapper { List<CeActivityDto> selectByQuery(@Param("query") CeActivityQuery query, RowBounds rowBounds); + List<CeActivityDto> selectOlderThan(@Param("beforeDate") long beforeDate); + int countByQuery(@Param("query") CeActivityQuery query); void insert(CeActivityDto dto); @@ -43,5 +45,5 @@ public interface CeActivityMapper { void updateIsLastToTrueForUuid(@Param("uuid") String uuid, @Param("updatedAt") long updatedAt); - void deleteOlderThan(@Param("beforeDate") long beforeDate); + void deleteByUuid(@Param("uuid") String uuid); } diff --git a/sonar-db/src/main/java/org/sonar/db/ce/CeTaskTypes.java b/sonar-db/src/main/java/org/sonar/db/ce/CeTaskTypes.java index 042ff5eec0e..3136e8295ca 100644 --- a/sonar-db/src/main/java/org/sonar/db/ce/CeTaskTypes.java +++ b/sonar-db/src/main/java/org/sonar/db/ce/CeTaskTypes.java @@ -19,7 +19,7 @@ */ package org.sonar.db.ce; -public class CeTaskTypes { +public final class CeTaskTypes { private CeTaskTypes() { // only statics 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 d6a13c87fac..c466d93cbcc 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 @@ -93,6 +93,12 @@ </where> </select> + <select id="selectOlderThan" parameterType="long" resultType="org.sonar.db.ce.CeActivityDto"> + select <include refid="columns"/> + from ce_activity ca + where ca.created_at < #{beforeDate,jdbcType=BIGINT} + </select> + <insert id="insert" parameterType="org.sonar.db.ce.CeActivityDto" useGeneratedKeys="false"> insert into ce_activity (uuid, component_uuid, status, task_type, is_last, is_last_key, submitter_login, submitted_at, started_at, @@ -128,9 +134,8 @@ where uuid=#{uuid} </update> - <delete id="deleteOlderThan" parameterType="long"> + <delete id="deleteByUuid" parameterType="string"> delete from ce_activity - where created_at < #{beforeDate,jdbcType=BIGINT} + where uuid=#{uuid} </delete> - </mapper> 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 b52f6da2272..e714e688bf1 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 @@ -80,7 +80,7 @@ public class CeActivityDaoTest { } @Test - public void test_selectByQuery() throws Exception { + public void test_selectByQuery() { 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); @@ -116,7 +116,7 @@ public class CeActivityDaoTest { } @Test - public void test_countByQuery() throws Exception { + 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); @@ -146,7 +146,7 @@ public class CeActivityDaoTest { } @Test - public void select_and_count_by_date() throws Exception { + 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); @@ -181,17 +181,33 @@ public class CeActivityDaoTest { } @Test - public void deleteOlderThan() throws Exception { + public void selectOlderThan() { insertWithCreationDate("TASK_1", 1_450_000_000_000L); insertWithCreationDate("TASK_2", 1_460_000_000_000L); insertWithCreationDate("TASK_3", 1_470_000_000_000L); - underTest.deleteOlderThan(db.getSession(), 1_465_000_000_000L); - db.getSession().commit(); + List<CeActivityDto> dtos = underTest.selectOlderThan(db.getSession(), 1_465_000_000_000L); + assertThat(dtos).extracting("uuid").containsOnly("TASK_1", "TASK_2"); + } + + @Test + public void deleteByUuid() { + insert("TASK_1", "REPORT", "COMPONENT1", CeActivityDto.Status.SUCCESS); + insert("TASK_2", "REPORT", "COMPONENT1", CeActivityDto.Status.SUCCESS); + underTest.deleteByUuid(db.getSession(), "TASK_1"); assertThat(underTest.selectByUuid(db.getSession(), "TASK_1").isPresent()).isFalse(); - assertThat(underTest.selectByUuid(db.getSession(), "TASK_2").isPresent()).isFalse(); - assertThat(underTest.selectByUuid(db.getSession(), "TASK_3").isPresent()).isTrue(); + assertThat(underTest.selectByUuid(db.getSession(), "TASK_2").isPresent()).isTrue(); + } + + @Test + public void deleteByUuid_does_nothing_if_uuid_does_not_exist() { + insert("TASK_1", "REPORT", "COMPONENT1", CeActivityDto.Status.SUCCESS); + + // must not fail + underTest.deleteByUuid(db.getSession(), "TASK_2"); + + assertThat(underTest.selectByUuid(db.getSession(), "TASK_1").isPresent()).isTrue(); } private void insert(String uuid, String type, String componentUuid, CeActivityDto.Status status) { |