Skip to content

Commit acb8b43

Browse files
authored
Perform precise check for types warnings in cluster restart tests. (#37944)
Instead of using `WarningsHandler.PERMISSIVE`, we only match warnings that are due to types removal. This PR also renames `allowTypeRemovalWarnings` to `allowTypesRemovalWarnings`. Relates to #37920.
1 parent ef80728 commit acb8b43

File tree

6 files changed

+21
-35
lines changed

6 files changed

+21
-35
lines changed

qa/full-cluster-restart/src/test/java/org/elasticsearch/upgrades/FullClusterRestartIT.java

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,10 @@
2222
import org.apache.http.util.EntityUtils;
2323
import org.elasticsearch.Version;
2424
import org.elasticsearch.client.Request;
25-
import org.elasticsearch.client.RequestOptions;
2625
import org.elasticsearch.client.Response;
2726
import org.elasticsearch.client.ResponseException;
2827
import org.elasticsearch.client.RestClient;
2928
import org.elasticsearch.client.WarningFailureException;
30-
import org.elasticsearch.client.WarningsHandler;
3129
import org.elasticsearch.cluster.metadata.IndexMetaData;
3230
import org.elasticsearch.common.Booleans;
3331
import org.elasticsearch.common.CheckedFunction;
@@ -135,11 +133,10 @@ public void testSearch() throws Exception {
135133
mappingsAndSettings.endObject();
136134
}
137135
mappingsAndSettings.endObject();
136+
138137
Request createIndex = new Request("PUT", "/" + index);
139138
createIndex.setJsonEntity(Strings.toString(mappingsAndSettings));
140-
RequestOptions.Builder options = createIndex.getOptions().toBuilder();
141-
options.setWarningsHandler(WarningsHandler.PERMISSIVE);
142-
createIndex.setOptions(options);
139+
createIndex.setOptions(allowTypesRemovalWarnings());
143140
client().performRequest(createIndex);
144141

145142
count = randomIntBetween(2000, 3000);
@@ -200,11 +197,10 @@ public void testNewReplicasWork() throws Exception {
200197
mappingsAndSettings.endObject();
201198
}
202199
mappingsAndSettings.endObject();
200+
203201
Request createIndex = new Request("PUT", "/" + index);
204202
createIndex.setJsonEntity(Strings.toString(mappingsAndSettings));
205-
RequestOptions.Builder options = createIndex.getOptions().toBuilder();
206-
options.setWarningsHandler(WarningsHandler.PERMISSIVE);
207-
createIndex.setOptions(options);
203+
createIndex.setOptions(allowTypesRemovalWarnings());
208204
client().performRequest(createIndex);
209205

210206
int numDocs = randomIntBetween(2000, 3000);
@@ -320,12 +316,10 @@ public void testShrink() throws IOException {
320316
}
321317
}
322318
mappingsAndSettings.endObject();
319+
323320
Request createIndex = new Request("PUT", "/" + index);
324321
createIndex.setJsonEntity(Strings.toString(mappingsAndSettings));
325-
RequestOptions.Builder options = createIndex.getOptions().toBuilder();
326-
options.setWarningsHandler(WarningsHandler.PERMISSIVE);
327-
expectWarnings(RestIndexAction.TYPES_DEPRECATION_MESSAGE);
328-
createIndex.setOptions(options);
322+
createIndex.setOptions(allowTypesRemovalWarnings());
329323
client().performRequest(createIndex);
330324

331325
numDocs = randomIntBetween(512, 1024);
@@ -401,11 +395,10 @@ public void testShrinkAfterUpgrade() throws IOException {
401395
}
402396
}
403397
mappingsAndSettings.endObject();
398+
404399
Request createIndex = new Request("PUT", "/" + index);
405400
createIndex.setJsonEntity(Strings.toString(mappingsAndSettings));
406-
RequestOptions.Builder options = createIndex.getOptions().toBuilder();
407-
options.setWarningsHandler(WarningsHandler.PERMISSIVE);
408-
createIndex.setOptions(options);
401+
createIndex.setOptions(allowTypesRemovalWarnings());
409402
client().performRequest(createIndex);
410403

