Skip to content

Commit 47806ec

Browse files
author
Paul Sanwald
authored
backport ClusterClientIT fix (elastic#39005)
1 parent b986526 commit 47806ec

File tree

1 file changed

+23
-19
lines changed

1 file changed

+23
-19
lines changed

client/rest-high-level/src/test/java/org/elasticsearch/client/ClusterClientIT.java

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -168,10 +168,8 @@ public void testClusterHealthGreen() throws IOException {
168168
assertThat(response.isTimedOut(), equalTo(false));
169169
assertThat(response.status(), equalTo(RestStatus.OK));
170170
assertThat(response.getStatus(), equalTo(ClusterHealthStatus.GREEN));
171-
assertNoIndices(response);
172171
}
173172

174-
@AwaitsFix(bugUrl="https://github.com/elastic/elasticsearch/issues/35450")
175173
public void testClusterHealthYellowClusterLevel() throws IOException {
176174
createIndex("index", Settings.EMPTY);
177175
createIndex("index2", Settings.EMPTY);
@@ -182,14 +180,21 @@ public void testClusterHealthYellowClusterLevel() throws IOException {
182180

183181
logger.info("Shard stats\n{}", EntityUtils.toString(
184182
client().performRequest(new Request("GET", "/_cat/shards")).getEntity()));
185-
assertYellowShards(response);
186183
assertThat(response.getIndices().size(), equalTo(0));
187184
}
188185

189186
public void testClusterHealthYellowIndicesLevel() throws IOException {
190-
createIndex("index", Settings.EMPTY);
191-
createIndex("index2", Settings.EMPTY);
192-
ClusterHealthRequest request = new ClusterHealthRequest();
187+
String firstIndex = "index";
188+
String secondIndex = "index2";
189+
// including another index that we do not assert on, to ensure that we are not
190+
// accidentally asserting on entire cluster state
191+
String ignoredIndex = "tasks";
192+
createIndex(firstIndex, Settings.EMPTY);
193+
createIndex(secondIndex, Settings.EMPTY);
194+
if (randomBoolean()) {
195+
createIndex(ignoredIndex, Settings.EMPTY);
196+
}
197+
ClusterHealthRequest request = new ClusterHealthRequest(firstIndex, secondIndex);
193198
request.timeout("5s");
194199
request.level(ClusterHealthRequest.Level.INDICES);
195200
ClusterHealthResponse response = execute(request, highLevelClient().cluster()::health, highLevelClient().cluster()::healthAsync);
@@ -215,7 +220,6 @@ private static void assertYellowShards(ClusterHealthResponse response) {
215220
assertThat(response.getDelayedUnassignedShards(), equalTo(0));
216221
assertThat(response.getInitializingShards(), equalTo(0));
217222
assertThat(response.getUnassignedShards(), equalTo(10));
218-
assertThat(response.getActiveShardsPercent(), equalTo(50d));
219223
}
220224

221225
public void testClusterHealthYellowSpecificIndex() throws IOException {
@@ -236,7 +240,6 @@ public void testClusterHealthYellowSpecificIndex() throws IOException {
236240
assertThat(response.getDelayedUnassignedShards(), equalTo(0));
237241
assertThat(response.getInitializingShards(), equalTo(0));
238242
assertThat(response.getUnassignedShards(), equalTo(5));
239-
assertThat(response.getActiveShardsPercent(), equalTo(50d));
240243
assertThat(response.getIndices().size(), equalTo(1));
241244
Map.Entry<String, ClusterIndexHealth> index = response.getIndices().entrySet().iterator().next();
242245
assertYellowIndex(index.getKey(), index.getValue(), false);
@@ -272,7 +275,19 @@ private static void assertYellowShard(int shardId, ClusterShardHealth shardHealt
272275
assertThat(shardHealth.getRelocatingShards(), equalTo(0));
273276
}
274277

278+
private static void assertNoIndices(ClusterHealthResponse response) {
279+
assertThat(response.getIndices(), equalTo(emptyMap()));
280+
assertThat(response.getActivePrimaryShards(), equalTo(0));
281+
assertThat(response.getNumberOfDataNodes(), equalTo(1));
282+
assertThat(response.getNumberOfNodes(), equalTo(1));
283+
assertThat(response.getActiveShards(), equalTo(0));
284+
assertThat(response.getDelayedUnassignedShards(), equalTo(0));
285+
assertThat(response.getInitializingShards(), equalTo(0));
286+
assertThat(response.getUnassignedShards(), equalTo(0));
287+
}
288+
275289
public void testClusterHealthNotFoundIndex() throws IOException {
290+
createIndex("index", Settings.EMPTY);
276291
ClusterHealthRequest request = new ClusterHealthRequest("notexisted-index");
277292
request.timeout("5s");
278293
ClusterHealthResponse response = execute(request, highLevelClient().cluster()::health, highLevelClient().cluster()::healthAsync);
@@ -284,15 +299,4 @@ public void testClusterHealthNotFoundIndex() throws IOException {
284299
assertNoIndices(response);
285300
}
286301

287-
private static void assertNoIndices(ClusterHealthResponse response) {
288-
assertThat(response.getIndices(), equalTo(emptyMap()));
289-
assertThat(response.getActivePrimaryShards(), equalTo(0));
290-
assertThat(response.getNumberOfDataNodes(), equalTo(1));
291-
assertThat(response.getNumberOfNodes(), equalTo(1));
292-
assertThat(response.getActiveShards(), equalTo(0));
293-
assertThat(response.getDelayedUnassignedShards(), equalTo(0));
294-
assertThat(response.getInitializingShards(), equalTo(0));
295-
assertThat(response.getUnassignedShards(), equalTo(0));
296-
assertThat(response.getActiveShardsPercent(), equalTo(100d));
297-
}
298302
}

0 commit comments

Comments
 (0)