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.
@@ -1171,7 +1175,13 @@ protected static void wipeAllIndices(boolean preserveSecurityIndices) throws IOE
11711175 }
11721176 final Request deleteRequest = new Request ("DELETE" , Strings .collectionToCommaDelimitedString (indexPatterns ));
11731177 deleteRequest .addParameter ("expand_wildcards" , "open,closed" + (includeHidden ? ",hidden" : "" ));
1174- deleteRequest .setOptions (deleteRequest .getOptions ().toBuilder ().setWarningsHandler (ignoreAsyncSearchWarning ()).build ());
1178+
1179+ // If system index warning, ignore but log
1180+ // See: https://github.com/elastic/elasticsearch/issues/117099
1181+ // and: https://github.com/elastic/elasticsearch/issues/115809
1182+ deleteRequest .setOptions (
1183+ RequestOptions .DEFAULT .toBuilder ().setWarningsHandler (ESRestTestCase ::ignoreSystemIndexAccessWarnings )
1184+ );
11751185 final Response response = adminClient ().performRequest (deleteRequest );
11761186 try (InputStream is = response .getEntity ().getContent ()) {
11771187 assertTrue ((boolean ) XContentHelper .convertToMap (XContentType .JSON .xContent (), is , true ).get ("acknowledged" ));
@@ -1184,28 +1194,16 @@ protected static void wipeAllIndices(boolean preserveSecurityIndices) throws IOE
11841194 }
11851195 }
11861196
1187- // Make warnings handler that ignores the .async-search warning since .async-search may randomly appear when async requests are slow
1188- // See: https://github.com/elastic/elasticsearch/issues/117099
1189- protected static WarningsHandler ignoreAsyncSearchWarning () {
1190- return new WarningsHandler () {
1191- @ Override
1192- public boolean warningsShouldFailRequest (List <String > warnings ) {
1193- if (warnings .isEmpty ()) {
1194- return false ;
1195- }
1196- return warnings .equals (
1197- List .of (
1198- "this request accesses system indices: [.async-search], "
1199- + "but in a future major version, direct access to system indices will be prevented by default"
1200- )
1201- ) == false ;
1197+ private static boolean ignoreSystemIndexAccessWarnings (List <String > warnings ) {
1198+ for (String warning : warnings ) {
1199+ if (warning .startsWith ("this request accesses system indices:" )) {
1200+ SUITE_LOGGER .warn ("Ignoring system index access warning during test cleanup: {}" , warning );
1201+ } else {
1202+ return true ;
12021203 }
1204+ }
12031205
1204- @ Override
1205- public String toString () {
1206- return "ignore .async-search warning" ;
1207- }
1208- };
1206+ return false ;
12091207 }
12101208
12111209 protected static void wipeDataStreams () throws IOException {
0 commit comments