]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-13759 use uuid instead of id + use the real schema in test instead of a mocked...
authorPierre Guillot <50145663+pierre-guillot-sonarsource@users.noreply.github.com>
Thu, 13 Aug 2020 12:43:47 +0000 (14:43 +0200)
committersonartech <sonartech@sonarsource.com>
Thu, 13 Aug 2020 20:06:34 +0000 (20:06 +0000)
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/dbmigration/PopulateFileSourceLineCount.java
server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/dbmigration/PopulateFileSourceLineCountTest.java
server/sonar-ce-task-projectanalysis/src/test/resources/org/sonar/ce/task/projectanalysis/dbmigration/PopulateFileSourceLineCountTest/file_sources.sql [deleted file]
server/sonar-db-dao/src/testFixtures/java/org/sonar/db/DbTester.java

index 36675b6a89be0bad71d0488839082a1a64221a0b..ec6472084dddbf8eb281bc535284ac1cddb2647b 100644 (file)
@@ -49,22 +49,22 @@ public class PopulateFileSourceLineCount extends DataChange implements ProjectAn
 
     if (unInitializedFileSources != null && unInitializedFileSources > 0) {
       MassUpdate massUpdate = context.prepareMassUpdate();
-      massUpdate.select("select id,line_hashes from file_sources where line_count = ? and project_uuid = ?")
+      massUpdate.select("select uuid,line_hashes from file_sources where line_count = ? and project_uuid = ?")
         .setInt(1, LINE_COUNT_NOT_POPULATED)
         .setString(2, componentUuid);
-      massUpdate.update("update file_sources set line_count = ? where id = ?");
+      massUpdate.update("update file_sources set line_count = ? where uuid = ?");
       massUpdate.rowPluralName("line counts of sources of project " + componentUuid);
       massUpdate.execute(PopulateFileSourceLineCount::handle);
     }
   }
 
   private static boolean handle(Select.Row row, SqlStatement update) throws SQLException {
-    int rowId = row.getInt(1);
+    String rowUuid = row.getString(1);
     String rawData = row.getNullableString(2);
 
     int lineCount = rawData == null ? 0 : Iterables.size(FileSourceDto.LINES_HASHES_SPLITTER.split(rawData));
     update.setInt(1, lineCount);
-    update.setInt(2, rowId);
+    update.setString(2, rowUuid);
     return true;
   }
 }
index 129edf0d4bc90f952e1ef021e9547dd32dfd4360..139ce9547c06f4668f9049a38667618174e04e74 100644 (file)
@@ -30,6 +30,8 @@ import org.junit.Test;
 import org.junit.rules.ExpectedException;
 import org.sonar.api.utils.System2;
 import org.sonar.ce.task.CeTask;
+import org.sonar.core.util.SequenceUuidFactory;
+import org.sonar.core.util.UuidFactory;
 import org.sonar.db.DbTester;
 
 import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric;
@@ -44,7 +46,9 @@ public class PopulateFileSourceLineCountTest {
   public ExpectedException expectedException = ExpectedException.none();
 
   @Rule
-  public DbTester db = DbTester.createForSchema(System2.INSTANCE, PopulateFileSourceLineCountTest.class, "file_sources.sql");
+  public DbTester db = DbTester.create(System2.INSTANCE);
+
+  private UuidFactory uuidFactory = new SequenceUuidFactory();
 
   private Random random = new Random();
   private CeTask ceTask = mock(CeTask.class);
@@ -178,6 +182,7 @@ public class PopulateFileSourceLineCountTest {
   private void insertFileSource(String projectUuid, String fileUuid, @Nullable String lineHashes, int lineCount) {
     db.executeInsert(
       "FILE_SOURCES",
+      "UUID", uuidFactory.create(),
       "PROJECT_UUID", projectUuid,
       "FILE_UUID", fileUuid,
       "LINE_HASHES", lineHashes,
diff --git a/server/sonar-ce-task-projectanalysis/src/test/resources/org/sonar/ce/task/projectanalysis/dbmigration/PopulateFileSourceLineCountTest/file_sources.sql b/server/sonar-ce-task-projectanalysis/src/test/resources/org/sonar/ce/task/projectanalysis/dbmigration/PopulateFileSourceLineCountTest/file_sources.sql
deleted file mode 100644 (file)
index a9b661b..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-CREATE TABLE "FILE_SOURCES" (
-  "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
-  "PROJECT_UUID" VARCHAR(50) NOT NULL,
-  "FILE_UUID" VARCHAR(50) NOT NULL,
-  "LINE_HASHES" CLOB,
-  "LINE_COUNT" INTEGER NOT NULL,
-  "BINARY_DATA" BLOB,
-  "DATA_TYPE" VARCHAR(20),
-  "DATA_HASH" VARCHAR(50),
-  "SRC_HASH" VARCHAR(50),
-  "REVISION" VARCHAR(100),
-  "CREATED_AT" BIGINT NOT NULL,
-  "UPDATED_AT" BIGINT NOT NULL
-);
-CREATE INDEX "FILE_SOURCES_PROJECT_UUID" ON "FILE_SOURCES" ("PROJECT_UUID");
-CREATE UNIQUE INDEX "FILE_SOURCES_UUID_TYPE" ON "FILE_SOURCES" ("FILE_UUID", "DATA_TYPE");
-CREATE INDEX "FILE_SOURCES_UPDATED_AT" ON "FILE_SOURCES" ("UPDATED_AT");
index fba9a7404c93d6564f631115653fc227d0bf281d..33c99ce4421228694af742d9f8f0bba667199420 100644 (file)
@@ -150,12 +150,6 @@ public class DbTester extends AbstractDbTester<TestDbImpl> {
     return new DbTester(system2, null, new DbTesterMyBatisConfExtension(firstMapperClass, otherMapperClasses));
   }
 
-  public static DbTester createForSchema(System2 system2, Class testClass, String filename) {
-    String path = StringUtils.replaceChars(testClass.getCanonicalName(), '.', '/');
-    String schemaPath = path + "/" + filename;
-    return new DbTester(system2, schemaPath).setDisableDefaultOrganization(true);
-  }
-
   private void initDbClient() {
     TransientPicoContainer ioc = new TransientPicoContainer();
     ioc.addComponent(db.getMyBatis());