Skip to content

Commit

Permalink
Ignore 404-Not Found exceptions when cleaning up resources after tests (
Browse files Browse the repository at this point in the history
#73753) (#73760)

We're doing some clean up logic to delete indices, data streams, 
auto-follow patterns or searchable snapshot indices in some test 
classes after a test case is executed. Today we either fail or log 
a warning if the clean up failed but I think we should simply 
ignore the 404 - Not Found response exception, like we do in 
other places for regular indices.

Note that this change applies only:
- when cleaning up searchable snapshots indices in ESRestTestCase
- when cleaning up indices, data streams and auto-follow pattern in AutoFollowIT
  • Loading branch information
tlrx committed Jun 4, 2021
1 parent bd80cdd commit 32ea4fc
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -820,8 +820,14 @@ protected void wipeSearchableSnapshotsIndices() throws IOException {
Map<String, ?> indices = (Map<String, ?>) XContentMapValues.extractValue("metadata.indices", entityAsMap(response));
if (indices != null) {
for (String index : indices.keySet()) {
assertAcked("Failed to delete searchable snapshot index [" + index + ']',
adminClient().performRequest(new Request("DELETE", index)));
try {
assertAcked("Failed to delete searchable snapshot index [" + index + ']',
adminClient().performRequest(new Request("DELETE", index)));
} catch (ResponseException e) {
if (isNotFoundResponseException(e) == false) {
throw e;
}
}
}
}
}
Expand Down Expand Up @@ -1764,4 +1770,12 @@ protected static void useIgnoreMultipleMatchingTemplatesWarningsHandler(Request
});
request.setOptions(options);
}

protected static boolean isNotFoundResponseException(IOException ioe) {
if (ioe instanceof ResponseException) {
Response response = ((ResponseException) ioe).getResponse();
return response.getStatusLine().getStatusCode() == 404;
}
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -876,20 +876,29 @@ private void cleanUp(
try {
deleteAutoFollowPattern(client, autoFollowPattern);
} catch (IOException e) {
if (isNotFoundResponseException(e)) {
continue;
}
logger.warn(() -> new ParameterizedMessage("failed to delete auto-follow pattern [{}] after test", autoFollowPattern), e);
}
}
for (String dataStream : dataStreams) {
try {
deleteDataStream(client, dataStream);
} catch (IOException e) {
if (isNotFoundResponseException(e)) {
continue;
}
logger.warn(() -> new ParameterizedMessage("failed to delete data stream [{}] after test", dataStream), e);
}
}
for (String index : indices) {
try {
deleteIndex(client, index);
} catch (IOException e) {
if (isNotFoundResponseException(e)) {
continue;
}
logger.warn(() -> new ParameterizedMessage("failed to delete index [{}] after test", index), e);
}
}
Expand Down

0 comments on commit 32ea4fc

Please sign in to comment.