From d846ea43f403c2e469cf3dbd491ec18d071c4e0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20B=C3=BCscher?= Date: Thu, 19 Mar 2020 19:00:14 +0100 Subject: [PATCH] Fix ReloadSynonymAnalyzerIT failure (#53663) (#53806) There is an assertion in ReloadAnalyzersResponse.merge that compares index names of merged responses that was falsely using object equality instead of String.equals(). In the past this didn't seem to matter but with changes in the test setup we started to see failures. Correcting this and also simplifying test a bit to be able to run it repeatedly if needed. Backport of #53663 --- .../core/action/ReloadAnalyzersResponse.java | 2 +- .../rest/action/ReloadSynonymAnalyzerIT.java | 19 ++++++++++++++----- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/action/ReloadAnalyzersResponse.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/action/ReloadAnalyzersResponse.java index fd84ba2d8df..378aed90eed 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/action/ReloadAnalyzersResponse.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/action/ReloadAnalyzersResponse.java @@ -164,7 +164,7 @@ public class ReloadAnalyzersResponse extends BroadcastResponse { } void merge(ReloadResult other) { - assert this.indexName == other.index; + assert this.indexName.equals(other.index); this.reloadedAnalyzers.addAll(other.reloadedSearchAnalyzers); this.reloadedIndicesNodes.add(other.nodeId); } diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/rest/action/ReloadSynonymAnalyzerIT.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/rest/action/ReloadSynonymAnalyzerIT.java index 89a7dc7d6f8..3d1518a0339 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/rest/action/ReloadSynonymAnalyzerIT.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/rest/action/ReloadSynonymAnalyzerIT.java @@ -5,7 +5,6 @@ */ package org.elasticsearch.xpack.core.rest.action; -import org.apache.lucene.util.LuceneTestCase; import org.elasticsearch.action.admin.indices.analyze.AnalyzeAction.AnalyzeToken; import org.elasticsearch.action.admin.indices.analyze.AnalyzeAction.Response; import org.elasticsearch.action.search.SearchResponse; @@ -40,7 +39,6 @@ import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcke import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitCount; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoFailures; -@LuceneTestCase.AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/53443") public class ReloadSynonymAnalyzerIT extends ESIntegTestCase { @Override @@ -48,11 +46,24 @@ public class ReloadSynonymAnalyzerIT extends ESIntegTestCase { return Settings.builder().put(super.nodeSettings(nodeOrdinal)).put(XPackSettings.SECURITY_ENABLED.getKey(), false).build(); } + @Override + protected Settings transportClientSettings() { + return Settings.builder().put(XPackSettings.SECURITY_ENABLED.getKey(), false).build(); + } + @Override protected Collection> nodePlugins() { return Arrays.asList(LocalStateCompositeXPackPlugin.class, CommonAnalysisPlugin.class); } + /** + * Returns a collection of plugins that should be loaded when creating a transport client. + */ + @Override + protected Collection> transportClientPlugins() { + return Arrays.asList(LocalStateCompositeXPackPlugin.class); + } + /** * This test needs to write to the config directory, this is difficult in an external cluster so we overwrite this to force running with * {@link InternalTestCluster} @@ -66,10 +77,8 @@ public class ReloadSynonymAnalyzerIT extends ESIntegTestCase { Path config = internalCluster().getInstance(Environment.class).configFile(); String synonymsFileName = "synonyms.txt"; Path synonymsFile = config.resolve(synonymsFileName); - Files.createFile(synonymsFile); - assertTrue(Files.exists(synonymsFile)); try (PrintWriter out = new PrintWriter( - new OutputStreamWriter(Files.newOutputStream(synonymsFile, StandardOpenOption.CREATE), StandardCharsets.UTF_8))) { + new OutputStreamWriter(Files.newOutputStream(synonymsFile), StandardCharsets.UTF_8))) { out.println("foo, baz"); } assertAcked(client().admin().indices().prepareCreate("test").setSettings(Settings.builder()