[7.x] Wipe data streams in each REST test ()

This commit is contained in:
Dan Hermann 2020-04-15 07:27:39 -05:00 committed by GitHub
parent 9ec9866acb
commit 30638a0b41
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -438,6 +438,15 @@ public abstract class ESRestTestCase extends ESTestCase {
return false;
}
/**
* Determines if data streams are preserved upon completion of this test. The default implementation wipes data streams.
*
* @return whether or not to preserve data streams
*/
protected boolean preserveDataStreamsUponCompletion() {
return false;
}
/**
* Controls whether or not to preserve cluster settings upon completion of the test. The default implementation is to remove all cluster
* settings.
@ -551,6 +560,11 @@ public abstract class ESRestTestCase extends ESTestCase {
inProgressSnapshots.set(wipeSnapshots());
}
// wipe data streams before indices so that the backing indices for data streams are handled properly
if (preserveDataStreamsUponCompletion() == false) {
wipeDataStreams();
}
if (preserveIndicesUponCompletion() == false) {
// wipe indices
wipeAllIndices();
@ -629,6 +643,17 @@ public abstract class ESRestTestCase extends ESTestCase {
}
}
protected static void wipeDataStreams() throws IOException {
try {
adminClient().performRequest(new Request("DELETE", "_data_stream/*"));
} catch (ResponseException e) {
// We hit a version of ES that doesn't have data streams enabled so it's safe to ignore
if (e.getResponse().getStatusLine().getStatusCode() != 405 && e.getResponse().getStatusLine().getStatusCode() != 500) {
throw e;
}
}
}
/**
* Wipe fs snapshots we created one by one and all repositories so that the next test can create the repositories fresh and they'll
* start empty. There isn't an API to delete all snapshots. There is an API to delete all snapshot repositories but that leaves all of