]> source.dussan.org Git - sonarqube.git/commitdiff
Fix issue on UTs after ES upgrade
authorJacek <jacek.poreda@sonarsource.com>
Tue, 29 Mar 2022 09:07:36 +0000 (11:07 +0200)
committersonartech <sonartech@sonarsource.com>
Tue, 29 Mar 2022 20:03:37 +0000 (20:03 +0000)
build.gradle
server/sonar-server-common/build.gradle
server/sonar-server-common/src/testFixtures/java/org/sonar/server/es/EsTester.java
sonar-application/build.gradle

index dd6ba0e0bf6ac6cc9735203e9145dbe65144e117..c630c4c9eea0f07328190018b2e07fe53ea39869 100644 (file)
@@ -295,6 +295,7 @@ subprojects {
       dependency 'org.elasticsearch.plugin:transport-netty4-client:7.17.1'
       dependency 'org.elasticsearch:mocksocket:1.2'
       dependency 'org.codelibs.elasticsearch.module:analysis-common:7.17.1'
+      dependency 'org.codelibs.elasticsearch.module:reindex:7.17.1'
       dependency 'org.eclipse.jgit:org.eclipse.jgit:5.13.0.202109080827-r'
       dependency 'org.tmatesoft.svnkit:svnkit:1.10.4'
       dependency 'org.hamcrest:hamcrest-all:1.3'
index a6ffdd9d14008fa5c970d9575c56659f75fc27ea..4d768ea1f694522747930bf7088519954cf46e65 100644 (file)
@@ -50,5 +50,6 @@ dependencies {
   testFixturesImplementation 'org.elasticsearch.plugin:transport-netty4-client'
 
   testFixturesImplementation 'org.codelibs.elasticsearch.module:analysis-common'
+  testFixturesImplementation 'org.codelibs.elasticsearch.module:reindex'
   testFixturesImplementation 'org.elasticsearch:mocksocket'
 }
index 2cd357a2d7503bc94af59a9c29fc23e27b56f4ac..5ce592554f695df9874399efd3f40ff28e3d4268 100644 (file)
@@ -74,11 +74,13 @@ import org.elasticsearch.http.HttpTransportSettings;
 import org.elasticsearch.index.query.QueryBuilder;
 import org.elasticsearch.index.query.QueryBuilders;
 import org.elasticsearch.index.query.TermQueryBuilder;
+import org.elasticsearch.index.reindex.DeleteByQueryRequest;
 import org.elasticsearch.indices.recovery.RecoverySettings;
 import org.elasticsearch.join.ParentJoinPlugin;
 import org.elasticsearch.node.InternalSettingsPreparer;
 import org.elasticsearch.node.Node;
 import org.elasticsearch.node.NodeValidationException;
+import org.elasticsearch.reindex.ReindexPlugin;
 import org.elasticsearch.search.SearchHit;
 import org.elasticsearch.search.builder.SearchSourceBuilder;
 import org.elasticsearch.search.sort.SortOrder;
@@ -178,9 +180,15 @@ public class EsTester extends ExternalResource {
         .forEach(EsTester::deleteIndexIfExists);
     }
 
-    BulkIndexer.delete(ES_REST_CLIENT, IndexType.main(ALL_INDICES, "dummy"),
-      EsClient.prepareSearch(ALL_INDICES.getName())
-        .source(new SearchSourceBuilder().query(QueryBuilders.matchAllQuery())));
+    deleteAllDocumentsInIndexes();
+  }
+
+  private void deleteAllDocumentsInIndexes() {
+    try {
+      ES_REST_CLIENT.nativeClient().deleteByQuery(new DeleteByQueryRequest(ALL_INDICES.getName()).setQuery(QueryBuilders.matchAllQuery()).setRefresh(true), RequestOptions.DEFAULT);
+    } catch (IOException e) {
+      throw new IllegalStateException("Could not delete data from _all indices", e);
+    }
   }
 
   private static String[] getIndicesNames() {
@@ -475,6 +483,9 @@ public class EsTester extends ExternalResource {
       .put(NodeEnvironment.MAX_LOCAL_STORAGE_NODES_SETTING.getKey(), Integer.MAX_VALUE)
       .put("logger.level", "INFO")
       .put("action.auto_create_index", false)
+      // allows to drop all indices at once using `_all`
+      // this parameter will default to true in ES 8.X
+      .put("action.destructive_requires_name", false)
       // Default the watermarks to absurdly low to prevent the tests
       // from failing on nodes without enough disk space
       .put(DiskThresholdSettings.CLUSTER_ROUTING_ALLOCATION_LOW_DISK_WATERMARK_SETTING.getKey(), "1b")
@@ -489,6 +500,7 @@ public class EsTester extends ExternalResource {
     Node node = new Node(InternalSettingsPreparer.prepareEnvironment(settings, Collections.emptyMap(), null, null),
       ImmutableList.of(
         CommonAnalysisPlugin.class,
+        ReindexPlugin.class,
         // Netty4Plugin provides http and tcp transport
         Netty4Plugin.class,
         // install ParentJoin plugin required to create field of type "join"
index dc02002fc53335b02c68f7cc8c3c3eb76be00472..cbff50150d2f3a00f7862f1f2840e0cf37bff785 100644 (file)
@@ -188,7 +188,6 @@ task zip(type: Zip, dependsOn: [configurations.compileClasspath, tasks.downloadL
     exclude '**/modules/mapper-version/**'
     exclude '**/modules/percolator/**'
     exclude '**/modules/rank-eval/**'
-    exclude '**/modules/reindex/**'
     exclude '**/modules/repositories-metering-api/**'
     exclude '**/modules/repository-encrypted/**'
     exclude '**/modules/repository-url/**'