Skip to content

Commit

Permalink
Fix ReloadSynonymAnalyzerIT failure (#53663) (#53807)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Christoph Büscher committed Mar 19, 2020
1 parent 76693b0 commit 6504baf
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public Set<String> getReloadedAnalyzers() {
}

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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -40,19 +39,31 @@
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
protected Settings nodeSettings(int nodeOrdinal) {
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<Class<? extends Plugin>> 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<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
* {@link InternalTestCluster}
Expand All @@ -66,10 +77,8 @@ public void testSynonymsUpdateable() throws FileNotFoundException, IOException,
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()
Expand Down

0 comments on commit 6504baf

Please sign in to comment.