411404
numDocs = randomIntBetween(512, 1024);
@@ -489,7 +482,7 @@ public void testRollover() throws IOException {
489482

490483
if (isRunningAgainstOldCluster()) {
491484
Request rolloverRequest = new Request("POST", "/" + index + "_write/_rollover");
492-
rolloverRequest.setOptions(allowTypeRemovalWarnings());
485+
rolloverRequest.setOptions(allowTypesRemovalWarnings());
493486
rolloverRequest.setJsonEntity("{"
494487
+ " \"conditions\": {"
495488
+ " \"max_docs\": 5"
@@ -911,7 +904,7 @@ public void testSnapshotRestore() throws IOException {
911904
if (isRunningAgainstOldCluster() == false && getOldClusterVersion().major < 7) {
912905
createTemplateRequest.addParameter(INCLUDE_TYPE_NAME_PARAMETER, "true");
913906
}
914-
createTemplateRequest.setOptions(allowTypeRemovalWarnings());
907+
createTemplateRequest.setOptions(allowTypesRemovalWarnings());
915908

916909
client().performRequest(createTemplateRequest);
917910

@@ -1122,7 +1115,7 @@ && getOldClusterVersion().onOrAfter(Version.V_6_1_0) && getOldClusterVersion().b
11221115
if (isRunningAgainstAncientCluster() == false) {
11231116
getTemplateRequest.addParameter(INCLUDE_TYPE_NAME_PARAMETER, "true");
11241117
}
1125-
getTemplateRequest.setOptions(allowTypeRemovalWarnings());
1118+
getTemplateRequest.setOptions(allowTypesRemovalWarnings());
11261119

11271120
Map<String, Object> getTemplateResponse = entityAsMap(client().performRequest(getTemplateRequest));
11281121
Map<String, Object> expectedTemplate = new HashMap<>();

qa/full-cluster-restart/src/test/java/org/elasticsearch/upgrades/QueryBuilderBWCIT.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@
2222
import org.apache.http.util.EntityUtils;
2323
import org.elasticsearch.Version;
2424
import org.elasticsearch.client.Request;
25-
import org.elasticsearch.client.RequestOptions;
2625
import org.elasticsearch.client.Response;
27-
import org.elasticsearch.client.WarningsHandler;
2826
import org.elasticsearch.common.Strings;
2927
import org.elasticsearch.common.io.stream.InputStreamStreamInput;
3028
import org.elasticsearch.common.io.stream.NamedWriteableAwareStreamInput;
@@ -186,9 +184,7 @@ public void testQueryBuilderBWC() throws Exception {
186184
}
187185
mappingsAndSettings.endObject();
188186
Request request = new Request("PUT", "/" + index);
189-
RequestOptions.Builder options = request.getOptions().toBuilder();
190-
options.setWarningsHandler(WarningsHandler.PERMISSIVE);
191-
request.setOptions(options);
187+
request.setOptions(allowTypesRemovalWarnings());
192188
request.setJsonEntity(Strings.toString(mappingsAndSettings));
193189
Response rsp = client().performRequest(request);
194190
assertEquals(200, rsp.getStatusLine().getStatusCode());

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -256,13 +256,13 @@ public static RequestOptions expectVersionSpecificWarnings(Consumer<VersionSensi
256256
public static RequestOptions expectWarnings(String... warnings) {
257257
return expectVersionSpecificWarnings(consumer -> consumer.current(warnings));
258258
}
259-
259+
260260
/**
261-
* Creates RequestOptions designed to ignore [types removal] warnings but nothing else
261+
* Creates RequestOptions designed to ignore [types removal] warnings but nothing else
262262
* @deprecated this method is only required while we deprecate types and can be removed in 8.0
263263
*/
264264
@Deprecated
265-
public static RequestOptions allowTypeRemovalWarnings() {
265+
public static RequestOptions allowTypesRemovalWarnings() {
266266
Builder builder = RequestOptions.DEFAULT.toBuilder();
267267
builder.setWarningsHandler(new WarningsHandler() {
268268
@Override
@@ -277,7 +277,7 @@ public boolean warningsShouldFailRequest(List<String> warnings) {
277277
}
278278
});
279279
return builder.build();
280-
}
280+
}
281281

282282
/**
283283
* Construct an HttpHost from the given host and port

x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/test/rest/XPackRestTestHelper.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import org.elasticsearch.common.xcontent.XContentHelper;
1515
import org.elasticsearch.common.xcontent.json.JsonXContent;
1616
import org.elasticsearch.test.ESTestCase;
17-
import org.elasticsearch.test.rest.ESRestTestCase;
1817
import org.elasticsearch.xpack.core.ml.MlMetaIndex;
1918
import org.elasticsearch.xpack.core.ml.job.persistence.AnomalyDetectorsIndex;
2019
import org.elasticsearch.xpack.core.ml.job.persistence.AnomalyDetectorsIndexFields;
@@ -27,6 +26,8 @@
2726
import java.util.Map;
2827
import java.util.concurrent.atomic.AtomicReference;
2928

29+
import static org.elasticsearch.test.rest.ESRestTestCase.allowTypesRemovalWarnings;
30+
3031
public final class XPackRestTestHelper {
3132

3233
public static final List<String> ML_PRE_V660_TEMPLATES = Collections.unmodifiableList(
@@ -78,7 +79,7 @@ public static void waitForTemplates(RestClient client, List<String> templateName
7879
Map<?, ?> response;
7980
try {
8081
final Request getRequest = new Request("GET", "_template/" + template);
81-
getRequest.setOptions(ESRestTestCase.allowTypeRemovalWarnings());
82+
getRequest.setOptions(allowTypesRemovalWarnings());
8283
String string = EntityUtils.toString(client.performRequest(getRequest).getEntity());
8384
response = XContentHelper.convertToMap(JsonXContent.jsonXContent, string, false);
8485
} catch (ResponseException e) {

x-pack/qa/full-cluster-restart/src/test/java/org/elasticsearch/xpack/restart/MlMigrationFullClusterRestartIT.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@
77

88
import org.elasticsearch.Version;
99
import org.elasticsearch.client.Request;
10-
import org.elasticsearch.client.RequestOptions;
1110
import org.elasticsearch.client.Response;
12-
import org.elasticsearch.client.WarningsHandler;
1311
import org.elasticsearch.common.Strings;
1412
import org.elasticsearch.common.settings.Settings;
1513
import org.elasticsearch.common.unit.TimeValue;
@@ -72,9 +70,7 @@ private void createTestIndex() throws IOException {
7270
"\"airline\": {\"type\": \"keyword\"}," +
7371
"\"responsetime\": {\"type\": \"float\"}" +
7472
"}}}}");
75-
RequestOptions.Builder options = createTestIndex.getOptions().toBuilder();
76-
options.setWarningsHandler(WarningsHandler.PERMISSIVE);
77-
createTestIndex.setOptions(options);
73+
createTestIndex.setOptions(allowTypesRemovalWarnings());
7874
client().performRequest(createTestIndex);
7975
}
8076

x-pack/qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/AbstractUpgradeTestCase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public void setupForTests() throws Exception {
8787
for (String template : templatesToWaitFor()) {
8888
try {
8989
final Request headRequest = new Request("HEAD", "_template/" + template);
90-
headRequest.setOptions(allowTypeRemovalWarnings());
90+
headRequest.setOptions(allowTypesRemovalWarnings());
9191
final boolean exists = adminClient()
9292
.performRequest(headRequest)
9393
.getStatusLine().getStatusCode() == 200;

0 commit comments

Comments
 (0)