Acknowledge Indices Were Wiped Successfully in REST Tests (#45832) (#45842)

In internal test clusters tests we check that wiping all indices was acknowledged
but in REST tests we didn't.
This aligns the behavior in both kinds of tests.
Relates #45605 which might be caused by unacked deletes that were just slow.
This commit is contained in:
Armin Braun 2019-08-22 17:19:51 +02:00 committed by GitHub
parent a1b88ca009
commit bfddaaa2ae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 33 additions and 43 deletions

View File

@ -190,7 +190,7 @@ public abstract class ESRestTestCase extends ESTestCase {
} }
return cluster; return cluster;
} }
/** /**
* Helper class to check warnings in REST responses with sensitivity to versions * Helper class to check warnings in REST responses with sensitivity to versions
* used in the target cluster. * used in the target cluster.
@ -199,14 +199,14 @@ public abstract class ESRestTestCase extends ESTestCase {
Set<String> requiredSameVersionClusterWarnings = new HashSet<>(); Set<String> requiredSameVersionClusterWarnings = new HashSet<>();
Set<String> allowedWarnings = new HashSet<>(); Set<String> allowedWarnings = new HashSet<>();
final Set<Version> testNodeVersions; final Set<Version> testNodeVersions;
public VersionSensitiveWarningsHandler(Set<Version> nodeVersions) { public VersionSensitiveWarningsHandler(Set<Version> nodeVersions) {
this.testNodeVersions = nodeVersions; this.testNodeVersions = nodeVersions;
} }
/** /**
* Adds to the set of warnings that are all required in responses if the cluster * Adds to the set of warnings that are all required in responses if the cluster
* is formed from nodes all running the exact same version as the client. * is formed from nodes all running the exact same version as the client.
* @param requiredWarnings a set of required warnings * @param requiredWarnings a set of required warnings
*/ */
public void current(String... requiredWarnings) { public void current(String... requiredWarnings) {
@ -214,11 +214,11 @@ public abstract class ESRestTestCase extends ESTestCase {
} }
/** /**
* Adds to the set of warnings that are permissible (but not required) when running * Adds to the set of warnings that are permissible (but not required) when running
* in mixed-version clusters or those that differ in version from the test client. * in mixed-version clusters or those that differ in version from the test client.
* @param allowedWarnings optional warnings that will be ignored if received * @param allowedWarnings optional warnings that will be ignored if received
*/ */
public void compatible(String... allowedWarnings) { public void compatible(String... allowedWarnings) {
this.allowedWarnings.addAll(Arrays.asList(allowedWarnings)); this.allowedWarnings.addAll(Arrays.asList(allowedWarnings));
} }
@ -239,15 +239,15 @@ public abstract class ESRestTestCase extends ESTestCase {
return false; return false;
} }
} }
private boolean isExclusivelyTargetingCurrentVersionCluster() { private boolean isExclusivelyTargetingCurrentVersionCluster() {
assertFalse("Node versions running in the cluster are missing", testNodeVersions.isEmpty()); assertFalse("Node versions running in the cluster are missing", testNodeVersions.isEmpty());
return testNodeVersions.size() == 1 && return testNodeVersions.size() == 1 &&
testNodeVersions.iterator().next().equals(Version.CURRENT); testNodeVersions.iterator().next().equals(Version.CURRENT);
} }
} }
public static RequestOptions expectVersionSpecificWarnings(Consumer<VersionSensitiveWarningsHandler> expectationsSetter) { public static RequestOptions expectVersionSpecificWarnings(Consumer<VersionSensitiveWarningsHandler> expectationsSetter) {
Builder builder = RequestOptions.DEFAULT.toBuilder(); Builder builder = RequestOptions.DEFAULT.toBuilder();
VersionSensitiveWarningsHandler warningsHandler = new VersionSensitiveWarningsHandler(nodeVersions); VersionSensitiveWarningsHandler warningsHandler = new VersionSensitiveWarningsHandler(nodeVersions);
@ -513,14 +513,7 @@ public abstract class ESRestTestCase extends ESTestCase {
if (preserveIndicesUponCompletion() == false) { if (preserveIndicesUponCompletion() == false) {
// wipe indices // wipe indices
try { wipeAllIndices();
adminClient().performRequest(new Request("DELETE", "*"));
} catch (ResponseException e) {
// 404 here just means we had no indexes
if (e.getResponse().getStatusLine().getStatusCode() != 404) {
throw e;
}
}
} }
// wipe index templates // wipe index templates
@ -563,6 +556,20 @@ public abstract class ESRestTestCase extends ESTestCase {
assertThat("Found in progress snapshots [" + inProgressSnapshots.get() + "].", inProgressSnapshots.get(), anEmptyMap()); assertThat("Found in progress snapshots [" + inProgressSnapshots.get() + "].", inProgressSnapshots.get(), anEmptyMap());
} }
protected static void wipeAllIndices() throws IOException {
try {
final Response response = adminClient().performRequest(new Request("DELETE", "*"));
try (InputStream is = response.getEntity().getContent()) {
assertTrue((boolean) XContentHelper.convertToMap(XContentType.JSON.xContent(), is, true).get("acknowledged"));
}
} catch (ResponseException e) {
// 404 here just means we had no indexes
if (e.getResponse().getStatusLine().getStatusCode() != 404) {
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 * 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 * 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

View File

@ -355,7 +355,7 @@ public abstract class DataFrameRestTestCase extends ESRestTestCase {
public static void removeIndices() throws Exception { public static void removeIndices() throws Exception {
// we might have disabled wiping indices, but now its time to get rid of them // we might have disabled wiping indices, but now its time to get rid of them
// note: can not use super.cleanUpCluster() as this method must be static // note: can not use super.cleanUpCluster() as this method must be static
wipeIndices(); wipeAllIndices();
} }
public void wipeDataFrameTransforms() throws IOException { public void wipeDataFrameTransforms() throws IOException {
@ -403,17 +403,6 @@ public abstract class DataFrameRestTestCase extends ESRestTestCase {
waitForPendingTasks(adminClient(), taskName -> taskName.startsWith(DataFrameField.TASK_NAME) == false); waitForPendingTasks(adminClient(), taskName -> taskName.startsWith(DataFrameField.TASK_NAME) == false);
} }
protected static void wipeIndices() throws IOException {
try {
adminClient().performRequest(new Request("DELETE", "*"));
} catch (ResponseException e) {
// 404 here just means we had no indexes
if (e.getResponse().getStatusLine().getStatusCode() != 404) {
throw e;
}
}
}
static int getDataFrameCheckpoint(String transformId) throws IOException { static int getDataFrameCheckpoint(String transformId) throws IOException {
Response statsResponse = client().performRequest(new Request("GET", DATAFRAME_ENDPOINT + transformId + "/_stats")); Response statsResponse = client().performRequest(new Request("GET", DATAFRAME_ENDPOINT + transformId + "/_stats"));

View File

@ -13,7 +13,6 @@ import org.elasticsearch.action.admin.indices.get.GetIndexRequest;
import org.elasticsearch.action.fieldcaps.FieldCapabilitiesAction; import org.elasticsearch.action.fieldcaps.FieldCapabilitiesAction;
import org.elasticsearch.action.fieldcaps.FieldCapabilitiesRequest; import org.elasticsearch.action.fieldcaps.FieldCapabilitiesRequest;
import org.elasticsearch.client.Request; import org.elasticsearch.client.Request;
import org.elasticsearch.client.ResponseException;
import org.elasticsearch.common.Strings; import org.elasticsearch.common.Strings;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
@ -97,14 +96,14 @@ public abstract class SqlSecurityTestCase extends ESRestTestCase {
} }
return Paths.get(auditLogFileString); return Paths.get(auditLogFileString);
} }
@SuppressForbidden(reason="security doesn't work with mock filesystem") @SuppressForbidden(reason="security doesn't work with mock filesystem")
private static Path lookupRolledOverAuditLog() { private static Path lookupRolledOverAuditLog() {
String auditLogFileString = System.getProperty("tests.audit.yesterday.logfile"); String auditLogFileString = System.getProperty("tests.audit.yesterday.logfile");
if (null == auditLogFileString) { if (null == auditLogFileString) {
throw new IllegalStateException("tests.audit.yesterday.logfile must be set to run this test. It should be automatically " throw new IllegalStateException("tests.audit.yesterday.logfile must be set to run this test. It should be automatically "
+ "set by gradle."); + "set by gradle.");
} }
return Paths.get(auditLogFileString); return Paths.get(auditLogFileString);
} }
@ -120,7 +119,7 @@ public abstract class SqlSecurityTestCase extends ESRestTestCase {
* How much of the audit log was written before the test started. * How much of the audit log was written before the test started.
*/ */
private static long auditLogWrittenBeforeTestStart; private static long auditLogWrittenBeforeTestStart;
/** /**
* If the audit log file rolled over. This is a rare case possible only at midnight. * If the audit log file rolled over. This is a rare case possible only at midnight.
*/ */
@ -188,7 +187,7 @@ public abstract class SqlSecurityTestCase extends ESRestTestCase {
} catch (IOException e) { } catch (IOException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
// The log file can roll over without being caught by assertLogs() method: in those tests where exceptions are being handled // The log file can roll over without being caught by assertLogs() method: in those tests where exceptions are being handled
// and no audit logs being read (and, thus, assertLogs() is not called) - for example testNoMonitorMain() method: there are no // and no audit logs being read (and, thus, assertLogs() is not called) - for example testNoMonitorMain() method: there are no
// calls to auditLogs(), and the method could run while the audit file is rolled over. // calls to auditLogs(), and the method could run while the audit file is rolled over.
@ -205,12 +204,7 @@ public abstract class SqlSecurityTestCase extends ESRestTestCase {
@AfterClass @AfterClass
public static void wipeIndicesAfterTests() throws IOException { public static void wipeIndicesAfterTests() throws IOException {
try { try {
adminClient().performRequest(new Request("DELETE", "*")); wipeAllIndices();
} catch (ResponseException e) {
// 404 here just means we had no indexes
if (e.getResponse().getStatusLine().getStatusCode() != 404) {
throw e;
}
} finally { } finally {
// Clear the static state so other subclasses can reuse it later // Clear the static state so other subclasses can reuse it later
oneTimeSetup = false; oneTimeSetup = false;
@ -586,7 +580,7 @@ public abstract class SqlSecurityTestCase extends ESRestTestCase {
if (sm != null) { if (sm != null) {
sm.checkPermission(new SpecialPermission()); sm.checkPermission(new SpecialPermission());
} }
BufferedReader[] logReaders = new BufferedReader[2]; BufferedReader[] logReaders = new BufferedReader[2];
AccessController.doPrivileged((PrivilegedAction<Void>) () -> { AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
try { try {
@ -604,7 +598,7 @@ public abstract class SqlSecurityTestCase extends ESRestTestCase {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
}); });
// The "index" is used as a way of reading from both rolled over file and current audit file in order: rolled over file // The "index" is used as a way of reading from both rolled over file and current audit file in order: rolled over file
// first, then the audit log file. Very rarely we will read from the rolled over file: when the test happened to run // first, then the audit log file. Very rarely we will read from the rolled over file: when the test happened to run
// at midnight and the audit file rolled over during the test. // at midnight and the audit file rolled over during the test.