Skip to content

Commit 408a800

Browse files
author
Paul Sanwald
authored
ClusterClientIT refactor (elastic#38872) (elastic#39002)
Add fixes for ClusterClientIT test and unmute tests.
1 parent 204480d commit 408a800

File tree

1 file changed

+24
-22
lines changed

1 file changed

+24
-22
lines changed

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

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -165,10 +165,8 @@ public void testClusterHealthGreen() throws IOException {
165165
assertThat(response.isTimedOut(), equalTo(false));
166166
assertThat(response.status(), equalTo(RestStatus.OK));
167167
assertThat(response.getStatus(), equalTo(ClusterHealthStatus.GREEN));
168-
assertNoIndices(response);
169168
}
170169

171-
@AwaitsFix(bugUrl="https://github.com/elastic/elasticsearch/issues/35450")
172170
public void testClusterHealthYellowClusterLevel() throws IOException {
173171
createIndex("index", Settings.EMPTY);
174172
createIndex("index2", Settings.EMPTY);
@@ -178,15 +176,21 @@ public void testClusterHealthYellowClusterLevel() throws IOException {
178176

179177
logger.info("Shard stats\n{}", EntityUtils.toString(
180178
client().performRequest(new Request("GET", "/_cat/shards")).getEntity()));
181-
assertYellowShards(response);
182179
assertThat(response.getIndices().size(), equalTo(0));
183180
}
184181

185-
@AwaitsFix(bugUrl="https://github.com/elastic/elasticsearch/issues/35450")
186182
public void testClusterHealthYellowIndicesLevel() throws IOException {
187-
createIndex("index", Settings.EMPTY);
188-
createIndex("index2", Settings.EMPTY);
189-
ClusterHealthRequest request = new ClusterHealthRequest();
183+
String firstIndex = "index";
184+
String secondIndex = "index2";
185+
// including another index that we do not assert on, to ensure that we are not
186+
// accidentally asserting on entire cluster state
187+
String ignoredIndex = "tasks";
188+
createIndex(firstIndex, Settings.EMPTY);
189+
createIndex(secondIndex, Settings.EMPTY);
190+
if (randomBoolean()) {
191+
createIndex(ignoredIndex, Settings.EMPTY);
192+
}
193+
ClusterHealthRequest request = new ClusterHealthRequest(firstIndex, secondIndex);
190194
request.timeout("5s");
191195
request.level(ClusterHealthRequest.Level.INDICES);
192196
ClusterHealthResponse response = execute(request, highLevelClient().cluster()::health, highLevelClient().cluster()::healthAsync);
@@ -212,11 +216,9 @@ private static void assertYellowShards(ClusterHealthResponse response) {
212216
assertThat(response.getDelayedUnassignedShards(), equalTo(0));
213217
assertThat(response.getInitializingShards(), equalTo(0));
214218
assertThat(response.getUnassignedShards(), equalTo(2));
215-
assertThat(response.getActiveShardsPercent(), equalTo(50d));
216219
}
217220

218-
219-
@AwaitsFix(bugUrl="https://github.com/elastic/elasticsearch/issues/35450")
221+
220222
public void testClusterHealthYellowSpecificIndex() throws IOException {
221223
createIndex("index", Settings.EMPTY);
222224
createIndex("index2", Settings.EMPTY);
@@ -236,7 +238,6 @@ public void testClusterHealthYellowSpecificIndex() throws IOException {
236238
assertThat(response.getDelayedUnassignedShards(), equalTo(0));
237239
assertThat(response.getInitializingShards(), equalTo(0));
238240
assertThat(response.getUnassignedShards(), equalTo(1));
239-
assertThat(response.getActiveShardsPercent(), equalTo(50d));
240241
assertThat(response.getIndices().size(), equalTo(1));
241242
Map.Entry<String, ClusterIndexHealth> index = response.getIndices().entrySet().iterator().next();
242243
assertYellowIndex(index.getKey(), index.getValue(), false);
@@ -272,7 +273,19 @@ private static void assertYellowShard(int shardId, ClusterShardHealth shardHealt
272273
assertThat(shardHealth.getRelocatingShards(), equalTo(0));
273274
}
274275

276+
private static void assertNoIndices(ClusterHealthResponse response) {
277+
assertThat(response.getIndices(), equalTo(emptyMap()));
278+
assertThat(response.getActivePrimaryShards(), equalTo(0));
279+
assertThat(response.getNumberOfDataNodes(), equalTo(1));
280+
assertThat(response.getNumberOfNodes(), equalTo(1));
281+
assertThat(response.getActiveShards(), equalTo(0));
282+
assertThat(response.getDelayedUnassignedShards(), equalTo(0));
283+
assertThat(response.getInitializingShards(), equalTo(0));
284+
assertThat(response.getUnassignedShards(), equalTo(0));
285+
}
286+
275287
public void testClusterHealthNotFoundIndex() throws IOException {
288+
createIndex("index", Settings.EMPTY);
276289
ClusterHealthRequest request = new ClusterHealthRequest("notexisted-index");
277290
request.timeout("5s");
278291
ClusterHealthResponse response = execute(request, highLevelClient().cluster()::health, highLevelClient().cluster()::healthAsync);
@@ -284,15 +297,4 @@ public void testClusterHealthNotFoundIndex() throws IOException {
284297
assertNoIndices(response);
285298
}
286299

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-
}
298300
}

0 commit comments

Comments
 (0)