Skip to content

Commit ba78aa8

Browse files
committed
Merge branch 'master' into ccr
* master: Deprecates indexing and querying a context completion field without context (#30712) Refactor Sniffer and make it testable (#29638) [Docs] Fix typo in Min Aggregation reference (#30899)
2 parents fa54be2 + 0f5e570 commit ba78aa8

File tree

16 files changed

+1015
-101
lines changed

16 files changed

+1015
-101
lines changed

client/rest/src/main/java/org/elasticsearch/client/RestClient.java

+9-1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
import java.util.HashMap;
6262
import java.util.HashSet;
6363
import java.util.Iterator;
64+
import java.util.LinkedHashSet;
6465
import java.util.List;
6566
import java.util.Locale;
6667
import java.util.Map;
@@ -132,7 +133,7 @@ public synchronized void setHosts(HttpHost... hosts) {
132133
if (hosts == null || hosts.length == 0) {
133134
throw new IllegalArgumentException("hosts must not be null nor empty");
134135
}
135-
Set<HttpHost> httpHosts = new HashSet<>();
136+
Set<HttpHost> httpHosts = new LinkedHashSet<>();
136137
AuthCache authCache = new BasicAuthCache();
137138
for (HttpHost host : hosts) {
138139
Objects.requireNonNull(host, "host cannot be null");
@@ -143,6 +144,13 @@ public synchronized void setHosts(HttpHost... hosts) {
143144
this.blacklist.clear();
144145
}
145146

147+
/**
148+
* Returns the configured hosts
149+
*/
150+
public List<HttpHost> getHosts() {
151+
return new ArrayList<>(hostTuple.hosts);
152+
}
153+
146154
/**
147155
* Sends a request to the Elasticsearch cluster that the client points to.
148156
* Blocks until the request is completed and returns its response or fails

client/rest/src/test/java/org/elasticsearch/client/RestClientTests.java

+32
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
import java.io.IOException;
2727
import java.net.URI;
28+
import java.util.Arrays;
2829
import java.util.Collections;
2930
import java.util.concurrent.CountDownLatch;
3031
import java.util.concurrent.TimeUnit;
@@ -251,6 +252,37 @@ public void testSetHostsWrongArguments() throws IOException {
251252
}
252253
}
253254

255+
public void testSetHostsPreservesOrdering() throws Exception {
256+
try (RestClient restClient = createRestClient()) {
257+
HttpHost[] hosts = randomHosts();
258+
restClient.setHosts(hosts);
259+
assertEquals(Arrays.asList(hosts), restClient.getHosts());
260+
}
261+
}
262+
263+
private static HttpHost[] randomHosts() {
264+
int numHosts = randomIntBetween(1, 10);
265+
HttpHost[] hosts = new HttpHost[numHosts];
266+
for (int i = 0; i < hosts.length; i++) {
267+
hosts[i] = new HttpHost("host-" + i, 9200);
268+
}
269+
return hosts;
270+
}
271+
272+
public void testSetHostsDuplicatedHosts() throws Exception {
273+
try (RestClient restClient = createRestClient()) {
274+
int numHosts = randomIntBetween(1, 10);
275+
HttpHost[] hosts = new HttpHost[numHosts];
276+
HttpHost host = new HttpHost("host", 9200);
277+
for (int i = 0; i < hosts.length; i++) {
278+
hosts[i] = host;
279+
}
280+
restClient.setHosts(hosts);
281+
assertEquals(1, restClient.getHosts().size());
282+
assertEquals(host, restClient.getHosts().get(0));
283+
}
284+
}
285+
254286
/**
255287
* @deprecated will remove method in 7.0 but needs tests until then. Replaced by {@link RequestTests#testConstructor()}.
256288
*/

client/sniffer/src/main/java/org/elasticsearch/client/sniff/SniffOnFailureListener.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ public void onFailure(HttpHost host) {
5858
if (sniffer == null) {
5959
throw new IllegalStateException("sniffer was not set, unable to sniff on failure");
6060
}
61-
//re-sniff immediately but take out the node that failed
62-
sniffer.sniffOnFailure(host);
61+
sniffer.sniffOnFailure();
6362
}
6463
}

0 commit comments

Comments
 (0)