Skip to content

Commit ca161b8

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

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

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

Lines changed: 17 additions & 1 deletion
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;
@@ -125,7 +127,6 @@
125127
import java.util.function.Supplier;
126128
import java.util.regex.Pattern;
127129
import java.util.stream.Collectors;
128-
129130
import javax.net.ssl.SSLContext;
130131

131132
import static java.util.Collections.sort;
@@ -160,6 +161,8 @@ public abstract class ESRestTestCase extends ESTestCase {
160161

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

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

0 commit comments

Comments
 (0)