From df64c184d1427f74592459b42093e8b0b6878c98 Mon Sep 17 00:00:00 2001 From: Pierre Guillot <50145663+pierre-guillot-sonarsource@users.noreply.github.com> Date: Thu, 13 Aug 2020 14:43:47 +0200 Subject: [PATCH] SONAR-13759 use uuid instead of id + use the real schema in test instead of a mocked one.. (#3048) --- .../PopulateFileSourceLineCount.java | 8 ++++---- .../PopulateFileSourceLineCountTest.java | 7 ++++++- .../file_sources.sql | 17 ----------------- .../java/org/sonar/db/DbTester.java | 6 ------ 4 files changed, 10 insertions(+), 28 deletions(-) delete mode 100644 server/sonar-ce-task-projectanalysis/src/test/resources/org/sonar/ce/task/projectanalysis/dbmigration/PopulateFileSourceLineCountTest/file_sources.sql diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/dbmigration/PopulateFileSourceLineCount.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/dbmigration/PopulateFileSourceLineCount.java index 36675b6a89b..ec6472084dd 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/dbmigration/PopulateFileSourceLineCount.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/dbmigration/PopulateFileSourceLineCount.java @@ -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; } } diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/dbmigration/PopulateFileSourceLineCountTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/dbmigration/PopulateFileSourceLineCountTest.java index 129edf0d4bc..139ce9547c0 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/dbmigration/PopulateFileSourceLineCountTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/dbmigration/PopulateFileSourceLineCountTest.java @@ -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 index a9b661b01a3..00000000000 --- a/server/sonar-ce-task-projectanalysis/src/test/resources/org/sonar/ce/task/projectanalysis/dbmigration/PopulateFileSourceLineCountTest/file_sources.sql +++ /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"); diff --git a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/DbTester.java b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/DbTester.java index fba9a7404c9..33c99ce4421 100644 --- a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/DbTester.java +++ b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/DbTester.java @@ -150,12 +150,6 @@ public class DbTester extends AbstractDbTester { 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()); -- 2.39.5