2020import org .elasticsearch .common .settings .Settings ;
2121import org .elasticsearch .common .util .concurrent .ThreadContext ;
2222import org .elasticsearch .core .Nullable ;
23+ import org .elasticsearch .rest .RestStatus ;
2324import org .elasticsearch .test .cluster .ElasticsearchCluster ;
2425import org .elasticsearch .test .cluster .FeatureFlag ;
2526import org .elasticsearch .test .cluster .local .distribution .DistributionType ;
@@ -170,7 +171,7 @@ public void testGeoIpSystemFeaturesMigration() throws Exception {
170171 @ SuppressWarnings ("unchecked" )
171172 private void testDatabasesLoaded () throws IOException {
172173 Request getTaskState = new Request ("GET" , "/_cluster/state" );
173- ObjectPath state = ObjectPath .createFromResponse (client ().performRequest (getTaskState ));
174+ ObjectPath state = ObjectPath .createFromResponse (assertOK ( client ().performRequest (getTaskState ) ));
174175
175176 List <?> tasks = state .evaluate ("metadata.persistent_tasks.tasks" );
176177 // Short-circuit to avoid using steams if the list is empty
@@ -196,7 +197,10 @@ private void testDatabasesLoaded() throws IOException {
196197
197198 private void testCatIndices (List <String > indexNames , @ Nullable List <String > additionalIndexNames ) throws IOException {
198199 Request catIndices = new Request ("GET" , "_cat/indices/*?s=index&h=index&expand_wildcards=all" );
199- String response = EntityUtils .toString (client ().performRequest (catIndices ).getEntity ());
200+ // the cat APIs can sometimes 404, erroneously
201+ // see https://github.com/elastic/elasticsearch/issues/104371
202+ setIgnoredErrorResponseCodes (catIndices , RestStatus .NOT_FOUND );
203+ String response = EntityUtils .toString (assertOK (client ().performRequest (catIndices )).getEntity ());
200204 List <String > indices = List .of (response .trim ().split ("\\ s+" ));
201205
202206 if (additionalIndexNames != null && additionalIndexNames .isEmpty () == false ) {
@@ -215,7 +219,7 @@ private void testIndexGeoDoc() throws IOException {
215219 assertOK (client ().performRequest (putDoc ));
216220
217221 Request getDoc = new Request ("GET" , "/my-index-00001/_doc/my_id" );
218- ObjectPath doc = ObjectPath .createFromResponse (client ().performRequest (getDoc ));
222+ ObjectPath doc = ObjectPath .createFromResponse (assertOK ( client ().performRequest (getDoc ) ));
219223 assertNull (doc .evaluate ("_source.tags" ));
220224 assertEquals ("Sweden" , doc .evaluate ("_source.geo.country_name" ));
221225 }
@@ -225,8 +229,7 @@ private void testGetStar(List<String> indexNames, @Nullable List<String> additio
225229 getStar .setOptions (
226230 RequestOptions .DEFAULT .toBuilder ().setWarningsHandler (WarningsHandler .PERMISSIVE ) // we don't care about warnings, just errors
227231 );
228- Response response = client ().performRequest (getStar );
229- assertOK (response );
232+ Response response = assertOK (client ().performRequest (getStar ));
230233
231234 if (additionalIndexNames != null && additionalIndexNames .isEmpty () == false ) {
232235 indexNames = new ArrayList <>(indexNames ); // recopy into a mutable list
@@ -244,8 +247,7 @@ private void testGetStarAsKibana(List<String> indexNames, @Nullable List<String>
244247 .addHeader ("X-elastic-product-origin" , "kibana" )
245248 .setWarningsHandler (WarningsHandler .PERMISSIVE ) // we don't care about warnings, just errors
246249 );
247- Response response = client ().performRequest (getStar );
248- assertOK (response );
250+ Response response = assertOK (client ().performRequest (getStar ));
249251
250252 if (additionalIndexNames != null && additionalIndexNames .isEmpty () == false ) {
251253 indexNames = new ArrayList <>(indexNames ); // recopy into a mutable list
0 commit comments