aboutsummaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorDuarte Meneses <duarte.meneses@sonarsource.com>2022-10-14 11:21:47 -0500
committersonartech <sonartech@sonarsource.com>2022-10-17 20:03:02 +0000
commit596bd1fa592c7dd164a70e8b151c6324f3c2c4c3 (patch)
treef6cd091a14c26f80024f5b0b0b3ed6423fe0fe1a /server
parent1ed052648d862aef9386adb7735305c1350fc57d (diff)
downloadsonarqube-596bd1fa592c7dd164a70e8b151c6324f3c2c4c3.tar.gz
sonarqube-596bd1fa592c7dd164a70e8b151c6324f3c2c4c3.zip
SONAR-17477 Analyzer cache not purged when branch is deleted
Diffstat (limited to 'server')
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeDao.java1
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeDaoTest.java32
2 files changed, 33 insertions, 0 deletions
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeDao.java
index fc50e9d72e5..1b07bd18e85 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeDao.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeDao.java
@@ -222,6 +222,7 @@ public class PurgeDao implements Dao {
private static void deleteRootComponent(String rootUuid, PurgeMapper mapper, PurgeCommands commands) {
List<String> rootAndModulesOrSubviews = mapper.selectRootAndModulesOrSubviewsByProjectUuid(rootUuid);
commands.deleteLinks(rootUuid);
+ commands.deleteScannerCache(rootUuid);
commands.deleteAnalyses(rootUuid);
commands.deleteByRootAndModulesOrSubviews(rootAndModulesOrSubviews);
commands.deleteIssues(rootUuid);
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeDaoTest.java
index 00826d4dbb5..2cbdf4302a7 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeDaoTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeDaoTest.java
@@ -21,6 +21,7 @@ package org.sonar.db.purge;
import com.google.common.collect.ImmutableSet;
import java.io.ByteArrayInputStream;
+import java.io.IOException;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.util.Arrays;
@@ -35,11 +36,13 @@ import java.util.function.Consumer;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.Stream;
+import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.math.RandomUtils;
import org.apache.commons.lang.time.DateUtils;
import org.junit.Rule;
import org.junit.Test;
import org.sonar.api.issue.Issue;
+import org.sonar.api.resources.Qualifiers;
import org.sonar.api.utils.System2;
import org.sonar.core.util.CloseableIterator;
import org.sonar.core.util.UuidFactoryFast;
@@ -83,6 +86,7 @@ import org.sonar.db.webhook.WebhookDeliveryLiteDto;
import org.sonar.db.webhook.WebhookDto;
import static com.google.common.base.MoreObjects.firstNonNull;
+import static java.nio.charset.StandardCharsets.UTF_8;
import static java.time.ZoneOffset.UTC;
import static java.util.Arrays.asList;
import static java.util.Collections.emptySet;
@@ -1384,6 +1388,34 @@ public class PurgeDaoTest {
}
@Test
+ public void deleteBranch_deletes_scanner_cache() throws IOException {
+ ProjectDto project = db.components().insertPublicProjectDto();
+ BranchDto branch = db.components().insertProjectBranch(project);
+ dbClient.scannerAnalysisCacheDao().insert(dbSession, branch.getUuid(), IOUtils.toInputStream("test1", UTF_8));
+ dbClient.scannerAnalysisCacheDao().insert(dbSession, project.getUuid(), IOUtils.toInputStream("test2", UTF_8));
+
+ underTest.deleteBranch(dbSession, branch.getUuid());
+
+ assertThat(dbClient.scannerAnalysisCacheDao().selectData(dbSession, branch.getUuid())).isNull();
+ DbInputStream mainBranchCache = dbClient.scannerAnalysisCacheDao().selectData(dbSession, project.getUuid());
+
+ assertThat(IOUtils.toString(mainBranchCache, UTF_8)).isEqualTo("test2");
+ }
+
+ @Test
+ public void deleteProject_deletes_scanner_cache() throws IOException {
+ ProjectDto project = db.components().insertPublicProjectDto();
+ BranchDto branch = db.components().insertProjectBranch(project);
+ dbClient.scannerAnalysisCacheDao().insert(dbSession, branch.getUuid(), IOUtils.toInputStream("test1", UTF_8));
+ dbClient.scannerAnalysisCacheDao().insert(dbSession, project.getUuid(), IOUtils.toInputStream("test2", UTF_8));
+
+ underTest.deleteProject(dbSession,project.getUuid(), Qualifiers.PROJECT, "project", "project");
+
+ assertThat(dbClient.scannerAnalysisCacheDao().selectData(dbSession, project.getUuid())).isNull();
+ assertThat(dbClient.scannerAnalysisCacheDao().selectData(dbSession, branch.getUuid())).isNull();
+ }
+
+ @Test
public void deleteProject_deletes_project_badge_tokens() {
ProjectDto project = db.components().insertPublicProjectDto();
ProjectDto otherProject = db.components().insertPublicProjectDto();