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
This commit is contained in:
Christoph Büscher 2020-03-19 19:00:14 +01:00 committed by GitHub
parent 433952b595
commit d846ea43f4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 6 deletions

View File

@ -164,7 +164,7 @@ public class ReloadAnalyzersResponse extends BroadcastResponse {
} }
void merge(ReloadResult other) { void merge(ReloadResult other) {
assert this.indexName == other.index; assert this.indexName.equals(other.index);
this.reloadedAnalyzers.addAll(other.reloadedSearchAnalyzers); this.reloadedAnalyzers.addAll(other.reloadedSearchAnalyzers);
this.reloadedIndicesNodes.add(other.nodeId); this.reloadedIndicesNodes.add(other.nodeId);
} }

View File

@ -5,7 +5,6 @@
*/ */
package org.elasticsearch.xpack.core.rest.action; 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.AnalyzeToken;
import org.elasticsearch.action.admin.indices.analyze.AnalyzeAction.Response; import org.elasticsearch.action.admin.indices.analyze.AnalyzeAction.Response;
import org.elasticsearch.action.search.SearchResponse; 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.assertHitCount;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoFailures; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoFailures;
@LuceneTestCase.AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/53443")
public class ReloadSynonymAnalyzerIT extends ESIntegTestCase { public class ReloadSynonymAnalyzerIT extends ESIntegTestCase {
@Override @Override
@ -48,11 +46,24 @@ public class ReloadSynonymAnalyzerIT extends ESIntegTestCase {
return Settings.builder().put(super.nodeSettings(nodeOrdinal)).put(XPackSettings.SECURITY_ENABLED.getKey(), false).build(); 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 @Override
protected Collection<Class<? extends Plugin>> nodePlugins() { protected Collection<Class<? extends Plugin>> nodePlugins() {
return Arrays.asList(LocalStateCompositeXPackPlugin.class, CommonAnalysisPlugin.class); return Arrays.asList(LocalStateCompositeXPackPlugin.class, CommonAnalysisPlugin.class);
} }
/**
* Returns a collection of plugins that should be loaded when creating a transport client.
*/
@Override
protected Collection<Class<? extends Plugin>> 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 * 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} * {@link InternalTestCluster}
@ -66,10 +77,8 @@ public class ReloadSynonymAnalyzerIT extends ESIntegTestCase {
Path config = internalCluster().getInstance(Environment.class).configFile(); Path config = internalCluster().getInstance(Environment.class).configFile();
String synonymsFileName = "synonyms.txt"; String synonymsFileName = "synonyms.txt";
Path synonymsFile = config.resolve(synonymsFileName); Path synonymsFile = config.resolve(synonymsFileName);
Files.createFile(synonymsFile);
assertTrue(Files.exists(synonymsFile));
try (PrintWriter out = new PrintWriter( 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"); out.println("foo, baz");
} }
assertAcked(client().admin().indices().prepareCreate("test").setSettings(Settings.builder() assertAcked(client().admin().indices().prepareCreate("test").setSettings(Settings.builder()