2626import org .apache .http .ssl .SSLContextBuilder ;
2727import org .apache .http .ssl .SSLContexts ;
2828import org .apache .http .util .EntityUtils ;
29+ import org .apache .logging .log4j .LogManager ;
30+ import org .apache .logging .log4j .Logger ;
2931import org .elasticsearch .Build ;
3032import org .elasticsearch .TransportVersion ;
3133import org .elasticsearch .TransportVersions ;
@@ -158,6 +160,8 @@ public abstract class ESRestTestCase extends ESTestCase {
158160
159161 private static final Pattern SEMANTIC_VERSION_PATTERN = Pattern .compile ("^(\\ d+\\ .\\ d+\\ .\\ d+)\\ D?.*" );
160162
163+ private static final Logger SUITE_LOGGER = LogManager .getLogger (ESRestTestCase .class );
164+
161165 /**
162166 * Convert the entity from a {@link Response} into a map of maps.
163167 * Consumes the underlying HttpEntity, releasing any resources it may be holding.
@@ -1111,7 +1115,14 @@ protected static void wipeAllIndices(boolean preserveSecurityIndices) throws IOE
11111115 }
11121116 final Request deleteRequest = new Request ("DELETE" , Strings .collectionToCommaDelimitedString (indexPatterns ));
11131117 deleteRequest .addParameter ("expand_wildcards" , "open,closed,hidden" );
1114- deleteRequest .setOptions (deleteRequest .getOptions ().toBuilder ().setWarningsHandler (ignoreAsyncSearchWarning ()).build ());
1118+
1119+ // If system index warning, ignore but log
1120+ // See: https://github.com/elastic/elasticsearch/issues/117099
1121+ // and: https://github.com/elastic/elasticsearch/issues/115809
1122+ deleteRequest .setOptions (
1123+ RequestOptions .DEFAULT .toBuilder ().setWarningsHandler (ESRestTestCase ::ignoreSystemIndexAccessWarnings )
1124+ );
1125+
11151126 final Response response = adminClient ().performRequest (deleteRequest );
11161127 try (InputStream is = response .getEntity ().getContent ()) {
11171128 assertTrue ((boolean ) XContentHelper .convertToMap (XContentType .JSON .xContent (), is , true ).get ("acknowledged" ));
@@ -1124,28 +1135,16 @@ protected static void wipeAllIndices(boolean preserveSecurityIndices) throws IOE
11241135 }
11251136 }
11261137
1127- // Make warnings handler that ignores the .async-search warning since .async-search may randomly appear when async requests are slow
1128- // See: https://github.com/elastic/elasticsearch/issues/117099
1129- protected static WarningsHandler ignoreAsyncSearchWarning () {
1130- return new WarningsHandler () {
1131- @ Override
1132- public boolean warningsShouldFailRequest (List <String > warnings ) {
1133- if (warnings .isEmpty ()) {
1134- return false ;
1135- }
1136- return warnings .equals (
1137- List .of (
1138- "this request accesses system indices: [.async-search], "
1139- + "but in a future major version, direct access to system indices will be prevented by default"
1140- )
1141- ) == false ;
1138+ private static boolean ignoreSystemIndexAccessWarnings (List <String > warnings ) {
1139+ for (String warning : warnings ) {
1140+ if (warning .startsWith ("this request accesses system indices:" )) {
1141+ SUITE_LOGGER .warn ("Ignoring system index access warning during test cleanup: {}" , warning );
1142+ } else {
1143+ return true ;
11421144 }
1145+ }
11431146
1144- @ Override
1145- public String toString () {
1146- return "ignore .async-search warning" ;
1147- }
1148- };
1147+ return false ;
11491148 }
11501149
11511150 protected static void wipeDataStreams () throws IOException {
0 commit comments