]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-9507 ensure sonar.ce.workerCount doesn't exist in Properties
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Tue, 4 Jul 2017 15:45:51 +0000 (17:45 +0200)
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Mon, 17 Jul 2017 08:52:47 +0000 (10:52 +0200)
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v65/DbVersion65.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v65/DeleteCeWorkerCountSetting.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v65/DbVersion65Test.java
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v65/DeleteCeWorkerCountSettingTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v65/DeleteCeWorkerCountSettingTest/properties.sql [new file with mode: 0644]

index 66788574f1adda9aacc61b244006748660d60b82..1ba76a485dde55af90129ff12fb56828a7d2f86a 100644 (file)
@@ -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 (file)
index 0000000..c08bb87
--- /dev/null
@@ -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();
+  }
+}
index 61243077c0a01570b6a0328db3883fe81edbf7ee..2b88bf59c9760ecc0bbd46c2477773029b536917 100644 (file)
@@ -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 (file)
index 0000000..d7835f4
--- /dev/null
@@ -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 (file)
index 0000000..dfc39d8
--- /dev/null
@@ -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");