aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-db-migration
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@sonarsource.com>2018-05-29 22:17:15 +0200
committerSonarTech <sonartech@sonarsource.com>2018-06-12 20:20:59 +0200
commitfb3151df4890c325cb44dc48a049a77e460e420b (patch)
tree3908a2f7dfef136bc487943ee55264352d58cb43 /server/sonar-db-migration
parentc9f8b68cd5523d57690a230f62663c72b9a8f7a7 (diff)
downloadsonarqube-fb3151df4890c325cb44dc48a049a77e460e420b.tar.gz
sonarqube-fb3151df4890c325cb44dc48a049a77e460e420b.zip
SONAR-10691 remove coupling of migrations with ElasticsearchClient
Diffstat (limited to 'server/sonar-db-migration')
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/es/MigrationEsClient.java (renamed from server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/es/ElasticsearchClient.java)6
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v72/RenameSubmitterLoginToSubmitterUuidOnTableCeActivity.java8
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/step/ElasticsearchChangeTest.java51
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v72/RenameSubmitterLoginToSubmitterUuidOnTableCeActivityTest.java8
4 files changed, 16 insertions, 57 deletions
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/es/ElasticsearchClient.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/es/MigrationEsClient.java
index 677118f24a9..0c63c22256e 100644
--- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/es/ElasticsearchClient.java
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/es/MigrationEsClient.java
@@ -20,10 +20,10 @@
package org.sonar.server.platform.db.migration.es;
-public interface ElasticsearchClient {
+public interface MigrationEsClient {
/**
- * This method is reentrant and does not fail if indexName or otherIndexNames does not exist
+ * This method is re-entrant and does not fail if indexName or otherIndexNames do not exist
*/
- void deleteIndexes(String... otherIndexNames);
+ void deleteIndexes(String name, String... otherNames);
}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v72/RenameSubmitterLoginToSubmitterUuidOnTableCeActivity.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v72/RenameSubmitterLoginToSubmitterUuidOnTableCeActivity.java
index 59eaae83706..073b24ed540 100644
--- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v72/RenameSubmitterLoginToSubmitterUuidOnTableCeActivity.java
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v72/RenameSubmitterLoginToSubmitterUuidOnTableCeActivity.java
@@ -22,6 +22,7 @@ package org.sonar.server.platform.db.migration.version.v72;
import java.sql.SQLException;
import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.es.MigrationEsClient;
import org.sonar.server.platform.db.migration.sql.RenameColumnsBuilder;
import org.sonar.server.platform.db.migration.step.DdlChange;
@@ -29,8 +30,11 @@ import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVar
public class RenameSubmitterLoginToSubmitterUuidOnTableCeActivity extends DdlChange {
- public RenameSubmitterLoginToSubmitterUuidOnTableCeActivity(Database db) {
+ private final MigrationEsClient esClient;
+
+ public RenameSubmitterLoginToSubmitterUuidOnTableCeActivity(Database db, MigrationEsClient esClient) {
super(db);
+ this.esClient = esClient;
}
@Override
@@ -44,6 +48,6 @@ public class RenameSubmitterLoginToSubmitterUuidOnTableCeActivity extends DdlCha
.build())
.build());
- context.deleteIndexes("users");
+ esClient.deleteIndexes("users");
}
}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/step/ElasticsearchChangeTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/step/ElasticsearchChangeTest.java
deleted file mode 100644
index 7b1c1456c1a..00000000000
--- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/step/ElasticsearchChangeTest.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2018 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.step;
-
-import java.sql.SQLException;
-import org.junit.Test;
-import org.mockito.ArgumentCaptor;
-import org.sonar.server.platform.db.migration.es.ElasticsearchClient;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
-
-public class ElasticsearchChangeTest {
-
- private ElasticsearchClient client = mock(ElasticsearchClient.class);
-
- @Test
- public void deleteIndice_call() throws SQLException {
- ArgumentCaptor<String> indices = ArgumentCaptor.forClass(String.class);
-
- new ElasticsearchChange(client) {
- @Override
- protected void execute(Context context) throws SQLException {
- context.deleteIndice("a", "b", "c");
- }
- }.execute();
-
- verify(client, times(1)).deleteIndice(indices.capture());
- assertThat(indices.getAllValues()).containsExactly("a", "b", "c");
- }
-}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v72/RenameSubmitterLoginToSubmitterUuidOnTableCeActivityTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v72/RenameSubmitterLoginToSubmitterUuidOnTableCeActivityTest.java
index 988b2bec020..4cf1ee0bf1f 100644
--- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v72/RenameSubmitterLoginToSubmitterUuidOnTableCeActivityTest.java
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v72/RenameSubmitterLoginToSubmitterUuidOnTableCeActivityTest.java
@@ -25,8 +25,11 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.es.MigrationEsClient;
import static java.sql.Types.VARCHAR;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
public class RenameSubmitterLoginToSubmitterUuidOnTableCeActivityTest {
@@ -36,7 +39,8 @@ public class RenameSubmitterLoginToSubmitterUuidOnTableCeActivityTest {
@Rule
public ExpectedException expectedException = ExpectedException.none();
- private RenameSubmitterLoginToSubmitterUuidOnTableCeActivity underTest = new RenameSubmitterLoginToSubmitterUuidOnTableCeActivity(db.database());
+ private MigrationEsClient esClient = mock(MigrationEsClient.class);
+ private RenameSubmitterLoginToSubmitterUuidOnTableCeActivity underTest = new RenameSubmitterLoginToSubmitterUuidOnTableCeActivity(db.database(), esClient);
@Test
public void rename_column() throws SQLException {
@@ -44,6 +48,8 @@ public class RenameSubmitterLoginToSubmitterUuidOnTableCeActivityTest {
db.assertColumnDefinition("ce_activity", "submitter_uuid", VARCHAR, 255, true);
db.assertColumnDoesNotExist("ce_activity", "submitter_login");
+
+ verify(esClient).deleteIndexes("users");
}
public void migration_is_not_reentrant() throws SQLException {