Skip to content

Commit c706836

Browse files
committed
Ignore system index access errors in YAML test index cleanup method
1 parent 830c504 commit c706836

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

test/framework/src/main/java/org/elasticsearch/test/rest/ESRestTestCase.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
import org.apache.http.ssl.SSLContextBuilder;
2727
import org.apache.http.ssl.SSLContexts;
2828
import org.apache.http.util.EntityUtils;
29+
import org.apache.logging.log4j.LogManager;
30+
import org.apache.logging.log4j.Logger;
2931
import org.elasticsearch.Build;
3032
import org.elasticsearch.TransportVersion;
3133
import org.elasticsearch.TransportVersions;
@@ -160,6 +162,8 @@ public abstract class ESRestTestCase extends ESTestCase {
160162

161163
private static final Pattern SEMANTIC_VERSION_PATTERN = Pattern.compile("^(\\d+\\.\\d+\\.\\d+)\\D?.*");
162164

165+
private static final Logger SUITE_LOGGER = LogManager.getLogger(ESRestTestCase.class);
166+
163167
/**
164168
* Convert the entity from a {@link Response} into a map of maps.
165169
* Consumes the underlying HttpEntity, releasing any resources it may be holding.
@@ -1131,6 +1135,19 @@ protected static void wipeAllIndices(boolean preserveSecurityIndices) throws IOE
11311135
}
11321136
final Request deleteRequest = new Request("DELETE", Strings.collectionToCommaDelimitedString(indexPatterns));
11331137
deleteRequest.addParameter("expand_wildcards", "open,closed,hidden");
1138+
1139+
// If system index warning, ignore but log
1140+
deleteRequest.setOptions(RequestOptions.DEFAULT.toBuilder().setWarningsHandler(warnings -> {
1141+
for (String warning : warnings) {
1142+
if (warning.startsWith("this request accesses system indices:")) {
1143+
SUITE_LOGGER.warn("Ignoring system index access warning during test cleanup: {}", warning);
1144+
} else {
1145+
return true;
1146+
}
1147+
}
1148+
return false;
1149+
}));
1150+
11341151
final Response response = adminClient().performRequest(deleteRequest);
11351152
try (InputStream is = response.getEntity().getContent()) {
11361153
assertTrue((boolean) XContentHelper.convertToMap(XContentType.JSON.xContent(), is, true).get("acknowledged"));

0 commit comments

Comments
 (0)