diff options
author | Sébastien Lesaint <sebastien.lesaint@sonarsource.com> | 2017-07-04 17:45:51 +0200 |
---|---|---|
committer | Sébastien Lesaint <sebastien.lesaint@sonarsource.com> | 2017-07-17 10:52:47 +0200 |
commit | ce973089af35b80082b7f6a169f3a976f00f6ec4 (patch) | |
tree | 2bb567ba1e40eb03bfaa25520e698a6d0c127407 /server | |
parent | 28886acf8527efacf4f6c9732852aa10b8576459 (diff) | |
download | sonarqube-ce973089af35b80082b7f6a169f3a976f00f6ec4.tar.gz sonarqube-ce973089af35b80082b7f6a169f3a976f00f6ec4.zip |
SONAR-9507 ensure sonar.ce.workerCount doesn't exist in Properties
Diffstat (limited to 'server')
5 files changed, 133 insertions, 1 deletions
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v65/DbVersion65.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v65/DbVersion65.java index 66788574f1a..1ba76a485dd 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v65/DbVersion65.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v65/DbVersion65.java @@ -62,6 +62,7 @@ public class DbVersion65 implements DbVersion { .add(1732, "Make USERS.ONBOARDED not nullable", MakeUsersOnboardedNotNullable.class) .add(1733, "Create table es_queue", CreateEsQueueTable.class) .add(1734, "Add index on es_queue.created_at", AddIndexOnEsQueueCreatedAt.class) + .add(1735, "Delete sonar.ce.workerCount setting", DeleteCeWorkerCountSetting.class) ; } } diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v65/DeleteCeWorkerCountSetting.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v65/DeleteCeWorkerCountSetting.java new file mode 100644 index 00000000000..c08bb874ad0 --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v65/DeleteCeWorkerCountSetting.java @@ -0,0 +1,38 @@ +/* + * SonarQube + * Copyright (C) 2009-2017 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.server.platform.db.migration.version.v65; + +import java.sql.SQLException; +import org.sonar.db.Database; +import org.sonar.server.platform.db.migration.step.DataChange; + +public class DeleteCeWorkerCountSetting extends DataChange { + public DeleteCeWorkerCountSetting(Database db) { + super(db); + } + + @Override + protected void execute(Context context) throws SQLException { + context.prepareUpsert("delete from properties where prop_key=?") + .setString(1, "sonar.ce.workerCount") + .execute() + .commit(); + } +} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v65/DbVersion65Test.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v65/DbVersion65Test.java index 61243077c0a..2b88bf59c97 100644 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v65/DbVersion65Test.java +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v65/DbVersion65Test.java @@ -35,6 +35,6 @@ public class DbVersion65Test { @Test public void verify_migration_count() { - verifyMigrationCount(underTest, 35); + verifyMigrationCount(underTest, 36); } } diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v65/DeleteCeWorkerCountSettingTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v65/DeleteCeWorkerCountSettingTest.java new file mode 100644 index 00000000000..d7835f43f36 --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v65/DeleteCeWorkerCountSettingTest.java @@ -0,0 +1,82 @@ +/* + * SonarQube + * Copyright (C) 2009-2017 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.server.platform.db.migration.version.v65; + +import java.sql.SQLException; +import java.util.Random; +import org.apache.commons.lang.RandomStringUtils; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.db.CoreDbTester; + +import static java.lang.String.valueOf; +import static org.assertj.core.api.Assertions.assertThat; + +public class DeleteCeWorkerCountSettingTest { + + private static final String TABLE_PROPERTIES = "properties"; + private static final String PROPERTY_SONAR_CE_WORKER_COUNT = "sonar.ce.workerCount"; + + @Rule + public CoreDbTester db = CoreDbTester.createForSchema(DeleteCeWorkerCountSettingTest.class, "properties.sql"); + + private DeleteCeWorkerCountSetting underTest = new DeleteCeWorkerCountSetting(db.database()); + + @Test + public void execute_does_not_fail_when_table_is_empty() throws SQLException { + underTest.execute(); + } + + @Test + public void execute_deletes_ce_worker_count_property() throws SQLException { + insertProperty(PROPERTY_SONAR_CE_WORKER_COUNT); + + underTest.execute(); + + assertThat(db.countRowsOfTable(TABLE_PROPERTIES)).isZero(); + } + + @Test + public void execute_is_case_sensitive() throws SQLException { + insertProperty(PROPERTY_SONAR_CE_WORKER_COUNT.toUpperCase()); + + underTest.execute(); + + assertThat(db.countRowsOfTable(TABLE_PROPERTIES)).isEqualTo(1); + } + + @Test + public void execute_does_not_delete_other_property() throws SQLException { + insertProperty(RandomStringUtils.randomAlphanumeric(3)); + + underTest.execute(); + + assertThat(db.countRowsOfTable(TABLE_PROPERTIES)).isEqualTo(1); + } + + public void insertProperty(String propertyName) { + Random random = new Random(); + db.executeInsert( + TABLE_PROPERTIES, + "prop_key", propertyName, + "is_empty", valueOf(random.nextBoolean()), + "text_value", random.nextBoolean() ? null : RandomStringUtils.randomAlphabetic(2)); + } +} diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v65/DeleteCeWorkerCountSettingTest/properties.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v65/DeleteCeWorkerCountSettingTest/properties.sql new file mode 100644 index 00000000000..dfc39d8d285 --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v65/DeleteCeWorkerCountSettingTest/properties.sql @@ -0,0 +1,11 @@ +CREATE TABLE "PROPERTIES" ( + "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1), + "PROP_KEY" VARCHAR(512) NOT NULL, + "RESOURCE_ID" INTEGER, + "USER_ID" INTEGER, + "IS_EMPTY" BOOLEAN NOT NULL, + "TEXT_VALUE" VARCHAR(4000), + "CLOB_VALUE" CLOB(2147483647), + "CREATED_AT" BIGINT +); +CREATE INDEX "PROPERTIES_KEY" ON "PROPERTIES" ("PROP_KEY"); |