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 ;
@@ -168,7 +169,7 @@ public void testGeoIpSystemFeaturesMigration() throws Exception {
168169 @ SuppressWarnings ("unchecked" )
169170 private void testDatabasesLoaded () throws IOException {
170171 Request getTaskState = new Request ("GET" , "/_cluster/state" );
171- ObjectPath state = ObjectPath .createFromResponse (client ().performRequest (getTaskState ));
172+ ObjectPath state = ObjectPath .createFromResponse (assertOK ( client ().performRequest (getTaskState ) ));
172173
173174 List <?> tasks = state .evaluate ("metadata.persistent_tasks.tasks" );
174175 // Short-circuit to avoid using steams if the list is empty
@@ -194,7 +195,10 @@ private void testDatabasesLoaded() throws IOException {
194195
195196 private void testCatIndices (List <String > indexNames , @ Nullable List <String > additionalIndexNames ) throws IOException {
196197 Request catIndices = new Request ("GET" , "_cat/indices/*?s=index&h=index&expand_wildcards=all" );
197- String response = EntityUtils .toString (client ().performRequest (catIndices ).getEntity ());
198+ // the cat APIs can sometimes 404, erroneously
199+ // see https://github.com/elastic/elasticsearch/issues/104371
200+ setIgnoredErrorResponseCodes (catIndices , RestStatus .NOT_FOUND );
201+ String response = EntityUtils .toString (assertOK (client ().performRequest (catIndices )).getEntity ());
198202 List <String > indices = List .of (response .trim ().split ("\\ s+" ));
199203
200204 if (additionalIndexNames != null && additionalIndexNames .isEmpty () == false ) {
@@ -213,7 +217,7 @@ private void testIndexGeoDoc() throws IOException {
213217 assertOK (client ().performRequest (putDoc ));
214218
215219 Request getDoc = new Request ("GET" , "/my-index-00001/_doc/my_id" );
216- ObjectPath doc = ObjectPath .createFromResponse (client ().performRequest (getDoc ));
220+ ObjectPath doc = ObjectPath .createFromResponse (assertOK ( client ().performRequest (getDoc ) ));
217221 assertNull (doc .evaluate ("_source.tags" ));
218222 assertEquals ("Sweden" , doc .evaluate ("_source.geo.country_name" ));
219223 }
@@ -223,8 +227,7 @@ private void testGetStar(List<String> indexNames, @Nullable List<String> additio
223227 getStar .setOptions (
224228 RequestOptions .DEFAULT .toBuilder ().setWarningsHandler (WarningsHandler .PERMISSIVE ) // we don't care about warnings, just errors
225229 );
226- Response response = client ().performRequest (getStar );
227- assertOK (response );
230+ Response response = assertOK (client ().performRequest (getStar ));
228231
229232 if (additionalIndexNames != null && additionalIndexNames .isEmpty () == false ) {
230233 indexNames = new ArrayList <>(indexNames ); // recopy into a mutable list
@@ -242,8 +245,7 @@ private void testGetStarAsKibana(List<String> indexNames, @Nullable List<String>
242245 .addHeader ("X-elastic-product-origin" , "kibana" )
243246 .setWarningsHandler (WarningsHandler .PERMISSIVE ) // we don't care about warnings, just errors
244247 );
245- Response response = client ().performRequest (getStar );
246- assertOK (response );
248+ Response response = assertOK (client ().performRequest (getStar ));
247249
248250 if (additionalIndexNames != null && additionalIndexNames .isEmpty () == false ) {
249251 indexNames = new ArrayList <>(indexNames ); // recopy into a mutable list
0 commit comments