]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-10301 delete from CE_TASK_CHARACTERISTICS when deleting project
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Fri, 9 Feb 2018 10:38:23 +0000 (11:38 +0100)
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Tue, 13 Feb 2018 13:50:35 +0000 (14:50 +0100)
server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeCommands.java
server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeMapper.java
server/sonar-db-dao/src/main/resources/org/sonar/db/purge/PurgeMapper.xml
server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeDaoTest.java

index 51115390b5d4fe8ae726e17f8c43afa6620f3fee..4f3fc10738b067dd544edfcc079698b7e77f098b 100644 (file)
@@ -251,6 +251,10 @@ class PurgeCommands {
     purgeMapper.deleteCeScannerContextOfCeActivityByProjectUuid(rootUuid);
     session.commit();
     profiler.stop();
+    profiler.start("deleteCeActivity (ce_task_characteristics)");
+    purgeMapper.deleteCeTaskCharacteristicsOfCeActivityByProjectUuid(rootUuid);
+    session.commit();
+    profiler.stop();
     profiler.start("deleteCeActivity (ce_activity)");
     purgeMapper.deleteCeActivityByProjectUuid(rootUuid);
     session.commit();
@@ -262,6 +266,10 @@ class PurgeCommands {
     purgeMapper.deleteCeScannerContextOfCeQueueByProjectUuid(rootUuid);
     session.commit();
     profiler.stop();
+    profiler.start("deleteCeQueue (ce_task_characteristics)");
+    purgeMapper.deleteCeTaskCharacteristicsOfCeQueueByProjectUuid(rootUuid);
+    session.commit();
+    profiler.stop();
     profiler.start("deleteCeQueue (ce_queue)");
     purgeMapper.deleteCeQueueByProjectUuid(rootUuid);
     session.commit();
index c7626d029711360731d03cdea5d10a5bea990c22..684160434175e042ee757f7824df2d8685ba0fe7 100644 (file)
@@ -90,12 +90,16 @@ public interface PurgeMapper {
 
   void deleteFileSourcesByFileUuid(@Param("fileUuids") List<String> fileUuids);
 
+  void deleteCeTaskCharacteristicsOfCeActivityByProjectUuid(@Param("projectUuid") String projectUuid);
+
   void deleteCeScannerContextOfCeActivityByProjectUuid(@Param("projectUuid") String projectUuid);
 
   void deleteCeActivityByProjectUuid(@Param("projectUuid") String projectUuid);
 
   void deleteCeScannerContextOfCeQueueByProjectUuid(@Param("projectUuid") String projectUuid);
 
+  void deleteCeTaskCharacteristicsOfCeQueueByProjectUuid(@Param("projectUuid") String projectUuid);
+
   void deleteCeQueueByProjectUuid(@Param("projectUuid") String projectUuid);
 
   void deleteWebhookDeliveriesByProjectUuid(@Param("projectUuid") String projectUuid);
index f12fd5007d9258e3befe501df85fd37d64749200..eb599b6b61bee94b0405586c71e0afdccdad9ad8 100644 (file)
       task_uuid in (select uuid from ce_activity where component_uuid=#{projectUuid,jdbcType=VARCHAR})
   </delete>
 
+  <delete id="deleteCeTaskCharacteristicsOfCeActivityByProjectUuid">
+    delete from ce_task_characteristics
+    where
+      task_uuid in (select uuid from ce_activity where component_uuid=#{projectUuid,jdbcType=VARCHAR})
+  </delete>
+
   <delete id="deleteCeActivityByProjectUuid">
       delete from ce_activity where component_uuid=#{projectUuid,jdbcType=VARCHAR}
   </delete>
       task_uuid in (select uuid from ce_queue where component_uuid=#{projectUuid,jdbcType=VARCHAR})
   </delete>
 
+  <delete id="deleteCeTaskCharacteristicsOfCeQueueByProjectUuid">
+    delete from ce_task_characteristics
+    where
+      task_uuid in (select uuid from ce_queue where component_uuid=#{projectUuid,jdbcType=VARCHAR})
+  </delete>
+
   <delete id="deleteCeQueueByProjectUuid">
     delete from ce_queue where component_uuid=#{projectUuid,jdbcType=VARCHAR}
   </delete>
index d05790e8b3d6e631c06c2ff1e083fb1e990f0072..02d5b5cc797f173134e63df12c614de2831f3ecb 100644 (file)
@@ -28,6 +28,7 @@ import java.util.List;
 import java.util.Optional;
 import java.util.Random;
 import java.util.stream.Collectors;
+import java.util.stream.IntStream;
 import java.util.stream.Stream;
 import org.apache.commons.lang.math.RandomUtils;
 import org.apache.commons.lang.time.DateUtils;
@@ -46,6 +47,7 @@ import org.sonar.db.DbTester;
 import org.sonar.db.ce.CeActivityDto;
 import org.sonar.db.ce.CeQueueDto;
 import org.sonar.db.ce.CeQueueDto.Status;
+import org.sonar.db.ce.CeTaskCharacteristicDto;
 import org.sonar.db.component.BranchType;
 import org.sonar.db.component.ComponentDbTester;
 import org.sonar.db.component.ComponentDto;
@@ -248,6 +250,31 @@ public class PurgeDaoTest {
       .containsOnly(toNotDelete.getUuid(), "non existing task");
   }
 
+  @Test
+  public void delete_row_in_ce_task_characteristics_referring_to_a_row_in_ce_activity_when_deleting_project() {
+    ComponentDto projectToBeDeleted = ComponentTesting.newPrivateProjectDto(dbTester.getDefaultOrganization());
+    ComponentDto anotherLivingProject = ComponentTesting.newPrivateProjectDto(dbTester.getDefaultOrganization());
+    dbClient.componentDao().insert(dbSession, projectToBeDeleted, anotherLivingProject);
+
+    // Insert 2 rows in CE_ACTIVITY : one for the project that will be deleted, and one on another project
+    CeActivityDto toBeDeleted = insertCeActivity(projectToBeDeleted);
+    insertCeTaskCharacteristics(toBeDeleted.getUuid(), 3);
+    CeActivityDto toNotDelete = insertCeActivity(anotherLivingProject);
+    insertCeTaskCharacteristics(toNotDelete.getUuid(), 2);
+    insertCeTaskCharacteristics("non existing task", 5);
+    dbSession.commit();
+
+    underTest.deleteProject(dbSession, projectToBeDeleted.uuid());
+    dbSession.commit();
+
+    assertThat(dbTester.select("select uuid as \"UUID\" from ce_activity"))
+      .extracting(row -> (String) row.get("UUID"))
+      .containsOnly(toNotDelete.getUuid());
+    assertThat(dbTester.select("select task_uuid as \"UUID\" from ce_task_characteristics"))
+      .extracting(row -> (String) row.get("UUID"))
+      .containsOnly(toNotDelete.getUuid(), "non existing task");
+  }
+
   @Test
   public void delete_tasks_in_ce_queue_when_deleting_project() {
     ComponentDto projectToBeDeleted = dbTester.components().insertPrivateProject();
@@ -292,6 +319,31 @@ public class PurgeDaoTest {
       .containsOnly(toNotDelete.getUuid(), "non existing task");
   }
 
+  @Test
+  public void delete_row_in_ce_task_characteristics_referring_to_a_row_in_ce_queue_when_deleting_project() {
+    ComponentDto projectToBeDeleted = ComponentTesting.newPrivateProjectDto(dbTester.getDefaultOrganization());
+    ComponentDto anotherLivingProject = ComponentTesting.newPrivateProjectDto(dbTester.getDefaultOrganization());
+    dbClient.componentDao().insert(dbSession, projectToBeDeleted, anotherLivingProject);
+
+    // Insert 2 rows in CE_ACTIVITY : one for the project that will be deleted, and one on another project
+    CeQueueDto toBeDeleted = insertCeQueue(projectToBeDeleted);
+    insertCeTaskCharacteristics(toBeDeleted.getUuid(), 3);
+    CeQueueDto toNotDelete = insertCeQueue(anotherLivingProject);
+    insertCeTaskCharacteristics(toNotDelete.getUuid(), 2);
+    insertCeTaskCharacteristics("non existing task", 5);
+    dbSession.commit();
+
+    underTest.deleteProject(dbSession, projectToBeDeleted.uuid());
+    dbSession.commit();
+
+    assertThat(dbTester.select("select uuid as \"UUID\" from ce_queue"))
+      .extracting(row -> (String) row.get("UUID"))
+      .containsOnly(toNotDelete.getUuid());
+    assertThat(dbTester.select("select task_uuid as \"UUID\" from ce_task_characteristics"))
+      .extracting(row -> (String) row.get("UUID"))
+      .containsOnly(toNotDelete.getUuid(), "non existing task");
+  }
+
   private ComponentDto insertProjectWithBranchAndRelatedData() {
     RuleDefinitionDto rule = dbTester.rules().insert();
     ComponentDto project = dbTester.components().insertMainBranch();
@@ -712,6 +764,18 @@ public class PurgeDaoTest {
     dbSession.commit();
   }
 
+  private void insertCeTaskCharacteristics(String uuid, int count) {
+    List<CeTaskCharacteristicDto> dtos = IntStream.range(0, count)
+      .mapToObj(i -> new CeTaskCharacteristicDto()
+        .setUuid(UuidFactoryFast.getInstance().create())
+        .setTaskUuid(uuid)
+        .setKey("key_" + uuid.hashCode() + i)
+        .setValue("value_" + uuid.hashCode() + i))
+      .collect(Collectors.toList());
+    dbClient.ceTaskCharacteristicsDao().insert(dbSession, dtos);
+    dbSession.commit();
+  }
+
   private static PurgeableAnalysisDto getById(List<PurgeableAnalysisDto> snapshots, String uuid) {
     return snapshots.stream()
       .filter(snapshot -> uuid.equals(snapshot.getAnalysisUuid()))