Skip to content

Commit

Permalink
Perform precise check for types warnings in cluster restart tests. (#…
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
jtibshirani committed Feb 13, 2019
1 parent bab5311 commit d35a049
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,10 @@
import org.apache.http.util.EntityUtils;
import org.elasticsearch.Version;
import org.elasticsearch.client.Request;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.Response;
import org.elasticsearch.client.ResponseException;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.WarningFailureException;
import org.elasticsearch.client.WarningsHandler;
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.common.Booleans;
import org.elasticsearch.common.CheckedFunction;
Expand Down Expand Up @@ -125,11 +123,10 @@ public void testSearch() throws Exception {
mappingsAndSettings.endObject();
}
mappingsAndSettings.endObject();

Request createIndex = new Request("PUT", "/" + index);
createIndex.setJsonEntity(Strings.toString(mappingsAndSettings));
RequestOptions.Builder options = createIndex.getOptions().toBuilder();
options.setWarningsHandler(WarningsHandler.PERMISSIVE);
createIndex.setOptions(options);
createIndex.setOptions(allowTypesRemovalWarnings());
client().performRequest(createIndex);

count = randomIntBetween(2000, 3000);
Expand Down Expand Up @@ -183,11 +180,10 @@ public void testNewReplicasWork() throws Exception {
mappingsAndSettings.endObject();
}
mappingsAndSettings.endObject();

Request createIndex = new Request("PUT", "/" + index);
createIndex.setJsonEntity(Strings.toString(mappingsAndSettings));
RequestOptions.Builder options = createIndex.getOptions().toBuilder();
options.setWarningsHandler(WarningsHandler.PERMISSIVE);
createIndex.setOptions(options);
createIndex.setOptions(allowTypesRemovalWarnings());
client().performRequest(createIndex);

int numDocs = randomIntBetween(2000, 3000);
Expand Down Expand Up @@ -360,11 +356,10 @@ public void testShrink() throws IOException {
mappingsAndSettings.endObject();
}
mappingsAndSettings.endObject();

Request createIndex = new Request("PUT", "/" + index);
createIndex.setJsonEntity(Strings.toString(mappingsAndSettings));
RequestOptions.Builder options = createIndex.getOptions().toBuilder();
options.setWarningsHandler(WarningsHandler.PERMISSIVE);
createIndex.setOptions(options);
createIndex.setOptions(allowTypesRemovalWarnings());
client().performRequest(createIndex);

numDocs = randomIntBetween(512, 1024);
Expand Down Expand Up @@ -431,11 +426,10 @@ public void testShrinkAfterUpgrade() throws IOException {
mappingsAndSettings.endObject();
}
mappingsAndSettings.endObject();

Request createIndex = new Request("PUT", "/" + index);
createIndex.setJsonEntity(Strings.toString(mappingsAndSettings));
RequestOptions.Builder options = createIndex.getOptions().toBuilder();
options.setWarningsHandler(WarningsHandler.PERMISSIVE);
createIndex.setOptions(options);
createIndex.setOptions(allowTypesRemovalWarnings());
client().performRequest(createIndex);

numDocs = randomIntBetween(512, 1024);
Expand Down Expand Up @@ -518,7 +512,7 @@ public void testRollover() throws IOException {

if (isRunningAgainstOldCluster()) {
Request rolloverRequest = new Request("POST", "/" + index + "_write/_rollover");
rolloverRequest.setOptions(allowTypeRemovalWarnings());
rolloverRequest.setOptions(allowTypesRemovalWarnings());
rolloverRequest.setJsonEntity("{"
+ " \"conditions\": {"
+ " \"max_docs\": 5"
Expand Down Expand Up @@ -925,7 +919,7 @@ public void testSnapshotRestore() throws IOException {
if (isRunningAgainstOldCluster() == false) {
createTemplateRequest.addParameter(INCLUDE_TYPE_NAME_PARAMETER, "true");
}
createTemplateRequest.setOptions(allowTypeRemovalWarnings());
createTemplateRequest.setOptions(allowTypesRemovalWarnings());

client().performRequest(createTemplateRequest);

Expand Down Expand Up @@ -1135,7 +1129,7 @@ && getOldClusterVersion().onOrAfter(Version.V_6_1_0) && getOldClusterVersion().b
if (isRunningAgainstOldCluster() == false) {
getTemplateRequest.addParameter(INCLUDE_TYPE_NAME_PARAMETER, "true");
}
getTemplateRequest.setOptions(allowTypeRemovalWarnings());
getTemplateRequest.setOptions(allowTypesRemovalWarnings());

Map<String, Object> getTemplateResponse = entityAsMap(client().performRequest(getTemplateRequest));
Map<String, Object> expectedTemplate = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@

import org.apache.http.util.EntityUtils;
import org.elasticsearch.client.Request;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.Response;
import org.elasticsearch.client.WarningsHandler;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.io.stream.InputStreamStreamInput;
import org.elasticsearch.common.io.stream.NamedWriteableAwareStreamInput;
Expand Down Expand Up @@ -180,9 +178,7 @@ public void testQueryBuilderBWC() throws Exception {
}
mappingsAndSettings.endObject();
Request request = new Request("PUT", "/" + index);
RequestOptions.Builder options = request.getOptions().toBuilder();
options.setWarningsHandler(WarningsHandler.PERMISSIVE);
request.setOptions(options);
request.setOptions(allowTypesRemovalWarnings());
request.setJsonEntity(Strings.toString(mappingsAndSettings));
Response rsp = client().performRequest(request);
assertEquals(200, rsp.getStatusLine().getStatusCode());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,13 +256,13 @@ public static RequestOptions expectVersionSpecificWarnings(Consumer<VersionSensi
public static RequestOptions expectWarnings(String... warnings) {
return expectVersionSpecificWarnings(consumer -> consumer.current(warnings));
}

/**
* Creates RequestOptions designed to ignore [types removal] warnings but nothing else
* Creates RequestOptions designed to ignore [types removal] warnings but nothing else
* @deprecated this method is only required while we deprecate types and can be removed in 8.0
*/
@Deprecated
public static RequestOptions allowTypeRemovalWarnings() {
public static RequestOptions allowTypesRemovalWarnings() {
Builder builder = RequestOptions.DEFAULT.toBuilder();
builder.setWarningsHandler(new WarningsHandler() {
@Override
Expand All @@ -277,7 +277,7 @@ public boolean warningsShouldFailRequest(List<String> warnings) {
}
});
return builder.build();
}
}

/**
* Construct an HttpHost from the given host and port
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import org.elasticsearch.common.xcontent.XContentHelper;
import org.elasticsearch.common.xcontent.json.JsonXContent;
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.test.rest.ESRestTestCase;
import org.elasticsearch.xpack.core.ml.MlMetaIndex;
import org.elasticsearch.xpack.core.ml.job.persistence.AnomalyDetectorsIndex;
import org.elasticsearch.xpack.core.ml.job.persistence.AnomalyDetectorsIndexFields;
Expand All @@ -27,6 +26,8 @@
import java.util.Map;
import java.util.concurrent.atomic.AtomicReference;

import static org.elasticsearch.test.rest.ESRestTestCase.allowTypesRemovalWarnings;

public final class XPackRestTestHelper {

public static final List<String> ML_PRE_V660_TEMPLATES = Collections.unmodifiableList(
Expand Down Expand Up @@ -78,7 +79,7 @@ public static void waitForTemplates(RestClient client, List<String> templateName
Map<?, ?> response;
try {
final Request getRequest = new Request("GET", "_template/" + template);
getRequest.setOptions(ESRestTestCase.allowTypeRemovalWarnings());
getRequest.setOptions(allowTypesRemovalWarnings());
String string = EntityUtils.toString(client.performRequest(getRequest).getEntity());
response = XContentHelper.convertToMap(JsonXContent.jsonXContent, string, false);
} catch (ResponseException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@

import org.elasticsearch.Version;
import org.elasticsearch.client.Request;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.Response;
import org.elasticsearch.client.WarningsHandler;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.TimeValue;
Expand Down Expand Up @@ -72,9 +70,7 @@ private void createTestIndex() throws IOException {
"\"airline\": {\"type\": \"keyword\"}," +
"\"responsetime\": {\"type\": \"float\"}" +
"}}}}");
RequestOptions.Builder options = createTestIndex.getOptions().toBuilder();
options.setWarningsHandler(WarningsHandler.PERMISSIVE);
createTestIndex.setOptions(options);
createTestIndex.setOptions(allowTypesRemovalWarnings());
client().performRequest(createTestIndex);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public void setupForTests() throws Exception {
for (String template : templatesToWaitFor()) {
try {
final Request headRequest = new Request("HEAD", "_template/" + template);
headRequest.setOptions(allowTypeRemovalWarnings());
headRequest.setOptions(allowTypesRemovalWarnings());
final boolean exists = adminClient()
.performRequest(headRequest)
.getStatusLine().getStatusCode() == 200;
Expand Down

0 comments on commit d35a049

Please sign in to comment.