Skip to content

Commit 8faea7b

Browse files
Acknowledge Indices Were Wiped Successfully in REST Tests (#45832)
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.
1 parent c73a2ef commit 8faea7b

File tree

3 files changed

+33
-43
lines changed

3 files changed

+33
-43
lines changed

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

+25-18
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ protected String getTestRestCluster() {
190190
}
191191
return cluster;
192192
}
193-
193+
194194
/**
195195
* Helper class to check warnings in REST responses with sensitivity to versions
196196
* used in the target cluster.
@@ -199,26 +199,26 @@ public static class VersionSensitiveWarningsHandler implements WarningsHandler {
199199
Set<String> requiredSameVersionClusterWarnings = new HashSet<>();
200200
Set<String> allowedWarnings = new HashSet<>();
201201
final Set<Version> testNodeVersions;
202-
202+
203203
public VersionSensitiveWarningsHandler(Set<Version> nodeVersions) {
204204
this.testNodeVersions = nodeVersions;
205205
}
206206

207207
/**
208208
* Adds to the set of warnings that are all required in responses if the cluster
209-
* is formed from nodes all running the exact same version as the client.
209+
* is formed from nodes all running the exact same version as the client.
210210
* @param requiredWarnings a set of required warnings
211211
*/
212212
public void current(String... requiredWarnings) {
213213
requiredSameVersionClusterWarnings.addAll(Arrays.asList(requiredWarnings));
214214
}
215215

