Skip to content

Commit

Permalink
Fiw when running with one node not available
Browse files Browse the repository at this point in the history
  • Loading branch information
dadoonet committed Feb 25, 2022
1 parent 4cd61ea commit 8df0e52
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ public ElasticsearchClient(Path config, FsSettings settings) {
hosts.add(node.decodedUrl());
initialHosts.add(node.decodedUrl());
});
if (hosts.size() == 1) {
// We have only one node so we won't have to select a specific one but the only one.
currentNode = 0;
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@

import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import java.util.Properties;

import static fr.pilato.elasticsearch.crawler.fs.client.ElasticsearchClient.CHECK_NODES_EVERY;
Expand Down Expand Up @@ -644,4 +645,24 @@ public void testWithNonRunningNodes() {
assertThat(ex.getMessage(), containsString("All nodes are failing"));
}
}

@Test
public void testWithNonRunningNode() {
// Build a client with a non-running node
Elasticsearch elasticsearch = Elasticsearch.builder()
.setNodes(List.of(new ServerUrl("http://127.0.0.1:9206")))
.setUsername(testClusterUser)
.setPassword(testClusterPass)
.build();
FsSettings fsSettings = FsSettings.builder("esClient").setElasticsearch(elasticsearch).build();

try (IElasticsearchClient localClient = new ElasticsearchClient(metadataDir, fsSettings)) {
localClient.start();
fail("We should have raised a " + ElasticsearchClientException.class.getSimpleName());
} catch (IOException ex) {
fail("We should have raised a " + ElasticsearchClientException.class.getSimpleName());
} catch (ElasticsearchClientException ex) {
assertThat(ex.getMessage(), containsString("All nodes are failing"));
}
}
}

0 comments on commit 8df0e52

Please sign in to comment.