@@ -168,10 +168,8 @@ public void testClusterHealthGreen() throws IOException {
168
168
assertThat (response .isTimedOut (), equalTo (false ));
169
169
assertThat (response .status (), equalTo (RestStatus .OK ));
170
170
assertThat (response .getStatus (), equalTo (ClusterHealthStatus .GREEN ));
171
- assertNoIndices (response );
172
171
}
173
172
174
- @ AwaitsFix (bugUrl ="https://github.com/elastic/elasticsearch/issues/35450" )
175
173
public void testClusterHealthYellowClusterLevel () throws IOException {
176
174
createIndex ("index" , Settings .EMPTY );
177
175
createIndex ("index2" , Settings .EMPTY );
@@ -182,14 +180,21 @@ public void testClusterHealthYellowClusterLevel() throws IOException {
182
180
183
181
logger .info ("Shard stats\n {}" , EntityUtils .toString (
184
182
client ().performRequest (new Request ("GET" , "/_cat/shards" )).getEntity ()));
185
- assertYellowShards (response );
186
183
assertThat (response .getIndices ().size (), equalTo (0 ));
187
184
}
188
185
189
186
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 );
193
198
request .timeout ("5s" );
194
199
request .level (ClusterHealthRequest .Level .INDICES );
195
200
ClusterHealthResponse response = execute (request , highLevelClient ().cluster ()::health , highLevelClient ().cluster ()::healthAsync );
@@ -215,7 +220,6 @@ private static void assertYellowShards(ClusterHealthResponse response) {
215
220
assertThat (response .getDelayedUnassignedShards (), equalTo (0 ));
216
221
assertThat (response .getInitializingShards (), equalTo (0 ));
217
222
assertThat (response .getUnassignedShards (), equalTo (10 ));
218
- assertThat (response .getActiveShardsPercent (), equalTo (50d ));
219
223
}
220
224
221
225
public void testClusterHealthYellowSpecificIndex () throws IOException {
@@ -236,7 +240,6 @@ public void testClusterHealthYellowSpecificIndex() throws IOException {
236
240
assertThat (response .getDelayedUnassignedShards (), equalTo (0 ));
237
241
assertThat (response .getInitializingShards (), equalTo (0 ));
238
242
assertThat (response .getUnassignedShards (), equalTo (5 ));
239
- assertThat (response .getActiveShardsPercent (), equalTo (50d ));
240
243
assertThat (response .getIndices ().size (), equalTo (1 ));
241
244
Map .Entry <String , ClusterIndexHealth > index = response .getIndices ().entrySet ().iterator ().next ();
242
245
assertYellowIndex (index .getKey (), index .getValue (), false );
@@ -272,7 +275,19 @@ private static void assertYellowShard(int shardId, ClusterShardHealth shardHealt
272
275
assertThat (shardHealth .getRelocatingShards (), equalTo (0 ));
273
276
}
274
277
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
+
275
289
public void testClusterHealthNotFoundIndex () throws IOException {
290
+ createIndex ("index" , Settings .EMPTY );
276
291
ClusterHealthRequest request = new ClusterHealthRequest ("notexisted-index" );
277
292
request .timeout ("5s" );
278
293
ClusterHealthResponse response = execute (request , highLevelClient ().cluster ()::health , highLevelClient ().cluster ()::healthAsync );
@@ -284,15 +299,4 @@ public void testClusterHealthNotFoundIndex() throws IOException {
284
299
assertNoIndices (response );
285
300
}
286
301
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
- }
298
302
}
0 commit comments