diff options
author | Eric Hartmann <hartmann.eric@gmail.com> | 2018-05-25 15:56:30 +0200 |
---|---|---|
committer | SonarTech <sonartech@sonarsource.com> | 2018-06-12 20:20:59 +0200 |
commit | aadcb25039c2d98c6a0fe3e13f05c819dab4823c (patch) | |
tree | b2e72c5109e1a2d1fba05074e4f93d618883dc3c /server/sonar-db-migration | |
parent | 4264ca3f1c21187231007c084844b223a84137d4 (diff) | |
download | sonarqube-aadcb25039c2d98c6a0fe3e13f05c819dab4823c.tar.gz sonarqube-aadcb25039c2d98c6a0fe3e13f05c819dab4823c.zip |
SONAR-10691 Introduce ES drop in DB migration
Diffstat (limited to 'server/sonar-db-migration')
4 files changed, 105 insertions, 1 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/ElasticsearchClient.java new file mode 100644 index 00000000000..677118f24a9 --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/es/ElasticsearchClient.java @@ -0,0 +1,29 @@ +/* + * 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.es; + +public interface ElasticsearchClient { + + /** + * This method is reentrant and does not fail if indexName or otherIndexNames does not exist + */ + void deleteIndexes(String... otherIndexNames); +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/es/package-info.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/es/package-info.java new file mode 100644 index 00000000000..a3ef5bf6209 --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/es/package-info.java @@ -0,0 +1,24 @@ +/* + * 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. + */ +@ParametersAreNonnullByDefault +package org.sonar.server.platform.db.migration.es; + +import javax.annotation.ParametersAreNonnullByDefault; + diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/step/SelectImpl.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/step/SelectImpl.java index aed210f2175..3a7a91c29bd 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/step/SelectImpl.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/step/SelectImpl.java @@ -28,7 +28,7 @@ import java.util.List; import org.apache.commons.dbutils.DbUtils; import org.sonar.db.Database; -public class SelectImpl extends BaseSqlStatement<Select>implements Select { +public class SelectImpl extends BaseSqlStatement<Select> implements Select { private SelectImpl(PreparedStatement pstmt) { super(pstmt); 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 new file mode 100644 index 00000000000..7b1c1456c1a --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/step/ElasticsearchChangeTest.java @@ -0,0 +1,51 @@ +/* + * 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"); + } +} |