aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>2019-10-09 12:47:08 +0200
committerSonarTech <sonartech@sonarsource.com>2019-10-09 20:21:07 +0200
commitd17f0721a3a82e2f2b0fb424c8076159f9331bf0 (patch)
tree11f90eb01c172b8bc32feeac0b031edfb711707e
parente09ebc0335e929355d1f096b31c97aa46d06d288 (diff)
downloadsonarqube-d17f0721a3a82e2f2b0fb424c8076159f9331bf0.tar.gz
sonarqube-d17f0721a3a82e2f2b0fb424c8076159f9331bf0.zip
SONAR-12513 last used date is never set on new Quality Profiles
all QP start with no last used date in the Database, which is represented by a null value in the column, the update method ensures no update is done if new date is older than the current one it does so by comparing the new date with the current value, however, this test always returns false if the current value is null this way of updating the last used date was introduced to fix SONAR-10462 (Update of last used date on Quality Profile can fail with Deadlock on Postgres) since then, last used date of new QP (which includes any new install of SQ since 7.8, including the LTS) is never set
-rw-r--r--server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/QualityProfileMapper.xml2
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QualityProfileDaoTest.java15
2 files changed, 15 insertions, 2 deletions
diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/QualityProfileMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/QualityProfileMapper.xml
index dcbdaefe4ea..5a74720b17a 100644
--- a/server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/QualityProfileMapper.xml
+++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/QualityProfileMapper.xml
@@ -98,7 +98,7 @@
updated_at = #{now, jdbcType=BIGINT}
where
uuid = #{uuid, jdbcType=VARCHAR}
- and last_used &lt; #{lastUsedDate, jdbcType=BIGINT}
+ and (last_used is null or last_used &lt; #{lastUsedDate, jdbcType=BIGINT})
</update>
<delete id="deleteRuleProfilesByUuids" parameterType="String">
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QualityProfileDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QualityProfileDaoTest.java
index b27df5e28cf..a05098c9525 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QualityProfileDaoTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QualityProfileDaoTest.java
@@ -149,7 +149,20 @@ public class QualityProfileDaoTest {
}
@Test
- public void test_updateLastUsedDate() {
+ public void test_updateLastUsedDate_if_never_been_set_yet() {
+ QProfileDto initial = QualityProfileTesting.newQualityProfileDto()
+ .setLastUsed(null);
+ underTest.insert(dbSession, initial);
+
+ int count = underTest.updateLastUsedDate(dbSession, initial, 15_000L);
+
+ assertThat(count).isEqualTo(1);
+ QProfileDto reloaded = underTest.selectByUuid(dbSession, initial.getKee());
+ assertThat(reloaded.getLastUsed()).isEqualTo(15_000L);
+ }
+
+ @Test
+ public void test_updateLastUsedDate_if_more_recent() {
QProfileDto initial = QualityProfileTesting.newQualityProfileDto()
.setLastUsed(10_000L);
underTest.insert(dbSession, initial);