summaryrefslogtreecommitdiff
path: root/test/framework/src/main/java/org/elasticsearch
diff options
context:
space:
mode:
Diffstat (limited to 'test/framework/src/main/java/org/elasticsearch')
-rw-r--r--test/framework/src/main/java/org/elasticsearch/index/shard/IndexShardTestCase.java11
-rw-r--r--test/framework/src/main/java/org/elasticsearch/test/ESIntegTestCase.java7
-rw-r--r--test/framework/src/main/java/org/elasticsearch/test/ESTestCase.java2
-rw-r--r--test/framework/src/main/java/org/elasticsearch/test/XContentTestUtils.java2
-rw-r--r--test/framework/src/main/java/org/elasticsearch/test/rest/FakeRestChannel.java6
-rw-r--r--test/framework/src/main/java/org/elasticsearch/test/rest/FakeRestRequest.java44
-rw-r--r--test/framework/src/main/java/org/elasticsearch/test/rest/yaml/ClientYamlTestClient.java15
-rw-r--r--test/framework/src/main/java/org/elasticsearch/test/rest/yaml/ClientYamlTestExecutionContext.java4
-rw-r--r--test/framework/src/main/java/org/elasticsearch/test/rest/yaml/ClientYamlTestResponse.java18
-rw-r--r--test/framework/src/main/java/org/elasticsearch/test/rest/yaml/ClientYamlTestResponseException.java5
-rw-r--r--test/framework/src/main/java/org/elasticsearch/test/rest/yaml/ESClientYamlSuiteTestCase.java17
11 files changed, 86 insertions, 45 deletions
diff --git a/test/framework/src/main/java/org/elasticsearch/index/shard/IndexShardTestCase.java b/test/framework/src/main/java/org/elasticsearch/index/shard/IndexShardTestCase.java
index 1e716d4f16..20c869d38c 100644
--- a/test/framework/src/main/java/org/elasticsearch/index/shard/IndexShardTestCase.java
+++ b/test/framework/src/main/java/org/elasticsearch/index/shard/IndexShardTestCase.java
@@ -41,6 +41,7 @@ import org.elasticsearch.common.lucene.uid.Versions;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.ByteSizeUnit;
import org.elasticsearch.common.util.BigArrays;
+import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.env.NodeEnvironment;
import org.elasticsearch.index.IndexSettings;
import org.elasticsearch.index.MapperTestUtils;
@@ -473,17 +474,23 @@ public abstract class IndexShardTestCase extends ESTestCase {
}
protected Engine.Index indexDoc(IndexShard shard, String type, String id, String source) throws IOException {
+ return indexDoc(shard, type, id, source, XContentType.JSON);
+ }
+
+ protected Engine.Index indexDoc(IndexShard shard, String type, String id, String source, XContentType xContentType) throws IOException {
final Engine.Index index;
if (shard.routingEntry().primary()) {
index = shard.prepareIndexOnPrimary(
- SourceToParse.source(SourceToParse.Origin.PRIMARY, shard.shardId().getIndexName(), type, id, new BytesArray(source)),
+ SourceToParse.source(SourceToParse.Origin.PRIMARY, shard.shardId().getIndexName(), type, id, new BytesArray(source),
+ xContentType),
Versions.MATCH_ANY,
VersionType.INTERNAL,
IndexRequest.UNSET_AUTO_GENERATED_TIMESTAMP,
false);
} else {
index = shard.prepareIndexOnReplica(
- SourceToParse.source(SourceToParse.Origin.PRIMARY, shard.shardId().getIndexName(), type, id, new BytesArray(source)),
+ SourceToParse.source(SourceToParse.Origin.PRIMARY, shard.shardId().getIndexName(), type, id, new BytesArray(source),
+ xContentType),
randomInt(1 << 10), 1, VersionType.EXTERNAL, IndexRequest.UNSET_AUTO_GENERATED_TIMESTAMP, false);
}
shard.index(index);
diff --git a/test/framework/src/main/java/org/elasticsearch/test/ESIntegTestCase.java b/test/framework/src/main/java/org/elasticsearch/test/ESIntegTestCase.java
index 245ea6c08f..b1d66fd399 100644
--- a/test/framework/src/main/java/org/elasticsearch/test/ESIntegTestCase.java
+++ b/test/framework/src/main/java/org/elasticsearch/test/ESIntegTestCase.java
@@ -96,6 +96,7 @@ import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.common.xcontent.XContentHelper;
+import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.common.xcontent.json.JsonXContent;
import org.elasticsearch.common.xcontent.support.XContentMapValues;
import org.elasticsearch.discovery.Discovery;
@@ -1226,10 +1227,10 @@ public abstract class ESIntegTestCase extends ESTestCase {
* return client().prepareIndex(index, type, id).setSource(source).execute().actionGet();
* </pre>
* <p>
- * where source is a String.
+ * where source is a JSON String.
*/
protected final IndexResponse index(String index, String type, String id, String source) {
- return client().prepareIndex(index, type, id).setSource(source).execute().actionGet();
+ return client().prepareIndex(index, type, id).setSource(source, XContentType.JSON).execute().actionGet();
}
/**
@@ -1387,7 +1388,7 @@ public abstract class ESIntegTestCase extends ESTestCase {
String id = randomRealisticUnicodeOfLength(unicodeLen) + Integer.toString(dummmyDocIdGenerator.incrementAndGet());
String index = RandomPicks.randomFrom(random, indices);
bogusIds.add(new Tuple<>(index, id));
- builders.add(client().prepareIndex(index, RANDOM_BOGUS_TYPE, id).setSource("{}"));
+ builders.add(client().prepareIndex(index, RANDOM_BOGUS_TYPE, id).setSource("{}", XContentType.JSON));
}
}
final String[] indices = indicesSet.toArray(new String[indicesSet.size()]);
diff --git a/test/framework/src/main/java/org/elasticsearch/test/ESTestCase.java b/test/framework/src/main/java/org/elasticsearch/test/ESTestCase.java
index c7203f9719..633a04f5f6 100644
--- a/test/framework/src/main/java/org/elasticsearch/test/ESTestCase.java
+++ b/test/framework/src/main/java/org/elasticsearch/test/ESTestCase.java
@@ -294,7 +294,7 @@ public abstract class ESTestCase extends LuceneTestCase {
}
private void ensureNoWarnings() throws IOException {
- //Check that there are no unaccounted warning headers. These should be checked with {@link #checkWarningHeaders(String...)} in the
+ //Check that there are no unaccounted warning headers. These should be checked with {@link #assertWarnings(String...)} in the
//appropriate test
try {
final List<String> warnings = threadContext.getResponseHeaders().get(DeprecationLogger.WARNING_HEADER);
diff --git a/test/framework/src/main/java/org/elasticsearch/test/XContentTestUtils.java b/test/framework/src/main/java/org/elasticsearch/test/XContentTestUtils.java
index 31380e25eb..dcad7187fb 100644
--- a/test/framework/src/main/java/org/elasticsearch/test/XContentTestUtils.java
+++ b/test/framework/src/main/java/org/elasticsearch/test/XContentTestUtils.java
@@ -41,7 +41,7 @@ public final class XContentTestUtils {
builder.startObject();
part.toXContent(builder, EMPTY_PARAMS);
builder.endObject();
- return XContentHelper.convertToMap(builder.bytes(), false).v2();
+ return XContentHelper.convertToMap(builder.bytes(), false, builder.contentType()).v2();
}
diff --git a/test/framework/src/main/java/org/elasticsearch/test/rest/FakeRestChannel.java b/test/framework/src/main/java/org/elasticsearch/test/rest/FakeRestChannel.java
index 3d1ce29143..bca4af7bd6 100644
--- a/test/framework/src/main/java/org/elasticsearch/test/rest/FakeRestChannel.java
+++ b/test/framework/src/main/java/org/elasticsearch/test/rest/FakeRestChannel.java
@@ -19,9 +19,9 @@
package org.elasticsearch.test.rest;
import org.elasticsearch.common.Nullable;
-import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.io.stream.BytesStreamOutput;
import org.elasticsearch.common.xcontent.XContentBuilder;
+import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.rest.AbstractRestChannel;
import org.elasticsearch.rest.RestRequest;
import org.elasticsearch.rest.RestResponse;
@@ -53,8 +53,8 @@ public final class FakeRestChannel extends AbstractRestChannel {
}
@Override
- public XContentBuilder newBuilder(@Nullable BytesReference autoDetectSource, boolean useFiltering) throws IOException {
- return super.newBuilder(autoDetectSource, useFiltering);
+ public XContentBuilder newBuilder(@Nullable XContentType requestContentType, boolean useFiltering) throws IOException {
+ return super.newBuilder(requestContentType, useFiltering);
}
@Override
diff --git a/test/framework/src/main/java/org/elasticsearch/test/rest/FakeRestRequest.java b/test/framework/src/main/java/org/elasticsearch/test/rest/FakeRestRequest.java
index ae8c4c82c4..83caf0293e 100644
--- a/test/framework/src/main/java/org/elasticsearch/test/rest/FakeRestRequest.java
+++ b/test/framework/src/main/java/org/elasticsearch/test/rest/FakeRestRequest.java
@@ -21,28 +21,31 @@ package org.elasticsearch.test.rest;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
+import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.rest.RestRequest;
+import java.net.SocketAddress;
+import java.util.Collections;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
public class FakeRestRequest extends RestRequest {
- private final Map<String, String> headers;
private final BytesReference content;
private final Method method;
-
+ private final SocketAddress remoteAddress;
public FakeRestRequest() {
- this(NamedXContentRegistry.EMPTY, new HashMap<>(), new HashMap<>(), null, Method.GET, "/");
+ this(NamedXContentRegistry.EMPTY, new HashMap<>(), new HashMap<>(), null, Method.GET, "/", null);
}
- private FakeRestRequest(NamedXContentRegistry xContentRegistry, Map<String, String> headers, Map<String, String> params,
- BytesReference content, Method method, String path) {
- super(xContentRegistry, params, path);
- this.headers = headers;
+ private FakeRestRequest(NamedXContentRegistry xContentRegistry, Map<String, List<String>> headers, Map<String, String> params,
+ BytesReference content, Method method, String path, SocketAddress remoteAddress) {
+ super(xContentRegistry, params, path, headers);
this.content = content;
this.method = method;
+ this.remoteAddress = remoteAddress;
}
@Override
@@ -66,19 +69,14 @@ public class FakeRestRequest extends RestRequest {
}
@Override
- public String header(String name) {
- return headers.get(name);
- }
-
- @Override
- public Iterable<Map.Entry<String, String>> headers() {
- return headers.entrySet();
+ public SocketAddress getRemoteAddress() {
+ return remoteAddress;
}
public static class Builder {
private final NamedXContentRegistry xContentRegistry;
- private Map<String, String> headers = new HashMap<>();
+ private Map<String, List<String>> headers = new HashMap<>();
private Map<String, String> params = new HashMap<>();
@@ -88,11 +86,13 @@ public class FakeRestRequest extends RestRequest {
private Method method = Method.GET;
+ private SocketAddress address = null;
+
public Builder(NamedXContentRegistry xContentRegistry) {
this.xContentRegistry = xContentRegistry;
}
- public Builder withHeaders(Map<String, String> headers) {
+ public Builder withHeaders(Map<String, List<String>> headers) {
this.headers = headers;
return this;
}
@@ -102,8 +102,11 @@ public class FakeRestRequest extends RestRequest {
return this;
}
- public Builder withContent(BytesReference content) {
+ public Builder withContent(BytesReference content, XContentType xContentType) {
this.content = content;
+ if (xContentType != null) {
+ headers.put("Content-Type", Collections.singletonList(xContentType.mediaType()));
+ }
return this;
}
@@ -117,8 +120,13 @@ public class FakeRestRequest extends RestRequest {
return this;
}
+ public Builder withRemoteAddress(SocketAddress address) {
+ this.address = address;
+ return this;
+ }
+
public FakeRestRequest build() {
- return new FakeRestRequest(xContentRegistry, headers, params, content, method, path);
+ return new FakeRestRequest(xContentRegistry, headers, params, content, method, path, address);
}
}
diff --git a/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/ClientYamlTestClient.java b/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/ClientYamlTestClient.java
index c18dad907b..aa51efaa33 100644
--- a/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/ClientYamlTestClient.java
+++ b/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/ClientYamlTestClient.java
@@ -55,13 +55,15 @@ public class ClientYamlTestClient {
private final ClientYamlSuiteRestSpec restSpec;
private final RestClient restClient;
private final Version esVersion;
+ private final Map<HttpHost, Version> hostVersionMap;
public ClientYamlTestClient(ClientYamlSuiteRestSpec restSpec, RestClient restClient, List<HttpHost> hosts,
- Version esVersion) throws IOException {
+ Version esVersion, Map<HttpHost, Version> hostVersionMap) throws IOException {
assert hosts.size() > 0;
this.restSpec = restSpec;
this.restClient = restClient;
this.esVersion = esVersion;
+ this.hostVersionMap = hostVersionMap;
}
public Version getEsVersion() {
@@ -86,9 +88,9 @@ public class ClientYamlTestClient {
// And everything else is a url parameter!
try {
Response response = restClient.performRequest(method, path, queryStringParams, entity);
- return new ClientYamlTestResponse(response);
+ return new ClientYamlTestResponse(response, hostVersionMap.get(response.getHost()));
} catch(ResponseException e) {
- throw new ClientYamlTestResponseException(e);
+ throw new ClientYamlTestResponseException(e, hostVersionMap.get(e.getResponse().getHost()));
}
}
@@ -122,6 +124,9 @@ public class ClientYamlTestClient {
if (supportedMethods.contains("GET") && RandomizedTest.rarely()) {
logger.debug("sending the request body as source param with GET method");
queryStringParams.put("source", body);
+ if (esVersion.after(Version.V_5_3_0_UNRELEASED)) { // TODO make onOrAfter with backport
+ queryStringParams.put("source_content_type", ContentType.APPLICATION_JSON.toString());
+ }
requestMethod = "GET";
} else {
requestMethod = RandomizedTest.randomFrom(supportedMethods);
@@ -168,9 +173,9 @@ public class ClientYamlTestClient {
logger.debug("calling api [{}]", apiName);
try {
Response response = restClient.performRequest(requestMethod, requestPath, queryStringParams, requestBody, requestHeaders);
- return new ClientYamlTestResponse(response);
+ return new ClientYamlTestResponse(response, hostVersionMap.get(response.getHost()));
} catch(ResponseException e) {
- throw new ClientYamlTestResponseException(e);
+ throw new ClientYamlTestResponseException(e, hostVersionMap.get(e.getResponse().getHost()));
}
}
diff --git a/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/ClientYamlTestExecutionContext.java b/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/ClientYamlTestExecutionContext.java
index 8215105887..27653a13f2 100644
--- a/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/ClientYamlTestExecutionContext.java
+++ b/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/ClientYamlTestExecutionContext.java
@@ -71,9 +71,9 @@ public class ClientYamlTestExecutionContext {
throw e;
} finally {
// if we hit a bad exception the response is null
- Object repsponseBody = response != null ? response.getBody() : null;
+ Object responseBody = response != null ? response.getBody() : null;
//we always stash the last response body
- stash.stashValue("body", repsponseBody);
+ stash.stashValue("body", responseBody);
}
}
diff --git a/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/ClientYamlTestResponse.java b/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/ClientYamlTestResponse.java
index 481ae752d0..f47cfd68d4 100644
--- a/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/ClientYamlTestResponse.java
+++ b/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/ClientYamlTestResponse.java
@@ -21,6 +21,7 @@ package org.elasticsearch.test.rest.yaml;
import org.apache.http.Header;
import org.apache.http.client.methods.HttpHead;
import org.apache.http.util.EntityUtils;
+import org.elasticsearch.Version;
import org.elasticsearch.client.Response;
import org.elasticsearch.common.xcontent.XContentType;
@@ -37,10 +38,12 @@ public class ClientYamlTestResponse {
private final Response response;
private final String body;
+ private final Version nodeVersion;
private ObjectPath parsedResponse;
- ClientYamlTestResponse(Response response) throws IOException {
+ ClientYamlTestResponse(Response response, Version version) throws IOException {
this.response = response;
+ this.nodeVersion = version;
if (response.getEntity() != null) {
try {
this.body = EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8);
@@ -80,7 +83,18 @@ public class ClientYamlTestResponse {
List<String> warningHeaders = new ArrayList<>();
for (Header header : response.getHeaders()) {
if (header.getName().equals("Warning")) {
- warningHeaders.add(header.getValue());
+ if (nodeVersion.after(Version.V_5_3_0_UNRELEASED) && response.getRequestLine().getMethod().equals("GET")
+ && response.getRequestLine().getUri().contains("source")
+ && response.getRequestLine().getUri().contains("source_content_type") == false && header.getValue().startsWith(
+ "Deprecated use of the [source] parameter without the [source_content_type] parameter.")) {
+ // this is because we do not send the source content type header when the node is 5.3.0 or below and the request
+ // might have been sent to a node with a version > 5.3.0 when running backwards 5.0 tests. The Java RestClient
+ // has control of the node the request is sent to so we can only detect this after the fact right now
+ // TODO remove this when we bump versions
+ } else {
+ warningHeaders.add(header.getValue());
+ }
+
}
}
return warningHeaders;
diff --git a/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/ClientYamlTestResponseException.java b/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/ClientYamlTestResponseException.java
index 7d983d4802..48a7ee578d 100644
--- a/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/ClientYamlTestResponseException.java
+++ b/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/ClientYamlTestResponseException.java
@@ -19,6 +19,7 @@
package org.elasticsearch.test.rest.yaml;
+import org.elasticsearch.Version;
import org.elasticsearch.client.ResponseException;
import java.io.IOException;
@@ -32,10 +33,10 @@ public class ClientYamlTestResponseException extends IOException {
private final ClientYamlTestResponse restTestResponse;
private final ResponseException responseException;
- ClientYamlTestResponseException(ResponseException responseException) throws IOException {
+ ClientYamlTestResponseException(ResponseException responseException, Version version) throws IOException {
super(responseException);
this.responseException = responseException;
- this.restTestResponse = new ClientYamlTestResponse(responseException.getResponse());
+ this.restTestResponse = new ClientYamlTestResponse(responseException.getResponse(), version);
}
/**
diff --git a/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/ESClientYamlSuiteTestCase.java b/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/ESClientYamlSuiteTestCase.java
index a45d92c969..411f657329 100644
--- a/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/ESClientYamlSuiteTestCase.java
+++ b/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/ESClientYamlSuiteTestCase.java
@@ -53,6 +53,7 @@ import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
import java.util.ArrayList;
import java.util.Collections;
+import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -125,6 +126,7 @@ public abstract class ESClientYamlSuiteTestCase extends ESRestTestCase {
validateSpec(restSpec);
List<HttpHost> hosts = getClusterHosts();
RestClient restClient = client();
+ Tuple<Version, Map<HttpHost, Version>> versionMapTuple = readVersionsFromInfo(restClient, hosts.size());
Version esVersion;
try {
Tuple<Version, Version> versionVersionTuple = readVersionsFromCatNodes(restClient);
@@ -135,13 +137,14 @@ public abstract class ESClientYamlSuiteTestCase extends ESRestTestCase {
} catch (ResponseException ex) {
if (ex.getResponse().getStatusLine().getStatusCode() == 403) {
logger.warn("Fallback to simple info '/' request, _cat/nodes is not authorized");
- esVersion = readVersionsFromInfo(restClient, hosts.size());
+ esVersion = versionMapTuple.v1();
logger.info("initializing yaml client, minimum es version: [{}] hosts: {}", esVersion, hosts);
} else {
throw ex;
}
}
- ClientYamlTestClient clientYamlTestClient = new ClientYamlTestClient(restSpec, restClient, hosts, esVersion);
+ ClientYamlTestClient clientYamlTestClient =
+ new ClientYamlTestClient(restSpec, restClient, hosts, esVersion, versionMapTuple.v2());
restTestExecutionContext = new ClientYamlTestExecutionContext(clientYamlTestClient);
adminExecutionContext = new ClientYamlTestExecutionContext(clientYamlTestClient);
String[] blacklist = resolvePathsProperty(REST_TESTS_BLACKLIST, null);
@@ -290,7 +293,7 @@ public abstract class ESClientYamlSuiteTestCase extends ESRestTestCase {
private static Tuple<Version, Version> readVersionsFromCatNodes(RestClient restClient) throws IOException {
// we simply go to the _cat/nodes API and parse all versions in the cluster
Response response = restClient.performRequest("GET", "/_cat/nodes", Collections.singletonMap("h", "version,master"));
- ClientYamlTestResponse restTestResponse = new ClientYamlTestResponse(response);
+ ClientYamlTestResponse restTestResponse = new ClientYamlTestResponse(response, Version.CURRENT);
String nodesCatResponse = restTestResponse.getBodyAsString();
String[] split = nodesCatResponse.split("\n");
Version version = null;
@@ -313,12 +316,13 @@ public abstract class ESClientYamlSuiteTestCase extends ESRestTestCase {
return new Tuple<>(version, masterVersion);
}
- private static Version readVersionsFromInfo(RestClient restClient, int numHosts) throws IOException {
+ private static Tuple<Version, Map<HttpHost, Version>> readVersionsFromInfo(RestClient restClient, int numHosts) throws IOException {
Version version = null;
+ Map<HttpHost, Version> hostVersionMap = new HashMap<>();
for (int i = 0; i < numHosts; i++) {
//we don't really use the urls here, we rely on the client doing round-robin to touch all the nodes in the cluster
Response response = restClient.performRequest("GET", "/");
- ClientYamlTestResponse restTestResponse = new ClientYamlTestResponse(response);
+ ClientYamlTestResponse restTestResponse = new ClientYamlTestResponse(response, Version.CURRENT);
Object latestVersion = restTestResponse.evaluate("version.number");
if (latestVersion == null) {
throw new RuntimeException("elasticsearch version not found in the response");
@@ -329,8 +333,9 @@ public abstract class ESClientYamlSuiteTestCase extends ESRestTestCase {
} else if (version.onOrAfter(currentVersion)) {
version = currentVersion;
}
+ hostVersionMap.put(response.getHost(), currentVersion);
}
- return version;
+ return new Tuple<>(version, Collections.unmodifiableMap(hostVersionMap));
}
public void test() throws IOException {