216216
/**
217-
* Adds to the set of warnings that are permissible (but not required) when running
217+
* Adds to the set of warnings that are permissible (but not required) when running
218218
* in mixed-version clusters or those that differ in version from the test client.
219219
* @param allowedWarnings optional warnings that will be ignored if received
220220
*/
221-
public void compatible(String... allowedWarnings) {
221+
public void compatible(String... allowedWarnings) {
222222
this.allowedWarnings.addAll(Arrays.asList(allowedWarnings));
223223
}
224224

@@ -239,15 +239,15 @@ public boolean warningsShouldFailRequest(List<String> warnings) {
239239
return false;
240240
}
241241
}
242-
242+
243243
private boolean isExclusivelyTargetingCurrentVersionCluster() {
244244
assertFalse("Node versions running in the cluster are missing", testNodeVersions.isEmpty());
245-
return testNodeVersions.size() == 1 &&
245+
return testNodeVersions.size() == 1 &&
246246
testNodeVersions.iterator().next().equals(Version.CURRENT);
247-
}
248-
247+
}
248+
249249
}
250-
250+
251251
public static RequestOptions expectVersionSpecificWarnings(Consumer<VersionSensitiveWarningsHandler> expectationsSetter) {
252252
Builder builder = RequestOptions.DEFAULT.toBuilder();
253253
VersionSensitiveWarningsHandler warningsHandler = new VersionSensitiveWarningsHandler(nodeVersions);
@@ -508,14 +508,7 @@ private void wipeCluster() throws Exception {
508508

509509
if (preserveIndicesUponCompletion() == false) {
510510
// wipe indices
511-
try {
512-
adminClient().performRequest(new Request("DELETE", "*"));
513-
} catch (ResponseException e) {
514-
// 404 here just means we had no indexes
515-
if (e.getResponse().getStatusLine().getStatusCode() != 404) {
516-
throw e;
517-
}
518-
}
511+
wipeAllIndices();
519512
}
520513

521514
// wipe index templates
@@ -558,6 +551,20 @@ private void wipeCluster() throws Exception {
558551
assertThat("Found in progress snapshots [" + inProgressSnapshots.get() + "].", inProgressSnapshots.get(), anEmptyMap());
559552
}
560553

554+
protected static void wipeAllIndices() throws IOException {
555+
try {
556+
final Response response = adminClient().performRequest(new Request("DELETE", "*"));
557+
try (InputStream is = response.getEntity().getContent()) {
558+
assertTrue((boolean) XContentHelper.convertToMap(XContentType.JSON.xContent(), is, true).get("acknowledged"));
559+
}
560+
} catch (ResponseException e) {
561+
// 404 here just means we had no indexes
562+
if (e.getResponse().getStatusLine().getStatusCode() != 404) {
563+
throw e;
564+
}
565+
}
566+
}
567+
561568
/**
562569
* Wipe fs snapshots we created one by one and all repositories so that the next test can create the repositories fresh and they'll
563570
* 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

x-pack/plugin/data-frame/qa/single-node-tests/src/test/java/org/elasticsearch/xpack/dataframe/integration/DataFrameRestTestCase.java

+1-12
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ public void waitForDataFrame() throws Exception {
355355
public static void removeIndices() throws Exception {
356356
// we might have disabled wiping indices, but now its time to get rid of them
357357
// note: can not use super.cleanUpCluster() as this method must be static
358-
wipeIndices();
358+
wipeAllIndices();
359359
}
360360

361361
public void wipeDataFrameTransforms() throws IOException {
@@ -403,17 +403,6 @@ protected static void waitForPendingDataFrameTasks() throws Exception {
403403
waitForPendingTasks(adminClient(), taskName -> taskName.startsWith(DataFrameField.TASK_NAME) == false);
404404
}
405405

406-
protected static void wipeIndices() throws IOException {
407-
try {
408-
adminClient().performRequest(new Request("DELETE", "*"));
409-
} catch (ResponseException e) {
410-
// 404 here just means we had no indexes
411-
if (e.getResponse().getStatusLine().getStatusCode() != 404) {
412-
throw e;
413-
}
414-
}
415-
}
416-
417406
static int getDataFrameCheckpoint(String transformId) throws IOException {
418407
Response statsResponse = client().performRequest(new Request("GET", DATAFRAME_ENDPOINT + transformId + "/_stats"));
419408

x-pack/plugin/sql/qa/security/src/test/java/org/elasticsearch/xpack/sql/qa/security/SqlSecurityTestCase.java

+7-13
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import org.elasticsearch.action.fieldcaps.FieldCapabilitiesAction;
1414
import org.elasticsearch.action.fieldcaps.FieldCapabilitiesRequest;
1515
import org.elasticsearch.client.Request;
16-
import org.elasticsearch.client.ResponseException;
1716
import org.elasticsearch.common.Strings;
1817
import org.elasticsearch.common.settings.Settings;
1918
import org.elasticsearch.common.xcontent.XContentBuilder;
@@ -97,14 +96,14 @@ private static Path lookupAuditLog() {
9796
}
9897
return Paths.get(auditLogFileString);
9998
}
100-
99+
101100
@SuppressForbidden(reason="security doesn't work with mock filesystem")
102101
private static Path lookupRolledOverAuditLog() {
103102
String auditLogFileString = System.getProperty("tests.audit.yesterday.logfile");
104103
if (null == auditLogFileString) {
105104
throw new IllegalStateException("tests.audit.yesterday.logfile must be set to run this test. It should be automatically "
106105
+ "set by gradle.");
107-
}
106+
}
108107
return Paths.get(auditLogFileString);
109108
}
110109

@@ -120,7 +119,7 @@ private static Path lookupRolledOverAuditLog() {
120119
* How much of the audit log was written before the test started.
121120
*/
122121
private static long auditLogWrittenBeforeTestStart;
123-
122+
124123
/**
125124
* If the audit log file rolled over. This is a rare case possible only at midnight.
126125
*/
@@ -188,7 +187,7 @@ public void setInitialAuditLogOffset() {
188187
} catch (IOException e) {
189188
throw new RuntimeException(e);
190189
}
191-
190+
192191
// The log file can roll over without being caught by assertLogs() method: in those tests where exceptions are being handled
193192
// and no audit logs being read (and, thus, assertLogs() is not called) - for example testNoMonitorMain() method: there are no
194193
// calls to auditLogs(), and the method could run while the audit file is rolled over.
@@ -205,12 +204,7 @@ public void setInitialAuditLogOffset() {
205204
@AfterClass
206205
public static void wipeIndicesAfterTests() throws IOException {
207206
try {
208-
adminClient().performRequest(new Request("DELETE", "*"));
209-
} catch (ResponseException e) {
210-
// 404 here just means we had no indexes
211-
if (e.getResponse().getStatusLine().getStatusCode() != 404) {
212-
throw e;
213-
}
207+
wipeAllIndices();
214208
} finally {
215209
// Clear the static state so other subclasses can reuse it later
216210
oneTimeSetup = false;
@@ -586,7 +580,7 @@ public void assertLogs() throws Exception {
586580
if (sm != null) {
587581
sm.checkPermission(new SpecialPermission());
588582
}
589-
583+
590584
BufferedReader[] logReaders = new BufferedReader[2];
591585
AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
592586
try {
@@ -604,7 +598,7 @@ public void assertLogs() throws Exception {
604598
throw new RuntimeException(e);
605599
}
606600
});
607-
601+
608602
// The "index" is used as a way of reading from both rolled over file and current audit file in order: rolled over file
609603
// first, then the audit log file. Very rarely we will read from the rolled over file: when the test happened to run
610604
// at midnight and the audit file rolled over during the test.

0 commit comments

Comments
 (0)