diff --git a/build.gradle b/build.gradle index c2bf6c9309f..f1b57d7857b 100644 --- a/build.gradle +++ b/build.gradle @@ -166,6 +166,7 @@ subprojects { "org.elasticsearch.client:rest:${version}": ':client:rest', "org.elasticsearch.client:sniffer:${version}": ':client:sniffer', "org.elasticsearch.client:test:${version}": ':client:test', + "org.elasticsearch.client:transport:${version}": ':client:transport', "org.elasticsearch.test:framework:${version}": ':test:framework', "org.elasticsearch.distribution.integ-test-zip:elasticsearch:${version}": ':distribution:integ-test-zip', "org.elasticsearch.distribution.zip:elasticsearch:${version}": ':distribution:zip', diff --git a/client/sniffer/src/main/java/org/elasticsearch/client/sniff/ElasticsearchHostsSniffer.java b/client/sniffer/src/main/java/org/elasticsearch/client/sniff/ElasticsearchHostsSniffer.java new file mode 100644 index 00000000000..34a49883586 --- /dev/null +++ b/client/sniffer/src/main/java/org/elasticsearch/client/sniff/ElasticsearchHostsSniffer.java @@ -0,0 +1,170 @@ +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.client.sniff; + +import com.fasterxml.jackson.core.JsonFactory; +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.core.JsonToken; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.http.HttpEntity; +import org.apache.http.HttpHost; +import org.elasticsearch.client.Response; +import org.elasticsearch.client.RestClient; + +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.concurrent.TimeUnit; + +/** + * Class responsible for sniffing the http hosts from elasticsearch through the nodes info api and returning them back. + * Compatible with elasticsearch 5.x and 2.x. + */ +public final class ElasticsearchHostsSniffer implements HostsSniffer { + + private static final Log logger = LogFactory.getLog(ElasticsearchHostsSniffer.class); + + public static final long DEFAULT_SNIFF_REQUEST_TIMEOUT = TimeUnit.SECONDS.toMillis(1); + + private final RestClient restClient; + private final Map sniffRequestParams; + private final Scheme scheme; + private final JsonFactory jsonFactory = new JsonFactory(); + + /** + * Creates a new instance of the Elasticsearch sniffer. It will use the provided {@link RestClient} to fetch the hosts, + * through the nodes info api, the default sniff request timeout value {@link #DEFAULT_SNIFF_REQUEST_TIMEOUT} and http + * as the scheme for all the hosts. + * @param restClient client used to fetch the hosts from elasticsearch through nodes info api. Usually the same instance + * that is also provided to {@link Sniffer#builder(RestClient)}, so that the hosts are set to the same + * client that was used to fetch them. + */ + public ElasticsearchHostsSniffer(RestClient restClient) { + this(restClient, DEFAULT_SNIFF_REQUEST_TIMEOUT, ElasticsearchHostsSniffer.Scheme.HTTP); + } + + /** + * Creates a new instance of the Elasticsearch sniffer. It will use the provided {@link RestClient} to fetch the hosts + * through the nodes info api, the provided sniff request timeout value and scheme. + * @param restClient client used to fetch the hosts from elasticsearch through nodes info api. Usually the same instance + * that is also provided to {@link Sniffer#builder(RestClient)}, so that the hosts are set to the same + * client that was used to sniff them. + * @param sniffRequestTimeoutMillis the sniff request timeout (in milliseconds) to be passed in as a query string parameter + * to elasticsearch. Allows to halt the request without any failure, as only the nodes + * that have responded within this timeout will be returned. + * @param scheme the scheme to associate sniffed nodes with (as it is not returned by elasticsearch) + */ + public ElasticsearchHostsSniffer(RestClient restClient, long sniffRequestTimeoutMillis, Scheme scheme) { + this.restClient = Objects.requireNonNull(restClient, "restClient cannot be null"); + if (sniffRequestTimeoutMillis < 0) { + throw new IllegalArgumentException("sniffRequestTimeoutMillis must be greater than 0"); + } + this.sniffRequestParams = Collections.singletonMap("timeout", sniffRequestTimeoutMillis + "ms"); + this.scheme = Objects.requireNonNull(scheme, "scheme cannot be null"); + } + + /** + * Calls the elasticsearch nodes info api, parses the response and returns all the found http hosts + */ + public List sniffHosts() throws IOException { + Response response = restClient.performRequest("get", "/_nodes/http", sniffRequestParams); + return readHosts(response.getEntity()); + } + + private List readHosts(HttpEntity entity) throws IOException { + try (InputStream inputStream = entity.getContent()) { + JsonParser parser = jsonFactory.createParser(inputStream); + if (parser.nextToken() != JsonToken.START_OBJECT) { + throw new IOException("expected data to start with an object"); + } + List hosts = new ArrayList<>(); + while (parser.nextToken() != JsonToken.END_OBJECT) { + if (parser.getCurrentToken() == JsonToken.START_OBJECT) { + if ("nodes".equals(parser.getCurrentName())) { + while (parser.nextToken() != JsonToken.END_OBJECT) { + JsonToken token = parser.nextToken(); + assert token == JsonToken.START_OBJECT; + String nodeId = parser.getCurrentName(); + HttpHost sniffedHost = readHost(nodeId, parser, this.scheme); + if (sniffedHost != null) { + logger.trace("adding node [" + nodeId + "]"); + hosts.add(sniffedHost); + } + } + } else { + parser.skipChildren(); + } + } + } + return hosts; + } + } + + private static HttpHost readHost(String nodeId, JsonParser parser, Scheme scheme) throws IOException { + HttpHost httpHost = null; + String fieldName = null; + while (parser.nextToken() != JsonToken.END_OBJECT) { + if (parser.getCurrentToken() == JsonToken.FIELD_NAME) { + fieldName = parser.getCurrentName(); + } else if (parser.getCurrentToken() == JsonToken.START_OBJECT) { + if ("http".equals(fieldName)) { + while (parser.nextToken() != JsonToken.END_OBJECT) { + if (parser.getCurrentToken() == JsonToken.VALUE_STRING && "publish_address".equals(parser.getCurrentName())) { + URI boundAddressAsURI = URI.create(scheme + "://" + parser.getValueAsString()); + httpHost = new HttpHost(boundAddressAsURI.getHost(), boundAddressAsURI.getPort(), + boundAddressAsURI.getScheme()); + } else if (parser.getCurrentToken() == JsonToken.START_OBJECT) { + parser.skipChildren(); + } + } + } else { + parser.skipChildren(); + } + } + } + //http section is not present if http is not enabled on the node, ignore such nodes + if (httpHost == null) { + logger.debug("skipping node [" + nodeId + "] with http disabled"); + return null; + } + return httpHost; + } + + public enum Scheme { + HTTP("http"), HTTPS("https"); + + private final String name; + + Scheme(String name) { + this.name = name; + } + + @Override + public String toString() { + return name; + } + } +} diff --git a/client/sniffer/src/main/java/org/elasticsearch/client/sniff/HostsSniffer.java b/client/sniffer/src/main/java/org/elasticsearch/client/sniff/HostsSniffer.java index d5b2c67ee02..9eb7b344259 100644 --- a/client/sniffer/src/main/java/org/elasticsearch/client/sniff/HostsSniffer.java +++ b/client/sniffer/src/main/java/org/elasticsearch/client/sniff/HostsSniffer.java @@ -19,175 +19,17 @@ package org.elasticsearch.client.sniff; -import com.fasterxml.jackson.core.JsonFactory; -import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.core.JsonToken; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.apache.http.HttpEntity; import org.apache.http.HttpHost; -import org.elasticsearch.client.Response; -import org.elasticsearch.client.RestClient; import java.io.IOException; -import java.io.InputStream; -import java.net.URI; -import java.util.ArrayList; -import java.util.Collections; import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.concurrent.TimeUnit; /** - * Class responsible for sniffing the http hosts from elasticsearch through the nodes info api and returning them back. - * Compatible with elasticsearch 5.x and 2.x. + * Responsible for sniffing the http hosts */ -public class HostsSniffer { - - private static final Log logger = LogFactory.getLog(HostsSniffer.class); - - private final RestClient restClient; - private final Map sniffRequestParams; - private final Scheme scheme; - private final JsonFactory jsonFactory = new JsonFactory(); - - protected HostsSniffer(RestClient restClient, long sniffRequestTimeoutMillis, Scheme scheme) { - this.restClient = restClient; - this.sniffRequestParams = Collections.singletonMap("timeout", sniffRequestTimeoutMillis + "ms"); - this.scheme = scheme; - } - +public interface HostsSniffer { /** - * Calls the elasticsearch nodes info api, parses the response and returns all the found http hosts + * Returns the sniffed http hosts */ - public List sniffHosts() throws IOException { - Response response = restClient.performRequest("get", "/_nodes/http", sniffRequestParams); - return readHosts(response.getEntity()); - } - - private List readHosts(HttpEntity entity) throws IOException { - try (InputStream inputStream = entity.getContent()) { - JsonParser parser = jsonFactory.createParser(inputStream); - if (parser.nextToken() != JsonToken.START_OBJECT) { - throw new IOException("expected data to start with an object"); - } - List hosts = new ArrayList<>(); - while (parser.nextToken() != JsonToken.END_OBJECT) { - if (parser.getCurrentToken() == JsonToken.START_OBJECT) { - if ("nodes".equals(parser.getCurrentName())) { - while (parser.nextToken() != JsonToken.END_OBJECT) { - JsonToken token = parser.nextToken(); - assert token == JsonToken.START_OBJECT; - String nodeId = parser.getCurrentName(); - HttpHost sniffedHost = readHost(nodeId, parser, this.scheme); - if (sniffedHost != null) { - logger.trace("adding node [" + nodeId + "]"); - hosts.add(sniffedHost); - } - } - } else { - parser.skipChildren(); - } - } - } - return hosts; - } - } - - private static HttpHost readHost(String nodeId, JsonParser parser, Scheme scheme) throws IOException { - HttpHost httpHost = null; - String fieldName = null; - while (parser.nextToken() != JsonToken.END_OBJECT) { - if (parser.getCurrentToken() == JsonToken.FIELD_NAME) { - fieldName = parser.getCurrentName(); - } else if (parser.getCurrentToken() == JsonToken.START_OBJECT) { - if ("http".equals(fieldName)) { - while (parser.nextToken() != JsonToken.END_OBJECT) { - if (parser.getCurrentToken() == JsonToken.VALUE_STRING && "publish_address".equals(parser.getCurrentName())) { - URI boundAddressAsURI = URI.create(scheme + "://" + parser.getValueAsString()); - httpHost = new HttpHost(boundAddressAsURI.getHost(), boundAddressAsURI.getPort(), - boundAddressAsURI.getScheme()); - } else if (parser.getCurrentToken() == JsonToken.START_OBJECT) { - parser.skipChildren(); - } - } - } else { - parser.skipChildren(); - } - } - } - //http section is not present if http is not enabled on the node, ignore such nodes - if (httpHost == null) { - logger.debug("skipping node [" + nodeId + "] with http disabled"); - return null; - } - return httpHost; - } - - /** - * Returns a new {@link Builder} to help with {@link HostsSniffer} creation. - */ - public static Builder builder(RestClient restClient) { - return new Builder(restClient); - } - - public enum Scheme { - HTTP("http"), HTTPS("https"); - - private final String name; - - Scheme(String name) { - this.name = name; - } - - @Override - public String toString() { - return name; - } - } - - /** - * HostsSniffer builder. Helps creating a new {@link HostsSniffer}. - */ - public static class Builder { - public static final long DEFAULT_SNIFF_REQUEST_TIMEOUT = TimeUnit.SECONDS.toMillis(1); - - private final RestClient restClient; - private long sniffRequestTimeoutMillis = DEFAULT_SNIFF_REQUEST_TIMEOUT; - private Scheme scheme = Scheme.HTTP; - - private Builder(RestClient restClient) { - Objects.requireNonNull(restClient, "restClient cannot be null"); - this.restClient = restClient; - } - - /** - * Sets the sniff request timeout (in milliseconds) to be passed in as a query string parameter to elasticsearch. - * Allows to halt the request without any failure, as only the nodes that have responded within this timeout will be returned. - */ - public Builder setSniffRequestTimeoutMillis(int sniffRequestTimeoutMillis) { - if (sniffRequestTimeoutMillis <= 0) { - throw new IllegalArgumentException("sniffRequestTimeoutMillis must be greater than 0"); - } - this.sniffRequestTimeoutMillis = sniffRequestTimeoutMillis; - return this; - } - - /** - * Sets the scheme to associate sniffed nodes with (as it is not returned by elasticsearch) - */ - public Builder setScheme(Scheme scheme) { - Objects.requireNonNull(scheme, "scheme cannot be null"); - this.scheme = scheme; - return this; - } - - /** - * Creates a new {@link HostsSniffer} instance given the provided configuration - */ - public HostsSniffer build() { - return new HostsSniffer(restClient, sniffRequestTimeoutMillis, scheme); - } - } + List sniffHosts() throws IOException; } diff --git a/client/sniffer/src/main/java/org/elasticsearch/client/sniff/Sniffer.java b/client/sniffer/src/main/java/org/elasticsearch/client/sniff/Sniffer.java index 61fa32e7b62..247206bbbc9 100644 --- a/client/sniffer/src/main/java/org/elasticsearch/client/sniff/Sniffer.java +++ b/client/sniffer/src/main/java/org/elasticsearch/client/sniff/Sniffer.java @@ -28,7 +28,6 @@ import org.elasticsearch.client.RestClientBuilder; import java.io.Closeable; import java.io.IOException; import java.util.List; -import java.util.Objects; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledFuture; @@ -36,12 +35,12 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; /** - * Class responsible for sniffing nodes from an elasticsearch cluster and setting them to a provided instance of {@link RestClient}. - * Must be created via {@link Builder}, which allows to set all of the different options or rely on defaults. + * Class responsible for sniffing nodes from some source (default is elasticsearch itself) and setting them to a provided instance of + * {@link RestClient}. Must be created via {@link SnifferBuilder}, which allows to set all of the different options or rely on defaults. * A background task fetches the nodes through the {@link HostsSniffer} and sets them to the {@link RestClient} instance. * It is possible to perform sniffing on failure by creating a {@link SniffOnFailureListener} and providing it as an argument to - * {@link RestClientBuilder#setFailureListener(RestClient.FailureListener)}. The Sniffer implementation - * needs to be lazily set to the previously created SniffOnFailureListener through {@link SniffOnFailureListener#setSniffer(Sniffer)}. + * {@link RestClientBuilder#setFailureListener(RestClient.FailureListener)}. The Sniffer implementation needs to be lazily set to the + * previously created SniffOnFailureListener through {@link SniffOnFailureListener#setSniffer(Sniffer)}. */ public final class Sniffer implements Closeable { @@ -49,7 +48,7 @@ public final class Sniffer implements Closeable { private final Task task; - private Sniffer(RestClient restClient, HostsSniffer hostsSniffer, long sniffInterval, long sniffAfterFailureDelay) { + Sniffer(RestClient restClient, HostsSniffer hostsSniffer, long sniffInterval, long sniffAfterFailureDelay) { this.task = new Task(hostsSniffer, restClient, sniffInterval, sniffAfterFailureDelay); } @@ -144,64 +143,12 @@ public final class Sniffer implements Closeable { } /** - * Returns a new {@link Builder} to help with {@link Sniffer} creation. + * Returns a new {@link SnifferBuilder} to help with {@link Sniffer} creation. + * + * @param restClient the client that gets its hosts set (via {@link RestClient#setHosts(HttpHost...)}) once they are fetched + * @return a new instance of {@link SnifferBuilder} */ - public static Builder builder(RestClient restClient, HostsSniffer hostsSniffer) { - return new Builder(restClient, hostsSniffer); - } - - /** - * Sniffer builder. Helps creating a new {@link Sniffer}. - */ - public static final class Builder { - public static final long DEFAULT_SNIFF_INTERVAL = TimeUnit.MINUTES.toMillis(5); - public static final long DEFAULT_SNIFF_AFTER_FAILURE_DELAY = TimeUnit.MINUTES.toMillis(1); - - private final RestClient restClient; - private final HostsSniffer hostsSniffer; - private long sniffIntervalMillis = DEFAULT_SNIFF_INTERVAL; - private long sniffAfterFailureDelayMillis = DEFAULT_SNIFF_AFTER_FAILURE_DELAY; - - /** - * Creates a new builder instance by providing the {@link RestClient} that will be used to communicate with elasticsearch, - * and the - */ - private Builder(RestClient restClient, HostsSniffer hostsSniffer) { - Objects.requireNonNull(restClient, "restClient cannot be null"); - this.restClient = restClient; - Objects.requireNonNull(hostsSniffer, "hostsSniffer cannot be null"); - this.hostsSniffer = hostsSniffer; - } - - /** - * Sets the interval between consecutive ordinary sniff executions in milliseconds. Will be honoured when - * sniffOnFailure is disabled or when there are no failures between consecutive sniff executions. - * @throws IllegalArgumentException if sniffIntervalMillis is not greater than 0 - */ - public Builder setSniffIntervalMillis(int sniffIntervalMillis) { - if (sniffIntervalMillis <= 0) { - throw new IllegalArgumentException("sniffIntervalMillis must be greater than 0"); - } - this.sniffIntervalMillis = sniffIntervalMillis; - return this; - } - - /** - * Sets the delay of a sniff execution scheduled after a failure (in milliseconds) - */ - public Builder setSniffAfterFailureDelayMillis(int sniffAfterFailureDelayMillis) { - if (sniffAfterFailureDelayMillis <= 0) { - throw new IllegalArgumentException("sniffAfterFailureDelayMillis must be greater than 0"); - } - this.sniffAfterFailureDelayMillis = sniffAfterFailureDelayMillis; - return this; - } - - /** - * Creates the {@link Sniffer} based on the provided configuration. - */ - public Sniffer build() { - return new Sniffer(restClient, hostsSniffer, sniffIntervalMillis, sniffAfterFailureDelayMillis); - } + public static SnifferBuilder builder(RestClient restClient) { + return new SnifferBuilder(restClient); } } diff --git a/client/sniffer/src/main/java/org/elasticsearch/client/sniff/SnifferBuilder.java b/client/sniffer/src/main/java/org/elasticsearch/client/sniff/SnifferBuilder.java new file mode 100644 index 00000000000..010a8a4a78d --- /dev/null +++ b/client/sniffer/src/main/java/org/elasticsearch/client/sniff/SnifferBuilder.java @@ -0,0 +1,91 @@ +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.client.sniff; + +import org.elasticsearch.client.RestClient; + +import java.util.Objects; +import java.util.concurrent.TimeUnit; + +/** + * Sniffer builder. Helps creating a new {@link Sniffer}. + */ +public final class SnifferBuilder { + public static final long DEFAULT_SNIFF_INTERVAL = TimeUnit.MINUTES.toMillis(5); + public static final long DEFAULT_SNIFF_AFTER_FAILURE_DELAY = TimeUnit.MINUTES.toMillis(1); + + private final RestClient restClient; + private long sniffIntervalMillis = DEFAULT_SNIFF_INTERVAL; + private long sniffAfterFailureDelayMillis = DEFAULT_SNIFF_AFTER_FAILURE_DELAY; + private HostsSniffer hostsSniffer; + + /** + * Creates a new builder instance by providing the {@link RestClient} that will be used to communicate with elasticsearch + */ + SnifferBuilder(RestClient restClient) { + Objects.requireNonNull(restClient, "restClient cannot be null"); + this.restClient = restClient; + } + + /** + * Sets the interval between consecutive ordinary sniff executions in milliseconds. Will be honoured when + * sniffOnFailure is disabled or when there are no failures between consecutive sniff executions. + * @throws IllegalArgumentException if sniffIntervalMillis is not greater than 0 + */ + public SnifferBuilder setSniffIntervalMillis(int sniffIntervalMillis) { + if (sniffIntervalMillis <= 0) { + throw new IllegalArgumentException("sniffIntervalMillis must be greater than 0"); + } + this.sniffIntervalMillis = sniffIntervalMillis; + return this; + } + + /** + * Sets the delay of a sniff execution scheduled after a failure (in milliseconds) + */ + public SnifferBuilder setSniffAfterFailureDelayMillis(int sniffAfterFailureDelayMillis) { + if (sniffAfterFailureDelayMillis <= 0) { + throw new IllegalArgumentException("sniffAfterFailureDelayMillis must be greater than 0"); + } + this.sniffAfterFailureDelayMillis = sniffAfterFailureDelayMillis; + return this; + } + + /** + * Sets the {@link HostsSniffer} to be used to read hosts. A default instance of {@link ElasticsearchHostsSniffer} + * is created when not provided. This method can be used to change the configuration of the {@link ElasticsearchHostsSniffer}, + * or to provide a different implementation (e.g. in case hosts need to taken from a different source). + */ + public SnifferBuilder setHostsSniffer(HostsSniffer hostsSniffer) { + Objects.requireNonNull(hostsSniffer, "hostsSniffer cannot be null"); + this.hostsSniffer = hostsSniffer; + return this; + } + + /** + * Creates the {@link Sniffer} based on the provided configuration. + */ + public Sniffer build() { + if (hostsSniffer == null) { + this.hostsSniffer = new ElasticsearchHostsSniffer(restClient); + } + return new Sniffer(restClient, hostsSniffer, sniffIntervalMillis, sniffAfterFailureDelayMillis); + } +} diff --git a/client/sniffer/src/test/java/org/elasticsearch/client/sniff/HostsSnifferTests.java b/client/sniffer/src/test/java/org/elasticsearch/client/sniff/ElasticsearchHostsSnifferTests.java similarity index 87% rename from client/sniffer/src/test/java/org/elasticsearch/client/sniff/HostsSnifferTests.java rename to client/sniffer/src/test/java/org/elasticsearch/client/sniff/ElasticsearchHostsSnifferTests.java index bb375834097..a926cabb87d 100644 --- a/client/sniffer/src/test/java/org/elasticsearch/client/sniff/HostsSnifferTests.java +++ b/client/sniffer/src/test/java/org/elasticsearch/client/sniff/ElasticsearchHostsSnifferTests.java @@ -60,17 +60,17 @@ import static org.junit.Assert.fail; //animal-sniffer doesn't like our usage of com.sun.net.httpserver.* classes @IgnoreJRERequirement -public class HostsSnifferTests extends RestClientTestCase { +public class ElasticsearchHostsSnifferTests extends RestClientTestCase { private int sniffRequestTimeout; - private HostsSniffer.Scheme scheme; + private ElasticsearchHostsSniffer.Scheme scheme; private SniffResponse sniffResponse; private HttpServer httpServer; @Before public void startHttpServer() throws IOException { this.sniffRequestTimeout = RandomInts.randomIntBetween(getRandom(), 1000, 10000); - this.scheme = RandomPicks.randomFrom(getRandom(), HostsSniffer.Scheme.values()); + this.scheme = RandomPicks.randomFrom(getRandom(), ElasticsearchHostsSniffer.Scheme.values()); if (rarely()) { this.sniffResponse = SniffResponse.buildFailure(); } else { @@ -85,14 +85,35 @@ public class HostsSnifferTests extends RestClientTestCase { httpServer.stop(0); } + public void testConstructorValidation() throws IOException { + try { + new ElasticsearchHostsSniffer(null, 1, ElasticsearchHostsSniffer.Scheme.HTTP); + fail("should have failed"); + } catch(NullPointerException e) { + assertEquals("restClient cannot be null", e.getMessage()); + } + HttpHost httpHost = new HttpHost(httpServer.getAddress().getHostString(), httpServer.getAddress().getPort()); + try (RestClient restClient = RestClient.builder(httpHost).build()) { + try { + new ElasticsearchHostsSniffer(restClient, 1, null); + fail("should have failed"); + } catch (NullPointerException e) { + assertEquals(e.getMessage(), "scheme cannot be null"); + } + try { + new ElasticsearchHostsSniffer(restClient, RandomInts.randomIntBetween(getRandom(), Integer.MIN_VALUE, 0), + ElasticsearchHostsSniffer.Scheme.HTTP); + fail("should have failed"); + } catch (IllegalArgumentException e) { + assertEquals(e.getMessage(), "sniffRequestTimeoutMillis must be greater than 0"); + } + } + } + public void testSniffNodes() throws IOException { HttpHost httpHost = new HttpHost(httpServer.getAddress().getHostString(), httpServer.getAddress().getPort()); try (RestClient restClient = RestClient.builder(httpHost).build()) { - HostsSniffer.Builder builder = HostsSniffer.builder(restClient).setSniffRequestTimeoutMillis(sniffRequestTimeout); - if (scheme != HostsSniffer.Scheme.HTTP || randomBoolean()) { - builder.setScheme(scheme); - } - HostsSniffer sniffer = builder.build(); + ElasticsearchHostsSniffer sniffer = new ElasticsearchHostsSniffer(restClient, sniffRequestTimeout, scheme); try { List sniffedHosts = sniffer.sniffHosts(); if (sniffResponse.isFailure) { @@ -153,7 +174,7 @@ public class HostsSnifferTests extends RestClientTestCase { } } - private static SniffResponse buildSniffResponse(HostsSniffer.Scheme scheme) throws IOException { + private static SniffResponse buildSniffResponse(ElasticsearchHostsSniffer.Scheme scheme) throws IOException { int numNodes = RandomInts.randomIntBetween(getRandom(), 1, 5); List hosts = new ArrayList<>(numNodes); JsonFactory jsonFactory = new JsonFactory(); diff --git a/client/sniffer/src/test/java/org/elasticsearch/client/sniff/HostsSnifferBuilderTests.java b/client/sniffer/src/test/java/org/elasticsearch/client/sniff/HostsSnifferBuilderTests.java deleted file mode 100644 index c167a3a104b..00000000000 --- a/client/sniffer/src/test/java/org/elasticsearch/client/sniff/HostsSnifferBuilderTests.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Licensed to Elasticsearch under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.client.sniff; - -import com.carrotsearch.randomizedtesting.generators.RandomInts; -import com.carrotsearch.randomizedtesting.generators.RandomPicks; -import org.apache.http.HttpHost; -import org.elasticsearch.client.RestClient; -import org.elasticsearch.client.RestClientTestCase; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.fail; - -public class HostsSnifferBuilderTests extends RestClientTestCase { - - public void testBuild() throws Exception { - try { - HostsSniffer.builder(null); - fail("should have failed"); - } catch(NullPointerException e) { - assertEquals(e.getMessage(), "restClient cannot be null"); - } - - int numNodes = RandomInts.randomIntBetween(getRandom(), 1, 5); - HttpHost[] hosts = new HttpHost[numNodes]; - for (int i = 0; i < numNodes; i++) { - hosts[i] = new HttpHost("localhost", 9200 + i); - } - - try (RestClient client = RestClient.builder(hosts).build()) { - try { - HostsSniffer.builder(client).setScheme(null); - fail("should have failed"); - } catch(NullPointerException e) { - assertEquals(e.getMessage(), "scheme cannot be null"); - } - - try { - HostsSniffer.builder(client).setSniffRequestTimeoutMillis(RandomInts.randomIntBetween(getRandom(), Integer.MIN_VALUE, 0)); - fail("should have failed"); - } catch(IllegalArgumentException e) { - assertEquals(e.getMessage(), "sniffRequestTimeoutMillis must be greater than 0"); - } - - HostsSniffer.Builder builder = HostsSniffer.builder(client); - if (getRandom().nextBoolean()) { - builder.setScheme(RandomPicks.randomFrom(getRandom(), HostsSniffer.Scheme.values())); - } - if (getRandom().nextBoolean()) { - builder.setSniffRequestTimeoutMillis(RandomInts.randomIntBetween(getRandom(), 1, Integer.MAX_VALUE)); - } - assertNotNull(builder.build()); - } - } -} diff --git a/client/sniffer/src/test/java/org/elasticsearch/client/sniff/MockHostsSniffer.java b/client/sniffer/src/test/java/org/elasticsearch/client/sniff/MockHostsSniffer.java index bdc052d07c8..5a52151d76e 100644 --- a/client/sniffer/src/test/java/org/elasticsearch/client/sniff/MockHostsSniffer.java +++ b/client/sniffer/src/test/java/org/elasticsearch/client/sniff/MockHostsSniffer.java @@ -22,18 +22,15 @@ package org.elasticsearch.client.sniff; import org.apache.http.HttpHost; import java.io.IOException; -import java.util.ArrayList; +import java.util.Collections; import java.util.List; -class MockHostsSniffer extends HostsSniffer { - MockHostsSniffer() { - super(null, -1, null); - } - +/** + * Mock implementation of {@link HostsSniffer}. Useful to prevent any connection attempt while testing builders etc. + */ +class MockHostsSniffer implements HostsSniffer { @Override public List sniffHosts() throws IOException { - List hosts = new ArrayList<>(); - hosts.add(new HttpHost("localhost", 9200)); - return hosts; + return Collections.singletonList(new HttpHost("localhost", 9200)); } } diff --git a/client/sniffer/src/test/java/org/elasticsearch/client/sniff/SniffOnFailureListenerTests.java b/client/sniffer/src/test/java/org/elasticsearch/client/sniff/SniffOnFailureListenerTests.java index bbb1de35663..1fece270ffe 100644 --- a/client/sniffer/src/test/java/org/elasticsearch/client/sniff/SniffOnFailureListenerTests.java +++ b/client/sniffer/src/test/java/org/elasticsearch/client/sniff/SniffOnFailureListenerTests.java @@ -46,7 +46,7 @@ public class SniffOnFailureListenerTests extends RestClientTestCase { } try (RestClient restClient = RestClient.builder(new HttpHost("localhost", 9200)).build()) { - try (Sniffer sniffer = Sniffer.builder(restClient, new MockHostsSniffer()).build()) { + try (Sniffer sniffer = Sniffer.builder(restClient).setHostsSniffer(new MockHostsSniffer()).build()) { listener.setSniffer(sniffer); try { listener.setSniffer(sniffer); diff --git a/client/sniffer/src/test/java/org/elasticsearch/client/sniff/SnifferBuilderTests.java b/client/sniffer/src/test/java/org/elasticsearch/client/sniff/SnifferBuilderTests.java index defa83554a4..b0c387d733a 100644 --- a/client/sniffer/src/test/java/org/elasticsearch/client/sniff/SnifferBuilderTests.java +++ b/client/sniffer/src/test/java/org/elasticsearch/client/sniff/SnifferBuilderTests.java @@ -37,50 +37,52 @@ public class SnifferBuilderTests extends RestClientTestCase { hosts[i] = new HttpHost("localhost", 9200 + i); } - HostsSniffer hostsSniffer = new MockHostsSniffer(); - try (RestClient client = RestClient.builder(hosts).build()) { try { - Sniffer.builder(null, hostsSniffer).build(); + Sniffer.builder(null).build(); fail("should have failed"); } catch(NullPointerException e) { assertEquals("restClient cannot be null", e.getMessage()); } try { - Sniffer.builder(client, null).build(); - fail("should have failed"); - } catch(NullPointerException e) { - assertEquals("hostsSniffer cannot be null", e.getMessage()); - } - - try { - Sniffer.builder(client, hostsSniffer) - .setSniffIntervalMillis(RandomInts.randomIntBetween(getRandom(), Integer.MIN_VALUE, 0)); + Sniffer.builder(client).setSniffIntervalMillis(RandomInts.randomIntBetween(getRandom(), Integer.MIN_VALUE, 0)); fail("should have failed"); } catch(IllegalArgumentException e) { assertEquals("sniffIntervalMillis must be greater than 0", e.getMessage()); } try { - Sniffer.builder(client, hostsSniffer) - .setSniffAfterFailureDelayMillis(RandomInts.randomIntBetween(getRandom(), Integer.MIN_VALUE, 0)); + Sniffer.builder(client).setSniffAfterFailureDelayMillis(RandomInts.randomIntBetween(getRandom(), Integer.MIN_VALUE, 0)); fail("should have failed"); } catch(IllegalArgumentException e) { assertEquals("sniffAfterFailureDelayMillis must be greater than 0", e.getMessage()); } - try (Sniffer sniffer = Sniffer.builder(client, hostsSniffer).build()) { + + try { + Sniffer.builder(client).setHostsSniffer(null); + fail("should have failed"); + } catch(NullPointerException e) { + assertEquals("hostsSniffer cannot be null", e.getMessage()); + } + + + try (Sniffer sniffer = Sniffer.builder(client).build()) { assertNotNull(sniffer); } - Sniffer.Builder builder = Sniffer.builder(client, hostsSniffer); + SnifferBuilder builder = Sniffer.builder(client); if (getRandom().nextBoolean()) { builder.setSniffIntervalMillis(RandomInts.randomIntBetween(getRandom(), 1, Integer.MAX_VALUE)); } if (getRandom().nextBoolean()) { builder.setSniffAfterFailureDelayMillis(RandomInts.randomIntBetween(getRandom(), 1, Integer.MAX_VALUE)); } + if (getRandom().nextBoolean()) { + builder.setHostsSniffer(new MockHostsSniffer()); + } + try (Sniffer sniffer = builder.build()) { assertNotNull(sniffer); } diff --git a/core/src/main/java/org/elasticsearch/action/DocWriteResponse.java b/core/src/main/java/org/elasticsearch/action/DocWriteResponse.java index 49ac5d4f8a4..95689e66d3f 100644 --- a/core/src/main/java/org/elasticsearch/action/DocWriteResponse.java +++ b/core/src/main/java/org/elasticsearch/action/DocWriteResponse.java @@ -25,6 +25,7 @@ import org.elasticsearch.action.support.replication.ReplicationResponse; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; +import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.common.xcontent.StatusToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.index.IndexSettings; @@ -32,29 +33,83 @@ import org.elasticsearch.index.shard.ShardId; import org.elasticsearch.rest.RestStatus; import java.io.IOException; +import java.util.Locale; /** * A base class for the response of a write operation that involves a single doc */ public abstract class DocWriteResponse extends ReplicationResponse implements WriteResponse, StatusToXContent { + public enum Operation implements Writeable { + CREATE(0), + INDEX(1), + DELETE(2), + NOOP(3); + + private final byte op; + private final String lowercase; + + Operation(int op) { + this.op = (byte) op; + this.lowercase = this.toString().toLowerCase(Locale.ENGLISH); + } + + public byte getOp() { + return op; + } + + public String getLowercase() { + return lowercase; + } + + public static Operation readFrom(StreamInput in) throws IOException{ + Byte opcode = in.readByte(); + switch(opcode){ + case 0: + return CREATE; + case 1: + return INDEX; + case 2: + return DELETE; + case 3: + return NOOP; + default: + throw new IllegalArgumentException("Unknown operation code: " + opcode); + } + } + + @Override + public void writeTo(StreamOutput out) throws IOException { + out.writeByte(op); + } + } + private ShardId shardId; private String id; private String type; private long version; private boolean forcedRefresh; + protected Operation operation; - public DocWriteResponse(ShardId shardId, String type, String id, long version) { + public DocWriteResponse(ShardId shardId, String type, String id, long version, Operation operation) { this.shardId = shardId; this.type = type; this.id = id; this.version = version; + this.operation = operation; } // needed for deserialization protected DocWriteResponse() { } + /** + * The change that occurred to the document. + */ + public Operation getOperation() { + return operation; + } + /** * The index the document was changed in. */ @@ -143,6 +198,7 @@ public abstract class DocWriteResponse extends ReplicationResponse implements Wr id = in.readString(); version = in.readZLong(); forcedRefresh = in.readBoolean(); + operation = Operation.readFrom(in); } @Override @@ -153,22 +209,17 @@ public abstract class DocWriteResponse extends ReplicationResponse implements Wr out.writeString(id); out.writeZLong(version); out.writeBoolean(forcedRefresh); - } - - static final class Fields { - static final String _INDEX = "_index"; - static final String _TYPE = "_type"; - static final String _ID = "_id"; - static final String _VERSION = "_version"; + operation.writeTo(out); } @Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { ReplicationResponse.ShardInfo shardInfo = getShardInfo(); - builder.field(Fields._INDEX, shardId.getIndexName()) - .field(Fields._TYPE, type) - .field(Fields._ID, id) - .field(Fields._VERSION, version) + builder.field("_index", shardId.getIndexName()) + .field("_type", type) + .field("_id", id) + .field("_version", version) + .field("_operation", getOperation().getLowercase()) .field("forced_refresh", forcedRefresh); shardInfo.toXContent(builder, params); return builder; diff --git a/core/src/main/java/org/elasticsearch/action/bulk/TransportShardBulkAction.java b/core/src/main/java/org/elasticsearch/action/bulk/TransportShardBulkAction.java index 45fc97dca98..cb3bb6bdea8 100644 --- a/core/src/main/java/org/elasticsearch/action/bulk/TransportShardBulkAction.java +++ b/core/src/main/java/org/elasticsearch/action/bulk/TransportShardBulkAction.java @@ -248,7 +248,7 @@ public class TransportShardBulkAction extends TransportWriteAction 0) { Tuple> sourceAndContent = XContentHelper.convertToMap(indexSourceAsBytes, true); updateResponse.setGetResult(updateHelper.extractGetResult(updateRequest, request.index(), indexResponse.getVersion(), sourceAndContent.v2(), sourceAndContent.v1(), indexSourceAsBytes)); @@ -261,7 +261,7 @@ public class TransportShardBulkAction extends TransportWriteAction writeResult = updateResult.writeResult; DeleteResponse response = writeResult.getResponse(); DeleteRequest deleteRequest = updateResult.request(); - updateResponse = new UpdateResponse(response.getShardInfo(), response.getShardId(), response.getType(), response.getId(), response.getVersion(), false); + updateResponse = new UpdateResponse(response.getShardInfo(), response.getShardId(), response.getType(), response.getId(), response.getVersion(), response.getOperation()); updateResponse.setGetResult(updateHelper.extractGetResult(updateRequest, request.index(), response.getVersion(), updateResult.result.updatedSourceAsMap(), updateResult.result.updateSourceContentType(), null)); // Replace the update request to the translated delete request to execute on the replica. item = request.items()[requestIndex] = new BulkItemRequest(request.items()[requestIndex].id(), deleteRequest); diff --git a/core/src/main/java/org/elasticsearch/action/delete/DeleteResponse.java b/core/src/main/java/org/elasticsearch/action/delete/DeleteResponse.java index f40c419b7ff..aed4ced897f 100644 --- a/core/src/main/java/org/elasticsearch/action/delete/DeleteResponse.java +++ b/core/src/main/java/org/elasticsearch/action/delete/DeleteResponse.java @@ -20,8 +20,6 @@ package org.elasticsearch.action.delete; import org.elasticsearch.action.DocWriteResponse; -import org.elasticsearch.common.io.stream.StreamInput; -import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.index.shard.ShardId; import org.elasticsearch.rest.RestStatus; @@ -36,52 +34,29 @@ import java.io.IOException; */ public class DeleteResponse extends DocWriteResponse { - private boolean found; - public DeleteResponse() { } public DeleteResponse(ShardId shardId, String type, String id, long version, boolean found) { - super(shardId, type, id, version); - this.found = found; + super(shardId, type, id, version, found ? Operation.DELETE : Operation.NOOP); } - /** * Returns true if a doc was found to delete. */ public boolean isFound() { - return found; - } - - @Override - public void readFrom(StreamInput in) throws IOException { - super.readFrom(in); - found = in.readBoolean(); - } - - @Override - public void writeTo(StreamOutput out) throws IOException { - super.writeTo(out); - out.writeBoolean(found); + return operation == Operation.DELETE; } @Override public RestStatus status() { - if (found == false) { - return RestStatus.NOT_FOUND; - } - return super.status(); - } - - static final class Fields { - static final String FOUND = "found"; + return isFound() ? super.status() : RestStatus.NOT_FOUND; } @Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { - builder.field(Fields.FOUND, isFound()); + builder.field("found", isFound()); super.toXContent(builder, params); return builder; } @@ -94,7 +69,7 @@ public class DeleteResponse extends DocWriteResponse { builder.append(",type=").append(getType()); builder.append(",id=").append(getId()); builder.append(",version=").append(getVersion()); - builder.append(",found=").append(found); + builder.append(",operation=").append(getOperation().getLowercase()); builder.append(",shards=").append(getShardInfo()); return builder.append("]").toString(); } diff --git a/core/src/main/java/org/elasticsearch/action/index/IndexResponse.java b/core/src/main/java/org/elasticsearch/action/index/IndexResponse.java index b37e86ccb2c..851b6bc0e08 100644 --- a/core/src/main/java/org/elasticsearch/action/index/IndexResponse.java +++ b/core/src/main/java/org/elasticsearch/action/index/IndexResponse.java @@ -36,42 +36,24 @@ import java.io.IOException; */ public class IndexResponse extends DocWriteResponse { - private boolean created; - public IndexResponse() { } public IndexResponse(ShardId shardId, String type, String id, long version, boolean created) { - super(shardId, type, id, version); - this.created = created; + super(shardId, type, id, version, created ? Operation.CREATE : Operation.INDEX); } /** * Returns true if the document was created, false if updated. */ public boolean isCreated() { - return this.created; + return this.operation == Operation.CREATE; } @Override public RestStatus status() { - if (created) { - return RestStatus.CREATED; - } - return super.status(); - } - - @Override - public void readFrom(StreamInput in) throws IOException { - super.readFrom(in); - created = in.readBoolean(); - } - - @Override - public void writeTo(StreamOutput out) throws IOException { - super.writeTo(out); - out.writeBoolean(created); + return isCreated() ? RestStatus.CREATED : super.status(); } @Override @@ -82,19 +64,15 @@ public class IndexResponse extends DocWriteResponse { builder.append(",type=").append(getType()); builder.append(",id=").append(getId()); builder.append(",version=").append(getVersion()); - builder.append(",created=").append(created); + builder.append(",operation=").append(getOperation().getLowercase()); builder.append(",shards=").append(getShardInfo()); return builder.append("]").toString(); } - static final class Fields { - static final String CREATED = "created"; - } - @Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { super.toXContent(builder, params); - builder.field(Fields.CREATED, isCreated()); + builder.field("created", isCreated()); return builder; } } diff --git a/core/src/main/java/org/elasticsearch/action/ingest/GetPipelineRequest.java b/core/src/main/java/org/elasticsearch/action/ingest/GetPipelineRequest.java index 6525c26c6c6..1ba22bce805 100644 --- a/core/src/main/java/org/elasticsearch/action/ingest/GetPipelineRequest.java +++ b/core/src/main/java/org/elasticsearch/action/ingest/GetPipelineRequest.java @@ -21,26 +21,25 @@ package org.elasticsearch.action.ingest; import org.elasticsearch.action.ActionRequestValidationException; import org.elasticsearch.action.support.master.MasterNodeReadRequest; +import org.elasticsearch.common.Strings; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import java.io.IOException; -import java.util.Objects; - -import static org.elasticsearch.action.ValidateActions.addValidationError; public class GetPipelineRequest extends MasterNodeReadRequest { private String[] ids; public GetPipelineRequest(String... ids) { - if (ids == null || ids.length == 0) { - throw new IllegalArgumentException("No ids specified"); + if (ids == null) { + throw new IllegalArgumentException("ids cannot be null"); } this.ids = ids; } GetPipelineRequest() { + this.ids = Strings.EMPTY_ARRAY; } public String[] getIds() { diff --git a/core/src/main/java/org/elasticsearch/action/ingest/WriteableIngestDocument.java b/core/src/main/java/org/elasticsearch/action/ingest/WriteableIngestDocument.java index 137914701db..84c41ae689b 100644 --- a/core/src/main/java/org/elasticsearch/action/ingest/WriteableIngestDocument.java +++ b/core/src/main/java/org/elasticsearch/action/ingest/WriteableIngestDocument.java @@ -41,15 +41,14 @@ final class WriteableIngestDocument implements Writeable, ToXContent { WriteableIngestDocument(StreamInput in) throws IOException { Map sourceAndMetadata = in.readMap(); - @SuppressWarnings("unchecked") - Map ingestMetadata = (Map) in.readGenericValue(); + Map ingestMetadata = in.readMap(); this.ingestDocument = new IngestDocument(sourceAndMetadata, ingestMetadata); } @Override public void writeTo(StreamOutput out) throws IOException { out.writeMap(ingestDocument.getSourceAndMetadata()); - out.writeGenericValue(ingestDocument.getIngestMetadata()); + out.writeMap(ingestDocument.getIngestMetadata()); } IngestDocument getIngestDocument() { @@ -66,11 +65,7 @@ final class WriteableIngestDocument implements Writeable, ToXContent { } } builder.field("_source", ingestDocument.getSourceAndMetadata()); - builder.startObject("_ingest"); - for (Map.Entry ingestMetadata : ingestDocument.getIngestMetadata().entrySet()) { - builder.field(ingestMetadata.getKey(), ingestMetadata.getValue()); - } - builder.endObject(); + builder.field("_ingest", ingestDocument.getIngestMetadata()); builder.endObject(); return builder; } diff --git a/core/src/main/java/org/elasticsearch/action/update/TransportUpdateAction.java b/core/src/main/java/org/elasticsearch/action/update/TransportUpdateAction.java index 3bff01cb8a6..86d42e4db12 100644 --- a/core/src/main/java/org/elasticsearch/action/update/TransportUpdateAction.java +++ b/core/src/main/java/org/elasticsearch/action/update/TransportUpdateAction.java @@ -22,6 +22,7 @@ package org.elasticsearch.action.update; import org.elasticsearch.ExceptionsHelper; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.ActionRunnable; +import org.elasticsearch.action.DocWriteResponse; import org.elasticsearch.action.RoutingMissingException; import org.elasticsearch.action.admin.indices.create.CreateIndexRequest; import org.elasticsearch.action.admin.indices.create.CreateIndexResponse; @@ -185,7 +186,7 @@ public class TransportUpdateAction extends TransportInstanceSingleOperationActio indexAction.execute(upsertRequest, new ActionListener() { @Override public void onResponse(IndexResponse response) { - UpdateResponse update = new UpdateResponse(response.getShardInfo(), response.getShardId(), response.getType(), response.getId(), response.getVersion(), response.isCreated()); + UpdateResponse update = new UpdateResponse(response.getShardInfo(), response.getShardId(), response.getType(), response.getId(), response.getVersion(), response.getOperation()); if (request.fields() != null && request.fields().length > 0) { Tuple> sourceAndContent = XContentHelper.convertToMap(upsertSourceBytes, true); update.setGetResult(updateHelper.extractGetResult(request, request.concreteIndex(), response.getVersion(), sourceAndContent.v2(), sourceAndContent.v1(), upsertSourceBytes)); @@ -223,7 +224,7 @@ public class TransportUpdateAction extends TransportInstanceSingleOperationActio indexAction.execute(indexRequest, new ActionListener() { @Override public void onResponse(IndexResponse response) { - UpdateResponse update = new UpdateResponse(response.getShardInfo(), response.getShardId(), response.getType(), response.getId(), response.getVersion(), response.isCreated()); + UpdateResponse update = new UpdateResponse(response.getShardInfo(), response.getShardId(), response.getType(), response.getId(), response.getVersion(), response.getOperation()); update.setGetResult(updateHelper.extractGetResult(request, request.concreteIndex(), response.getVersion(), result.updatedSourceAsMap(), result.updateSourceContentType(), indexSourceBytes)); update.setForcedRefresh(response.forcedRefresh()); listener.onResponse(update); @@ -252,7 +253,7 @@ public class TransportUpdateAction extends TransportInstanceSingleOperationActio deleteAction.execute(deleteRequest, new ActionListener() { @Override public void onResponse(DeleteResponse response) { - UpdateResponse update = new UpdateResponse(response.getShardInfo(), response.getShardId(), response.getType(), response.getId(), response.getVersion(), false); + UpdateResponse update = new UpdateResponse(response.getShardInfo(), response.getShardId(), response.getType(), response.getId(), response.getVersion(), response.getOperation()); update.setGetResult(updateHelper.extractGetResult(request, request.concreteIndex(), response.getVersion(), result.updatedSourceAsMap(), result.updateSourceContentType(), null)); update.setForcedRefresh(response.forcedRefresh()); listener.onResponse(update); diff --git a/core/src/main/java/org/elasticsearch/action/update/UpdateHelper.java b/core/src/main/java/org/elasticsearch/action/update/UpdateHelper.java index aa92510e38b..cb876f706e0 100644 --- a/core/src/main/java/org/elasticsearch/action/update/UpdateHelper.java +++ b/core/src/main/java/org/elasticsearch/action/update/UpdateHelper.java @@ -116,7 +116,7 @@ public class UpdateHelper extends AbstractComponent { request.script.getScript()); } UpdateResponse update = new UpdateResponse(shardId, getResult.getType(), getResult.getId(), - getResult.getVersion(), false); + getResult.getVersion(), UpdateResponse.convert(Operation.NONE)); update.setGetResult(getResult); return new Result(update, Operation.NONE, upsertDoc, XContentType.JSON); } @@ -234,12 +234,12 @@ public class UpdateHelper extends AbstractComponent { .setRefreshPolicy(request.getRefreshPolicy()); return new Result(deleteRequest, Operation.DELETE, updatedSourceAsMap, updateSourceContentType); } else if ("none".equals(operation)) { - UpdateResponse update = new UpdateResponse(shardId, getResult.getType(), getResult.getId(), getResult.getVersion(), false); + UpdateResponse update = new UpdateResponse(shardId, getResult.getType(), getResult.getId(), getResult.getVersion(), UpdateResponse.convert(Operation.NONE)); update.setGetResult(extractGetResult(request, request.index(), getResult.getVersion(), updatedSourceAsMap, updateSourceContentType, getResult.internalSourceRef())); return new Result(update, Operation.NONE, updatedSourceAsMap, updateSourceContentType); } else { logger.warn("Used update operation [{}] for script [{}], doing nothing...", operation, request.script.getScript()); - UpdateResponse update = new UpdateResponse(shardId, getResult.getType(), getResult.getId(), getResult.getVersion(), false); + UpdateResponse update = new UpdateResponse(shardId, getResult.getType(), getResult.getId(), getResult.getVersion(), UpdateResponse.convert(Operation.NONE)); return new Result(update, Operation.NONE, updatedSourceAsMap, updateSourceContentType); } } diff --git a/core/src/main/java/org/elasticsearch/action/update/UpdateResponse.java b/core/src/main/java/org/elasticsearch/action/update/UpdateResponse.java index 8d2eeeb383b..16633fd4126 100644 --- a/core/src/main/java/org/elasticsearch/action/update/UpdateResponse.java +++ b/core/src/main/java/org/elasticsearch/action/update/UpdateResponse.java @@ -29,11 +29,8 @@ import org.elasticsearch.rest.RestStatus; import java.io.IOException; -/** - */ public class UpdateResponse extends DocWriteResponse { - private boolean created; private GetResult getResult; public UpdateResponse() { @@ -43,14 +40,28 @@ public class UpdateResponse extends DocWriteResponse { * Constructor to be used when a update didn't translate in a write. * For example: update script with operation set to none */ - public UpdateResponse(ShardId shardId, String type, String id, long version, boolean created) { - this(new ShardInfo(0, 0), shardId, type, id, version, created); + public UpdateResponse(ShardId shardId, String type, String id, long version, Operation operation) { + this(new ShardInfo(0, 0), shardId, type, id, version, operation); } - public UpdateResponse(ShardInfo shardInfo, ShardId shardId, String type, String id, long version, boolean created) { - super(shardId, type, id, version); + public UpdateResponse(ShardInfo shardInfo, ShardId shardId, String type, String id, + long version, Operation operation) { + super(shardId, type, id, version, operation); setShardInfo(shardInfo); - this.created = created; + } + + public static Operation convert(UpdateHelper.Operation op) { + switch(op) { + case UPSERT: + return Operation.CREATE; + case INDEX: + return Operation.INDEX; + case DELETE: + return Operation.DELETE; + case NONE: + return Operation.NOOP; + } + throw new IllegalArgumentException(); } public void setGetResult(GetResult getResult) { @@ -65,22 +76,17 @@ public class UpdateResponse extends DocWriteResponse { * Returns true if document was created due to an UPSERT operation */ public boolean isCreated() { - return this.created; - + return this.operation == Operation.CREATE; } @Override public RestStatus status() { - if (created) { - return RestStatus.CREATED; - } - return super.status(); + return isCreated() ? RestStatus.CREATED : super.status(); } @Override public void readFrom(StreamInput in) throws IOException { super.readFrom(in); - created = in.readBoolean(); if (in.readBoolean()) { getResult = GetResult.readGetResult(in); } @@ -89,7 +95,6 @@ public class UpdateResponse extends DocWriteResponse { @Override public void writeTo(StreamOutput out) throws IOException { super.writeTo(out); - out.writeBoolean(created); if (getResult == null) { out.writeBoolean(false); } else { @@ -122,7 +127,7 @@ public class UpdateResponse extends DocWriteResponse { builder.append(",type=").append(getType()); builder.append(",id=").append(getId()); builder.append(",version=").append(getVersion()); - builder.append(",created=").append(created); + builder.append(",operation=").append(getOperation().getLowercase()); builder.append(",shards=").append(getShardInfo()); return builder.append("]").toString(); } diff --git a/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataCreateIndexService.java b/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataCreateIndexService.java index bab03febaae..3e5e0e92237 100644 --- a/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataCreateIndexService.java +++ b/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataCreateIndexService.java @@ -202,8 +202,10 @@ public class MetaDataCreateIndexService extends AbstractComponent { if (response.isAcknowledged()) { activeShardsObserver.waitForActiveShards(request.index(), request.waitForActiveShards(), request.ackTimeout(), shardsAcked -> { - logger.debug("[{}] index created, but the operation timed out while waiting for " + - "enough shards to be started.", request.index()); + if (shardsAcked == false) { + logger.debug("[{}] index created, but the operation timed out while waiting for " + + "enough shards to be started.", request.index()); + } listener.onResponse(new CreateIndexClusterStateUpdateResponse(response.isAcknowledged(), shardsAcked)); }, listener::onFailure); } else { diff --git a/core/src/main/java/org/elasticsearch/common/transport/NetworkExceptionHelper.java b/core/src/main/java/org/elasticsearch/common/transport/NetworkExceptionHelper.java index 0317026b6be..5d6211c3fec 100644 --- a/core/src/main/java/org/elasticsearch/common/transport/NetworkExceptionHelper.java +++ b/core/src/main/java/org/elasticsearch/common/transport/NetworkExceptionHelper.java @@ -58,6 +58,9 @@ public class NetworkExceptionHelper { if (e.getMessage().equals("Socket is closed")) { return true; } + if (e.getMessage().equals("Socket closed")) { + return true; + } } return false; } diff --git a/core/src/main/java/org/elasticsearch/index/query/QueryParseContext.java b/core/src/main/java/org/elasticsearch/index/query/QueryParseContext.java index 510a8049630..daf0f6838b5 100644 --- a/core/src/main/java/org/elasticsearch/index/query/QueryParseContext.java +++ b/core/src/main/java/org/elasticsearch/index/query/QueryParseContext.java @@ -73,9 +73,6 @@ public class QueryParseContext implements ParseFieldMatcherSupplier { } } } - if (queryBuilder == null) { - throw new ParsingException(parser.getTokenLocation(), "Required query is missing"); - } return queryBuilder; } catch (ParsingException e) { throw e; @@ -113,7 +110,7 @@ public class QueryParseContext implements ParseFieldMatcherSupplier { // move to the next START_OBJECT token = parser.nextToken(); if (token != XContentParser.Token.START_OBJECT && token != XContentParser.Token.START_ARRAY) { - throw new ParsingException(parser.getTokenLocation(), "[_na] query malformed, no field after start_object"); + throw new ParsingException(parser.getTokenLocation(), "[_na] query malformed, no start_object after query name"); } @SuppressWarnings("unchecked") Optional result = (Optional) indicesQueriesRegistry.lookup(queryName, parseFieldMatcher, diff --git a/core/src/main/java/org/elasticsearch/index/translog/Checkpoint.java b/core/src/main/java/org/elasticsearch/index/translog/Checkpoint.java index f630ba3faba..0fd59090944 100644 --- a/core/src/main/java/org/elasticsearch/index/translog/Checkpoint.java +++ b/core/src/main/java/org/elasticsearch/index/translog/Checkpoint.java @@ -61,7 +61,7 @@ class Checkpoint { Channels.writeToChannel(buffer, channel); } - private void write(DataOutput out) throws IOException { + void write(DataOutput out) throws IOException { out.writeLong(offset); out.writeInt(numOps); out.writeLong(generation); diff --git a/core/src/main/java/org/elasticsearch/index/translog/TranslogReader.java b/core/src/main/java/org/elasticsearch/index/translog/TranslogReader.java index fcb3daea796..581e8d6a903 100644 --- a/core/src/main/java/org/elasticsearch/index/translog/TranslogReader.java +++ b/core/src/main/java/org/elasticsearch/index/translog/TranslogReader.java @@ -113,7 +113,9 @@ public class TranslogReader extends BaseTranslogReader implements Closeable { headerStream.read(ref.bytes, ref.offset, ref.length); BytesRef uuidBytes = new BytesRef(translogUUID); if (uuidBytes.bytesEquals(ref) == false) { - throw new TranslogCorruptedException("expected shard UUID [" + uuidBytes + "] but got: [" + ref + "] this translog file belongs to a different translog. path:" + path); + throw new TranslogCorruptedException("expected shard UUID " + uuidBytes + "/" + uuidBytes.utf8ToString() + + " but got: " + ref + "/" + ref.utf8ToString() + + " this translog file belongs to a different translog. path:" + path); } return new TranslogReader(checkpoint.generation, channel, path, ref.length + CodecUtil.headerLength(TranslogWriter.TRANSLOG_CODEC) + Integer.BYTES, checkpoint.offset, checkpoint.numOps); default: diff --git a/core/src/main/java/org/elasticsearch/index/translog/TranslogToolCli.java b/core/src/main/java/org/elasticsearch/index/translog/TranslogToolCli.java new file mode 100644 index 00000000000..eaf50f25a01 --- /dev/null +++ b/core/src/main/java/org/elasticsearch/index/translog/TranslogToolCli.java @@ -0,0 +1,56 @@ +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.index.translog; + +import org.elasticsearch.cli.MultiCommand; +import org.elasticsearch.cli.Terminal; +import org.elasticsearch.common.logging.LogConfigurator; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.env.Environment; +import org.elasticsearch.index.translog.TruncateTranslogCommand; +import org.elasticsearch.node.internal.InternalSettingsPreparer; + +/** + * Class encapsulating and dispatching commands from the {@code elasticsearch-translog} command line tool + */ +public class TranslogToolCli extends MultiCommand { + + public TranslogToolCli() { + super("A CLI tool for various Elasticsearch translog actions"); + subcommands.put("truncate", new TruncateTranslogCommand()); + } + + public static void main(String[] args) throws Exception { + // initialize default for es.logger.level because we will not read the logging.yml + String loggerLevel = System.getProperty("es.logger.level", "INFO"); + String pathHome = System.getProperty("es.path.home"); + // Set the appender for all potential log files to terminal so that other components that use the logger print out the + // same terminal. + Environment loggingEnvironment = InternalSettingsPreparer.prepareEnvironment(Settings.builder() + .put("path.home", pathHome) + .put("appender.terminal.type", "terminal") + .put("rootLogger", "${logger.level}, terminal") + .put("logger.level", loggerLevel) + .build(), Terminal.DEFAULT); + LogConfigurator.configure(loggingEnvironment.settings(), false); + + exit(new TranslogToolCli().main(args, Terminal.DEFAULT)); + } +} diff --git a/core/src/main/java/org/elasticsearch/index/translog/TranslogWriter.java b/core/src/main/java/org/elasticsearch/index/translog/TranslogWriter.java index 89d12983b07..bb4a84651c5 100644 --- a/core/src/main/java/org/elasticsearch/index/translog/TranslogWriter.java +++ b/core/src/main/java/org/elasticsearch/index/translog/TranslogWriter.java @@ -76,10 +76,16 @@ public class TranslogWriter extends BaseTranslogReader implements Closeable { return getHeaderLength(new BytesRef(translogUUID).length); } - private static int getHeaderLength(int uuidLength) { + static int getHeaderLength(int uuidLength) { return CodecUtil.headerLength(TRANSLOG_CODEC) + uuidLength + Integer.BYTES; } + static void writeHeader(OutputStreamDataOutput out, BytesRef ref) throws IOException { + CodecUtil.writeHeader(out, TRANSLOG_CODEC, VERSION); + out.writeInt(ref.length); + out.writeBytes(ref.bytes, ref.offset, ref.length); + } + public static TranslogWriter create(ShardId shardId, String translogUUID, long fileGeneration, Path file, ChannelFactory channelFactory, ByteSizeValue bufferSize) throws IOException { final BytesRef ref = new BytesRef(translogUUID); final int headerLength = getHeaderLength(ref.length); @@ -88,9 +94,7 @@ public class TranslogWriter extends BaseTranslogReader implements Closeable { // This OutputStreamDataOutput is intentionally not closed because // closing it will close the FileChannel final OutputStreamDataOutput out = new OutputStreamDataOutput(java.nio.channels.Channels.newOutputStream(channel)); - CodecUtil.writeHeader(out, TRANSLOG_CODEC, VERSION); - out.writeInt(ref.length); - out.writeBytes(ref.bytes, ref.offset, ref.length); + writeHeader(out, ref); channel.force(true); writeCheckpoint(channelFactory, headerLength, 0, file.getParent(), fileGeneration); final TranslogWriter writer = new TranslogWriter(channelFactory, shardId, fileGeneration, channel, file, bufferSize); diff --git a/core/src/main/java/org/elasticsearch/index/translog/TruncateTranslogCommand.java b/core/src/main/java/org/elasticsearch/index/translog/TruncateTranslogCommand.java new file mode 100644 index 00000000000..b6b91f14ba8 --- /dev/null +++ b/core/src/main/java/org/elasticsearch/index/translog/TruncateTranslogCommand.java @@ -0,0 +1,224 @@ +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.index.translog; + +import joptsimple.OptionParser; +import joptsimple.OptionSet; +import joptsimple.OptionSpec; +import org.apache.lucene.index.DirectoryReader; +import org.apache.lucene.index.IndexCommit; +import org.apache.lucene.index.IndexWriter; +import org.apache.lucene.store.Directory; +import org.apache.lucene.store.FSDirectory; +import org.apache.lucene.store.Lock; +import org.apache.lucene.store.LockObtainFailedException; +import org.apache.lucene.store.NativeFSLockFactory; +import org.apache.lucene.store.OutputStreamDataOutput; +import org.apache.lucene.util.BytesRef; +import org.apache.lucene.util.IOUtils; +import org.elasticsearch.ElasticsearchException; +import org.elasticsearch.cli.SettingCommand; +import org.elasticsearch.cli.Terminal; +import org.elasticsearch.common.Strings; +import org.elasticsearch.common.SuppressForbidden; +import org.elasticsearch.common.io.PathUtils; +import org.elasticsearch.index.IndexNotFoundException; +import org.elasticsearch.index.translog.Checkpoint; + +import java.io.IOException; +import java.nio.channels.Channels; +import java.nio.channels.FileChannel; +import java.nio.file.DirectoryStream; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.StandardCopyOption; +import java.nio.file.StandardOpenOption; +import java.util.Arrays; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +public class TruncateTranslogCommand extends SettingCommand { + + private final OptionSpec translogFolder; + private final OptionSpec batchMode; + + public TruncateTranslogCommand() { + super("Truncates a translog to create a new, empty translog"); + this.translogFolder = parser.acceptsAll(Arrays.asList("d", "dir"), + "Translog Directory location on disk") + .withRequiredArg() + .required(); + this.batchMode = parser.acceptsAll(Arrays.asList("b", "batch"), + "Enable batch mode explicitly, automatic confirmation of warnings"); + } + + // Visible for testing + public OptionParser getParser() { + return this.parser; + } + + @Override + protected void printAdditionalHelp(Terminal terminal) { + terminal.println("This tool truncates the translog and translog"); + terminal.println("checkpoint files to create a new translog"); + } + + @SuppressForbidden(reason = "Necessary to use the path passed in") + private Path getTranslogPath(OptionSet options) { + return PathUtils.get(translogFolder.value(options), "", ""); + } + + @Override + protected void execute(Terminal terminal, OptionSet options, Map settings) throws Exception { + boolean batch = options.has(batchMode); + + Path translogPath = getTranslogPath(options); + Path idxLocation = translogPath.getParent().resolve("index"); + + if (Files.exists(translogPath) == false || Files.isDirectory(translogPath) == false) { + throw new ElasticsearchException("translog directory [" + translogPath + "], must exist and be a directory"); + } + + if (Files.exists(idxLocation) == false || Files.isDirectory(idxLocation) == false) { + throw new ElasticsearchException("unable to find a shard at [" + idxLocation + "], which must exist and be a directory"); + } + + // Hold the lock open for the duration of the tool running + try (Directory dir = FSDirectory.open(idxLocation, NativeFSLockFactory.INSTANCE); + Lock writeLock = dir.obtainLock(IndexWriter.WRITE_LOCK_NAME)) { + Set translogFiles; + try { + terminal.println("Checking existing translog files"); + translogFiles = filesInDirectory(translogPath); + } catch (IOException e) { + terminal.println("encountered IOException while listing directory, aborting..."); + throw new ElasticsearchException("failed to find existing translog files", e); + } + + // Warn about ES being stopped and files being deleted + warnAboutDeletingFiles(terminal, translogFiles, batch); + + List commits; + try { + terminal.println("Reading translog UUID information from Lucene commit from shard at [" + idxLocation + "]"); + commits = DirectoryReader.listCommits(dir); + } catch (IndexNotFoundException infe) { + throw new ElasticsearchException("unable to find a valid shard at [" + idxLocation + "]", infe); + } + + // Retrieve the generation and UUID from the existing data + Map commitData = commits.get(commits.size() - 1).getUserData(); + String translogGeneration = commitData.get(Translog.TRANSLOG_GENERATION_KEY); + String translogUUID = commitData.get(Translog.TRANSLOG_UUID_KEY); + if (translogGeneration == null || translogUUID == null) { + throw new ElasticsearchException("shard must have a valid translog generation and UUID but got: [{}] and: [{}]", + translogGeneration, translogUUID); + } + terminal.println("Translog Generation: " + translogGeneration); + terminal.println("Translog UUID : " + translogUUID); + + Path tempEmptyCheckpoint = translogPath.resolve("temp-" + Translog.CHECKPOINT_FILE_NAME); + Path realEmptyCheckpoint = translogPath.resolve(Translog.CHECKPOINT_FILE_NAME); + Path tempEmptyTranslog = translogPath.resolve("temp-" + Translog.TRANSLOG_FILE_PREFIX + + translogGeneration + Translog.TRANSLOG_FILE_SUFFIX); + Path realEmptyTranslog = translogPath.resolve(Translog.TRANSLOG_FILE_PREFIX + + translogGeneration + Translog.TRANSLOG_FILE_SUFFIX); + + // Write empty checkpoint and translog to empty files + long gen = Long.parseLong(translogGeneration); + int translogLen = writeEmptyTranslog(tempEmptyTranslog, translogUUID); + writeEmptyCheckpoint(tempEmptyCheckpoint, translogLen, gen); + + terminal.println("Removing existing translog files"); + IOUtils.rm(translogFiles.toArray(new Path[]{})); + + terminal.println("Creating new empty checkpoint at [" + realEmptyCheckpoint + "]"); + Files.move(tempEmptyCheckpoint, realEmptyCheckpoint, StandardCopyOption.ATOMIC_MOVE); + terminal.println("Creating new empty translog at [" + realEmptyTranslog + "]"); + Files.move(tempEmptyTranslog, realEmptyTranslog, StandardCopyOption.ATOMIC_MOVE); + + // Fsync the translog directory after rename + IOUtils.fsync(translogPath, true); + + } catch (LockObtainFailedException lofe) { + throw new ElasticsearchException("Failed to lock shard's directory at [" + idxLocation + "], is Elasticsearch still running?"); + } + + terminal.println("Done."); + } + + /** Write a checkpoint file to the given location with the given generation */ + public static void writeEmptyCheckpoint(Path filename, int translogLength, long translogGeneration) throws IOException { + try (FileChannel fc = FileChannel.open(filename, StandardOpenOption.WRITE, StandardOpenOption.READ, StandardOpenOption.CREATE_NEW); + OutputStreamDataOutput out = new OutputStreamDataOutput(Channels.newOutputStream(fc))) { + Checkpoint emptyCheckpoint = new Checkpoint(translogLength, 0, translogGeneration); + emptyCheckpoint.write(out); + fc.force(true); + } + } + + /** + * Write a translog containing the given translog UUID to the given location. Returns the number of bytes written. + */ + public static int writeEmptyTranslog(Path filename, String translogUUID) throws IOException { + final BytesRef translogRef = new BytesRef(translogUUID); + try (FileChannel fc = FileChannel.open(filename, StandardOpenOption.WRITE, StandardOpenOption.READ, StandardOpenOption.CREATE_NEW); + OutputStreamDataOutput out = new OutputStreamDataOutput(Channels.newOutputStream(fc))) { + TranslogWriter.writeHeader(out, translogRef); + fc.force(true); + } + return TranslogWriter.getHeaderLength(translogRef.length); + } + + /** Show a warning about deleting files, asking for a confirmation if {@code batchMode} is false */ + public static void warnAboutDeletingFiles(Terminal terminal, Set files, boolean batchMode) { + terminal.println("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); + terminal.println("! WARNING: Elasticsearch MUST be stopped before running this tool !"); + terminal.println("! !"); + terminal.println("! WARNING: Documents inside of translog files will be lost !"); + terminal.println("! !"); + terminal.println("! WARNING: The following files will be DELETED! !"); + terminal.println("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); + for (Path file : files) { + terminal.println("--> " + file); + } + terminal.println(""); + if (batchMode == false) { + String text = terminal.readText("Continue and DELETE files? [y/N] "); + if (!text.equalsIgnoreCase("y")) { + throw new ElasticsearchException("aborted by user"); + } + } + } + + /** Return a Set of all files in a given directory */ + public static Set filesInDirectory(Path directory) throws IOException { + Set files = new HashSet<>(); + try (DirectoryStream stream = Files.newDirectoryStream(directory)) { + for (Path file : stream) { + files.add(file); + } + } + return files; + } + +} diff --git a/core/src/main/java/org/elasticsearch/ingest/CompoundProcessor.java b/core/src/main/java/org/elasticsearch/ingest/CompoundProcessor.java index 501e8c1b2f9..3ab7c078cd7 100644 --- a/core/src/main/java/org/elasticsearch/ingest/CompoundProcessor.java +++ b/core/src/main/java/org/elasticsearch/ingest/CompoundProcessor.java @@ -135,14 +135,14 @@ public class CompoundProcessor implements Processor { List processorTagHeader = cause.getHeader("processor_tag"); String failedProcessorType = (processorTypeHeader != null) ? processorTypeHeader.get(0) : null; String failedProcessorTag = (processorTagHeader != null) ? processorTagHeader.get(0) : null; - Map ingestMetadata = ingestDocument.getIngestMetadata(); + Map ingestMetadata = ingestDocument.getIngestMetadata(); ingestMetadata.put(ON_FAILURE_MESSAGE_FIELD, cause.getRootCause().getMessage()); ingestMetadata.put(ON_FAILURE_PROCESSOR_TYPE_FIELD, failedProcessorType); ingestMetadata.put(ON_FAILURE_PROCESSOR_TAG_FIELD, failedProcessorTag); } private void removeFailureMetadata(IngestDocument ingestDocument) { - Map ingestMetadata = ingestDocument.getIngestMetadata(); + Map ingestMetadata = ingestDocument.getIngestMetadata(); ingestMetadata.remove(ON_FAILURE_MESSAGE_FIELD); ingestMetadata.remove(ON_FAILURE_PROCESSOR_TYPE_FIELD); ingestMetadata.remove(ON_FAILURE_PROCESSOR_TAG_FIELD); diff --git a/core/src/main/java/org/elasticsearch/ingest/IngestDocument.java b/core/src/main/java/org/elasticsearch/ingest/IngestDocument.java index baa0f3acd0d..86eaf7d179f 100644 --- a/core/src/main/java/org/elasticsearch/ingest/IngestDocument.java +++ b/core/src/main/java/org/elasticsearch/ingest/IngestDocument.java @@ -54,7 +54,7 @@ public final class IngestDocument { static final String TIMESTAMP = "timestamp"; private final Map sourceAndMetadata; - private final Map ingestMetadata; + private final Map ingestMetadata; public IngestDocument(String index, String type, String id, String routing, String parent, String timestamp, String ttl, Map source) { @@ -94,7 +94,7 @@ public final class IngestDocument { * source and ingest metadata. This is needed because the ingest metadata will be initialized with the current timestamp at * init time, which makes equality comparisons impossible in tests. */ - public IngestDocument(Map sourceAndMetadata, Map ingestMetadata) { + public IngestDocument(Map sourceAndMetadata, Map ingestMetadata) { this.sourceAndMetadata = sourceAndMetadata; this.ingestMetadata = ingestMetadata; } @@ -517,7 +517,7 @@ public final class IngestDocument { * Returns the available ingest metadata fields, by default only timestamp, but it is possible to set additional ones. * Use only for reading values, modify them instead using {@link #setFieldValue(String, Object)} and {@link #removeField(String)} */ - public Map getIngestMetadata() { + public Map getIngestMetadata() { return this.ingestMetadata; } diff --git a/core/src/main/java/org/elasticsearch/ingest/PipelineStore.java b/core/src/main/java/org/elasticsearch/ingest/PipelineStore.java index 50ae19a2ca1..713001c233e 100644 --- a/core/src/main/java/org/elasticsearch/ingest/PipelineStore.java +++ b/core/src/main/java/org/elasticsearch/ingest/PipelineStore.java @@ -207,6 +207,11 @@ public class PipelineStore extends AbstractComponent implements ClusterStateList return Collections.emptyList(); } + // if we didn't ask for _any_ ID, then we get them all (this is the same as if they ask for '*') + if (ids.length == 0) { + return new ArrayList<>(ingestMetadata.getPipelines().values()); + } + List result = new ArrayList<>(ids.length); for (String id : ids) { if (Regex.isSimpleMatchPattern(id)) { diff --git a/core/src/main/java/org/elasticsearch/rest/action/ingest/RestGetPipelineAction.java b/core/src/main/java/org/elasticsearch/rest/action/ingest/RestGetPipelineAction.java index 55f14cfaa84..2b7adedcacf 100644 --- a/core/src/main/java/org/elasticsearch/rest/action/ingest/RestGetPipelineAction.java +++ b/core/src/main/java/org/elasticsearch/rest/action/ingest/RestGetPipelineAction.java @@ -35,6 +35,7 @@ public class RestGetPipelineAction extends BaseRestHandler { @Inject public RestGetPipelineAction(Settings settings, RestController controller) { super(settings); + controller.registerHandler(RestRequest.Method.GET, "/_ingest/pipeline", this); controller.registerHandler(RestRequest.Method.GET, "/_ingest/pipeline/{id}", this); } diff --git a/core/src/test/java/org/elasticsearch/ExceptionSerializationTests.java b/core/src/test/java/org/elasticsearch/ExceptionSerializationTests.java index 0cebf280acb..a7dbb145e40 100644 --- a/core/src/test/java/org/elasticsearch/ExceptionSerializationTests.java +++ b/core/src/test/java/org/elasticsearch/ExceptionSerializationTests.java @@ -121,7 +121,7 @@ public class ExceptionSerializationTests extends ESTestCase { final Path startPath = PathUtils.get(ElasticsearchException.class.getProtectionDomain().getCodeSource().getLocation().toURI()) .resolve("org").resolve("elasticsearch"); final Set> ignore = Sets.newHashSet( - org.elasticsearch.test.rest.parser.RestTestParseException.class, + org.elasticsearch.test.rest.yaml.parser.ClientYamlTestParseException.class, CancellableThreadsTests.CustomException.class, org.elasticsearch.rest.BytesRestResponseTests.WithHeadersException.class, AbstractClientHeadersTestCase.InternalException.class); diff --git a/core/src/test/java/org/elasticsearch/action/DocWriteResponseTests.java b/core/src/test/java/org/elasticsearch/action/DocWriteResponseTests.java index e652a670a67..7b2dac678fd 100644 --- a/core/src/test/java/org/elasticsearch/action/DocWriteResponseTests.java +++ b/core/src/test/java/org/elasticsearch/action/DocWriteResponseTests.java @@ -19,12 +19,13 @@ package org.elasticsearch.action; +import org.elasticsearch.action.DocWriteResponse.Operation; import org.elasticsearch.index.shard.ShardId; import org.elasticsearch.test.ESTestCase; public class DocWriteResponseTests extends ESTestCase { public void testGetLocation() { - DocWriteResponse response = new DocWriteResponse(new ShardId("index", "uuid", 0), "type", "id", 0) { + DocWriteResponse response = new DocWriteResponse(new ShardId("index", "uuid", 0), "type", "id", 0, Operation.CREATE) { // DocWriteResponse is abstract so we have to sneak a subclass in here to test it. }; assertEquals("/index/type/id", response.getLocation(null)); diff --git a/core/src/test/java/org/elasticsearch/action/ingest/SimulateExecutionServiceTests.java b/core/src/test/java/org/elasticsearch/action/ingest/SimulateExecutionServiceTests.java index 5b3551b24d1..8cf05509813 100644 --- a/core/src/test/java/org/elasticsearch/action/ingest/SimulateExecutionServiceTests.java +++ b/core/src/test/java/org/elasticsearch/action/ingest/SimulateExecutionServiceTests.java @@ -145,7 +145,7 @@ public class SimulateExecutionServiceTests extends ESTestCase { assertThat(simulateDocumentVerboseResult.getProcessorResults().get(1).getIngestDocument(), not(sameInstance(ingestDocument))); IngestDocument ingestDocumentWithOnFailureMetadata = new IngestDocument(ingestDocument); - Map metadata = ingestDocumentWithOnFailureMetadata.getIngestMetadata(); + Map metadata = ingestDocumentWithOnFailureMetadata.getIngestMetadata(); metadata.put(CompoundProcessor.ON_FAILURE_PROCESSOR_TYPE_FIELD, "mock"); metadata.put(CompoundProcessor.ON_FAILURE_PROCESSOR_TAG_FIELD, "processor_0"); metadata.put(CompoundProcessor.ON_FAILURE_MESSAGE_FIELD, "processor failed"); diff --git a/core/src/test/java/org/elasticsearch/action/ingest/TrackingResultProcessorTests.java b/core/src/test/java/org/elasticsearch/action/ingest/TrackingResultProcessorTests.java index 999cbe435f2..3572a04529b 100644 --- a/core/src/test/java/org/elasticsearch/action/ingest/TrackingResultProcessorTests.java +++ b/core/src/test/java/org/elasticsearch/action/ingest/TrackingResultProcessorTests.java @@ -111,7 +111,7 @@ public class TrackingResultProcessorTests extends ESTestCase { assertThat(resultList.get(0).getFailure(), equalTo(exception)); assertThat(resultList.get(0).getProcessorTag(), equalTo(expectedFailResult.getProcessorTag())); - Map metadata = resultList.get(1).getIngestDocument().getIngestMetadata(); + Map metadata = resultList.get(1).getIngestDocument().getIngestMetadata(); assertThat(metadata.get(ON_FAILURE_MESSAGE_FIELD), equalTo("fail")); assertThat(metadata.get(ON_FAILURE_PROCESSOR_TYPE_FIELD), equalTo("test")); assertThat(metadata.get(ON_FAILURE_PROCESSOR_TAG_FIELD), equalTo("fail")); diff --git a/core/src/test/java/org/elasticsearch/action/ingest/WriteableIngestDocumentTests.java b/core/src/test/java/org/elasticsearch/action/ingest/WriteableIngestDocumentTests.java index b4908846e97..5df0aa1de0c 100644 --- a/core/src/test/java/org/elasticsearch/action/ingest/WriteableIngestDocumentTests.java +++ b/core/src/test/java/org/elasticsearch/action/ingest/WriteableIngestDocumentTests.java @@ -47,7 +47,7 @@ public class WriteableIngestDocumentTests extends ESTestCase { for (int i = 0; i < numFields; i++) { sourceAndMetadata.put(randomFrom(IngestDocument.MetaData.values()).getFieldName(), randomAsciiOfLengthBetween(5, 10)); } - Map ingestMetadata = new HashMap<>(); + Map ingestMetadata = new HashMap<>(); numFields = randomIntBetween(1, 5); for (int i = 0; i < numFields; i++) { ingestMetadata.put(randomAsciiOfLengthBetween(5, 10), randomAsciiOfLengthBetween(5, 10)); @@ -70,7 +70,7 @@ public class WriteableIngestDocumentTests extends ESTestCase { changed = true; } - Map otherIngestMetadata; + Map otherIngestMetadata; if (randomBoolean()) { otherIngestMetadata = new HashMap<>(); numFields = randomIntBetween(1, 5); @@ -103,7 +103,7 @@ public class WriteableIngestDocumentTests extends ESTestCase { for (int i = 0; i < numFields; i++) { sourceAndMetadata.put(randomFrom(IngestDocument.MetaData.values()).getFieldName(), randomAsciiOfLengthBetween(5, 10)); } - Map ingestMetadata = new HashMap<>(); + Map ingestMetadata = new HashMap<>(); numFields = randomIntBetween(1, 5); for (int i = 0; i < numFields; i++) { ingestMetadata.put(randomAsciiOfLengthBetween(5, 10), randomAsciiOfLengthBetween(5, 10)); @@ -131,7 +131,7 @@ public class WriteableIngestDocumentTests extends ESTestCase { Map toXContentDoc = (Map) toXContentMap.get("doc"); Map toXContentSource = (Map) toXContentDoc.get("_source"); - Map toXContentIngestMetadata = (Map) toXContentDoc.get("_ingest"); + Map toXContentIngestMetadata = (Map) toXContentDoc.get("_ingest"); Map metadataMap = ingestDocument.extractMetadata(); for (Map.Entry metadata : metadataMap.entrySet()) { diff --git a/core/src/test/java/org/elasticsearch/index/query/QueryParseContextTests.java b/core/src/test/java/org/elasticsearch/index/query/QueryParseContextTests.java new file mode 100644 index 00000000000..fb88adfc95f --- /dev/null +++ b/core/src/test/java/org/elasticsearch/index/query/QueryParseContextTests.java @@ -0,0 +1,128 @@ +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.index.query; + +import org.elasticsearch.common.ParseFieldMatcher; +import org.elasticsearch.common.ParsingException; +import org.elasticsearch.common.io.stream.NamedWriteableRegistry; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.xcontent.XContentFactory; +import org.elasticsearch.common.xcontent.XContentParser; +import org.elasticsearch.common.xcontent.json.JsonXContent; +import org.elasticsearch.indices.query.IndicesQueriesRegistry; +import org.elasticsearch.search.SearchModule; +import org.elasticsearch.test.ESTestCase; +import org.junit.BeforeClass; + +import java.io.IOException; +import java.util.Optional; + +import static java.util.Collections.emptyList; + +public class QueryParseContextTests extends ESTestCase { + + private static IndicesQueriesRegistry indicesQueriesRegistry; + + @BeforeClass + public static void init() { + indicesQueriesRegistry = new SearchModule(Settings.EMPTY, new NamedWriteableRegistry(), false, emptyList()) + .getQueryParserRegistry(); + } + + public void testParseTopLevelBuilder() throws IOException { + QueryBuilder query = new MatchQueryBuilder("foo", "bar"); + String requestBody = "{ \"query\" : " + query.toString() + "}"; + try (XContentParser parser = XContentFactory.xContent(requestBody).createParser(requestBody)) { + QueryParseContext context = new QueryParseContext(indicesQueriesRegistry, parser, ParseFieldMatcher.STRICT); + QueryBuilder actual = context.parseTopLevelQueryBuilder(); + assertEquals(query, actual); + } + } + + public void testParseTopLevelBuilderEmptyObject() throws IOException { + String requestBody = "{}"; + try (XContentParser parser = XContentFactory.xContent(requestBody).createParser(requestBody)) { + QueryParseContext context = new QueryParseContext(indicesQueriesRegistry, parser, ParseFieldMatcher.STRICT); + QueryBuilder query = context.parseTopLevelQueryBuilder(); + assertNull(query); + } + } + + public void testParseTopLevelBuilderUnknownParameter() throws IOException { + String requestBody = "{ \"foo\" : \"bar\"}"; + try (XContentParser parser = XContentFactory.xContent(requestBody).createParser(requestBody)) { + QueryParseContext context = new QueryParseContext(indicesQueriesRegistry, parser, ParseFieldMatcher.STRICT); + ParsingException exception = expectThrows(ParsingException.class, () -> context.parseTopLevelQueryBuilder()); + assertEquals("request does not support [foo]", exception.getMessage()); + } + } + + public void testParseInnerQueryBuilder() throws IOException { + QueryBuilder query = new MatchQueryBuilder("foo", "bar"); + String source = query.toString(); + try (XContentParser parser = XContentFactory.xContent(source).createParser(source)) { + QueryParseContext context = new QueryParseContext(indicesQueriesRegistry, parser, ParseFieldMatcher.STRICT); + Optional actual = context.parseInnerQueryBuilder(); + assertEquals(query, actual.get()); + } + } + + public void testParseInnerQueryBuilderEmptyBody() throws IOException { + String source = "{}"; + try (XContentParser parser = XContentFactory.xContent(source).createParser(source)) { + QueryParseContext context = new QueryParseContext(indicesQueriesRegistry, parser, ParseFieldMatcher.EMPTY); + Optional emptyQuery = context.parseInnerQueryBuilder(); + assertFalse(emptyQuery.isPresent()); + } + } + + public void testParseInnerQueryBuilderExceptions() throws IOException { + String source = "{ \"foo\": \"bar\" }"; + try (XContentParser parser = JsonXContent.jsonXContent.createParser(source)) { + parser.nextToken(); + parser.nextToken(); // don't start with START_OBJECT to provoke exception + QueryParseContext context = new QueryParseContext(indicesQueriesRegistry, parser, ParseFieldMatcher.STRICT); + ParsingException exception = expectThrows(ParsingException.class, () -> context.parseInnerQueryBuilder()); + assertEquals("[_na] query malformed, must start with start_object", exception.getMessage()); + } + + source = "{}"; + try (XContentParser parser = JsonXContent.jsonXContent.createParser(source)) { + QueryParseContext context = new QueryParseContext(indicesQueriesRegistry, parser, ParseFieldMatcher.STRICT); + IllegalArgumentException exception = expectThrows(IllegalArgumentException.class, () -> context.parseInnerQueryBuilder()); + assertEquals("query malformed, empty clause found at [1:2]", exception.getMessage()); + } + + source = "{ \"foo\" : \"bar\" }"; + try (XContentParser parser = JsonXContent.jsonXContent.createParser(source)) { + QueryParseContext context = new QueryParseContext(indicesQueriesRegistry, parser, ParseFieldMatcher.STRICT); + ParsingException exception = expectThrows(ParsingException.class, () -> context.parseInnerQueryBuilder()); + assertEquals("[_na] query malformed, no start_object after query name", exception.getMessage()); + } + + source = "{ \"foo\" : {} }"; + try (XContentParser parser = JsonXContent.jsonXContent.createParser(source)) { + QueryParseContext context = new QueryParseContext(indicesQueriesRegistry, parser, ParseFieldMatcher.STRICT); + ParsingException exception = expectThrows(ParsingException.class, () -> context.parseInnerQueryBuilder()); + assertEquals("no [query] registered for [foo]", exception.getMessage()); + } + } + +} diff --git a/core/src/test/java/org/elasticsearch/index/store/CorruptedFileIT.java b/core/src/test/java/org/elasticsearch/index/store/CorruptedFileIT.java index a8f8a9f802d..7813c8402f0 100644 --- a/core/src/test/java/org/elasticsearch/index/store/CorruptedFileIT.java +++ b/core/src/test/java/org/elasticsearch/index/store/CorruptedFileIT.java @@ -70,6 +70,7 @@ import org.elasticsearch.test.CorruptionUtils; import org.elasticsearch.test.ESIntegTestCase; import org.elasticsearch.test.InternalSettingsPlugin; import org.elasticsearch.test.MockIndexEventListener; +import org.elasticsearch.test.junit.annotations.TestLogging; import org.elasticsearch.test.store.MockFSIndexStore; import org.elasticsearch.test.transport.MockTransportService; import org.elasticsearch.transport.TransportException; @@ -471,6 +472,7 @@ public class CorruptedFileIT extends ESIntegTestCase { * TODO once checksum verification on snapshotting is implemented this test needs to be fixed or split into several * parts... We should also corrupt files on the actual snapshot and check that we don't restore the corrupted shard. */ + @TestLogging("monitor.fs:DEBUG") public void testCorruptFileThenSnapshotAndRestore() throws ExecutionException, InterruptedException, IOException { int numDocs = scaledRandomIntBetween(100, 1000); internalCluster().ensureAtLeastNumDataNodes(2); diff --git a/core/src/test/java/org/elasticsearch/index/translog/TruncateTranslogIT.java b/core/src/test/java/org/elasticsearch/index/translog/TruncateTranslogIT.java new file mode 100644 index 00000000000..fa8a87cf382 --- /dev/null +++ b/core/src/test/java/org/elasticsearch/index/translog/TruncateTranslogIT.java @@ -0,0 +1,256 @@ +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.index.translog; + +import com.carrotsearch.randomizedtesting.generators.RandomPicks; +import joptsimple.OptionParser; +import joptsimple.OptionSet; +import org.apache.lucene.index.IndexWriter; +import org.apache.lucene.store.Directory; +import org.apache.lucene.store.FSDirectory; +import org.apache.lucene.store.Lock; +import org.apache.lucene.store.LockObtainFailedException; +import org.apache.lucene.store.NativeFSLockFactory; +import org.elasticsearch.ElasticsearchException; +import org.elasticsearch.action.admin.cluster.node.stats.NodesStatsResponse; +import org.elasticsearch.action.index.IndexRequestBuilder; +import org.elasticsearch.action.search.SearchPhaseExecutionException; +import org.elasticsearch.action.search.SearchResponse; +import org.elasticsearch.cli.MockTerminal; +import org.elasticsearch.cluster.ClusterState; +import org.elasticsearch.cluster.routing.GroupShardsIterator; +import org.elasticsearch.cluster.routing.ShardIterator; +import org.elasticsearch.cluster.routing.ShardRouting; +import org.elasticsearch.common.Priority; +import org.elasticsearch.common.io.PathUtils; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.unit.ByteSizeUnit; +import org.elasticsearch.common.unit.ByteSizeValue; +import org.elasticsearch.common.unit.TimeValue; +import org.elasticsearch.index.Index; +import org.elasticsearch.index.IndexSettings; +import org.elasticsearch.index.MockEngineFactoryPlugin; +import org.elasticsearch.index.translog.TruncateTranslogCommand; +import org.elasticsearch.monitor.fs.FsInfo; +import org.elasticsearch.plugins.Plugin; +import org.elasticsearch.test.ESIntegTestCase; +import org.elasticsearch.test.engine.MockEngineSupport; +import org.elasticsearch.test.hamcrest.ElasticsearchAssertions; +import org.elasticsearch.test.transport.MockTransportService; + +import java.io.IOException; +import java.nio.ByteBuffer; +import java.nio.channels.FileChannel; +import java.nio.file.DirectoryStream; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.StandardOpenOption; +import java.util.Arrays; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Set; +import java.util.TreeSet; +import java.util.concurrent.TimeUnit; + +import static org.elasticsearch.common.util.CollectionUtils.iterableAsArrayList; +import static org.elasticsearch.index.query.QueryBuilders.matchAllQuery; +import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; +import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.notNullValue; + +@ESIntegTestCase.ClusterScope(scope = ESIntegTestCase.Scope.SUITE, numDataNodes = 0) +public class TruncateTranslogIT extends ESIntegTestCase { + + @Override + protected Collection> nodePlugins() { + return pluginList(MockTransportService.TestPlugin.class, MockEngineFactoryPlugin.class); + } + + public void testCorruptTranslogTruncation() throws Exception { + internalCluster().startNodesAsync(1, Settings.EMPTY).get(); + + assertAcked(prepareCreate("test").setSettings(Settings.builder() + .put("index.number_of_shards", 1) + .put("index.number_of_replicas", 0) + .put("index.refresh_interval", "-1") + .put(MockEngineSupport.DISABLE_FLUSH_ON_CLOSE.getKey(), true) // never flush - always recover from translog + )); + ensureYellow(); + + // Index some documents + int numDocs = scaledRandomIntBetween(100, 1000); + IndexRequestBuilder[] builders = new IndexRequestBuilder[numDocs]; + for (int i = 0; i < builders.length; i++) { + builders[i] = client().prepareIndex("test", "type").setSource("foo", "bar"); + } + disableTranslogFlush("test"); + indexRandom(false, false, false, Arrays.asList(builders)); + Set translogDirs = getTranslogDirs("test"); + + TruncateTranslogCommand ttc = new TruncateTranslogCommand(); + MockTerminal t = new MockTerminal(); + OptionParser parser = ttc.getParser(); + + for (Path translogDir : translogDirs) { + OptionSet options = parser.parse("-d", translogDir.toAbsolutePath().toString(), "-b"); + // Try running it before the shard is closed, it should flip out because it can't acquire the lock + try { + logger.info("--> running truncate while index is open on [{}]", translogDir.toAbsolutePath()); + ttc.execute(t, options, new HashMap()); + fail("expected the truncate command to fail not being able to acquire the lock"); + } catch (Exception e) { + assertThat(e.getMessage(), containsString("Failed to lock shard's directory")); + } + } + + // Corrupt the translog file(s) + logger.info("--> corrupting translog"); + corruptRandomTranslogFiles("test"); + + // Restart the single node + logger.info("--> restarting node"); + internalCluster().fullRestart(); + client().admin().cluster().prepareHealth().setWaitForYellowStatus() + .setTimeout(new TimeValue(1000, TimeUnit.MILLISECONDS)) + .setWaitForEvents(Priority.LANGUID) + .get(); + + try { + client().prepareSearch("test").setQuery(matchAllQuery()).get(); + fail("all shards should be failed due to a corrupted translog"); + } catch (SearchPhaseExecutionException e) { + // Good, all shards should be failed because there is only a + // single shard and its translog is corrupt + } + + // Close the index so we can actually truncate the translog + logger.info("--> closing 'test' index"); + client().admin().indices().prepareClose("test").get(); + + for (Path translogDir : translogDirs) { + final Path idxLocation = translogDir.getParent().resolve("index"); + assertBusy(() -> { + logger.info("--> checking that lock has been released for {}", idxLocation); + try (Directory dir = FSDirectory.open(idxLocation, NativeFSLockFactory.INSTANCE); + Lock writeLock = dir.obtainLock(IndexWriter.WRITE_LOCK_NAME)) { + // Great, do nothing, we just wanted to obtain the lock + } catch (LockObtainFailedException lofe) { + throw new ElasticsearchException("Still waiting for lock release at [" + idxLocation + "]"); + } catch (IOException ioe) { + fail("Got an IOException: " + ioe); + } + }); + + OptionSet options = parser.parse("-d", translogDir.toAbsolutePath().toString(), "-b"); + logger.info("--> running truncate translog command for [{}]", translogDir.toAbsolutePath()); + ttc.execute(t, options, new HashMap()); + logger.info("--> output:\n{}", t.getOutput()); + } + + // Re-open index + logger.info("--> opening 'test' index"); + client().admin().indices().prepareOpen("test").get(); + ensureYellow("test"); + + // Run a search and make sure it succeeds + SearchResponse resp = client().prepareSearch("test").setQuery(matchAllQuery()).get(); + ElasticsearchAssertions.assertNoFailures(resp); + } + + private Set getTranslogDirs(String indexName) throws IOException { + ClusterState state = client().admin().cluster().prepareState().get().getState(); + GroupShardsIterator shardIterators = state.getRoutingTable().activePrimaryShardsGrouped(new String[]{indexName}, false); + final Index idx = state.metaData().index(indexName).getIndex(); + List iterators = iterableAsArrayList(shardIterators); + ShardIterator shardIterator = RandomPicks.randomFrom(random(), iterators); + ShardRouting shardRouting = shardIterator.nextOrNull(); + assertNotNull(shardRouting); + assertTrue(shardRouting.primary()); + assertTrue(shardRouting.assignedToNode()); + String nodeId = shardRouting.currentNodeId(); + NodesStatsResponse nodeStatses = client().admin().cluster().prepareNodesStats(nodeId).setFs(true).get(); + Set translogDirs = new TreeSet<>(); // treeset makes sure iteration order is deterministic + for (FsInfo.Path fsPath : nodeStatses.getNodes().get(0).getFs()) { + String path = fsPath.getPath(); + final String relativeDataLocationPath = "indices/"+ idx.getUUID() +"/" + Integer.toString(shardRouting.getId()) + "/translog"; + Path translogPath = PathUtils.get(path).resolve(relativeDataLocationPath); + if (Files.isDirectory(translogPath)) { + translogDirs.add(translogPath); + } + } + return translogDirs; + } + + private void corruptRandomTranslogFiles(String indexName) throws IOException { + Set translogDirs = getTranslogDirs(indexName); + Set files = new TreeSet<>(); // treeset makes sure iteration order is deterministic + for (Path translogDir : translogDirs) { + if (Files.isDirectory(translogDir)) { + logger.info("--> path: {}", translogDir); + try (DirectoryStream stream = Files.newDirectoryStream(translogDir)) { + for (Path item : stream) { + logger.info("--> File: {}", item); + if (Files.isRegularFile(item) && item.getFileName().toString().startsWith("translog-")) { + files.add(item); + } + } + } + } + } + Path fileToCorrupt = null; + if (!files.isEmpty()) { + int corruptions = randomIntBetween(5, 20); + for (int i = 0; i < corruptions; i++) { + fileToCorrupt = RandomPicks.randomFrom(random(), files); + try (FileChannel raf = FileChannel.open(fileToCorrupt, StandardOpenOption.READ, StandardOpenOption.WRITE)) { + // read + raf.position(randomIntBetween(0, (int) Math.min(Integer.MAX_VALUE, raf.size() - 1))); + long filePointer = raf.position(); + ByteBuffer bb = ByteBuffer.wrap(new byte[1]); + raf.read(bb); + bb.flip(); + + // corrupt + byte oldValue = bb.get(0); + byte newValue = (byte) (oldValue + 1); + bb.put(0, newValue); + + // rewrite + raf.position(filePointer); + raf.write(bb); + logger.info("--> corrupting file {} -- flipping at position {} from {} to {} file: {}", + fileToCorrupt, filePointer, Integer.toHexString(oldValue), + Integer.toHexString(newValue), fileToCorrupt); + } + } + } + assertThat("no file corrupted", fileToCorrupt, notNullValue()); + } + + /** Disables translog flushing for the specified index */ + private static void disableTranslogFlush(String index) { + Settings settings = Settings.builder() + .put(IndexSettings.INDEX_TRANSLOG_FLUSH_THRESHOLD_SIZE_SETTING.getKey(), new ByteSizeValue(1, ByteSizeUnit.PB)) + .build(); + client().admin().indices().prepareUpdateSettings(index).setSettings(settings).get(); + } + +} diff --git a/core/src/test/java/org/elasticsearch/ingest/CompoundProcessorTests.java b/core/src/test/java/org/elasticsearch/ingest/CompoundProcessorTests.java index be6ec1059d6..aaede49a36d 100644 --- a/core/src/test/java/org/elasticsearch/ingest/CompoundProcessorTests.java +++ b/core/src/test/java/org/elasticsearch/ingest/CompoundProcessorTests.java @@ -86,7 +86,7 @@ public class CompoundProcessorTests extends ESTestCase { public void testSingleProcessorWithOnFailureProcessor() throws Exception { TestProcessor processor1 = new TestProcessor("id", "first", ingestDocument -> {throw new RuntimeException("error");}); TestProcessor processor2 = new TestProcessor(ingestDocument -> { - Map ingestMetadata = ingestDocument.getIngestMetadata(); + Map ingestMetadata = ingestDocument.getIngestMetadata(); assertThat(ingestMetadata.size(), equalTo(3)); assertThat(ingestMetadata.get(CompoundProcessor.ON_FAILURE_MESSAGE_FIELD), equalTo("error")); assertThat(ingestMetadata.get(CompoundProcessor.ON_FAILURE_PROCESSOR_TYPE_FIELD), equalTo("first")); @@ -104,7 +104,7 @@ public class CompoundProcessorTests extends ESTestCase { public void testSingleProcessorWithNestedFailures() throws Exception { TestProcessor processor = new TestProcessor("id", "first", ingestDocument -> {throw new RuntimeException("error");}); TestProcessor processorToFail = new TestProcessor("id2", "second", ingestDocument -> { - Map ingestMetadata = ingestDocument.getIngestMetadata(); + Map ingestMetadata = ingestDocument.getIngestMetadata(); assertThat(ingestMetadata.size(), equalTo(3)); assertThat(ingestMetadata.get(CompoundProcessor.ON_FAILURE_MESSAGE_FIELD), equalTo("error")); assertThat(ingestMetadata.get(CompoundProcessor.ON_FAILURE_PROCESSOR_TYPE_FIELD), equalTo("first")); @@ -112,7 +112,7 @@ public class CompoundProcessorTests extends ESTestCase { throw new RuntimeException("error"); }); TestProcessor lastProcessor = new TestProcessor(ingestDocument -> { - Map ingestMetadata = ingestDocument.getIngestMetadata(); + Map ingestMetadata = ingestDocument.getIngestMetadata(); assertThat(ingestMetadata.size(), equalTo(3)); assertThat(ingestMetadata.get(CompoundProcessor.ON_FAILURE_MESSAGE_FIELD), equalTo("error")); assertThat(ingestMetadata.get(CompoundProcessor.ON_FAILURE_PROCESSOR_TYPE_FIELD), equalTo("second")); @@ -131,7 +131,7 @@ public class CompoundProcessorTests extends ESTestCase { public void testCompoundProcessorExceptionFailWithoutOnFailure() throws Exception { TestProcessor firstProcessor = new TestProcessor("id1", "first", ingestDocument -> {throw new RuntimeException("error");}); TestProcessor secondProcessor = new TestProcessor("id3", "second", ingestDocument -> { - Map ingestMetadata = ingestDocument.getIngestMetadata(); + Map ingestMetadata = ingestDocument.getIngestMetadata(); assertThat(ingestMetadata.entrySet(), hasSize(3)); assertThat(ingestMetadata.get(CompoundProcessor.ON_FAILURE_MESSAGE_FIELD), equalTo("error")); assertThat(ingestMetadata.get(CompoundProcessor.ON_FAILURE_PROCESSOR_TYPE_FIELD), equalTo("first")); @@ -153,7 +153,7 @@ public class CompoundProcessorTests extends ESTestCase { TestProcessor failProcessor = new TestProcessor("tag_fail", "fail", ingestDocument -> {throw new RuntimeException("custom error message");}); TestProcessor secondProcessor = new TestProcessor("id3", "second", ingestDocument -> { - Map ingestMetadata = ingestDocument.getIngestMetadata(); + Map ingestMetadata = ingestDocument.getIngestMetadata(); assertThat(ingestMetadata.entrySet(), hasSize(3)); assertThat(ingestMetadata.get(CompoundProcessor.ON_FAILURE_MESSAGE_FIELD), equalTo("custom error message")); assertThat(ingestMetadata.get(CompoundProcessor.ON_FAILURE_PROCESSOR_TYPE_FIELD), equalTo("fail")); @@ -176,7 +176,7 @@ public class CompoundProcessorTests extends ESTestCase { TestProcessor failProcessor = new TestProcessor("tag_fail", "fail", ingestDocument -> {throw new RuntimeException("custom error message");}); TestProcessor secondProcessor = new TestProcessor("id3", "second", ingestDocument -> { - Map ingestMetadata = ingestDocument.getIngestMetadata(); + Map ingestMetadata = ingestDocument.getIngestMetadata(); assertThat(ingestMetadata.entrySet(), hasSize(3)); assertThat(ingestMetadata.get(CompoundProcessor.ON_FAILURE_MESSAGE_FIELD), equalTo("custom error message")); assertThat(ingestMetadata.get(CompoundProcessor.ON_FAILURE_PROCESSOR_TYPE_FIELD), equalTo("fail")); diff --git a/core/src/test/java/org/elasticsearch/ingest/IngestDocumentTests.java b/core/src/test/java/org/elasticsearch/ingest/IngestDocumentTests.java index ee4da02478d..fa146951283 100644 --- a/core/src/test/java/org/elasticsearch/ingest/IngestDocumentTests.java +++ b/core/src/test/java/org/elasticsearch/ingest/IngestDocumentTests.java @@ -907,7 +907,7 @@ public class IngestDocumentTests extends ESTestCase { for (int i = 0; i < numFields; i++) { sourceAndMetadata.put(randomFrom(IngestDocument.MetaData.values()).getFieldName(), randomAsciiOfLengthBetween(5, 10)); } - Map ingestMetadata = new HashMap<>(); + Map ingestMetadata = new HashMap<>(); numFields = randomIntBetween(1, 5); for (int i = 0; i < numFields; i++) { ingestMetadata.put(randomAsciiOfLengthBetween(5, 10), randomAsciiOfLengthBetween(5, 10)); @@ -930,7 +930,7 @@ public class IngestDocumentTests extends ESTestCase { changed = true; } - Map otherIngestMetadata; + Map otherIngestMetadata; if (randomBoolean()) { otherIngestMetadata = new HashMap<>(); numFields = randomIntBetween(1, 5); @@ -962,7 +962,7 @@ public class IngestDocumentTests extends ESTestCase { long before = System.currentTimeMillis(); IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random()); long after = System.currentTimeMillis(); - String timestampString = ingestDocument.getIngestMetadata().get("timestamp"); + String timestampString = (String) ingestDocument.getIngestMetadata().get("timestamp"); assertThat(timestampString, notNullValue()); assertThat(timestampString, endsWith("+0000")); DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZZ", Locale.ROOT); diff --git a/core/src/test/java/org/elasticsearch/ingest/PipelineStoreTests.java b/core/src/test/java/org/elasticsearch/ingest/PipelineStoreTests.java index 1510d25b695..29032ae4326 100644 --- a/core/src/test/java/org/elasticsearch/ingest/PipelineStoreTests.java +++ b/core/src/test/java/org/elasticsearch/ingest/PipelineStoreTests.java @@ -28,11 +28,9 @@ import org.elasticsearch.cluster.ClusterName; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.metadata.MetaData; import org.elasticsearch.cluster.node.DiscoveryNode; -import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.bytes.BytesArray; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.transport.LocalTransportAddress; -import org.elasticsearch.script.ScriptService; import org.elasticsearch.test.ESTestCase; import org.junit.Before; @@ -48,7 +46,6 @@ import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.notNullValue; import static org.hamcrest.Matchers.nullValue; -import static org.mockito.Mockito.mock; public class PipelineStoreTests extends ESTestCase { @@ -216,6 +213,19 @@ public class PipelineStoreTests extends ESTestCase { assertThat(pipelines.size(), equalTo(2)); assertThat(pipelines.get(0).getId(), equalTo("_id1")); assertThat(pipelines.get(1).getId(), equalTo("_id2")); + + // get all variants: (no IDs or '*') + pipelines = store.innerGetPipelines(ingestMetadata); + pipelines.sort((o1, o2) -> o1.getId().compareTo(o2.getId())); + assertThat(pipelines.size(), equalTo(2)); + assertThat(pipelines.get(0).getId(), equalTo("_id1")); + assertThat(pipelines.get(1).getId(), equalTo("_id2")); + + pipelines = store.innerGetPipelines(ingestMetadata, "*"); + pipelines.sort((o1, o2) -> o1.getId().compareTo(o2.getId())); + assertThat(pipelines.size(), equalTo(2)); + assertThat(pipelines.get(0).getId(), equalTo("_id1")); + assertThat(pipelines.get(1).getId(), equalTo("_id2")); } public void testCrud() throws Exception { diff --git a/distribution/tar/src/test/java/org/elasticsearch/test/rest/RestIT.java b/distribution/deb/src/test/java/org/elasticsearch/test/rest/DebClientYamlTestSuiteIT.java similarity index 74% rename from distribution/tar/src/test/java/org/elasticsearch/test/rest/RestIT.java rename to distribution/deb/src/test/java/org/elasticsearch/test/rest/DebClientYamlTestSuiteIT.java index 94629641849..a94f0faf2d2 100644 --- a/distribution/tar/src/test/java/org/elasticsearch/test/rest/RestIT.java +++ b/distribution/deb/src/test/java/org/elasticsearch/test/rest/DebClientYamlTestSuiteIT.java @@ -20,18 +20,21 @@ package org.elasticsearch.test.rest; import com.carrotsearch.randomizedtesting.annotations.ParametersFactory; -import org.elasticsearch.test.rest.parser.RestTestParseException; + +import org.elasticsearch.test.rest.yaml.ClientYamlTestCandidate; +import org.elasticsearch.test.rest.yaml.ESClientYamlSuiteTestCase; +import org.elasticsearch.test.rest.yaml.parser.ClientYamlTestParseException; import java.io.IOException; /** Rest integration test. Runs against a cluster started by {@code gradle integTest} */ -public class RestIT extends ESClientYamlSuiteTestCase { - public RestIT(RestTestCandidate testCandidate) { +public class DebClientYamlTestSuiteIT extends ESClientYamlSuiteTestCase { + public DebClientYamlTestSuiteIT(ClientYamlTestCandidate testCandidate) { super(testCandidate); } @ParametersFactory - public static Iterable parameters() throws IOException, RestTestParseException { + public static Iterable parameters() throws IOException, ClientYamlTestParseException { return createParameters(0, 1); } } diff --git a/distribution/integ-test-zip/src/test/java/org/elasticsearch/test/rest/IntegTestZipClientYamlTestSuiteIT.java b/distribution/integ-test-zip/src/test/java/org/elasticsearch/test/rest/IntegTestZipClientYamlTestSuiteIT.java new file mode 100644 index 00000000000..ca54a3becd9 --- /dev/null +++ b/distribution/integ-test-zip/src/test/java/org/elasticsearch/test/rest/IntegTestZipClientYamlTestSuiteIT.java @@ -0,0 +1,40 @@ +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.test.rest; + +import com.carrotsearch.randomizedtesting.annotations.ParametersFactory; + +import org.elasticsearch.test.rest.yaml.ClientYamlTestCandidate; +import org.elasticsearch.test.rest.yaml.ESClientYamlSuiteTestCase; +import org.elasticsearch.test.rest.yaml.parser.ClientYamlTestParseException; + +import java.io.IOException; + +/** Rest integration test. Runs against a cluster started by {@code gradle integTest} */ +public class IntegTestZipClientYamlTestSuiteIT extends ESClientYamlSuiteTestCase { + public IntegTestZipClientYamlTestSuiteIT(ClientYamlTestCandidate testCandidate) { + super(testCandidate); + } + + @ParametersFactory + public static Iterable parameters() throws IOException, ClientYamlTestParseException { + return createParameters(0, 1); + } +} diff --git a/distribution/rpm/src/test/java/org/elasticsearch/test/rest/RestIT.java b/distribution/rpm/src/test/java/org/elasticsearch/test/rest/RpmClientYamlTestSuiteIT.java similarity index 74% rename from distribution/rpm/src/test/java/org/elasticsearch/test/rest/RestIT.java rename to distribution/rpm/src/test/java/org/elasticsearch/test/rest/RpmClientYamlTestSuiteIT.java index 94629641849..a5b7f46269f 100644 --- a/distribution/rpm/src/test/java/org/elasticsearch/test/rest/RestIT.java +++ b/distribution/rpm/src/test/java/org/elasticsearch/test/rest/RpmClientYamlTestSuiteIT.java @@ -20,18 +20,21 @@ package org.elasticsearch.test.rest; import com.carrotsearch.randomizedtesting.annotations.ParametersFactory; -import org.elasticsearch.test.rest.parser.RestTestParseException; + +import org.elasticsearch.test.rest.yaml.ClientYamlTestCandidate; +import org.elasticsearch.test.rest.yaml.ESClientYamlSuiteTestCase; +import org.elasticsearch.test.rest.yaml.parser.ClientYamlTestParseException; import java.io.IOException; /** Rest integration test. Runs against a cluster started by {@code gradle integTest} */ -public class RestIT extends ESClientYamlSuiteTestCase { - public RestIT(RestTestCandidate testCandidate) { +public class RpmClientYamlTestSuiteIT extends ESClientYamlSuiteTestCase { + public RpmClientYamlTestSuiteIT(ClientYamlTestCandidate testCandidate) { super(testCandidate); } @ParametersFactory - public static Iterable parameters() throws IOException, RestTestParseException { + public static Iterable parameters() throws IOException, ClientYamlTestParseException { return createParameters(0, 1); } } diff --git a/distribution/src/main/resources/bin/elasticsearch-translog b/distribution/src/main/resources/bin/elasticsearch-translog new file mode 100755 index 00000000000..47a48f02b47 --- /dev/null +++ b/distribution/src/main/resources/bin/elasticsearch-translog @@ -0,0 +1,90 @@ +#!/bin/bash + +CDPATH="" +SCRIPT="$0" + +# SCRIPT may be an arbitrarily deep series of symlinks. Loop until we have the concrete path. +while [ -h "$SCRIPT" ] ; do + ls=`ls -ld "$SCRIPT"` + # Drop everything prior to -> + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + SCRIPT="$link" + else + SCRIPT=`dirname "$SCRIPT"`/"$link" + fi +done + +# determine elasticsearch home +ES_HOME=`dirname "$SCRIPT"`/.. + +# make ELASTICSEARCH_HOME absolute +ES_HOME=`cd "$ES_HOME"; pwd` + + +# Sets the default values for elasticsearch variables used in this script +if [ -z "$CONF_DIR" ]; then + CONF_DIR="${path.conf}" +fi + +# The default env file is defined at building/packaging time. +# For a ${project.name} package, the value is "${path.env}". +ES_ENV_FILE="${path.env}" + +# If an include is specified with the ES_INCLUDE environment variable, use it +if [ -n "$ES_INCLUDE" ]; then + ES_ENV_FILE="$ES_INCLUDE" +fi + +# Source the environment file +if [ -n "$ES_ENV_FILE" ]; then + + # If the ES_ENV_FILE is not found, try to resolve the path + # against the ES_HOME directory + if [ ! -f "$ES_ENV_FILE" ]; then + ES_ENV_FILE="$ELASTIC_HOME/$ES_ENV_FILE" + fi + + . "$ES_ENV_FILE" + if [ $? -ne 0 ]; then + echo "Unable to source environment file: $ES_ENV_FILE" >&2 + exit 1 + fi +fi + +# don't let JAVA_TOOL_OPTIONS slip in (e.g. crazy agents in ubuntu) +# works around https://bugs.launchpad.net/ubuntu/+source/jayatana/+bug/1441487 +if [ "x$JAVA_TOOL_OPTIONS" != "x" ]; then + echo "Warning: Ignoring JAVA_TOOL_OPTIONS=$JAVA_TOOL_OPTIONS" + unset JAVA_TOOL_OPTIONS +fi + +# CONF_FILE setting was removed +if [ ! -z "$CONF_FILE" ]; then + echo "CONF_FILE setting is no longer supported. elasticsearch.yml must be placed in the config directory and cannot be renamed." + exit 1 +fi + +if [ -x "$JAVA_HOME/bin/java" ]; then + JAVA=$JAVA_HOME/bin/java +else + JAVA=`which java` +fi + +if [ ! -x "$JAVA" ]; then + echo "Could not find any executable java binary. Please install java in your PATH or set JAVA_HOME" + exit 1 +fi + +# full hostname passed through cut for portability on systems that do not support hostname -s +# export on separate line for shells that do not support combining definition and export +HOSTNAME=`hostname | cut -d. -f1` +export HOSTNAME + +declare -a args=("$@") + +if [ -e "$CONF_DIR" ]; then + args=("${args[@]}" -Edefault.path.conf="$CONF_DIR") +fi + +exec "$JAVA" $ES_JAVA_OPTS -Delasticsearch -Des.path.home="$ES_HOME" -cp "$ES_HOME/lib/*" org.elasticsearch.index.translog.TranslogToolCli "${args[@]}" diff --git a/distribution/src/main/resources/bin/elasticsearch-translog.bat b/distribution/src/main/resources/bin/elasticsearch-translog.bat new file mode 100644 index 00000000000..636a6665c03 --- /dev/null +++ b/distribution/src/main/resources/bin/elasticsearch-translog.bat @@ -0,0 +1,61 @@ +@echo off + +SETLOCAL enabledelayedexpansion + +IF DEFINED JAVA_HOME ( + set JAVA=%JAVA_HOME%\bin\java.exe +) ELSE ( + FOR %%I IN (java.exe) DO set JAVA=%%~$PATH:I +) +IF NOT EXIST "%JAVA%" ( + ECHO Could not find any executable java binary. Please install java in your PATH or set JAVA_HOME 1>&2 + EXIT /B 1 +) + +set SCRIPT_DIR=%~dp0 +for %%I in ("%SCRIPT_DIR%..") do set ES_HOME=%%~dpfI + +TITLE Elasticsearch Plugin Manager ${project.version} + +SET properties= +SET args= + +:loop +SET "current=%~1" +SHIFT +IF "x!current!" == "x" GOTO breakloop + +IF "!current:~0,2%!" == "-D" ( + ECHO "!current!" | FINDSTR /C:"=">nul && ( + :: current matches -D*=* + IF "x!properties!" NEQ "x" ( + SET properties=!properties! "!current!" + ) ELSE ( + SET properties="!current!" + ) + ) || ( + :: current matches -D* + IF "x!properties!" NEQ "x" ( + SET properties=!properties! "!current!=%~1" + ) ELSE ( + SET properties="!current!=%~1" + ) + SHIFT + ) +) ELSE ( + :: current matches * + IF "x!args!" NEQ "x" ( + SET args=!args! "!current!" + ) ELSE ( + SET args="!current!" + ) +) + +GOTO loop +:breakloop + +SET HOSTNAME=%COMPUTERNAME% + +"%JAVA%" %ES_JAVA_OPTS% -Des.path.home="%ES_HOME%" !properties! -cp "%ES_HOME%/lib/*;" "org.elasticsearch.index.translog.TranslogToolCli" !args! + +ENDLOCAL diff --git a/distribution/deb/src/test/java/org/elasticsearch/test/rest/RestIT.java b/distribution/tar/src/test/java/org/elasticsearch/test/rest/TarClientYamlTestSuiteIT.java similarity index 74% rename from distribution/deb/src/test/java/org/elasticsearch/test/rest/RestIT.java rename to distribution/tar/src/test/java/org/elasticsearch/test/rest/TarClientYamlTestSuiteIT.java index 94629641849..73d323f7d50 100644 --- a/distribution/deb/src/test/java/org/elasticsearch/test/rest/RestIT.java +++ b/distribution/tar/src/test/java/org/elasticsearch/test/rest/TarClientYamlTestSuiteIT.java @@ -20,18 +20,21 @@ package org.elasticsearch.test.rest; import com.carrotsearch.randomizedtesting.annotations.ParametersFactory; -import org.elasticsearch.test.rest.parser.RestTestParseException; + +import org.elasticsearch.test.rest.yaml.ClientYamlTestCandidate; +import org.elasticsearch.test.rest.yaml.ESClientYamlSuiteTestCase; +import org.elasticsearch.test.rest.yaml.parser.ClientYamlTestParseException; import java.io.IOException; /** Rest integration test. Runs against a cluster started by {@code gradle integTest} */ -public class RestIT extends ESClientYamlSuiteTestCase { - public RestIT(RestTestCandidate testCandidate) { +public class TarClientYamlTestSuiteIT extends ESClientYamlSuiteTestCase { + public TarClientYamlTestSuiteIT(ClientYamlTestCandidate testCandidate) { super(testCandidate); } @ParametersFactory - public static Iterable parameters() throws IOException, RestTestParseException { + public static Iterable parameters() throws IOException, ClientYamlTestParseException { return createParameters(0, 1); } } diff --git a/distribution/zip/src/test/java/org/elasticsearch/test/rest/RestIT.java b/distribution/zip/src/test/java/org/elasticsearch/test/rest/RestIT.java deleted file mode 100644 index 94629641849..00000000000 --- a/distribution/zip/src/test/java/org/elasticsearch/test/rest/RestIT.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Licensed to Elasticsearch under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.test.rest; - -import com.carrotsearch.randomizedtesting.annotations.ParametersFactory; -import org.elasticsearch.test.rest.parser.RestTestParseException; - -import java.io.IOException; - -/** Rest integration test. Runs against a cluster started by {@code gradle integTest} */ -public class RestIT extends ESClientYamlSuiteTestCase { - public RestIT(RestTestCandidate testCandidate) { - super(testCandidate); - } - - @ParametersFactory - public static Iterable parameters() throws IOException, RestTestParseException { - return createParameters(0, 1); - } -} diff --git a/distribution/integ-test-zip/src/test/java/org/elasticsearch/test/rest/RestIT.java b/distribution/zip/src/test/java/org/elasticsearch/test/rest/ZipClientYamlTestSuiteIT.java similarity index 74% rename from distribution/integ-test-zip/src/test/java/org/elasticsearch/test/rest/RestIT.java rename to distribution/zip/src/test/java/org/elasticsearch/test/rest/ZipClientYamlTestSuiteIT.java index 94629641849..329c8259d0b 100644 --- a/distribution/integ-test-zip/src/test/java/org/elasticsearch/test/rest/RestIT.java +++ b/distribution/zip/src/test/java/org/elasticsearch/test/rest/ZipClientYamlTestSuiteIT.java @@ -20,18 +20,21 @@ package org.elasticsearch.test.rest; import com.carrotsearch.randomizedtesting.annotations.ParametersFactory; -import org.elasticsearch.test.rest.parser.RestTestParseException; + +import org.elasticsearch.test.rest.yaml.ClientYamlTestCandidate; +import org.elasticsearch.test.rest.yaml.ESClientYamlSuiteTestCase; +import org.elasticsearch.test.rest.yaml.parser.ClientYamlTestParseException; import java.io.IOException; /** Rest integration test. Runs against a cluster started by {@code gradle integTest} */ -public class RestIT extends ESClientYamlSuiteTestCase { - public RestIT(RestTestCandidate testCandidate) { +public class ZipClientYamlTestSuiteIT extends ESClientYamlSuiteTestCase { + public ZipClientYamlTestSuiteIT(ClientYamlTestCandidate testCandidate) { super(testCandidate); } @ParametersFactory - public static Iterable parameters() throws IOException, RestTestParseException { + public static Iterable parameters() throws IOException, ClientYamlTestParseException { return createParameters(0, 1); } } diff --git a/docs/build.gradle b/docs/build.gradle index 26560ce064a..5459c9a754f 100644 --- a/docs/build.gradle +++ b/docs/build.gradle @@ -63,6 +63,13 @@ buildRestTests.docs = fileTree(projectDir) { Closure setupTwitter = { String name, int count -> buildRestTests.setups[name] = ''' + - do: + indices.create: + index: twitter + body: + settings: + number_of_shards: 1 + number_of_replicas: 1 - do: bulk: index: twitter diff --git a/docs/reference/aggregations/metrics/percentile-aggregation.asciidoc b/docs/reference/aggregations/metrics/percentile-aggregation.asciidoc index dc8c8837344..db15d0a6a66 100644 --- a/docs/reference/aggregations/metrics/percentile-aggregation.asciidoc +++ b/docs/reference/aggregations/metrics/percentile-aggregation.asciidoc @@ -190,7 +190,9 @@ This balance can be controlled using a `compression` parameter: "load_time_outlier" : { "percentiles" : { "field" : "load_time", - "compression" : 200 <1> + "tdigest": { + "compression" : 200 <1> + } } } } @@ -218,11 +220,11 @@ the TDigest will use less memory. experimental[] -https://github.com/HdrHistogram/HdrHistogram[HDR Histogram] (High Dynamic Range Histogram) is an alternative implementation -that can be useful when calculating percentiles for latency measurements as it can be faster than the t-digest implementation -with the trade-off of a larger memory footprint. This implementation maintains a fixed worse-case percentage error (specified -as a number of significant digits). This means that if data is recorded with values from 1 microsecond up to 1 hour -(3,600,000,000 microseconds) in a histogram set to 3 significant digits, it will maintain a value resolution of 1 microsecond +https://github.com/HdrHistogram/HdrHistogram[HDR Histogram] (High Dynamic Range Histogram) is an alternative implementation +that can be useful when calculating percentiles for latency measurements as it can be faster than the t-digest implementation +with the trade-off of a larger memory footprint. This implementation maintains a fixed worse-case percentage error (specified +as a number of significant digits). This means that if data is recorded with values from 1 microsecond up to 1 hour +(3,600,000,000 microseconds) in a histogram set to 3 significant digits, it will maintain a value resolution of 1 microsecond for values up to 1 millisecond and 3.6 seconds (or better) for the maximum tracked value (1 hour). The HDR Histogram can be used by specifying the `method` parameter in the request: @@ -235,17 +237,18 @@ The HDR Histogram can be used by specifying the `method` parameter in the reques "percentiles" : { "field" : "load_time", "percents" : [95, 99, 99.9], - "method" : "hdr", <1> - "number_of_significant_value_digits" : 3 <2> + "hdr": { <1> + "number_of_significant_value_digits" : 3 <2> + } } } } } -------------------------------------------------- -<1> The `method` parameter is set to `hdr` to indicate that HDR Histogram should be used to calculate the percentiles +<1> `hdr` object indicates that HDR Histogram should be used to calculate the percentiles and specific settings for this algorithm can be specified inside the object <2> `number_of_significant_value_digits` specifies the resolution of values for the histogram in number of significant digits -The HDRHistogram only supports positive values and will error if it is passed a negative value. It is also not a good idea to use +The HDRHistogram only supports positive values and will error if it is passed a negative value. It is also not a good idea to use the HDRHistogram if the range of values is unknown as this could lead to high memory usage. ==== Missing value diff --git a/docs/reference/aggregations/metrics/percentile-rank-aggregation.asciidoc b/docs/reference/aggregations/metrics/percentile-rank-aggregation.asciidoc index dcb953ae252..d4df92105de 100644 --- a/docs/reference/aggregations/metrics/percentile-rank-aggregation.asciidoc +++ b/docs/reference/aggregations/metrics/percentile-rank-aggregation.asciidoc @@ -115,11 +115,11 @@ TIP: for indexed scripts replace the `file` parameter with an `id` parameter. experimental[] -https://github.com/HdrHistogram/HdrHistogram[HDR Histogram] (High Dynamic Range Histogram) is an alternative implementation -that can be useful when calculating percentile ranks for latency measurements as it can be faster than the t-digest implementation -with the trade-off of a larger memory footprint. This implementation maintains a fixed worse-case percentage error (specified as a -number of significant digits). This means that if data is recorded with values from 1 microsecond up to 1 hour (3,600,000,000 -microseconds) in a histogram set to 3 significant digits, it will maintain a value resolution of 1 microsecond for values up to +https://github.com/HdrHistogram/HdrHistogram[HDR Histogram] (High Dynamic Range Histogram) is an alternative implementation +that can be useful when calculating percentile ranks for latency measurements as it can be faster than the t-digest implementation +with the trade-off of a larger memory footprint. This implementation maintains a fixed worse-case percentage error (specified as a +number of significant digits). This means that if data is recorded with values from 1 microsecond up to 1 hour (3,600,000,000 +microseconds) in a histogram set to 3 significant digits, it will maintain a value resolution of 1 microsecond for values up to 1 millisecond and 3.6 seconds (or better) for the maximum tracked value (1 hour). The HDR Histogram can be used by specifying the `method` parameter in the request: @@ -132,17 +132,18 @@ The HDR Histogram can be used by specifying the `method` parameter in the reques "percentile_ranks" : { "field" : "load_time", "values" : [15, 30], - "method" : "hdr", <1> - "number_of_significant_value_digits" : 3 <2> + "hdr": { <1> + "number_of_significant_value_digits" : 3 <2> + } } } } } -------------------------------------------------- -<1> The `method` parameter is set to `hdr` to indicate that HDR Histogram should be used to calculate the percentile_ranks +<1> `hdr` object indicates that HDR Histogram should be used to calculate the percentiles and specific settings for this algorithm can be specified inside the object <2> `number_of_significant_value_digits` specifies the resolution of values for the histogram in number of significant digits -The HDRHistogram only supports positive values and will error if it is passed a negative value. It is also not a good idea to use +The HDRHistogram only supports positive values and will error if it is passed a negative value. It is also not a good idea to use the HDRHistogram if the range of values is unknown as this could lead to high memory usage. ==== Missing value @@ -166,4 +167,3 @@ had a value. -------------------------------------------------- <1> Documents without a value in the `grade` field will fall into the same bucket as documents that have the value `10`. - diff --git a/docs/reference/docs/bulk.asciidoc b/docs/reference/docs/bulk.asciidoc index c9189b57c01..76096967de1 100644 --- a/docs/reference/docs/bulk.asciidoc +++ b/docs/reference/docs/bulk.asciidoc @@ -57,7 +57,7 @@ $ cat requests { "index" : { "_index" : "test", "_type" : "type1", "_id" : "1" } } { "field1" : "value1" } $ curl -s -XPOST localhost:9200/_bulk --data-binary "@requests"; echo -{"took":7,"items":[{"create":{"_index":"test","_type":"type1","_id":"1","_version":1}}]} +{"took":7, "errors": false, "items":[{"index":{"_index":"test","_type":"type1","_id":"1","_version":1,"_operation":"create","forced_refresh":false}}]} -------------------------------------------------- Because this format uses literal `\n`'s as delimiters, please be sure diff --git a/docs/reference/docs/delete.asciidoc b/docs/reference/docs/delete.asciidoc index 18a370fc416..2494605f87e 100644 --- a/docs/reference/docs/delete.asciidoc +++ b/docs/reference/docs/delete.asciidoc @@ -25,7 +25,8 @@ The result of the above delete operation is: "_index" : "twitter", "_type" : "tweet", "_id" : "1", - "_version" : 2 + "_version" : 2, + "_operation: delete" } -------------------------------------------------- diff --git a/docs/reference/docs/index_.asciidoc b/docs/reference/docs/index_.asciidoc index dda75dd5aa5..2be399e4e40 100644 --- a/docs/reference/docs/index_.asciidoc +++ b/docs/reference/docs/index_.asciidoc @@ -31,6 +31,7 @@ The result of the above index operation is: "_id" : "1", "_version" : 1, "created" : true, + "_operation" : create, "forced_refresh": false } -------------------------------------------------- @@ -231,6 +232,7 @@ The result of the above index operation is: "_id" : "6a8ca01c-7896-48e9-81cc-9f70661fcb32", "_version" : 1, "created" : true, + "_operation": "create", "forced_refresh": false } -------------------------------------------------- diff --git a/docs/reference/docs/update.asciidoc b/docs/reference/docs/update.asciidoc index 2edb0a71a3f..f85e152f1b3 100644 --- a/docs/reference/docs/update.asciidoc +++ b/docs/reference/docs/update.asciidoc @@ -132,8 +132,20 @@ curl -XPOST 'localhost:9200/test/type1/1/_update' -d '{ }' -------------------------------------------------- -If `name` was `new_name` before the request was sent then document is still -reindexed. +If `name` was `new_name` before the request was sent then the entire update +request is ignored. The `operation` element in the response returns `noop` if +the request was ignored. + +[source,js] +-------------------------------------------------- +{ + "_index": "test", + "_type": "type1", + "_id": "1", + "_version": 1, + "_operation": noop +} +-------------------------------------------------- [[upserts]] [float] diff --git a/docs/reference/indices/flush.asciidoc b/docs/reference/indices/flush.asciidoc index acf2b7c1a6a..5864c16d4c1 100644 --- a/docs/reference/indices/flush.asciidoc +++ b/docs/reference/indices/flush.asciidoc @@ -153,18 +153,18 @@ sync-flushed: -------------------------------------------------- { "_shards": { - "total": 10, - "successful": 10, + "total": 2, + "successful": 2, "failed": 0 }, "twitter": { - "total": 10, - "successful": 10, + "total": 2, + "successful": 2, "failed": 0 } } -------------------------------------------------- -// TESTRESPONSE[s/"successful": 10/"successful": 5/] +// TESTRESPONSE[s/"successful": 2/"successful": 1/] Here is what it looks like when one shard group failed due to pending operations: diff --git a/docs/reference/ingest/ingest-node.asciidoc b/docs/reference/ingest/ingest-node.asciidoc index 00f25434073..25c42f17870 100644 --- a/docs/reference/ingest/ingest-node.asciidoc +++ b/docs/reference/ingest/ingest-node.asciidoc @@ -859,8 +859,16 @@ because it is likely that the number of elements in an array is unknown. For thi processor exists. By specifying the field holding array elements and a processor that defines what should happen to each element, array fields can easily be preprocessed. -A processor inside the foreach processor works in a different context, and the only valid top-level -field is `_value`, which holds the array element value. Under this field other fields may exist. +A processor inside the foreach processor works in the array element context and puts that in the ingest metadata +under the `_ingest._value` key. If the array element is a json object it holds all immediate fields of that json object. +and if the nested object is a value is `_ingest._value` just holds that value. Note that if a processor prior to the +`foreach` processor used `_ingest._value` key then the specified value will not be available to the processor inside +the `foreach` processor. The `foreach` processor does restore the original value, so that value is available to processors +after the `foreach` processor. + +Note that any other field from the document are accessible and modifiable like with all other processors. This processor +just puts the current array element being read into `_ingest._value` ingest metadata attribute, so that it may be +pre-processed. If the `foreach` processor fails to process an element inside the array, and no `on_failure` processor has been specified, then it aborts the execution and leaves the array unmodified. @@ -892,7 +900,7 @@ When this `foreach` processor operates on this sample document: "field" : "values", "processor" : { "uppercase" : { - "field" : "_value" + "field" : "_ingest._value" } } } @@ -936,7 +944,7 @@ so the following `foreach` processor is used: "field" : "persons", "processor" : { "remove" : { - "field" : "_value.id" + "field" : "_ingest._value.id" } } } @@ -959,9 +967,7 @@ After preprocessing the result is: } -------------------------------------------------- -As for any processor, you can define `on_failure` processors -in processors that are wrapped inside the `foreach` processor. - +The wrapped processor can have a `on_failure` definition. For example, the `id` field may not exist on all person objects. Instead of failing the index request, you can use an `on_failure` block to send the document to the 'failure_index' index for later inspection: diff --git a/docs/reference/migration/migrate_5_0/scripting.asciidoc b/docs/reference/migration/migrate_5_0/scripting.asciidoc index 3b44f899f59..0f50e6232c3 100644 --- a/docs/reference/migration/migrate_5_0/scripting.asciidoc +++ b/docs/reference/migration/migrate_5_0/scripting.asciidoc @@ -309,4 +309,9 @@ transportClient.addTransportAddress( -------------------------------------------------- Also the helper methods in `QueryBuilders` class that create a `TemplateQueryBuilder` instance have been removed, -instead the constructors on `TemplateQueryBuilder` should be used. \ No newline at end of file +instead the constructors on `TemplateQueryBuilder` should be used. + +==== Template query + +The `template` query has been deprecated in favour of the search template api. The `template` query is scheduled +to be removed in the next major version. \ No newline at end of file diff --git a/docs/reference/modules/discovery/zen.asciidoc b/docs/reference/modules/discovery/zen.asciidoc index 60823393d11..f51fecb9079 100644 --- a/docs/reference/modules/discovery/zen.asciidoc +++ b/docs/reference/modules/discovery/zen.asciidoc @@ -64,7 +64,7 @@ Nodes can be excluded from becoming a master by setting `node.master` to `false` The `discovery.zen.minimum_master_nodes` sets the minimum number of master eligible nodes that need to join a newly elected master in order for an election to -complete and for the elected node to accept it's mastership. The same setting controls the minimum number of +complete and for the elected node to accept its mastership. The same setting controls the minimum number of active master eligible nodes that should be a part of any active cluster. If this requirement is not met the active master node will step down and a new master election will be begin. diff --git a/docs/reference/search/suggesters.asciidoc b/docs/reference/search/suggesters.asciidoc index 71a62262338..2da4a607307 100644 --- a/docs/reference/search/suggesters.asciidoc +++ b/docs/reference/search/suggesters.asciidoc @@ -10,15 +10,25 @@ The suggest request part is either defined alongside the query part in a [source,js] -------------------------------------------------- -curl -s -XPOST 'localhost:9200/_search' -d '{ +POST twitter/_search +{ "query" : { - ... + "match": { + "message": "tring out Elasticsearch" + } }, "suggest" : { - ... + "my-suggestion" : { + "text" : "trying out Elasticsearch", + "term" : { + "field" : "message" + } + } } -}' +} -------------------------------------------------- +// CONSOLE +// TEST[setup:twitter] Suggest requests executed against the `_suggest` endpoint should omit the surrounding `suggest` element which is only used if the suggest @@ -26,15 +36,18 @@ request is part of a search. [source,js] -------------------------------------------------- -curl -XPOST 'localhost:9200/_suggest' -d '{ +POST _suggest +{ "my-suggestion" : { - "text" : "the amsterdma meetpu", + "text" : "tring out Elasticsearch", "term" : { - "field" : "body" + "field" : "message" } } -}' +} -------------------------------------------------- +// CONSOLE +// TEST[setup:twitter] Several suggestions can be specified per request. Each suggestion is identified with an arbitrary name. In the example below two suggestions @@ -43,21 +56,24 @@ the `term` suggester, but have a different `text`. [source,js] -------------------------------------------------- -"suggest" : { +POST _suggest +{ "my-suggest-1" : { - "text" : "the amsterdma meetpu", + "text" : "tring out Elasticsearch", "term" : { - "field" : "body" + "field" : "message" } }, "my-suggest-2" : { - "text" : "the rottredam meetpu", + "text" : "kmichy", "term" : { - "field" : "title" + "field" : "user" } } } -------------------------------------------------- +// CONSOLE +// TEST[setup:twitter] The below suggest response example includes the suggestion response for `my-suggest-1` and `my-suggest-2`. Each suggestion part contains @@ -68,44 +84,35 @@ in the suggest text and if found an arbitrary number of options. [source,js] -------------------------------------------------- { - ... - "suggest": { - "my-suggest-1": [ - { - "text" : "amsterdma", - "offset": 4, - "length": 9, - "options": [ - ... - ] - }, - ... - ], - "my-suggest-2" : [ - ... - ] - } - ... + "_shards": ... + "my-suggest-1": [ { + "text": "tring", + "offset": 0, + "length": 5, + "options": [ {"text": "trying", "score": 0.8, "freq": 1 } ] + }, { + "text": "out", + "offset": 6, + "length": 3, + "options": [] + }, { + "text": "elasticsearch", + "offset": 10, + "length": 13, + "options": [] + } ], + "my-suggest-2": ... } -------------------------------------------------- +// TESTRESPONSE[s/"_shards": \.\.\./"_shards": "$body._shards",/] +// TESTRESPONSE[s/"my-suggest-2": \.\.\./"my-suggest-2": "$body.my-suggest-2"/] + Each options array contains an option object that includes the suggested text, its document frequency and score compared to the suggest entry text. The meaning of the score depends on the used suggester. The term suggester's score is based on the edit distance. -[source,js] --------------------------------------------------- -"options": [ - { - "text": "amsterdam", - "freq": 77, - "score": 0.8888889 - }, - ... -] --------------------------------------------------- - [float] [[global-suggest]] === Global suggest text @@ -116,157 +123,27 @@ and applies to the `my-suggest-1` and `my-suggest-2` suggestions. [source,js] -------------------------------------------------- -"suggest" : { - "text" : "the amsterdma meetpu", +POST _suggest +{ + "text" : "tring out Elasticsearch", "my-suggest-1" : { "term" : { - "field" : "title" + "field" : "message" } }, "my-suggest-2" : { "term" : { - "field" : "body" + "field" : "user" } } } -------------------------------------------------- +// CONSOLE The suggest text can in the above example also be specified as suggestion specific option. The suggest text specified on suggestion level override the suggest text on the global level. -[float] -=== Other suggest example - -In the below example we request suggestions for the following suggest -text: `devloping distibutd saerch engies` on the `title` field with a -maximum of 3 suggestions per term inside the suggest text. Note that in -this example we set `size` to `0`. This isn't required, but a -nice optimization. The suggestions are gathered in the `query` phase and -in the case that we only care about suggestions (so no hits) we don't -need to execute the `fetch` phase. - -[source,js] --------------------------------------------------- -curl -s -XPOST 'localhost:9200/_search' -d '{ - "size": 0, - "suggest" : { - "my-title-suggestions-1" : { - "text" : "devloping distibutd saerch engies", - "term" : { - "size" : 3, - "field" : "title" - } - } - } -}' --------------------------------------------------- - -The above request could yield the response as stated in the code example -below. As you can see if we take the first suggested options of each -suggestion entry we get `developing distributed search engines` as -result. - -[source,js] --------------------------------------------------- -{ - ... - "suggest": { - "my-title-suggestions-1": [ - { - "text": "devloping", - "offset": 0, - "length": 9, - "options": [ - { - "text": "developing", - "freq": 77, - "score": 0.8888889 - }, - { - "text": "deloping", - "freq": 1, - "score": 0.875 - }, - { - "text": "deploying", - "freq": 2, - "score": 0.7777778 - } - ] - }, - { - "text": "distibutd", - "offset": 10, - "length": 9, - "options": [ - { - "text": "distributed", - "freq": 217, - "score": 0.7777778 - }, - { - "text": "disributed", - "freq": 1, - "score": 0.7777778 - }, - { - "text": "distribute", - "freq": 1, - "score": 0.7777778 - } - ] - }, - { - "text": "saerch", - "offset": 20, - "length": 6, - "options": [ - { - "text": "search", - "freq": 1038, - "score": 0.8333333 - }, - { - "text": "smerch", - "freq": 3, - "score": 0.8333333 - }, - { - "text": "serch", - "freq": 2, - "score": 0.8 - } - ] - }, - { - "text": "engies", - "offset": 27, - "length": 6, - "options": [ - { - "text": "engines", - "freq": 568, - "score": 0.8333333 - }, - { - "text": "engles", - "freq": 3, - "score": 0.8333333 - }, - { - "text": "eggies", - "freq": 1, - "score": 0.8333333 - } - ] - } - ] - } - ... -} --------------------------------------------------- - include::suggesters/term-suggest.asciidoc[] include::suggesters/phrase-suggest.asciidoc[] @@ -274,5 +151,3 @@ include::suggesters/phrase-suggest.asciidoc[] include::suggesters/completion-suggest.asciidoc[] include::suggesters/context-suggest.asciidoc[] - - diff --git a/docs/reference/search/suggesters/phrase-suggest.asciidoc b/docs/reference/search/suggesters/phrase-suggest.asciidoc index 7ba1c93540b..487075a5677 100644 --- a/docs/reference/search/suggesters/phrase-suggest.asciidoc +++ b/docs/reference/search/suggesters/phrase-suggest.asciidoc @@ -17,36 +17,94 @@ co-occurrence and frequencies. ==== API Example -The `phrase` request is defined along side the query part in the json -request: +In general the `phrase` suggester requires special mapping up front to work. +The `phrase` suggester examples on this page need the following mapping to +work. The `reverse` analyzer is used only in the last example. [source,js] -------------------------------------------------- -curl -XPOST 'localhost:9200/_search' -d '{ - "suggest" : { - "text" : "Xor the Got-Jewel", - "simple_phrase" : { - "phrase" : { - "analyzer" : "body", - "field" : "bigram", - "size" : 1, - "real_word_error_likelihood" : 0.95, - "max_errors" : 0.5, - "gram_size" : 2, - "direct_generator" : [ { - "field" : "body", - "suggest_mode" : "always", - "min_word_length" : 1 - } ], - "highlight": { - "pre_tag": "", - "post_tag": "" +POST test +{ + "settings": { + "index": { + "number_of_shards": 1, + "analysis": { + "analyzer": { + "trigram": { + "type": "custom", + "tokenizer": "standard", + "filter": ["standard", "shingle"] + }, + "reverse": { + "type": "custom", + "tokenizer": "standard", + "filter": ["standard", "reverse"] + } + }, + "filter": { + "shingle": { + "type": "shingle", + "min_shingle_size": 2, + "max_shingle_size": 3 + } + } + } + } + }, + "mappings": { + "test": { + "properties": { + "title": { + "type": "text", + "fields": { + "trigram": { + "type": "text", + "analyzer": "trigram" + }, + "reverse": { + "type": "text", + "analyzer": "reverse" + } + } } } } } -}' +} +POST test/test +{"title": "noble warriors"} +POST test/test +{"title": "nobel prize"} +POST _refresh -------------------------------------------------- +// TESTSETUP + +Once you have the analyzers and mappings set up you can use the `phrase` +suggester in the same spot you'd use the `term` suggester: + +[source,js] +-------------------------------------------------- +POST _suggest?pretty -d' +{ + "text": "noble prize", + "simple_phrase": { + "phrase": { + "field": "title.trigram", + "size": 1, + "gram_size": 3, + "direct_generator": [ { + "field": "title.trigram", + "suggest_mode": "always" + } ], + "highlight": { + "pre_tag": "", + "post_tag": "" + } + } + } +} +-------------------------------------------------- +// CONSOLE The response contains suggestions scored by the most likely spell correction first. In this case we received the expected correction @@ -57,37 +115,23 @@ can contain misspellings (See parameter descriptions below). [source,js] -------------------------------------------------- - { - "took" : 5, - "timed_out" : false, - "_shards" : { - "total" : 5, - "successful" : 5, - "failed" : 0 - }, - "hits" : { - "total" : 2938, - "max_score" : 0.0, - "hits" : [ ] - }, - "suggest" : { - "simple_phrase" : [ { - "text" : "Xor the Got-Jewel", +{ + "_shards": ... + "simple_phrase" : [ + { + "text" : "noble prize", "offset" : 0, - "length" : 17, + "length" : 11, "options" : [ { - "text" : "xorr the god jewel", - "highlighted": "xorr the god jewel", - "score" : 0.17877324 - }, { - "text" : "xor the god jewel", - "highlighted": "xor the god jewel", - "score" : 0.14231323 - } ] - } ] - } + "text" : "nobel prize", + "highlighted": "nobel prize", + "score" : 0.40765354 + }] + } + ] } -------------------------------------------------- +// TESTRESPONSE[s/"_shards": .../"_shards": "$body._shards",/] ==== Basic Phrase suggest API parameters @@ -178,34 +222,34 @@ can contain misspellings (See parameter descriptions below). [source,js] -------------------------------------------------- -curl -XPOST 'localhost:9200/_search' -d { - "suggest" : { - "text" : "Xor the Got-Jewel", - "simple_phrase" : { - "phrase" : { - "field" : "bigram", - "size" : 1, - "direct_generator" : [ { - "field" : "body", - "suggest_mode" : "always", - "min_word_length" : 1 - } ], - "collate": { - "query": { <1> - "inline" : { - "match": { - "{{field_name}}" : "{{suggestion}}" <2> - } - } - }, - "params": {"field_name" : "title"}, <3> - "prune": true <4> - } - } - } - } - } +POST _suggest +{ + "text" : "noble prize", + "simple_phrase" : { + "phrase" : { + "field" : "title.trigram", + "size" : 1, + "direct_generator" : [ { + "field" : "title.trigram", + "suggest_mode" : "always", + "min_word_length" : 1 + } ], + "collate": { + "query": { <1> + "inline" : { + "match": { + "{{field_name}}" : "{{suggestion}}" <2> + } + } + }, + "params": {"field_name" : "title"}, <3> + "prune": true <4> + } + } + } +} -------------------------------------------------- +// CONSOLE <1> This query will be run once for every suggestion. <2> The `{{suggestion}}` variable will be replaced by the text of each suggestion. @@ -342,33 +386,27 @@ accept ordinary analyzer names. [source,js] -------------------------------------------------- -curl -s -XPOST 'localhost:9200/_search' -d { - "suggest" : { - "text" : "Xor the Got-Jewel", - "simple_phrase" : { - "phrase" : { - "analyzer" : "body", - "field" : "bigram", - "size" : 4, - "real_word_error_likelihood" : 0.95, - "confidence" : 2.0, - "gram_size" : 2, - "direct_generator" : [ { - "field" : "body", - "suggest_mode" : "always", - "min_word_length" : 1 - }, { - "field" : "reverse", - "suggest_mode" : "always", - "min_word_length" : 1, - "pre_filter" : "reverse", - "post_filter" : "reverse" - } ] - } +POST _suggest +{ + "text" : "obel prize", + "simple_phrase" : { + "phrase" : { + "field" : "title.trigram", + "size" : 1, + "direct_generator" : [ { + "field" : "title.trigram", + "suggest_mode" : "always" + }, { + "field" : "title.reverse", + "suggest_mode" : "always", + "pre_filter" : "reverse", + "post_filter" : "reverse" + } ] } } } -------------------------------------------------- +// CONSOLE `pre_filter` and `post_filter` can also be used to inject synonyms after candidates are generated. For instance for the query `captain usq` we diff --git a/docs/reference/search/uri-request.asciidoc b/docs/reference/search/uri-request.asciidoc index ba36992f6fb..95ce6a8ff6a 100644 --- a/docs/reference/search/uri-request.asciidoc +++ b/docs/reference/search/uri-request.asciidoc @@ -21,19 +21,19 @@ And here is a sample response: "timed_out": false, "took": 62, "_shards":{ - "total" : 5, - "successful" : 5, + "total" : 1, + "successful" : 1, "failed" : 0 }, "hits":{ "total" : 1, - "max_score": 0.2876821, + "max_score": 1.3862944, "hits" : [ { "_index" : "twitter", "_type" : "tweet", "_id" : "0", - "_score": 0.2876821, + "_score": 1.3862944, "_source" : { "user" : "kimchy", "date" : "2009-11-15T14:12:12", diff --git a/docs/src/test/java/org/elasticsearch/smoketest/SmokeTestDocsIT.java b/docs/src/test/java/org/elasticsearch/smoketest/DocsClientYamlTestSuiteIT.java similarity index 80% rename from docs/src/test/java/org/elasticsearch/smoketest/SmokeTestDocsIT.java rename to docs/src/test/java/org/elasticsearch/smoketest/DocsClientYamlTestSuiteIT.java index d8eccda61a2..688eefc98d5 100644 --- a/docs/src/test/java/org/elasticsearch/smoketest/SmokeTestDocsIT.java +++ b/docs/src/test/java/org/elasticsearch/smoketest/DocsClientYamlTestSuiteIT.java @@ -22,21 +22,21 @@ package org.elasticsearch.smoketest; import com.carrotsearch.randomizedtesting.annotations.Name; import com.carrotsearch.randomizedtesting.annotations.ParametersFactory; -import org.elasticsearch.test.rest.ESClientYamlSuiteTestCase; -import org.elasticsearch.test.rest.RestTestCandidate; -import org.elasticsearch.test.rest.parser.RestTestParseException; +import org.elasticsearch.test.rest.yaml.ClientYamlTestCandidate; +import org.elasticsearch.test.rest.yaml.ESClientYamlSuiteTestCase; +import org.elasticsearch.test.rest.yaml.parser.ClientYamlTestParseException; import java.io.IOException; import java.util.List; -public class SmokeTestDocsIT extends ESClientYamlSuiteTestCase { +public class DocsClientYamlTestSuiteIT extends ESClientYamlSuiteTestCase { - public SmokeTestDocsIT(@Name("yaml") RestTestCandidate testCandidate) { + public DocsClientYamlTestSuiteIT(@Name("yaml") ClientYamlTestCandidate testCandidate) { super(testCandidate); } @ParametersFactory - public static Iterable parameters() throws IOException, RestTestParseException { + public static Iterable parameters() throws IOException, ClientYamlTestParseException { return ESClientYamlSuiteTestCase.createParameters(0, 1); } diff --git a/modules/aggs-matrix-stats/src/test/java/org/elasticsearch/search/aggregations/matrix/MatrixAggregationRestIT.java b/modules/aggs-matrix-stats/src/test/java/org/elasticsearch/search/aggregations/matrix/MatrixStatsClientYamlTestSuiteIT.java similarity index 73% rename from modules/aggs-matrix-stats/src/test/java/org/elasticsearch/search/aggregations/matrix/MatrixAggregationRestIT.java rename to modules/aggs-matrix-stats/src/test/java/org/elasticsearch/search/aggregations/matrix/MatrixStatsClientYamlTestSuiteIT.java index 47609494a61..6fb70ad3d63 100644 --- a/modules/aggs-matrix-stats/src/test/java/org/elasticsearch/search/aggregations/matrix/MatrixAggregationRestIT.java +++ b/modules/aggs-matrix-stats/src/test/java/org/elasticsearch/search/aggregations/matrix/MatrixStatsClientYamlTestSuiteIT.java @@ -20,22 +20,20 @@ package org.elasticsearch.search.aggregations.matrix; import com.carrotsearch.randomizedtesting.annotations.Name; import com.carrotsearch.randomizedtesting.annotations.ParametersFactory; -import org.elasticsearch.test.rest.ESClientYamlSuiteTestCase; -import org.elasticsearch.test.rest.RestTestCandidate; -import org.elasticsearch.test.rest.parser.RestTestParseException; + +import org.elasticsearch.test.rest.yaml.ClientYamlTestCandidate; +import org.elasticsearch.test.rest.yaml.ESClientYamlSuiteTestCase; +import org.elasticsearch.test.rest.yaml.parser.ClientYamlTestParseException; import java.io.IOException; -/** - * - */ -public class MatrixAggregationRestIT extends ESClientYamlSuiteTestCase { - public MatrixAggregationRestIT(@Name("yaml")RestTestCandidate testCandidate) { +public class MatrixStatsClientYamlTestSuiteIT extends ESClientYamlSuiteTestCase { + public MatrixStatsClientYamlTestSuiteIT(@Name("yaml")ClientYamlTestCandidate testCandidate) { super(testCandidate); } @ParametersFactory - public static Iterable parameters() throws IOException, RestTestParseException { + public static Iterable parameters() throws IOException, ClientYamlTestParseException { return ESClientYamlSuiteTestCase.createParameters(0, 1); } } diff --git a/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/ForEachProcessor.java b/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/ForEachProcessor.java index c4640733d06..92804dc0513 100644 --- a/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/ForEachProcessor.java +++ b/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/ForEachProcessor.java @@ -62,11 +62,12 @@ public final class ForEachProcessor extends AbstractProcessor { List values = ingestDocument.getFieldValue(field, List.class); List newValues = new ArrayList<>(values.size()); for (Object value : values) { - Map innerSource = new HashMap<>(ingestDocument.getSourceAndMetadata()); - innerSource.put("_value", value); // scalar value to access the list item being evaluated - IngestDocument innerIngestDocument = new IngestDocument(innerSource, ingestDocument.getIngestMetadata()); - processor.execute(innerIngestDocument); - newValues.add(innerSource.get("_value")); + Object previousValue = ingestDocument.getIngestMetadata().put("_value", value); + try { + processor.execute(ingestDocument); + } finally { + newValues.add(ingestDocument.getIngestMetadata().put("_value", previousValue)); + } } ingestDocument.setFieldValue(field, newValues); } diff --git a/modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/ForEachProcessorTests.java b/modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/ForEachProcessorTests.java index 714722418e7..3f9ee8bc961 100644 --- a/modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/ForEachProcessorTests.java +++ b/modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/ForEachProcessorTests.java @@ -49,7 +49,7 @@ public class ForEachProcessorTests extends ESTestCase { ); ForEachProcessor processor = new ForEachProcessor( - "_tag", "values", new UppercaseProcessor("_tag", "_value") + "_tag", "values", new UppercaseProcessor("_tag", "_ingest._value") ); processor.execute(ingestDocument); @@ -65,7 +65,7 @@ public class ForEachProcessorTests extends ESTestCase { ); TestProcessor testProcessor = new TestProcessor(id -> { - if ("c".equals(id.getFieldValue("_value", String.class))) { + if ("c".equals(id.getFieldValue("_ingest._value", String.class))) { throw new RuntimeException("failure"); } }); @@ -80,11 +80,11 @@ public class ForEachProcessorTests extends ESTestCase { assertThat(ingestDocument.getFieldValue("values", List.class), equalTo(Arrays.asList("a", "b", "c"))); testProcessor = new TestProcessor(id -> { - String value = id.getFieldValue("_value", String.class); + String value = id.getFieldValue("_ingest._value", String.class); if ("c".equals(value)) { throw new RuntimeException("failure"); } else { - id.setFieldValue("_value", value.toUpperCase(Locale.ROOT)); + id.setFieldValue("_ingest._value", value.toUpperCase(Locale.ROOT)); } }); Processor onFailureProcessor = new TestProcessor(ingestDocument1 -> {}); @@ -105,9 +105,9 @@ public class ForEachProcessorTests extends ESTestCase { ); TestProcessor innerProcessor = new TestProcessor(id -> { - id.setFieldValue("_value.index", id.getSourceAndMetadata().get("_index")); - id.setFieldValue("_value.type", id.getSourceAndMetadata().get("_type")); - id.setFieldValue("_value.id", id.getSourceAndMetadata().get("_id")); + id.setFieldValue("_ingest._value.index", id.getSourceAndMetadata().get("_index")); + id.setFieldValue("_ingest._value.type", id.getSourceAndMetadata().get("_type")); + id.setFieldValue("_ingest._value.id", id.getSourceAndMetadata().get("_id")); }); ForEachProcessor processor = new ForEachProcessor("_tag", "values", innerProcessor); processor.execute(ingestDocument); @@ -136,7 +136,7 @@ public class ForEachProcessorTests extends ESTestCase { TemplateService ts = TestTemplateService.instance(); ForEachProcessor processor = new ForEachProcessor( - "_tag", "values", new SetProcessor("_tag", ts.compile("_value.new_field"), (model) -> model.get("other")) + "_tag", "values", new SetProcessor("_tag", ts.compile("_ingest._value.new_field"), (model) -> model.get("other")) ); processor.execute(ingestDocument); @@ -151,8 +151,8 @@ public class ForEachProcessorTests extends ESTestCase { Processor innerProcessor = new Processor() { @Override public void execute(IngestDocument ingestDocument) throws Exception { - String existingValue = ingestDocument.getFieldValue("_value", String.class); - ingestDocument.setFieldValue("_value", existingValue + "."); + String existingValue = ingestDocument.getFieldValue("_ingest._value", String.class); + ingestDocument.setFieldValue("_ingest._value", existingValue + "."); } @Override @@ -184,4 +184,91 @@ public class ForEachProcessorTests extends ESTestCase { } } + public void testModifyFieldsOutsideArray() throws Exception { + List values = new ArrayList<>(); + values.add("string"); + values.add(1); + values.add(null); + IngestDocument ingestDocument = new IngestDocument( + "_index", "_type", "_id", null, null, null, null, Collections.singletonMap("values", values) + ); + + TemplateService ts = TestTemplateService.instance(); + + ForEachProcessor processor = new ForEachProcessor( + "_tag", "values", new CompoundProcessor(false, + Collections.singletonList(new UppercaseProcessor("_tag_upper", "_ingest._value")), + Collections.singletonList(new AppendProcessor("_tag", + ts.compile("errors"), (model) -> (Collections.singletonList("added")))) + )); + processor.execute(ingestDocument); + + List result = ingestDocument.getFieldValue("values", List.class); + assertThat(result.get(0), equalTo("STRING")); + assertThat(result.get(1), equalTo(1)); + assertThat(result.get(2), equalTo(null)); + + List errors = ingestDocument.getFieldValue("errors", List.class); + assertThat(errors.size(), equalTo(2)); + } + + public void testScalarValueAllowsUnderscoreValueFieldToRemainAccessible() throws Exception { + List values = new ArrayList<>(); + values.add("please"); + values.add("change"); + values.add("me"); + Map source = new HashMap<>(); + source.put("_value", "new_value"); + source.put("values", values); + IngestDocument ingestDocument = new IngestDocument( + "_index", "_type", "_id", null, null, null, null, source + ); + + TestProcessor processor = new TestProcessor(doc -> doc.setFieldValue("_ingest._value", + doc.getFieldValue("_source._value", String.class))); + ForEachProcessor forEachProcessor = new ForEachProcessor("_tag", "values", processor); + forEachProcessor.execute(ingestDocument); + + List result = ingestDocument.getFieldValue("values", List.class); + assertThat(result.get(0), equalTo("new_value")); + assertThat(result.get(1), equalTo("new_value")); + assertThat(result.get(2), equalTo("new_value")); + } + + public void testNestedForEach() throws Exception { + List> values = new ArrayList<>(); + List innerValues = new ArrayList<>(); + innerValues.add("abc"); + innerValues.add("def"); + Map value = new HashMap<>(); + value.put("values2", innerValues); + values.add(value); + + innerValues = new ArrayList<>(); + innerValues.add("ghi"); + innerValues.add("jkl"); + value = new HashMap<>(); + value.put("values2", innerValues); + values.add(value); + + IngestDocument ingestDocument = new IngestDocument( + "_index", "_type", "_id", null, null, null, null, Collections.singletonMap("values1", values) + ); + + TestProcessor testProcessor = new TestProcessor( + doc -> doc.setFieldValue("_ingest._value", doc.getFieldValue("_ingest._value", String.class).toUpperCase(Locale.ENGLISH)) + ); + ForEachProcessor processor = new ForEachProcessor( + "_tag", "values1", new ForEachProcessor("_tag", "_ingest._value.values2", testProcessor)); + processor.execute(ingestDocument); + + List result = ingestDocument.getFieldValue("values1.0.values2", List.class); + assertThat(result.get(0), equalTo("ABC")); + assertThat(result.get(1), equalTo("DEF")); + + result = ingestDocument.getFieldValue("values1.1.values2", List.class); + assertThat(result.get(0), equalTo("GHI")); + assertThat(result.get(1), equalTo("JKL")); + } + } diff --git a/modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/IngestCommonRestIT.java b/modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/IngestCommonClientYamlTestSuiteIT.java similarity index 73% rename from modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/IngestCommonRestIT.java rename to modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/IngestCommonClientYamlTestSuiteIT.java index 65ee917f30e..3c71f5710fd 100644 --- a/modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/IngestCommonRestIT.java +++ b/modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/IngestCommonClientYamlTestSuiteIT.java @@ -21,20 +21,21 @@ package org.elasticsearch.ingest.common; import com.carrotsearch.randomizedtesting.annotations.Name; import com.carrotsearch.randomizedtesting.annotations.ParametersFactory; -import org.elasticsearch.test.rest.ESClientYamlSuiteTestCase; -import org.elasticsearch.test.rest.RestTestCandidate; -import org.elasticsearch.test.rest.parser.RestTestParseException; + +import org.elasticsearch.test.rest.yaml.ClientYamlTestCandidate; +import org.elasticsearch.test.rest.yaml.ESClientYamlSuiteTestCase; +import org.elasticsearch.test.rest.yaml.parser.ClientYamlTestParseException; import java.io.IOException; -public class IngestCommonRestIT extends ESClientYamlSuiteTestCase { +public class IngestCommonClientYamlTestSuiteIT extends ESClientYamlSuiteTestCase { - public IngestCommonRestIT(@Name("yaml") RestTestCandidate testCandidate) { + public IngestCommonClientYamlTestSuiteIT(@Name("yaml") ClientYamlTestCandidate testCandidate) { super(testCandidate); } @ParametersFactory - public static Iterable parameters() throws IOException, RestTestParseException { + public static Iterable parameters() throws IOException, ClientYamlTestParseException { return ESClientYamlSuiteTestCase.createParameters(0, 1); } } diff --git a/modules/ingest-common/src/test/resources/rest-api-spec/test/ingest/100_date_index_name_processor.yaml b/modules/ingest-common/src/test/resources/rest-api-spec/test/ingest/100_date_index_name_processor.yaml index c99c1025c10..ccf83cc96bf 100644 --- a/modules/ingest-common/src/test/resources/rest-api-spec/test/ingest/100_date_index_name_processor.yaml +++ b/modules/ingest-common/src/test/resources/rest-api-spec/test/ingest/100_date_index_name_processor.yaml @@ -1,3 +1,10 @@ +--- +teardown: + - do: + ingest.delete_pipeline: + id: "1" + ignore: 404 + --- "Test date index name processor with defaults": - do: diff --git a/modules/ingest-common/src/test/resources/rest-api-spec/test/ingest/110_sort.yaml b/modules/ingest-common/src/test/resources/rest-api-spec/test/ingest/110_sort.yaml index 096e57fa4e1..e18a0dcd252 100644 --- a/modules/ingest-common/src/test/resources/rest-api-spec/test/ingest/110_sort.yaml +++ b/modules/ingest-common/src/test/resources/rest-api-spec/test/ingest/110_sort.yaml @@ -1,3 +1,10 @@ +--- +teardown: + - do: + ingest.delete_pipeline: + id: "my_pipeline" + ignore: 404 + --- "Test sort Processor": - do: diff --git a/modules/ingest-common/src/test/resources/rest-api-spec/test/ingest/120_grok.yaml b/modules/ingest-common/src/test/resources/rest-api-spec/test/ingest/120_grok.yaml index a51f5a102b0..0d77ccce61c 100644 --- a/modules/ingest-common/src/test/resources/rest-api-spec/test/ingest/120_grok.yaml +++ b/modules/ingest-common/src/test/resources/rest-api-spec/test/ingest/120_grok.yaml @@ -1,3 +1,10 @@ +--- +teardown: + - do: + ingest.delete_pipeline: + id: "my_pipeline" + ignore: 404 + --- "Test Grok Pipeline": - do: diff --git a/modules/ingest-common/src/test/resources/rest-api-spec/test/ingest/20_crud.yaml b/modules/ingest-common/src/test/resources/rest-api-spec/test/ingest/20_crud.yaml index b494161aff1..2fb6ac230ff 100644 --- a/modules/ingest-common/src/test/resources/rest-api-spec/test/ingest/20_crud.yaml +++ b/modules/ingest-common/src/test/resources/rest-api-spec/test/ingest/20_crud.yaml @@ -1,3 +1,18 @@ +--- +teardown: + - do: + ingest.delete_pipeline: + id: "my_pipeline" + ignore: 404 + - do: + ingest.delete_pipeline: + id: "first_pipeline" + ignore: 404 + - do: + ingest.delete_pipeline: + id: "second_pipeline" + ignore: 404 + --- "Test basic pipeline crud": - do: @@ -23,6 +38,11 @@ - match: { pipelines.0.id: "my_pipeline" } - match: { pipelines.0.config.description: "_description" } + - do: + ingest.get_pipeline: {} + - match: { pipelines.0.id: "my_pipeline" } + - match: { pipelines.0.config.description: "_description" } + - do: ingest.delete_pipeline: id: "my_pipeline" @@ -33,6 +53,38 @@ ingest.get_pipeline: id: "my_pipeline" +--- +"Test Get All Pipelines (unordered)": + - do: + ingest.put_pipeline: + id: "first_pipeline" + body: > + { + "description": "first", + "processors": [ + { + "set" : { + "field" : "field1", + "value": "_value" + } + } + ] + } + - do: + ingest.put_pipeline: + id: "second_pipeline" + body: > + { + "description": "second", + "processors": [] + } + + # Order is not guaranteed by the response, so we check for length instead; above tests that we get appropriate values + - do: + ingest.get_pipeline: {} + - length: { pipelines: 2 } + + --- "Test invalid config": - do: diff --git a/modules/ingest-common/src/test/resources/rest-api-spec/test/ingest/30_date_processor.yaml b/modules/ingest-common/src/test/resources/rest-api-spec/test/ingest/30_date_processor.yaml index 33e25e4989b..93dfa52196f 100644 --- a/modules/ingest-common/src/test/resources/rest-api-spec/test/ingest/30_date_processor.yaml +++ b/modules/ingest-common/src/test/resources/rest-api-spec/test/ingest/30_date_processor.yaml @@ -1,3 +1,10 @@ +--- +teardown: + - do: + ingest.delete_pipeline: + id: "my_pipeline" + ignore: 404 + --- "Test date processor": - do: diff --git a/modules/ingest-common/src/test/resources/rest-api-spec/test/ingest/40_mutate.yaml b/modules/ingest-common/src/test/resources/rest-api-spec/test/ingest/40_mutate.yaml index c5d27f720cb..8150891ebd0 100644 --- a/modules/ingest-common/src/test/resources/rest-api-spec/test/ingest/40_mutate.yaml +++ b/modules/ingest-common/src/test/resources/rest-api-spec/test/ingest/40_mutate.yaml @@ -1,3 +1,10 @@ +--- +teardown: + - do: + ingest.delete_pipeline: + id: "my_pipeline" + ignore: 404 + --- "Test mutate processors": - do: diff --git a/modules/ingest-common/src/test/resources/rest-api-spec/test/ingest/50_on_failure.yaml b/modules/ingest-common/src/test/resources/rest-api-spec/test/ingest/50_on_failure.yaml index a4395427e04..53c1a9a7923 100644 --- a/modules/ingest-common/src/test/resources/rest-api-spec/test/ingest/50_on_failure.yaml +++ b/modules/ingest-common/src/test/resources/rest-api-spec/test/ingest/50_on_failure.yaml @@ -1,3 +1,10 @@ +--- +teardown: + - do: + ingest.delete_pipeline: + id: "my_pipeline" + ignore: 404 + --- "Test Pipeline With On Failure Block": - do: diff --git a/modules/ingest-common/src/test/resources/rest-api-spec/test/ingest/60_fail.yaml b/modules/ingest-common/src/test/resources/rest-api-spec/test/ingest/60_fail.yaml index 019c229ae38..e080991e13c 100644 --- a/modules/ingest-common/src/test/resources/rest-api-spec/test/ingest/60_fail.yaml +++ b/modules/ingest-common/src/test/resources/rest-api-spec/test/ingest/60_fail.yaml @@ -1,3 +1,10 @@ +--- +teardown: + - do: + ingest.delete_pipeline: + id: "my_pipeline" + ignore: 404 + --- "Test Fail Processor": - do: diff --git a/modules/ingest-common/src/test/resources/rest-api-spec/test/ingest/70_bulk.yaml b/modules/ingest-common/src/test/resources/rest-api-spec/test/ingest/70_bulk.yaml index d834d86b2ea..cf428b32524 100644 --- a/modules/ingest-common/src/test/resources/rest-api-spec/test/ingest/70_bulk.yaml +++ b/modules/ingest-common/src/test/resources/rest-api-spec/test/ingest/70_bulk.yaml @@ -31,6 +31,17 @@ setup: ] } +--- +teardown: + - do: + ingest.delete_pipeline: + id: "pipeline1" + ignore: 404 + - do: + ingest.delete_pipeline: + id: "pipeline2" + ignore: 404 + --- "Test bulk request without default pipeline": diff --git a/modules/ingest-common/src/test/resources/rest-api-spec/test/ingest/80_foreach.yaml b/modules/ingest-common/src/test/resources/rest-api-spec/test/ingest/80_foreach.yaml index 2ebfc089396..ab2be3bf81c 100644 --- a/modules/ingest-common/src/test/resources/rest-api-spec/test/ingest/80_foreach.yaml +++ b/modules/ingest-common/src/test/resources/rest-api-spec/test/ingest/80_foreach.yaml @@ -1,3 +1,10 @@ +--- +teardown: + - do: + ingest.delete_pipeline: + id: "my_pipeline" + ignore: 404 + --- "Test foreach Processor": - do: @@ -12,7 +19,7 @@ "field" : "values", "processor" : { "uppercase" : { - "field" : "_value" + "field" : "_ingest._value" } } } diff --git a/modules/ingest-common/src/test/resources/rest-api-spec/test/ingest/90_simulate.yaml b/modules/ingest-common/src/test/resources/rest-api-spec/test/ingest/90_simulate.yaml index 7ce30ee3bde..8b08535c124 100644 --- a/modules/ingest-common/src/test/resources/rest-api-spec/test/ingest/90_simulate.yaml +++ b/modules/ingest-common/src/test/resources/rest-api-spec/test/ingest/90_simulate.yaml @@ -1,3 +1,10 @@ +--- +teardown: + - do: + ingest.delete_pipeline: + id: "my_pipeline" + ignore: 404 + --- "Test simulate with stored ingest pipeline": - do: diff --git a/modules/lang-expression/src/test/java/org/elasticsearch/script/expression/ExpressionRestIT.java b/modules/lang-expression/src/test/java/org/elasticsearch/script/expression/LangExpressionClientYamlTestSuiteIT.java similarity index 73% rename from modules/lang-expression/src/test/java/org/elasticsearch/script/expression/ExpressionRestIT.java rename to modules/lang-expression/src/test/java/org/elasticsearch/script/expression/LangExpressionClientYamlTestSuiteIT.java index 8ff5168a7cf..3d1071ee17c 100644 --- a/modules/lang-expression/src/test/java/org/elasticsearch/script/expression/ExpressionRestIT.java +++ b/modules/lang-expression/src/test/java/org/elasticsearch/script/expression/LangExpressionClientYamlTestSuiteIT.java @@ -21,20 +21,21 @@ package org.elasticsearch.script.expression; import com.carrotsearch.randomizedtesting.annotations.Name; import com.carrotsearch.randomizedtesting.annotations.ParametersFactory; -import org.elasticsearch.test.rest.ESClientYamlSuiteTestCase; -import org.elasticsearch.test.rest.RestTestCandidate; -import org.elasticsearch.test.rest.parser.RestTestParseException; + +import org.elasticsearch.test.rest.yaml.ClientYamlTestCandidate; +import org.elasticsearch.test.rest.yaml.ESClientYamlSuiteTestCase; +import org.elasticsearch.test.rest.yaml.parser.ClientYamlTestParseException; import java.io.IOException; -public class ExpressionRestIT extends ESClientYamlSuiteTestCase { +public class LangExpressionClientYamlTestSuiteIT extends ESClientYamlSuiteTestCase { - public ExpressionRestIT(@Name("yaml") RestTestCandidate testCandidate) { + public LangExpressionClientYamlTestSuiteIT(@Name("yaml") ClientYamlTestCandidate testCandidate) { super(testCandidate); } @ParametersFactory - public static Iterable parameters() throws IOException, RestTestParseException { + public static Iterable parameters() throws IOException, ClientYamlTestParseException { return ESClientYamlSuiteTestCase.createParameters(0, 1); } } diff --git a/modules/lang-groovy/src/test/java/org/elasticsearch/script/groovy/GroovyRestIT.java b/modules/lang-groovy/src/test/java/org/elasticsearch/script/groovy/LangGroovyClientYamlTestSuiteIT.java similarity index 73% rename from modules/lang-groovy/src/test/java/org/elasticsearch/script/groovy/GroovyRestIT.java rename to modules/lang-groovy/src/test/java/org/elasticsearch/script/groovy/LangGroovyClientYamlTestSuiteIT.java index b681e5f6857..c8e9c74827a 100644 --- a/modules/lang-groovy/src/test/java/org/elasticsearch/script/groovy/GroovyRestIT.java +++ b/modules/lang-groovy/src/test/java/org/elasticsearch/script/groovy/LangGroovyClientYamlTestSuiteIT.java @@ -21,20 +21,21 @@ package org.elasticsearch.script.groovy; import com.carrotsearch.randomizedtesting.annotations.Name; import com.carrotsearch.randomizedtesting.annotations.ParametersFactory; -import org.elasticsearch.test.rest.ESClientYamlSuiteTestCase; -import org.elasticsearch.test.rest.RestTestCandidate; -import org.elasticsearch.test.rest.parser.RestTestParseException; + +import org.elasticsearch.test.rest.yaml.ClientYamlTestCandidate; +import org.elasticsearch.test.rest.yaml.ESClientYamlSuiteTestCase; +import org.elasticsearch.test.rest.yaml.parser.ClientYamlTestParseException; import java.io.IOException; -public class GroovyRestIT extends ESClientYamlSuiteTestCase { +public class LangGroovyClientYamlTestSuiteIT extends ESClientYamlSuiteTestCase { - public GroovyRestIT(@Name("yaml") RestTestCandidate testCandidate) { + public LangGroovyClientYamlTestSuiteIT(@Name("yaml") ClientYamlTestCandidate testCandidate) { super(testCandidate); } @ParametersFactory - public static Iterable parameters() throws IOException, RestTestParseException { + public static Iterable parameters() throws IOException, ClientYamlTestParseException { return ESClientYamlSuiteTestCase.createParameters(0, 1); } } diff --git a/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/TemplateQueryBuilder.java b/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/TemplateQueryBuilder.java index 297ff841a1f..4a19bcb4b93 100644 --- a/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/TemplateQueryBuilder.java +++ b/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/TemplateQueryBuilder.java @@ -23,6 +23,8 @@ import org.elasticsearch.common.ParsingException; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; +import org.elasticsearch.common.logging.DeprecationLogger; +import org.elasticsearch.common.logging.Loggers; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentParser; @@ -47,22 +49,26 @@ import java.util.Optional; /** * Facilitates creating template query requests. * */ +@Deprecated +// TODO remove this class in 6.0 public class TemplateQueryBuilder extends AbstractQueryBuilder { + public static final String NAME = "template"; + private static final DeprecationLogger DEPRECATION_LOGGER = new DeprecationLogger(Loggers.getLogger(TemplateQueryBuilder.class)); /** Template to fill. */ private final Script template; public TemplateQueryBuilder(String template, ScriptService.ScriptType scriptType, Map params) { - this.template = new Script(template, scriptType, "mustache", params); + this(new Script(template, scriptType, "mustache", params)); } public TemplateQueryBuilder(String template, ScriptService.ScriptType scriptType, Map params, XContentType ct) { - this.template = new Script(template, scriptType, "mustache", params, ct); + this(new Script(template, scriptType, "mustache", params, ct)); } - // for tests, so that mock script can be used: TemplateQueryBuilder(Script template) { + DEPRECATION_LOGGER.deprecated("[{}] query is deprecated, use search template api instead", NAME); if (template == null) { throw new IllegalArgumentException("query template cannot be null"); } diff --git a/modules/lang-mustache/src/test/java/org/elasticsearch/script/mustache/MustacheRestIT.java b/modules/lang-mustache/src/test/java/org/elasticsearch/script/mustache/LangMustacheClientYamlTestSuiteIT.java similarity index 73% rename from modules/lang-mustache/src/test/java/org/elasticsearch/script/mustache/MustacheRestIT.java rename to modules/lang-mustache/src/test/java/org/elasticsearch/script/mustache/LangMustacheClientYamlTestSuiteIT.java index 95f86dec3c7..160327dbab6 100644 --- a/modules/lang-mustache/src/test/java/org/elasticsearch/script/mustache/MustacheRestIT.java +++ b/modules/lang-mustache/src/test/java/org/elasticsearch/script/mustache/LangMustacheClientYamlTestSuiteIT.java @@ -21,20 +21,21 @@ package org.elasticsearch.script.mustache; import com.carrotsearch.randomizedtesting.annotations.Name; import com.carrotsearch.randomizedtesting.annotations.ParametersFactory; -import org.elasticsearch.test.rest.ESClientYamlSuiteTestCase; -import org.elasticsearch.test.rest.RestTestCandidate; -import org.elasticsearch.test.rest.parser.RestTestParseException; + +import org.elasticsearch.test.rest.yaml.ClientYamlTestCandidate; +import org.elasticsearch.test.rest.yaml.ESClientYamlSuiteTestCase; +import org.elasticsearch.test.rest.yaml.parser.ClientYamlTestParseException; import java.io.IOException; -public class MustacheRestIT extends ESClientYamlSuiteTestCase { +public class LangMustacheClientYamlTestSuiteIT extends ESClientYamlSuiteTestCase { - public MustacheRestIT(@Name("yaml") RestTestCandidate testCandidate) { + public LangMustacheClientYamlTestSuiteIT(@Name("yaml") ClientYamlTestCandidate testCandidate) { super(testCandidate); } @ParametersFactory - public static Iterable parameters() throws IOException, RestTestParseException { + public static Iterable parameters() throws IOException, ClientYamlTestParseException { return ESClientYamlSuiteTestCase.createParameters(0, 1); } } diff --git a/modules/lang-painless/src/test/java/org/elasticsearch/painless/PainlessRestIT.java b/modules/lang-painless/src/test/java/org/elasticsearch/painless/LangPainlessClientYamlTestSuiteIT.java similarity index 73% rename from modules/lang-painless/src/test/java/org/elasticsearch/painless/PainlessRestIT.java rename to modules/lang-painless/src/test/java/org/elasticsearch/painless/LangPainlessClientYamlTestSuiteIT.java index 353aa13f839..ca95dafd0b8 100644 --- a/modules/lang-painless/src/test/java/org/elasticsearch/painless/PainlessRestIT.java +++ b/modules/lang-painless/src/test/java/org/elasticsearch/painless/LangPainlessClientYamlTestSuiteIT.java @@ -21,21 +21,22 @@ package org.elasticsearch.painless; import com.carrotsearch.randomizedtesting.annotations.Name; import com.carrotsearch.randomizedtesting.annotations.ParametersFactory; -import org.elasticsearch.test.rest.ESClientYamlSuiteTestCase; -import org.elasticsearch.test.rest.RestTestCandidate; -import org.elasticsearch.test.rest.parser.RestTestParseException; + +import org.elasticsearch.test.rest.yaml.ClientYamlTestCandidate; +import org.elasticsearch.test.rest.yaml.ESClientYamlSuiteTestCase; +import org.elasticsearch.test.rest.yaml.parser.ClientYamlTestParseException; import java.io.IOException; /** Runs yaml rest tests */ -public class PainlessRestIT extends ESClientYamlSuiteTestCase { +public class LangPainlessClientYamlTestSuiteIT extends ESClientYamlSuiteTestCase { - public PainlessRestIT(@Name("yaml") RestTestCandidate testCandidate) { + public LangPainlessClientYamlTestSuiteIT(@Name("yaml") ClientYamlTestCandidate testCandidate) { super(testCandidate); } @ParametersFactory - public static Iterable parameters() throws IOException, RestTestParseException { + public static Iterable parameters() throws IOException, ClientYamlTestParseException { return ESClientYamlSuiteTestCase.createParameters(0, 1); } } diff --git a/modules/percolator/src/test/java/org/elasticsearch/percolator/PercolatorRestIT.java b/modules/percolator/src/test/java/org/elasticsearch/percolator/PercolatorClientYamlTestSuiteIT.java similarity index 73% rename from modules/percolator/src/test/java/org/elasticsearch/percolator/PercolatorRestIT.java rename to modules/percolator/src/test/java/org/elasticsearch/percolator/PercolatorClientYamlTestSuiteIT.java index f4ec1b5215e..24e92715ede 100644 --- a/modules/percolator/src/test/java/org/elasticsearch/percolator/PercolatorRestIT.java +++ b/modules/percolator/src/test/java/org/elasticsearch/percolator/PercolatorClientYamlTestSuiteIT.java @@ -21,19 +21,20 @@ package org.elasticsearch.percolator; import com.carrotsearch.randomizedtesting.annotations.Name; import com.carrotsearch.randomizedtesting.annotations.ParametersFactory; -import org.elasticsearch.test.rest.ESClientYamlSuiteTestCase; -import org.elasticsearch.test.rest.RestTestCandidate; -import org.elasticsearch.test.rest.parser.RestTestParseException; + +import org.elasticsearch.test.rest.yaml.ClientYamlTestCandidate; +import org.elasticsearch.test.rest.yaml.ESClientYamlSuiteTestCase; +import org.elasticsearch.test.rest.yaml.parser.ClientYamlTestParseException; import java.io.IOException; -public class PercolatorRestIT extends ESClientYamlSuiteTestCase { - public PercolatorRestIT(@Name("yaml") RestTestCandidate testCandidate) { +public class PercolatorClientYamlTestSuiteIT extends ESClientYamlSuiteTestCase { + public PercolatorClientYamlTestSuiteIT(@Name("yaml") ClientYamlTestCandidate testCandidate) { super(testCandidate); } @ParametersFactory - public static Iterable parameters() throws IOException, RestTestParseException { + public static Iterable parameters() throws IOException, ClientYamlTestParseException { return ESClientYamlSuiteTestCase.createParameters(0, 1); } } diff --git a/modules/reindex/src/test/java/org/elasticsearch/index/reindex/AsyncBulkByScrollActionTests.java b/modules/reindex/src/test/java/org/elasticsearch/index/reindex/AsyncBulkByScrollActionTests.java index 77e792b8333..bb44c4e6b85 100644 --- a/modules/reindex/src/test/java/org/elasticsearch/index/reindex/AsyncBulkByScrollActionTests.java +++ b/modules/reindex/src/test/java/org/elasticsearch/index/reindex/AsyncBulkByScrollActionTests.java @@ -314,7 +314,7 @@ public class AsyncBulkByScrollActionTests extends ESTestCase { }; ScrollableHitSource.Response response = new ScrollableHitSource.Response(false, emptyList(), 0, emptyList(), null); simulateScrollResponse(new DummyAbstractAsyncBulkByScrollAction(), timeValueNanos(System.nanoTime()), 10, response); - ExecutionException e = expectThrows(ExecutionException.class, () -> listener.get()); + ExecutionException e = expectThrows(ExecutionException.class, () -> listener.get()); assertThat(e.getMessage(), equalTo("EsRejectedExecutionException[test]")); assertThat(client.scrollsCleared, contains(scrollId)); @@ -773,7 +773,7 @@ public class AsyncBulkByScrollActionTests extends ESTestCase { UpdateRequest update = (UpdateRequest) item; opType = "update"; response = new UpdateResponse(shardId, update.type(), update.id(), - randomIntBetween(0, Integer.MAX_VALUE), true); + randomIntBetween(0, Integer.MAX_VALUE), DocWriteResponse.Operation.CREATE); } else if (item instanceof DeleteRequest) { DeleteRequest delete = (DeleteRequest) item; opType = "delete"; diff --git a/modules/reindex/src/test/java/org/elasticsearch/index/reindex/ReindexRestIT.java b/modules/reindex/src/test/java/org/elasticsearch/index/reindex/ReindexClientYamlTestSuiteIT.java similarity index 74% rename from modules/reindex/src/test/java/org/elasticsearch/index/reindex/ReindexRestIT.java rename to modules/reindex/src/test/java/org/elasticsearch/index/reindex/ReindexClientYamlTestSuiteIT.java index c67908f631d..186bb2f0a5e 100644 --- a/modules/reindex/src/test/java/org/elasticsearch/index/reindex/ReindexRestIT.java +++ b/modules/reindex/src/test/java/org/elasticsearch/index/reindex/ReindexClientYamlTestSuiteIT.java @@ -22,19 +22,19 @@ package org.elasticsearch.index.reindex; import com.carrotsearch.randomizedtesting.annotations.Name; import com.carrotsearch.randomizedtesting.annotations.ParametersFactory; -import org.elasticsearch.test.rest.ESClientYamlSuiteTestCase; -import org.elasticsearch.test.rest.RestTestCandidate; -import org.elasticsearch.test.rest.parser.RestTestParseException; +import org.elasticsearch.test.rest.yaml.ClientYamlTestCandidate; +import org.elasticsearch.test.rest.yaml.ESClientYamlSuiteTestCase; +import org.elasticsearch.test.rest.yaml.parser.ClientYamlTestParseException; import java.io.IOException; -public class ReindexRestIT extends ESClientYamlSuiteTestCase { - public ReindexRestIT(@Name("yaml") RestTestCandidate testCandidate) { +public class ReindexClientYamlTestSuiteIT extends ESClientYamlSuiteTestCase { + public ReindexClientYamlTestSuiteIT(@Name("yaml") ClientYamlTestCandidate testCandidate) { super(testCandidate); } @ParametersFactory - public static Iterable parameters() throws IOException, RestTestParseException { + public static Iterable parameters() throws IOException, ClientYamlTestParseException { return ESClientYamlSuiteTestCase.createParameters(0, 1); } } diff --git a/modules/transport-netty3/src/test/java/org/elasticsearch/http/netty3/Netty3RestIT.java b/modules/transport-netty3/src/test/java/org/elasticsearch/http/netty3/Netty3ClientYamlTestSuiteIT.java similarity index 74% rename from modules/transport-netty3/src/test/java/org/elasticsearch/http/netty3/Netty3RestIT.java rename to modules/transport-netty3/src/test/java/org/elasticsearch/http/netty3/Netty3ClientYamlTestSuiteIT.java index 9aa57bc312f..2fce8e3022d 100644 --- a/modules/transport-netty3/src/test/java/org/elasticsearch/http/netty3/Netty3RestIT.java +++ b/modules/transport-netty3/src/test/java/org/elasticsearch/http/netty3/Netty3ClientYamlTestSuiteIT.java @@ -22,20 +22,20 @@ package org.elasticsearch.http.netty3; import com.carrotsearch.randomizedtesting.annotations.Name; import com.carrotsearch.randomizedtesting.annotations.ParametersFactory; -import org.elasticsearch.test.rest.ESClientYamlSuiteTestCase; -import org.elasticsearch.test.rest.RestTestCandidate; -import org.elasticsearch.test.rest.parser.RestTestParseException; +import org.elasticsearch.test.rest.yaml.ClientYamlTestCandidate; +import org.elasticsearch.test.rest.yaml.ESClientYamlSuiteTestCase; +import org.elasticsearch.test.rest.yaml.parser.ClientYamlTestParseException; import java.io.IOException; -public class Netty3RestIT extends ESClientYamlSuiteTestCase { +public class Netty3ClientYamlTestSuiteIT extends ESClientYamlSuiteTestCase { - public Netty3RestIT(@Name("yaml") RestTestCandidate testCandidate) { + public Netty3ClientYamlTestSuiteIT(@Name("yaml") ClientYamlTestCandidate testCandidate) { super(testCandidate); } @ParametersFactory - public static Iterable parameters() throws IOException, RestTestParseException { + public static Iterable parameters() throws IOException, ClientYamlTestParseException { return ESClientYamlSuiteTestCase.createParameters(0, 1); } } diff --git a/modules/transport-netty4/src/test/java/org/elasticsearch/http/netty4/Netty4RestIT.java b/modules/transport-netty4/src/test/java/org/elasticsearch/http/netty4/Netty4ClientYamlTestSuiteIT.java similarity index 77% rename from modules/transport-netty4/src/test/java/org/elasticsearch/http/netty4/Netty4RestIT.java rename to modules/transport-netty4/src/test/java/org/elasticsearch/http/netty4/Netty4ClientYamlTestSuiteIT.java index 71cbf70abb3..8f7483e2791 100644 --- a/modules/transport-netty4/src/test/java/org/elasticsearch/http/netty4/Netty4RestIT.java +++ b/modules/transport-netty4/src/test/java/org/elasticsearch/http/netty4/Netty4ClientYamlTestSuiteIT.java @@ -21,25 +21,25 @@ package org.elasticsearch.http.netty4; import com.carrotsearch.randomizedtesting.annotations.Name; import com.carrotsearch.randomizedtesting.annotations.ParametersFactory; - import com.carrotsearch.randomizedtesting.annotations.TimeoutSuite; + import org.apache.lucene.util.TimeUnits; -import org.elasticsearch.test.rest.ESClientYamlSuiteTestCase; -import org.elasticsearch.test.rest.RestTestCandidate; -import org.elasticsearch.test.rest.parser.RestTestParseException; +import org.elasticsearch.test.rest.yaml.ClientYamlTestCandidate; +import org.elasticsearch.test.rest.yaml.ESClientYamlSuiteTestCase; +import org.elasticsearch.test.rest.yaml.parser.ClientYamlTestParseException; import java.io.IOException; //TODO: This is a *temporary* workaround to ensure a timeout does not mask other problems @TimeoutSuite(millis = 30 * TimeUnits.MINUTE) -public class Netty4RestIT extends ESClientYamlSuiteTestCase { +public class Netty4ClientYamlTestSuiteIT extends ESClientYamlSuiteTestCase { - public Netty4RestIT(@Name("yaml") RestTestCandidate testCandidate) { + public Netty4ClientYamlTestSuiteIT(@Name("yaml") ClientYamlTestCandidate testCandidate) { super(testCandidate); } @ParametersFactory - public static Iterable parameters() throws IOException, RestTestParseException { + public static Iterable parameters() throws IOException, ClientYamlTestParseException { return ESClientYamlSuiteTestCase.createParameters(0, 1); } diff --git a/plugins/analysis-icu/src/test/java/org/elasticsearch/index/analysis/AnalysisICURestIT.java b/plugins/analysis-icu/src/test/java/org/elasticsearch/index/analysis/IcuClientYamlTestSuiteIT.java similarity index 74% rename from plugins/analysis-icu/src/test/java/org/elasticsearch/index/analysis/AnalysisICURestIT.java rename to plugins/analysis-icu/src/test/java/org/elasticsearch/index/analysis/IcuClientYamlTestSuiteIT.java index 17e5e1c3ca7..47224836037 100644 --- a/plugins/analysis-icu/src/test/java/org/elasticsearch/index/analysis/AnalysisICURestIT.java +++ b/plugins/analysis-icu/src/test/java/org/elasticsearch/index/analysis/IcuClientYamlTestSuiteIT.java @@ -21,20 +21,21 @@ package org.elasticsearch.index.analysis; import com.carrotsearch.randomizedtesting.annotations.Name; import com.carrotsearch.randomizedtesting.annotations.ParametersFactory; -import org.elasticsearch.test.rest.ESClientYamlSuiteTestCase; -import org.elasticsearch.test.rest.RestTestCandidate; -import org.elasticsearch.test.rest.parser.RestTestParseException; + +import org.elasticsearch.test.rest.yaml.ClientYamlTestCandidate; +import org.elasticsearch.test.rest.yaml.ESClientYamlSuiteTestCase; +import org.elasticsearch.test.rest.yaml.parser.ClientYamlTestParseException; import java.io.IOException; -public class AnalysisICURestIT extends ESClientYamlSuiteTestCase { +public class IcuClientYamlTestSuiteIT extends ESClientYamlSuiteTestCase { - public AnalysisICURestIT(@Name("yaml") RestTestCandidate testCandidate) { + public IcuClientYamlTestSuiteIT(@Name("yaml") ClientYamlTestCandidate testCandidate) { super(testCandidate); } @ParametersFactory - public static Iterable parameters() throws IOException, RestTestParseException { + public static Iterable parameters() throws IOException, ClientYamlTestParseException { return ESClientYamlSuiteTestCase.createParameters(0, 1); } } diff --git a/plugins/analysis-smartcn/src/test/java/org/elasticsearch/index/analysis/AnalysisSmartChineseRestIT.java b/plugins/analysis-kuromoji/src/test/java/org/elasticsearch/index/analysis/KuromojiClientYamlTestSuiteIT.java similarity index 73% rename from plugins/analysis-smartcn/src/test/java/org/elasticsearch/index/analysis/AnalysisSmartChineseRestIT.java rename to plugins/analysis-kuromoji/src/test/java/org/elasticsearch/index/analysis/KuromojiClientYamlTestSuiteIT.java index 58c86acea84..e99c5c2bacf 100644 --- a/plugins/analysis-smartcn/src/test/java/org/elasticsearch/index/analysis/AnalysisSmartChineseRestIT.java +++ b/plugins/analysis-kuromoji/src/test/java/org/elasticsearch/index/analysis/KuromojiClientYamlTestSuiteIT.java @@ -21,20 +21,21 @@ package org.elasticsearch.index.analysis; import com.carrotsearch.randomizedtesting.annotations.Name; import com.carrotsearch.randomizedtesting.annotations.ParametersFactory; -import org.elasticsearch.test.rest.ESClientYamlSuiteTestCase; -import org.elasticsearch.test.rest.RestTestCandidate; -import org.elasticsearch.test.rest.parser.RestTestParseException; + +import org.elasticsearch.test.rest.yaml.ClientYamlTestCandidate; +import org.elasticsearch.test.rest.yaml.ESClientYamlSuiteTestCase; +import org.elasticsearch.test.rest.yaml.parser.ClientYamlTestParseException; import java.io.IOException; -public class AnalysisSmartChineseRestIT extends ESClientYamlSuiteTestCase { +public class KuromojiClientYamlTestSuiteIT extends ESClientYamlSuiteTestCase { - public AnalysisSmartChineseRestIT(@Name("yaml") RestTestCandidate testCandidate) { + public KuromojiClientYamlTestSuiteIT(@Name("yaml") ClientYamlTestCandidate testCandidate) { super(testCandidate); } @ParametersFactory - public static Iterable parameters() throws IOException, RestTestParseException { + public static Iterable parameters() throws IOException, ClientYamlTestParseException { return ESClientYamlSuiteTestCase.createParameters(0, 1); } } diff --git a/plugins/analysis-phonetic/src/test/java/org/elasticsearch/index/analysis/PhoneticClientYamlTestSuiteIT.java b/plugins/analysis-phonetic/src/test/java/org/elasticsearch/index/analysis/PhoneticClientYamlTestSuiteIT.java new file mode 100644 index 00000000000..975b84f1574 --- /dev/null +++ b/plugins/analysis-phonetic/src/test/java/org/elasticsearch/index/analysis/PhoneticClientYamlTestSuiteIT.java @@ -0,0 +1,42 @@ +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.index.analysis; + +import com.carrotsearch.randomizedtesting.annotations.Name; +import com.carrotsearch.randomizedtesting.annotations.ParametersFactory; + +import org.elasticsearch.test.rest.yaml.ClientYamlTestCandidate; +import org.elasticsearch.test.rest.yaml.ESClientYamlSuiteTestCase; +import org.elasticsearch.test.rest.yaml.parser.ClientYamlTestParseException; + +import java.io.IOException; + +public class PhoneticClientYamlTestSuiteIT extends ESClientYamlSuiteTestCase { + + public PhoneticClientYamlTestSuiteIT(@Name("yaml") ClientYamlTestCandidate testCandidate) { + super(testCandidate); + } + + @ParametersFactory + public static Iterable parameters() throws IOException, ClientYamlTestParseException { + return ESClientYamlSuiteTestCase.createParameters(0, 1); + } +} + diff --git a/plugins/analysis-kuromoji/src/test/java/org/elasticsearch/index/analysis/AnalysisKuromojiRestIT.java b/plugins/analysis-smartcn/src/test/java/org/elasticsearch/index/analysis/SmartCNClientYamlTestSuiteIT.java similarity index 73% rename from plugins/analysis-kuromoji/src/test/java/org/elasticsearch/index/analysis/AnalysisKuromojiRestIT.java rename to plugins/analysis-smartcn/src/test/java/org/elasticsearch/index/analysis/SmartCNClientYamlTestSuiteIT.java index 5697fb55bde..6415dc436eb 100644 --- a/plugins/analysis-kuromoji/src/test/java/org/elasticsearch/index/analysis/AnalysisKuromojiRestIT.java +++ b/plugins/analysis-smartcn/src/test/java/org/elasticsearch/index/analysis/SmartCNClientYamlTestSuiteIT.java @@ -21,20 +21,21 @@ package org.elasticsearch.index.analysis; import com.carrotsearch.randomizedtesting.annotations.Name; import com.carrotsearch.randomizedtesting.annotations.ParametersFactory; -import org.elasticsearch.test.rest.ESClientYamlSuiteTestCase; -import org.elasticsearch.test.rest.RestTestCandidate; -import org.elasticsearch.test.rest.parser.RestTestParseException; + +import org.elasticsearch.test.rest.yaml.ClientYamlTestCandidate; +import org.elasticsearch.test.rest.yaml.ESClientYamlSuiteTestCase; +import org.elasticsearch.test.rest.yaml.parser.ClientYamlTestParseException; import java.io.IOException; -public class AnalysisKuromojiRestIT extends ESClientYamlSuiteTestCase { +public class SmartCNClientYamlTestSuiteIT extends ESClientYamlSuiteTestCase { - public AnalysisKuromojiRestIT(@Name("yaml") RestTestCandidate testCandidate) { + public SmartCNClientYamlTestSuiteIT(@Name("yaml") ClientYamlTestCandidate testCandidate) { super(testCandidate); } @ParametersFactory - public static Iterable parameters() throws IOException, RestTestParseException { + public static Iterable parameters() throws IOException, ClientYamlTestParseException { return ESClientYamlSuiteTestCase.createParameters(0, 1); } } diff --git a/plugins/analysis-stempel/src/test/java/org/elasticsearch/index/analysis/AnalysisPolishRestIT.java b/plugins/analysis-stempel/src/test/java/org/elasticsearch/index/analysis/AnalysisPolishRestIT.java deleted file mode 100644 index 54da5de8e4a..00000000000 --- a/plugins/analysis-stempel/src/test/java/org/elasticsearch/index/analysis/AnalysisPolishRestIT.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Licensed to Elasticsearch under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.index.analysis; - -import com.carrotsearch.randomizedtesting.annotations.Name; -import com.carrotsearch.randomizedtesting.annotations.ParametersFactory; -import org.elasticsearch.test.rest.ESClientYamlSuiteTestCase; -import org.elasticsearch.test.rest.RestTestCandidate; -import org.elasticsearch.test.rest.parser.RestTestParseException; - -import java.io.IOException; - -public class AnalysisPolishRestIT extends ESClientYamlSuiteTestCase { - - public AnalysisPolishRestIT(@Name("yaml") RestTestCandidate testCandidate) { - super(testCandidate); - } - - @ParametersFactory - public static Iterable parameters() throws IOException, RestTestParseException { - return ESClientYamlSuiteTestCase.createParameters(0, 1); - } -} - diff --git a/plugins/analysis-phonetic/src/test/java/org/elasticsearch/index/analysis/AnalysisPhoneticRestIT.java b/plugins/analysis-stempel/src/test/java/org/elasticsearch/index/analysis/StempelClientYamlTestSuiteIT.java similarity index 73% rename from plugins/analysis-phonetic/src/test/java/org/elasticsearch/index/analysis/AnalysisPhoneticRestIT.java rename to plugins/analysis-stempel/src/test/java/org/elasticsearch/index/analysis/StempelClientYamlTestSuiteIT.java index 48f1c4b1716..34d264122ef 100644 --- a/plugins/analysis-phonetic/src/test/java/org/elasticsearch/index/analysis/AnalysisPhoneticRestIT.java +++ b/plugins/analysis-stempel/src/test/java/org/elasticsearch/index/analysis/StempelClientYamlTestSuiteIT.java @@ -21,20 +21,21 @@ package org.elasticsearch.index.analysis; import com.carrotsearch.randomizedtesting.annotations.Name; import com.carrotsearch.randomizedtesting.annotations.ParametersFactory; -import org.elasticsearch.test.rest.ESClientYamlSuiteTestCase; -import org.elasticsearch.test.rest.RestTestCandidate; -import org.elasticsearch.test.rest.parser.RestTestParseException; + +import org.elasticsearch.test.rest.yaml.ClientYamlTestCandidate; +import org.elasticsearch.test.rest.yaml.ESClientYamlSuiteTestCase; +import org.elasticsearch.test.rest.yaml.parser.ClientYamlTestParseException; import java.io.IOException; -public class AnalysisPhoneticRestIT extends ESClientYamlSuiteTestCase { +public class StempelClientYamlTestSuiteIT extends ESClientYamlSuiteTestCase { - public AnalysisPhoneticRestIT(@Name("yaml") RestTestCandidate testCandidate) { + public StempelClientYamlTestSuiteIT(@Name("yaml") ClientYamlTestCandidate testCandidate) { super(testCandidate); } @ParametersFactory - public static Iterable parameters() throws IOException, RestTestParseException { + public static Iterable parameters() throws IOException, ClientYamlTestParseException { return ESClientYamlSuiteTestCase.createParameters(0, 1); } } diff --git a/plugins/discovery-azure-classic/src/test/java/org/elasticsearch/discovery/azure/classic/AzureDiscoveryRestIT.java b/plugins/discovery-azure-classic/src/test/java/org/elasticsearch/discovery/azure/classic/DiscoveryAzureClassicClientYamlTestSuiteIT.java similarity index 72% rename from plugins/discovery-azure-classic/src/test/java/org/elasticsearch/discovery/azure/classic/AzureDiscoveryRestIT.java rename to plugins/discovery-azure-classic/src/test/java/org/elasticsearch/discovery/azure/classic/DiscoveryAzureClassicClientYamlTestSuiteIT.java index 5506169f79d..30276c16c89 100644 --- a/plugins/discovery-azure-classic/src/test/java/org/elasticsearch/discovery/azure/classic/AzureDiscoveryRestIT.java +++ b/plugins/discovery-azure-classic/src/test/java/org/elasticsearch/discovery/azure/classic/DiscoveryAzureClassicClientYamlTestSuiteIT.java @@ -21,20 +21,21 @@ package org.elasticsearch.discovery.azure.classic; import com.carrotsearch.randomizedtesting.annotations.Name; import com.carrotsearch.randomizedtesting.annotations.ParametersFactory; -import org.elasticsearch.test.rest.ESClientYamlSuiteTestCase; -import org.elasticsearch.test.rest.RestTestCandidate; -import org.elasticsearch.test.rest.parser.RestTestParseException; + +import org.elasticsearch.test.rest.yaml.ClientYamlTestCandidate; +import org.elasticsearch.test.rest.yaml.ESClientYamlSuiteTestCase; +import org.elasticsearch.test.rest.yaml.parser.ClientYamlTestParseException; import java.io.IOException; -public class AzureDiscoveryRestIT extends ESClientYamlSuiteTestCase { +public class DiscoveryAzureClassicClientYamlTestSuiteIT extends ESClientYamlSuiteTestCase { - public AzureDiscoveryRestIT(@Name("yaml") RestTestCandidate testCandidate) { + public DiscoveryAzureClassicClientYamlTestSuiteIT(@Name("yaml") ClientYamlTestCandidate testCandidate) { super(testCandidate); } @ParametersFactory - public static Iterable parameters() throws IOException, RestTestParseException { + public static Iterable parameters() throws IOException, ClientYamlTestParseException { return ESClientYamlSuiteTestCase.createParameters(0, 1); } } diff --git a/plugins/discovery-ec2/src/test/java/org/elasticsearch/cloud/aws/DiscoveryEc2RestIT.java b/plugins/discovery-ec2/src/test/java/org/elasticsearch/cloud/aws/CloudAwsClientYamlTestSuiteIT.java similarity index 73% rename from plugins/discovery-ec2/src/test/java/org/elasticsearch/cloud/aws/DiscoveryEc2RestIT.java rename to plugins/discovery-ec2/src/test/java/org/elasticsearch/cloud/aws/CloudAwsClientYamlTestSuiteIT.java index cc621dd5949..f5f49c14833 100644 --- a/plugins/discovery-ec2/src/test/java/org/elasticsearch/cloud/aws/DiscoveryEc2RestIT.java +++ b/plugins/discovery-ec2/src/test/java/org/elasticsearch/cloud/aws/CloudAwsClientYamlTestSuiteIT.java @@ -21,20 +21,21 @@ package org.elasticsearch.cloud.aws; import com.carrotsearch.randomizedtesting.annotations.Name; import com.carrotsearch.randomizedtesting.annotations.ParametersFactory; -import org.elasticsearch.test.rest.ESClientYamlSuiteTestCase; -import org.elasticsearch.test.rest.RestTestCandidate; -import org.elasticsearch.test.rest.parser.RestTestParseException; + +import org.elasticsearch.test.rest.yaml.ClientYamlTestCandidate; +import org.elasticsearch.test.rest.yaml.ESClientYamlSuiteTestCase; +import org.elasticsearch.test.rest.yaml.parser.ClientYamlTestParseException; import java.io.IOException; -public class DiscoveryEc2RestIT extends ESClientYamlSuiteTestCase { +public class CloudAwsClientYamlTestSuiteIT extends ESClientYamlSuiteTestCase { - public DiscoveryEc2RestIT(@Name("yaml") RestTestCandidate testCandidate) { + public CloudAwsClientYamlTestSuiteIT(@Name("yaml") ClientYamlTestCandidate testCandidate) { super(testCandidate); } @ParametersFactory - public static Iterable parameters() throws IOException, RestTestParseException { + public static Iterable parameters() throws IOException, ClientYamlTestParseException { return ESClientYamlSuiteTestCase.createParameters(0, 1); } } diff --git a/plugins/discovery-gce/src/test/java/org/elasticsearch/discovery/gce/DiscoveryGCERestIT.java b/plugins/discovery-gce/src/test/java/org/elasticsearch/discovery/gce/DiscoveryGceClientYamlTestSuiteIT.java similarity index 73% rename from plugins/discovery-gce/src/test/java/org/elasticsearch/discovery/gce/DiscoveryGCERestIT.java rename to plugins/discovery-gce/src/test/java/org/elasticsearch/discovery/gce/DiscoveryGceClientYamlTestSuiteIT.java index dae943f7bd2..8ce17ff9fa5 100644 --- a/plugins/discovery-gce/src/test/java/org/elasticsearch/discovery/gce/DiscoveryGCERestIT.java +++ b/plugins/discovery-gce/src/test/java/org/elasticsearch/discovery/gce/DiscoveryGceClientYamlTestSuiteIT.java @@ -21,20 +21,21 @@ package org.elasticsearch.discovery.gce; import com.carrotsearch.randomizedtesting.annotations.Name; import com.carrotsearch.randomizedtesting.annotations.ParametersFactory; -import org.elasticsearch.test.rest.ESClientYamlSuiteTestCase; -import org.elasticsearch.test.rest.RestTestCandidate; -import org.elasticsearch.test.rest.parser.RestTestParseException; + +import org.elasticsearch.test.rest.yaml.ClientYamlTestCandidate; +import org.elasticsearch.test.rest.yaml.ESClientYamlSuiteTestCase; +import org.elasticsearch.test.rest.yaml.parser.ClientYamlTestParseException; import java.io.IOException; -public class DiscoveryGCERestIT extends ESClientYamlSuiteTestCase { +public class DiscoveryGceClientYamlTestSuiteIT extends ESClientYamlSuiteTestCase { - public DiscoveryGCERestIT(@Name("yaml") RestTestCandidate testCandidate) { + public DiscoveryGceClientYamlTestSuiteIT(@Name("yaml") ClientYamlTestCandidate testCandidate) { super(testCandidate); } @ParametersFactory - public static Iterable parameters() throws IOException, RestTestParseException { + public static Iterable parameters() throws IOException, ClientYamlTestParseException { return ESClientYamlSuiteTestCase.createParameters(0, 1); } } diff --git a/plugins/ingest-attachment/src/test/java/org/elasticsearch/ingest/attachment/IngestAttachmentRestIT.java b/plugins/ingest-attachment/src/test/java/org/elasticsearch/ingest/attachment/IngestAttachmentClientYamlTestSuiteIT.java similarity index 73% rename from plugins/ingest-attachment/src/test/java/org/elasticsearch/ingest/attachment/IngestAttachmentRestIT.java rename to plugins/ingest-attachment/src/test/java/org/elasticsearch/ingest/attachment/IngestAttachmentClientYamlTestSuiteIT.java index 671b5b0ab95..d720a4abf28 100644 --- a/plugins/ingest-attachment/src/test/java/org/elasticsearch/ingest/attachment/IngestAttachmentRestIT.java +++ b/plugins/ingest-attachment/src/test/java/org/elasticsearch/ingest/attachment/IngestAttachmentClientYamlTestSuiteIT.java @@ -21,20 +21,21 @@ package org.elasticsearch.ingest.attachment; import com.carrotsearch.randomizedtesting.annotations.Name; import com.carrotsearch.randomizedtesting.annotations.ParametersFactory; -import org.elasticsearch.test.rest.ESClientYamlSuiteTestCase; -import org.elasticsearch.test.rest.RestTestCandidate; -import org.elasticsearch.test.rest.parser.RestTestParseException; + +import org.elasticsearch.test.rest.yaml.ClientYamlTestCandidate; +import org.elasticsearch.test.rest.yaml.ESClientYamlSuiteTestCase; +import org.elasticsearch.test.rest.yaml.parser.ClientYamlTestParseException; import java.io.IOException; -public class IngestAttachmentRestIT extends ESClientYamlSuiteTestCase { +public class IngestAttachmentClientYamlTestSuiteIT extends ESClientYamlSuiteTestCase { - public IngestAttachmentRestIT(@Name("yaml") RestTestCandidate testCandidate) { + public IngestAttachmentClientYamlTestSuiteIT(@Name("yaml") ClientYamlTestCandidate testCandidate) { super(testCandidate); } @ParametersFactory - public static Iterable parameters() throws IOException, RestTestParseException { + public static Iterable parameters() throws IOException, ClientYamlTestParseException { return ESClientYamlSuiteTestCase.createParameters(0, 1); } } diff --git a/plugins/ingest-geoip/src/test/java/org/elasticsearch/ingest/geoip/IngestGeoIpRestIT.java b/plugins/ingest-geoip/src/test/java/org/elasticsearch/ingest/geoip/IngestGeoIpClientYamlTestSuiteIT.java similarity index 73% rename from plugins/ingest-geoip/src/test/java/org/elasticsearch/ingest/geoip/IngestGeoIpRestIT.java rename to plugins/ingest-geoip/src/test/java/org/elasticsearch/ingest/geoip/IngestGeoIpClientYamlTestSuiteIT.java index 19cd7226d43..26838b600da 100644 --- a/plugins/ingest-geoip/src/test/java/org/elasticsearch/ingest/geoip/IngestGeoIpRestIT.java +++ b/plugins/ingest-geoip/src/test/java/org/elasticsearch/ingest/geoip/IngestGeoIpClientYamlTestSuiteIT.java @@ -21,22 +21,21 @@ package org.elasticsearch.ingest.geoip; import com.carrotsearch.randomizedtesting.annotations.Name; import com.carrotsearch.randomizedtesting.annotations.ParametersFactory; -import org.elasticsearch.plugins.Plugin; -import org.elasticsearch.test.rest.ESClientYamlSuiteTestCase; -import org.elasticsearch.test.rest.RestTestCandidate; -import org.elasticsearch.test.rest.parser.RestTestParseException; + +import org.elasticsearch.test.rest.yaml.ClientYamlTestCandidate; +import org.elasticsearch.test.rest.yaml.ESClientYamlSuiteTestCase; +import org.elasticsearch.test.rest.yaml.parser.ClientYamlTestParseException; import java.io.IOException; -import java.util.Collection; -public class IngestGeoIpRestIT extends ESClientYamlSuiteTestCase { +public class IngestGeoIpClientYamlTestSuiteIT extends ESClientYamlSuiteTestCase { - public IngestGeoIpRestIT(@Name("yaml") RestTestCandidate testCandidate) { + public IngestGeoIpClientYamlTestSuiteIT(@Name("yaml") ClientYamlTestCandidate testCandidate) { super(testCandidate); } @ParametersFactory - public static Iterable parameters() throws IOException, RestTestParseException { + public static Iterable parameters() throws IOException, ClientYamlTestParseException { return ESClientYamlSuiteTestCase.createParameters(0, 1); } } diff --git a/plugins/ingest-user-agent/src/test/java/org/elasticsearch/ingest/useragent/UserAgentRestIT.java b/plugins/ingest-user-agent/src/test/java/org/elasticsearch/ingest/useragent/IngestUserAgentClientYamlTestSuiteIT.java similarity index 73% rename from plugins/ingest-user-agent/src/test/java/org/elasticsearch/ingest/useragent/UserAgentRestIT.java rename to plugins/ingest-user-agent/src/test/java/org/elasticsearch/ingest/useragent/IngestUserAgentClientYamlTestSuiteIT.java index 0ca96698e3b..b0aa115a1a2 100644 --- a/plugins/ingest-user-agent/src/test/java/org/elasticsearch/ingest/useragent/UserAgentRestIT.java +++ b/plugins/ingest-user-agent/src/test/java/org/elasticsearch/ingest/useragent/IngestUserAgentClientYamlTestSuiteIT.java @@ -21,20 +21,21 @@ package org.elasticsearch.ingest.useragent; import com.carrotsearch.randomizedtesting.annotations.Name; import com.carrotsearch.randomizedtesting.annotations.ParametersFactory; -import org.elasticsearch.test.rest.ESClientYamlSuiteTestCase; -import org.elasticsearch.test.rest.RestTestCandidate; -import org.elasticsearch.test.rest.parser.RestTestParseException; + +import org.elasticsearch.test.rest.yaml.ClientYamlTestCandidate; +import org.elasticsearch.test.rest.yaml.ESClientYamlSuiteTestCase; +import org.elasticsearch.test.rest.yaml.parser.ClientYamlTestParseException; import java.io.IOException; -public class UserAgentRestIT extends ESClientYamlSuiteTestCase { +public class IngestUserAgentClientYamlTestSuiteIT extends ESClientYamlSuiteTestCase { - public UserAgentRestIT(@Name("yaml") RestTestCandidate testCandidate) { + public IngestUserAgentClientYamlTestSuiteIT(@Name("yaml") ClientYamlTestCandidate testCandidate) { super(testCandidate); } @ParametersFactory - public static Iterable parameters() throws IOException, RestTestParseException { + public static Iterable parameters() throws IOException, ClientYamlTestParseException { return ESClientYamlSuiteTestCase.createParameters(0, 1); } } diff --git a/plugins/jvm-example/src/test/java/org/elasticsearch/plugin/example/JvmExampleRestIT.java b/plugins/jvm-example/src/test/java/org/elasticsearch/plugin/example/JvmExampleClientYamlTestSuiteIT.java similarity index 73% rename from plugins/jvm-example/src/test/java/org/elasticsearch/plugin/example/JvmExampleRestIT.java rename to plugins/jvm-example/src/test/java/org/elasticsearch/plugin/example/JvmExampleClientYamlTestSuiteIT.java index 62be8332439..0ef413d9595 100644 --- a/plugins/jvm-example/src/test/java/org/elasticsearch/plugin/example/JvmExampleRestIT.java +++ b/plugins/jvm-example/src/test/java/org/elasticsearch/plugin/example/JvmExampleClientYamlTestSuiteIT.java @@ -21,20 +21,21 @@ package org.elasticsearch.plugin.example; import com.carrotsearch.randomizedtesting.annotations.Name; import com.carrotsearch.randomizedtesting.annotations.ParametersFactory; -import org.elasticsearch.test.rest.ESClientYamlSuiteTestCase; -import org.elasticsearch.test.rest.RestTestCandidate; -import org.elasticsearch.test.rest.parser.RestTestParseException; + +import org.elasticsearch.test.rest.yaml.ClientYamlTestCandidate; +import org.elasticsearch.test.rest.yaml.ESClientYamlSuiteTestCase; +import org.elasticsearch.test.rest.yaml.parser.ClientYamlTestParseException; import java.io.IOException; -public class JvmExampleRestIT extends ESClientYamlSuiteTestCase { +public class JvmExampleClientYamlTestSuiteIT extends ESClientYamlSuiteTestCase { - public JvmExampleRestIT(@Name("yaml") RestTestCandidate testCandidate) { + public JvmExampleClientYamlTestSuiteIT(@Name("yaml") ClientYamlTestCandidate testCandidate) { super(testCandidate); } @ParametersFactory - public static Iterable parameters() throws IOException, RestTestParseException { + public static Iterable parameters() throws IOException, ClientYamlTestParseException { return ESClientYamlSuiteTestCase.createParameters(0, 1); } } diff --git a/plugins/lang-javascript/src/test/java/org/elasticsearch/script/javascript/LangJavaScriptRestIT.java b/plugins/lang-javascript/src/test/java/org/elasticsearch/script/javascript/LangJavascriptClientYamlTestSuiteIT.java similarity index 73% rename from plugins/lang-javascript/src/test/java/org/elasticsearch/script/javascript/LangJavaScriptRestIT.java rename to plugins/lang-javascript/src/test/java/org/elasticsearch/script/javascript/LangJavascriptClientYamlTestSuiteIT.java index 014c7073e71..e89372c8b36 100644 --- a/plugins/lang-javascript/src/test/java/org/elasticsearch/script/javascript/LangJavaScriptRestIT.java +++ b/plugins/lang-javascript/src/test/java/org/elasticsearch/script/javascript/LangJavascriptClientYamlTestSuiteIT.java @@ -21,20 +21,21 @@ package org.elasticsearch.script.javascript; import com.carrotsearch.randomizedtesting.annotations.Name; import com.carrotsearch.randomizedtesting.annotations.ParametersFactory; -import org.elasticsearch.test.rest.ESClientYamlSuiteTestCase; -import org.elasticsearch.test.rest.RestTestCandidate; -import org.elasticsearch.test.rest.parser.RestTestParseException; + +import org.elasticsearch.test.rest.yaml.ClientYamlTestCandidate; +import org.elasticsearch.test.rest.yaml.ESClientYamlSuiteTestCase; +import org.elasticsearch.test.rest.yaml.parser.ClientYamlTestParseException; import java.io.IOException; -public class LangJavaScriptRestIT extends ESClientYamlSuiteTestCase { +public class LangJavascriptClientYamlTestSuiteIT extends ESClientYamlSuiteTestCase { - public LangJavaScriptRestIT(@Name("yaml") RestTestCandidate testCandidate) { + public LangJavascriptClientYamlTestSuiteIT(@Name("yaml") ClientYamlTestCandidate testCandidate) { super(testCandidate); } @ParametersFactory - public static Iterable parameters() throws IOException, RestTestParseException { + public static Iterable parameters() throws IOException, ClientYamlTestParseException { return ESClientYamlSuiteTestCase.createParameters(0, 1); } } diff --git a/plugins/lang-python/src/test/java/org/elasticsearch/script/python/LangPythonScriptRestIT.java b/plugins/lang-python/src/test/java/org/elasticsearch/script/python/LangPythonClientYamlTestSuiteIT.java similarity index 73% rename from plugins/lang-python/src/test/java/org/elasticsearch/script/python/LangPythonScriptRestIT.java rename to plugins/lang-python/src/test/java/org/elasticsearch/script/python/LangPythonClientYamlTestSuiteIT.java index cbf7547a580..618ea6b20e5 100644 --- a/plugins/lang-python/src/test/java/org/elasticsearch/script/python/LangPythonScriptRestIT.java +++ b/plugins/lang-python/src/test/java/org/elasticsearch/script/python/LangPythonClientYamlTestSuiteIT.java @@ -21,20 +21,21 @@ package org.elasticsearch.script.python; import com.carrotsearch.randomizedtesting.annotations.Name; import com.carrotsearch.randomizedtesting.annotations.ParametersFactory; -import org.elasticsearch.test.rest.ESClientYamlSuiteTestCase; -import org.elasticsearch.test.rest.RestTestCandidate; -import org.elasticsearch.test.rest.parser.RestTestParseException; + +import org.elasticsearch.test.rest.yaml.ClientYamlTestCandidate; +import org.elasticsearch.test.rest.yaml.ESClientYamlSuiteTestCase; +import org.elasticsearch.test.rest.yaml.parser.ClientYamlTestParseException; import java.io.IOException; -public class LangPythonScriptRestIT extends ESClientYamlSuiteTestCase { +public class LangPythonClientYamlTestSuiteIT extends ESClientYamlSuiteTestCase { - public LangPythonScriptRestIT(@Name("yaml") RestTestCandidate testCandidate) { + public LangPythonClientYamlTestSuiteIT(@Name("yaml") ClientYamlTestCandidate testCandidate) { super(testCandidate); } @ParametersFactory - public static Iterable parameters() throws IOException, RestTestParseException { + public static Iterable parameters() throws IOException, ClientYamlTestParseException { return ESClientYamlSuiteTestCase.createParameters(0, 1); } } diff --git a/plugins/mapper-attachments/src/test/java/org/elasticsearch/mapper/attachments/MapperAttachmentsRestIT.java b/plugins/mapper-attachments/src/test/java/org/elasticsearch/mapper/attachments/MapperAttachmentsClientYamlTestSuiteIT.java similarity index 72% rename from plugins/mapper-attachments/src/test/java/org/elasticsearch/mapper/attachments/MapperAttachmentsRestIT.java rename to plugins/mapper-attachments/src/test/java/org/elasticsearch/mapper/attachments/MapperAttachmentsClientYamlTestSuiteIT.java index 0958225ae18..53a5c5c2813 100644 --- a/plugins/mapper-attachments/src/test/java/org/elasticsearch/mapper/attachments/MapperAttachmentsRestIT.java +++ b/plugins/mapper-attachments/src/test/java/org/elasticsearch/mapper/attachments/MapperAttachmentsClientYamlTestSuiteIT.java @@ -21,20 +21,21 @@ package org.elasticsearch.mapper.attachments; import com.carrotsearch.randomizedtesting.annotations.Name; import com.carrotsearch.randomizedtesting.annotations.ParametersFactory; -import org.elasticsearch.test.rest.ESClientYamlSuiteTestCase; -import org.elasticsearch.test.rest.RestTestCandidate; -import org.elasticsearch.test.rest.parser.RestTestParseException; + +import org.elasticsearch.test.rest.yaml.ClientYamlTestCandidate; +import org.elasticsearch.test.rest.yaml.ESClientYamlSuiteTestCase; +import org.elasticsearch.test.rest.yaml.parser.ClientYamlTestParseException; import java.io.IOException; -public class MapperAttachmentsRestIT extends ESClientYamlSuiteTestCase { +public class MapperAttachmentsClientYamlTestSuiteIT extends ESClientYamlSuiteTestCase { - public MapperAttachmentsRestIT(@Name("yaml") RestTestCandidate testCandidate) { + public MapperAttachmentsClientYamlTestSuiteIT(@Name("yaml") ClientYamlTestCandidate testCandidate) { super(testCandidate); } @ParametersFactory - public static Iterable parameters() throws IOException, RestTestParseException { + public static Iterable parameters() throws IOException, ClientYamlTestParseException { return createParameters(0, 1); } } diff --git a/plugins/mapper-murmur3/src/test/java/org/elasticsearch/index/mapper/murmur3/MapperMurmur3RestIT.java b/plugins/mapper-murmur3/src/test/java/org/elasticsearch/index/mapper/murmur3/MapperMurmur3ClientYamlTestSuiteIT.java similarity index 73% rename from plugins/mapper-murmur3/src/test/java/org/elasticsearch/index/mapper/murmur3/MapperMurmur3RestIT.java rename to plugins/mapper-murmur3/src/test/java/org/elasticsearch/index/mapper/murmur3/MapperMurmur3ClientYamlTestSuiteIT.java index 37a4490d38c..204f6c07a99 100644 --- a/plugins/mapper-murmur3/src/test/java/org/elasticsearch/index/mapper/murmur3/MapperMurmur3RestIT.java +++ b/plugins/mapper-murmur3/src/test/java/org/elasticsearch/index/mapper/murmur3/MapperMurmur3ClientYamlTestSuiteIT.java @@ -21,20 +21,21 @@ package org.elasticsearch.index.mapper.murmur3; import com.carrotsearch.randomizedtesting.annotations.Name; import com.carrotsearch.randomizedtesting.annotations.ParametersFactory; -import org.elasticsearch.test.rest.ESClientYamlSuiteTestCase; -import org.elasticsearch.test.rest.RestTestCandidate; -import org.elasticsearch.test.rest.parser.RestTestParseException; + +import org.elasticsearch.test.rest.yaml.ClientYamlTestCandidate; +import org.elasticsearch.test.rest.yaml.ESClientYamlSuiteTestCase; +import org.elasticsearch.test.rest.yaml.parser.ClientYamlTestParseException; import java.io.IOException; -public class MapperMurmur3RestIT extends ESClientYamlSuiteTestCase { +public class MapperMurmur3ClientYamlTestSuiteIT extends ESClientYamlSuiteTestCase { - public MapperMurmur3RestIT(@Name("yaml") RestTestCandidate testCandidate) { + public MapperMurmur3ClientYamlTestSuiteIT(@Name("yaml") ClientYamlTestCandidate testCandidate) { super(testCandidate); } @ParametersFactory - public static Iterable parameters() throws IOException, RestTestParseException { + public static Iterable parameters() throws IOException, ClientYamlTestParseException { return createParameters(0, 1); } } diff --git a/plugins/mapper-size/src/test/java/org/elasticsearch/index/mapper/size/MapperSizeRestIT.java b/plugins/mapper-size/src/test/java/org/elasticsearch/index/mapper/size/MapperSizeClientYamlTestSuiteIT.java similarity index 73% rename from plugins/mapper-size/src/test/java/org/elasticsearch/index/mapper/size/MapperSizeRestIT.java rename to plugins/mapper-size/src/test/java/org/elasticsearch/index/mapper/size/MapperSizeClientYamlTestSuiteIT.java index f5ee35c5638..44f26c4ec51 100644 --- a/plugins/mapper-size/src/test/java/org/elasticsearch/index/mapper/size/MapperSizeRestIT.java +++ b/plugins/mapper-size/src/test/java/org/elasticsearch/index/mapper/size/MapperSizeClientYamlTestSuiteIT.java @@ -21,20 +21,21 @@ package org.elasticsearch.index.mapper.size; import com.carrotsearch.randomizedtesting.annotations.Name; import com.carrotsearch.randomizedtesting.annotations.ParametersFactory; -import org.elasticsearch.test.rest.ESClientYamlSuiteTestCase; -import org.elasticsearch.test.rest.RestTestCandidate; -import org.elasticsearch.test.rest.parser.RestTestParseException; + +import org.elasticsearch.test.rest.yaml.ClientYamlTestCandidate; +import org.elasticsearch.test.rest.yaml.ESClientYamlSuiteTestCase; +import org.elasticsearch.test.rest.yaml.parser.ClientYamlTestParseException; import java.io.IOException; -public class MapperSizeRestIT extends ESClientYamlSuiteTestCase { +public class MapperSizeClientYamlTestSuiteIT extends ESClientYamlSuiteTestCase { - public MapperSizeRestIT(@Name("yaml") RestTestCandidate testCandidate) { + public MapperSizeClientYamlTestSuiteIT(@Name("yaml") ClientYamlTestCandidate testCandidate) { super(testCandidate); } @ParametersFactory - public static Iterable parameters() throws IOException, RestTestParseException { + public static Iterable parameters() throws IOException, ClientYamlTestParseException { return createParameters(0, 1); } } diff --git a/plugins/repository-azure/src/test/java/org/elasticsearch/repositories/azure/AzureRepositoryRestIT.java b/plugins/repository-azure/src/test/java/org/elasticsearch/repositories/azure/RepositoryAzureClientYamlTestSuiteIT.java similarity index 73% rename from plugins/repository-azure/src/test/java/org/elasticsearch/repositories/azure/AzureRepositoryRestIT.java rename to plugins/repository-azure/src/test/java/org/elasticsearch/repositories/azure/RepositoryAzureClientYamlTestSuiteIT.java index 3c565d407ce..c7eeff27401 100644 --- a/plugins/repository-azure/src/test/java/org/elasticsearch/repositories/azure/AzureRepositoryRestIT.java +++ b/plugins/repository-azure/src/test/java/org/elasticsearch/repositories/azure/RepositoryAzureClientYamlTestSuiteIT.java @@ -21,20 +21,21 @@ package org.elasticsearch.repositories.azure; import com.carrotsearch.randomizedtesting.annotations.Name; import com.carrotsearch.randomizedtesting.annotations.ParametersFactory; -import org.elasticsearch.test.rest.ESClientYamlSuiteTestCase; -import org.elasticsearch.test.rest.RestTestCandidate; -import org.elasticsearch.test.rest.parser.RestTestParseException; + +import org.elasticsearch.test.rest.yaml.ClientYamlTestCandidate; +import org.elasticsearch.test.rest.yaml.ESClientYamlSuiteTestCase; +import org.elasticsearch.test.rest.yaml.parser.ClientYamlTestParseException; import java.io.IOException; -public class AzureRepositoryRestIT extends ESClientYamlSuiteTestCase { +public class RepositoryAzureClientYamlTestSuiteIT extends ESClientYamlSuiteTestCase { - public AzureRepositoryRestIT(@Name("yaml") RestTestCandidate testCandidate) { + public RepositoryAzureClientYamlTestSuiteIT(@Name("yaml") ClientYamlTestCandidate testCandidate) { super(testCandidate); } @ParametersFactory - public static Iterable parameters() throws IOException, RestTestParseException { + public static Iterable parameters() throws IOException, ClientYamlTestParseException { return ESClientYamlSuiteTestCase.createParameters(0, 1); } } diff --git a/plugins/repository-gcs/src/test/java/org/elasticsearch/repositories/gcs/GoogleCloudStorageRepositoryRestIT.java b/plugins/repository-gcs/src/test/java/org/elasticsearch/repositories/gcs/RepositoryGcsClientYamlTestSuiteIT.java similarity index 74% rename from plugins/repository-gcs/src/test/java/org/elasticsearch/repositories/gcs/GoogleCloudStorageRepositoryRestIT.java rename to plugins/repository-gcs/src/test/java/org/elasticsearch/repositories/gcs/RepositoryGcsClientYamlTestSuiteIT.java index b19b8623ace..52145bf87e2 100644 --- a/plugins/repository-gcs/src/test/java/org/elasticsearch/repositories/gcs/GoogleCloudStorageRepositoryRestIT.java +++ b/plugins/repository-gcs/src/test/java/org/elasticsearch/repositories/gcs/RepositoryGcsClientYamlTestSuiteIT.java @@ -21,20 +21,21 @@ package org.elasticsearch.repositories.gcs; import com.carrotsearch.randomizedtesting.annotations.Name; import com.carrotsearch.randomizedtesting.annotations.ParametersFactory; -import org.elasticsearch.test.rest.ESClientYamlSuiteTestCase; -import org.elasticsearch.test.rest.RestTestCandidate; -import org.elasticsearch.test.rest.parser.RestTestParseException; + +import org.elasticsearch.test.rest.yaml.ClientYamlTestCandidate; +import org.elasticsearch.test.rest.yaml.ESClientYamlSuiteTestCase; +import org.elasticsearch.test.rest.yaml.parser.ClientYamlTestParseException; import java.io.IOException; -public class GoogleCloudStorageRepositoryRestIT extends ESClientYamlSuiteTestCase { +public class RepositoryGcsClientYamlTestSuiteIT extends ESClientYamlSuiteTestCase { - public GoogleCloudStorageRepositoryRestIT(@Name("yaml") RestTestCandidate testCandidate) { + public RepositoryGcsClientYamlTestSuiteIT(@Name("yaml") ClientYamlTestCandidate testCandidate) { super(testCandidate); } @ParametersFactory - public static Iterable parameters() throws IOException, RestTestParseException { + public static Iterable parameters() throws IOException, ClientYamlTestParseException { return createParameters(0, 1); } } diff --git a/plugins/repository-hdfs/src/test/java/org/elasticsearch/repositories/hdfs/HdfsRepositoryRestIT.java b/plugins/repository-hdfs/src/test/java/org/elasticsearch/repositories/hdfs/RepositoryHdfsClientYamlTestSuiteIT.java similarity index 73% rename from plugins/repository-hdfs/src/test/java/org/elasticsearch/repositories/hdfs/HdfsRepositoryRestIT.java rename to plugins/repository-hdfs/src/test/java/org/elasticsearch/repositories/hdfs/RepositoryHdfsClientYamlTestSuiteIT.java index 147838df9ea..1dfbb3c51b7 100644 --- a/plugins/repository-hdfs/src/test/java/org/elasticsearch/repositories/hdfs/HdfsRepositoryRestIT.java +++ b/plugins/repository-hdfs/src/test/java/org/elasticsearch/repositories/hdfs/RepositoryHdfsClientYamlTestSuiteIT.java @@ -22,18 +22,19 @@ import java.io.IOException; import com.carrotsearch.randomizedtesting.annotations.Name; import com.carrotsearch.randomizedtesting.annotations.ParametersFactory; -import org.elasticsearch.test.rest.ESClientYamlSuiteTestCase; -import org.elasticsearch.test.rest.RestTestCandidate; -import org.elasticsearch.test.rest.parser.RestTestParseException; -public class HdfsRepositoryRestIT extends ESClientYamlSuiteTestCase { +import org.elasticsearch.test.rest.yaml.ClientYamlTestCandidate; +import org.elasticsearch.test.rest.yaml.ESClientYamlSuiteTestCase; +import org.elasticsearch.test.rest.yaml.parser.ClientYamlTestParseException; - public HdfsRepositoryRestIT(@Name("yaml") RestTestCandidate testCandidate) { +public class RepositoryHdfsClientYamlTestSuiteIT extends ESClientYamlSuiteTestCase { + + public RepositoryHdfsClientYamlTestSuiteIT(@Name("yaml") ClientYamlTestCandidate testCandidate) { super(testCandidate); } @ParametersFactory - public static Iterable parameters() throws IOException, RestTestParseException { + public static Iterable parameters() throws IOException, ClientYamlTestParseException { return ESClientYamlSuiteTestCase.createParameters(0, 1); } } diff --git a/plugins/repository-s3/src/test/java/org/elasticsearch/repositories/s3/RepositoryS3RestIT.java b/plugins/repository-s3/src/test/java/org/elasticsearch/repositories/s3/RepositoryS3ClientYamlTestSuiteIT.java similarity index 73% rename from plugins/repository-s3/src/test/java/org/elasticsearch/repositories/s3/RepositoryS3RestIT.java rename to plugins/repository-s3/src/test/java/org/elasticsearch/repositories/s3/RepositoryS3ClientYamlTestSuiteIT.java index 5dada2a2637..04c4f6fc0f1 100644 --- a/plugins/repository-s3/src/test/java/org/elasticsearch/repositories/s3/RepositoryS3RestIT.java +++ b/plugins/repository-s3/src/test/java/org/elasticsearch/repositories/s3/RepositoryS3ClientYamlTestSuiteIT.java @@ -21,20 +21,21 @@ package org.elasticsearch.repositories.s3; import com.carrotsearch.randomizedtesting.annotations.Name; import com.carrotsearch.randomizedtesting.annotations.ParametersFactory; -import org.elasticsearch.test.rest.ESClientYamlSuiteTestCase; -import org.elasticsearch.test.rest.RestTestCandidate; -import org.elasticsearch.test.rest.parser.RestTestParseException; + +import org.elasticsearch.test.rest.yaml.ClientYamlTestCandidate; +import org.elasticsearch.test.rest.yaml.ESClientYamlSuiteTestCase; +import org.elasticsearch.test.rest.yaml.parser.ClientYamlTestParseException; import java.io.IOException; -public class RepositoryS3RestIT extends ESClientYamlSuiteTestCase { +public class RepositoryS3ClientYamlTestSuiteIT extends ESClientYamlSuiteTestCase { - public RepositoryS3RestIT(@Name("yaml") RestTestCandidate testCandidate) { + public RepositoryS3ClientYamlTestSuiteIT(@Name("yaml") ClientYamlTestCandidate testCandidate) { super(testCandidate); } @ParametersFactory - public static Iterable parameters() throws IOException, RestTestParseException { + public static Iterable parameters() throws IOException, ClientYamlTestParseException { return ESClientYamlSuiteTestCase.createParameters(0, 1); } } diff --git a/plugins/store-smb/src/test/java/org/elasticsearch/index/store/SMBStoreRestIT.java b/plugins/store-smb/src/test/java/org/elasticsearch/index/store/StoreSmbClientYamlTestSuiteIT.java similarity index 73% rename from plugins/store-smb/src/test/java/org/elasticsearch/index/store/SMBStoreRestIT.java rename to plugins/store-smb/src/test/java/org/elasticsearch/index/store/StoreSmbClientYamlTestSuiteIT.java index 99617b94644..72394b79693 100644 --- a/plugins/store-smb/src/test/java/org/elasticsearch/index/store/SMBStoreRestIT.java +++ b/plugins/store-smb/src/test/java/org/elasticsearch/index/store/StoreSmbClientYamlTestSuiteIT.java @@ -21,20 +21,21 @@ package org.elasticsearch.index.store; import com.carrotsearch.randomizedtesting.annotations.Name; import com.carrotsearch.randomizedtesting.annotations.ParametersFactory; -import org.elasticsearch.test.rest.ESClientYamlSuiteTestCase; -import org.elasticsearch.test.rest.RestTestCandidate; -import org.elasticsearch.test.rest.parser.RestTestParseException; + +import org.elasticsearch.test.rest.yaml.ClientYamlTestCandidate; +import org.elasticsearch.test.rest.yaml.ESClientYamlSuiteTestCase; +import org.elasticsearch.test.rest.yaml.parser.ClientYamlTestParseException; import java.io.IOException; -public class SMBStoreRestIT extends ESClientYamlSuiteTestCase { +public class StoreSmbClientYamlTestSuiteIT extends ESClientYamlSuiteTestCase { - public SMBStoreRestIT(@Name("yaml") RestTestCandidate testCandidate) { + public StoreSmbClientYamlTestSuiteIT(@Name("yaml") ClientYamlTestCandidate testCandidate) { super(testCandidate); } @ParametersFactory - public static Iterable parameters() throws IOException, RestTestParseException { + public static Iterable parameters() throws IOException, ClientYamlTestParseException { return ESClientYamlSuiteTestCase.createParameters(0, 1); } } diff --git a/qa/backwards-5.0/src/test/java/org/elasticsearch/backwards/MultiNodeBackwardsIT.java b/qa/backwards-5.0/src/test/java/org/elasticsearch/backwards/Backwards50ClientYamlTestSuiteIT.java similarity index 76% rename from qa/backwards-5.0/src/test/java/org/elasticsearch/backwards/MultiNodeBackwardsIT.java rename to qa/backwards-5.0/src/test/java/org/elasticsearch/backwards/Backwards50ClientYamlTestSuiteIT.java index e23ca840025..e3ab68b3477 100644 --- a/qa/backwards-5.0/src/test/java/org/elasticsearch/backwards/MultiNodeBackwardsIT.java +++ b/qa/backwards-5.0/src/test/java/org/elasticsearch/backwards/Backwards50ClientYamlTestSuiteIT.java @@ -22,21 +22,21 @@ package org.elasticsearch.backwards; import com.carrotsearch.randomizedtesting.annotations.ParametersFactory; import com.carrotsearch.randomizedtesting.annotations.TimeoutSuite; import org.apache.lucene.util.TimeUnits; -import org.elasticsearch.test.rest.ESClientYamlSuiteTestCase; -import org.elasticsearch.test.rest.RestTestCandidate; -import org.elasticsearch.test.rest.parser.RestTestParseException; +import org.elasticsearch.test.rest.yaml.ClientYamlTestCandidate; +import org.elasticsearch.test.rest.yaml.ESClientYamlSuiteTestCase; +import org.elasticsearch.test.rest.yaml.parser.ClientYamlTestParseException; import java.io.IOException; @TimeoutSuite(millis = 40 * TimeUnits.MINUTE) // some of the windows test VMs are slow as hell -public class MultiNodeBackwardsIT extends ESClientYamlSuiteTestCase { +public class Backwards50ClientYamlTestSuiteIT extends ESClientYamlSuiteTestCase { - public MultiNodeBackwardsIT(RestTestCandidate testCandidate) { + public Backwards50ClientYamlTestSuiteIT(ClientYamlTestCandidate testCandidate) { super(testCandidate); } @ParametersFactory - public static Iterable parameters() throws IOException, RestTestParseException { + public static Iterable parameters() throws IOException, ClientYamlTestParseException { return createParameters(0, 1); } } diff --git a/qa/smoke-test-multinode/src/test/java/org/elasticsearch/smoketest/SmokeTestMultiIT.java b/qa/smoke-test-ingest-disabled/src/test/java/org/elasticsearch/smoketest/SmokeTestIngestDisabledClientYamlTestSuiteIT.java similarity index 72% rename from qa/smoke-test-multinode/src/test/java/org/elasticsearch/smoketest/SmokeTestMultiIT.java rename to qa/smoke-test-ingest-disabled/src/test/java/org/elasticsearch/smoketest/SmokeTestIngestDisabledClientYamlTestSuiteIT.java index 78d7acd8c24..c8d506424c0 100644 --- a/qa/smoke-test-multinode/src/test/java/org/elasticsearch/smoketest/SmokeTestMultiIT.java +++ b/qa/smoke-test-ingest-disabled/src/test/java/org/elasticsearch/smoketest/SmokeTestIngestDisabledClientYamlTestSuiteIT.java @@ -21,21 +21,22 @@ package org.elasticsearch.smoketest; import com.carrotsearch.randomizedtesting.annotations.Name; import com.carrotsearch.randomizedtesting.annotations.ParametersFactory; -import org.elasticsearch.test.rest.ESClientYamlSuiteTestCase; -import org.elasticsearch.test.rest.RestTestCandidate; -import org.elasticsearch.test.rest.parser.RestTestParseException; + +import org.elasticsearch.test.rest.yaml.ClientYamlTestCandidate; +import org.elasticsearch.test.rest.yaml.ESClientYamlSuiteTestCase; +import org.elasticsearch.test.rest.yaml.parser.ClientYamlTestParseException; import java.io.IOException; -public class SmokeTestMultiIT extends ESClientYamlSuiteTestCase { +public class SmokeTestIngestDisabledClientYamlTestSuiteIT extends ESClientYamlSuiteTestCase { - public SmokeTestMultiIT(@Name("yaml") RestTestCandidate testCandidate) { + public SmokeTestIngestDisabledClientYamlTestSuiteIT(@Name("yaml") ClientYamlTestCandidate testCandidate) { super(testCandidate); } @ParametersFactory - public static Iterable parameters() throws IOException, RestTestParseException { + public static Iterable parameters() throws IOException, ClientYamlTestParseException { return ESClientYamlSuiteTestCase.createParameters(0, 1); } -} +} diff --git a/qa/smoke-test-plugins/src/test/java/org/elasticsearch/smoketest/SmokeTestPluginsIT.java b/qa/smoke-test-ingest-with-all-dependencies/src/test/java/org/elasticsearch/smoketest/SmokeTestIngestWithAllDepsClientYamlTestSuiteIT.java similarity index 72% rename from qa/smoke-test-plugins/src/test/java/org/elasticsearch/smoketest/SmokeTestPluginsIT.java rename to qa/smoke-test-ingest-with-all-dependencies/src/test/java/org/elasticsearch/smoketest/SmokeTestIngestWithAllDepsClientYamlTestSuiteIT.java index 61903e62993..b3b84dfc55e 100644 --- a/qa/smoke-test-plugins/src/test/java/org/elasticsearch/smoketest/SmokeTestPluginsIT.java +++ b/qa/smoke-test-ingest-with-all-dependencies/src/test/java/org/elasticsearch/smoketest/SmokeTestIngestWithAllDepsClientYamlTestSuiteIT.java @@ -21,21 +21,22 @@ package org.elasticsearch.smoketest; import com.carrotsearch.randomizedtesting.annotations.Name; import com.carrotsearch.randomizedtesting.annotations.ParametersFactory; -import org.elasticsearch.test.rest.ESClientYamlSuiteTestCase; -import org.elasticsearch.test.rest.RestTestCandidate; -import org.elasticsearch.test.rest.parser.RestTestParseException; + +import org.elasticsearch.test.rest.yaml.ClientYamlTestCandidate; +import org.elasticsearch.test.rest.yaml.ESClientYamlSuiteTestCase; +import org.elasticsearch.test.rest.yaml.parser.ClientYamlTestParseException; import java.io.IOException; -public class SmokeTestPluginsIT extends ESClientYamlSuiteTestCase { +public class SmokeTestIngestWithAllDepsClientYamlTestSuiteIT extends ESClientYamlSuiteTestCase { - public SmokeTestPluginsIT(@Name("yaml") RestTestCandidate testCandidate) { + public SmokeTestIngestWithAllDepsClientYamlTestSuiteIT(@Name("yaml") ClientYamlTestCandidate testCandidate) { super(testCandidate); } @ParametersFactory - public static Iterable parameters() throws IOException, RestTestParseException { + public static Iterable parameters() throws IOException, ClientYamlTestParseException { return ESClientYamlSuiteTestCase.createParameters(0, 1); } -} +} diff --git a/qa/smoke-test-ingest-with-all-dependencies/src/test/resources/rest-api-spec/test/ingest/10_pipeline_with_mustache_templates.yaml b/qa/smoke-test-ingest-with-all-dependencies/src/test/resources/rest-api-spec/test/ingest/10_pipeline_with_mustache_templates.yaml index b0a729a6299..0e54ff0b7ad 100644 --- a/qa/smoke-test-ingest-with-all-dependencies/src/test/resources/rest-api-spec/test/ingest/10_pipeline_with_mustache_templates.yaml +++ b/qa/smoke-test-ingest-with-all-dependencies/src/test/resources/rest-api-spec/test/ingest/10_pipeline_with_mustache_templates.yaml @@ -234,7 +234,7 @@ "processor": { "append": { "field": "values_flat", - "value": "{{_value.key}}_{{_value.value}}" + "value": "{{_ingest._value.key}}_{{_ingest._value.value}}" } } } diff --git a/qa/smoke-test-ingest-with-all-dependencies/src/test/resources/rest-api-spec/test/ingest/20_combine_processors.yaml b/qa/smoke-test-ingest-with-all-dependencies/src/test/resources/rest-api-spec/test/ingest/20_combine_processors.yaml index 9a52979b930..1a29531651b 100644 --- a/qa/smoke-test-ingest-with-all-dependencies/src/test/resources/rest-api-spec/test/ingest/20_combine_processors.yaml +++ b/qa/smoke-test-ingest-with-all-dependencies/src/test/resources/rest-api-spec/test/ingest/20_combine_processors.yaml @@ -84,7 +84,7 @@ "field" : "friends", "processor" : { "remove" : { - "field" : "_value.id" + "field" : "_ingest._value.id" } } } @@ -106,7 +106,7 @@ "field" : "address", "processor" : { "trim" : { - "field" : "_value" + "field" : "_ingest._value" } } } diff --git a/qa/smoke-test-ingest-with-all-dependencies/src/test/java/org/elasticsearch/smoketest/IngestWithDependenciesIT.java b/qa/smoke-test-multinode/src/test/java/org/elasticsearch/smoketest/SmokeTestMultiNodeClientYamlTestSuiteIT.java similarity index 72% rename from qa/smoke-test-ingest-with-all-dependencies/src/test/java/org/elasticsearch/smoketest/IngestWithDependenciesIT.java rename to qa/smoke-test-multinode/src/test/java/org/elasticsearch/smoketest/SmokeTestMultiNodeClientYamlTestSuiteIT.java index 1ed23e7add5..456387e6c19 100644 --- a/qa/smoke-test-ingest-with-all-dependencies/src/test/java/org/elasticsearch/smoketest/IngestWithDependenciesIT.java +++ b/qa/smoke-test-multinode/src/test/java/org/elasticsearch/smoketest/SmokeTestMultiNodeClientYamlTestSuiteIT.java @@ -21,21 +21,22 @@ package org.elasticsearch.smoketest; import com.carrotsearch.randomizedtesting.annotations.Name; import com.carrotsearch.randomizedtesting.annotations.ParametersFactory; -import org.elasticsearch.test.rest.ESClientYamlSuiteTestCase; -import org.elasticsearch.test.rest.RestTestCandidate; -import org.elasticsearch.test.rest.parser.RestTestParseException; + +import org.elasticsearch.test.rest.yaml.ClientYamlTestCandidate; +import org.elasticsearch.test.rest.yaml.ESClientYamlSuiteTestCase; +import org.elasticsearch.test.rest.yaml.parser.ClientYamlTestParseException; import java.io.IOException; -public class IngestWithDependenciesIT extends ESClientYamlSuiteTestCase { +public class SmokeTestMultiNodeClientYamlTestSuiteIT extends ESClientYamlSuiteTestCase { - public IngestWithDependenciesIT(@Name("yaml") RestTestCandidate testCandidate) { + public SmokeTestMultiNodeClientYamlTestSuiteIT(@Name("yaml") ClientYamlTestCandidate testCandidate) { super(testCandidate); } @ParametersFactory - public static Iterable parameters() throws IOException, RestTestParseException { + public static Iterable parameters() throws IOException, ClientYamlTestParseException { return ESClientYamlSuiteTestCase.createParameters(0, 1); } - } + diff --git a/qa/smoke-test-ingest-disabled/src/test/java/org/elasticsearch/smoketest/IngestDisabledIT.java b/qa/smoke-test-plugins/src/test/java/org/elasticsearch/smoketest/SmokeTestPluginsClientYamlTestSuiteIT.java similarity index 73% rename from qa/smoke-test-ingest-disabled/src/test/java/org/elasticsearch/smoketest/IngestDisabledIT.java rename to qa/smoke-test-plugins/src/test/java/org/elasticsearch/smoketest/SmokeTestPluginsClientYamlTestSuiteIT.java index d1cb62cc54b..05021f3c2bb 100644 --- a/qa/smoke-test-ingest-disabled/src/test/java/org/elasticsearch/smoketest/IngestDisabledIT.java +++ b/qa/smoke-test-plugins/src/test/java/org/elasticsearch/smoketest/SmokeTestPluginsClientYamlTestSuiteIT.java @@ -21,21 +21,22 @@ package org.elasticsearch.smoketest; import com.carrotsearch.randomizedtesting.annotations.Name; import com.carrotsearch.randomizedtesting.annotations.ParametersFactory; -import org.elasticsearch.test.rest.ESClientYamlSuiteTestCase; -import org.elasticsearch.test.rest.RestTestCandidate; -import org.elasticsearch.test.rest.parser.RestTestParseException; + +import org.elasticsearch.test.rest.yaml.ClientYamlTestCandidate; +import org.elasticsearch.test.rest.yaml.ESClientYamlSuiteTestCase; +import org.elasticsearch.test.rest.yaml.parser.ClientYamlTestParseException; import java.io.IOException; -public class IngestDisabledIT extends ESClientYamlSuiteTestCase { +public class SmokeTestPluginsClientYamlTestSuiteIT extends ESClientYamlSuiteTestCase { - public IngestDisabledIT(@Name("yaml") RestTestCandidate testCandidate) { + public SmokeTestPluginsClientYamlTestSuiteIT(@Name("yaml") ClientYamlTestCandidate testCandidate) { super(testCandidate); } @ParametersFactory - public static Iterable parameters() throws IOException, RestTestParseException { + public static Iterable parameters() throws IOException, ClientYamlTestParseException { return ESClientYamlSuiteTestCase.createParameters(0, 1); } - } + diff --git a/qa/smoke-test-reindex-with-painless/src/test/java/org/elasticsearch/smoketest/SmokeTestReindexWithPainlessClientYamlTestSuiteIT.java b/qa/smoke-test-reindex-with-painless/src/test/java/org/elasticsearch/smoketest/SmokeTestReindexWithPainlessClientYamlTestSuiteIT.java new file mode 100644 index 00000000000..db01ce2dfe9 --- /dev/null +++ b/qa/smoke-test-reindex-with-painless/src/test/java/org/elasticsearch/smoketest/SmokeTestReindexWithPainlessClientYamlTestSuiteIT.java @@ -0,0 +1,40 @@ +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.smoketest; + +import com.carrotsearch.randomizedtesting.annotations.Name; +import com.carrotsearch.randomizedtesting.annotations.ParametersFactory; + +import org.elasticsearch.test.rest.yaml.ClientYamlTestCandidate; +import org.elasticsearch.test.rest.yaml.ESClientYamlSuiteTestCase; +import org.elasticsearch.test.rest.yaml.parser.ClientYamlTestParseException; + +import java.io.IOException; + +public class SmokeTestReindexWithPainlessClientYamlTestSuiteIT extends ESClientYamlSuiteTestCase { + public SmokeTestReindexWithPainlessClientYamlTestSuiteIT(@Name("yaml") ClientYamlTestCandidate testCandidate) { + super(testCandidate); + } + + @ParametersFactory + public static Iterable parameters() throws IOException, ClientYamlTestParseException { + return ESClientYamlSuiteTestCase.createParameters(0, 1); + } +} diff --git a/qa/smoke-test-reindex-with-painless/src/test/java/org/elasticsearch/smoketest/SmokeTestReindexWithPainlessIT.java b/qa/smoke-test-reindex-with-painless/src/test/java/org/elasticsearch/smoketest/SmokeTestReindexWithPainlessIT.java deleted file mode 100644 index b7061432325..00000000000 --- a/qa/smoke-test-reindex-with-painless/src/test/java/org/elasticsearch/smoketest/SmokeTestReindexWithPainlessIT.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Licensed to Elasticsearch under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.smoketest; - -import com.carrotsearch.randomizedtesting.annotations.Name; -import com.carrotsearch.randomizedtesting.annotations.ParametersFactory; -import org.elasticsearch.test.rest.ESClientYamlSuiteTestCase; -import org.elasticsearch.test.rest.RestTestCandidate; -import org.elasticsearch.test.rest.parser.RestTestParseException; - -import java.io.IOException; - -public class SmokeTestReindexWithPainlessIT extends ESClientYamlSuiteTestCase { - public SmokeTestReindexWithPainlessIT(@Name("yaml") RestTestCandidate testCandidate) { - super(testCandidate); - } - - @ParametersFactory - public static Iterable parameters() throws IOException, RestTestParseException { - return ESClientYamlSuiteTestCase.createParameters(0, 1); - } -} diff --git a/rest-api-spec/src/main/resources/rest-api-spec/api/ingest.get_pipeline.json b/rest-api-spec/src/main/resources/rest-api-spec/api/ingest.get_pipeline.json index 6c50657ae1a..5574ddbf5b7 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/api/ingest.get_pipeline.json +++ b/rest-api-spec/src/main/resources/rest-api-spec/api/ingest.get_pipeline.json @@ -4,7 +4,7 @@ "methods": [ "GET" ], "url": { "path": "/_ingest/pipeline/{id}", - "paths": [ "/_ingest/pipeline/{id}" ], + "paths": [ "/_ingest/pipeline", "/_ingest/pipeline/{id}" ], "parts": { "id": { "type" : "string", diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/count/10_basic.yaml b/rest-api-spec/src/main/resources/rest-api-spec/test/count/10_basic.yaml index f3eb0a5fae6..f38d2c315eb 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/count/10_basic.yaml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/count/10_basic.yaml @@ -37,6 +37,24 @@ setup: - match: {count : 0} +--- +"count with empty body": +# empty body should default to match_all query + - do: + count: + index: test + type: test + body: { } + + - match: {count : 1} + + - do: + count: + index: test + type: test + + - match: {count : 1} + --- "count body without query element": - do: diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/delete/12_operation.yaml b/rest-api-spec/src/main/resources/rest-api-spec/test/delete/12_operation.yaml new file mode 100644 index 00000000000..7dbc84a5078 --- /dev/null +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/delete/12_operation.yaml @@ -0,0 +1,26 @@ +--- +"Delete operation field": + + - do: + index: + index: test_1 + type: test + id: 1 + body: { foo: bar } + + - do: + delete: + index: test_1 + type: test + id: 1 + + - match: { _operation: delete } + + - do: + catch: missing + delete: + index: test_1 + type: test + id: 1 + + - match: { _operation: noop } diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/index/12_operation.yaml b/rest-api-spec/src/main/resources/rest-api-spec/test/index/12_operation.yaml new file mode 100644 index 00000000000..a935bda420d --- /dev/null +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/index/12_operation.yaml @@ -0,0 +1,21 @@ +--- +"Index operation field": + + - do: + index: + index: test_index + type: test + id: 1 + body: { foo: bar } + + - match: { _operation: create } + + - do: + index: + index: test_index + type: test + id: 1 + body: { foo: bar } + op_type: index + + - match: { _operation: index } diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/update/12_operation.yaml b/rest-api-spec/src/main/resources/rest-api-spec/test/update/12_operation.yaml new file mode 100644 index 00000000000..abbb8d4a59a --- /dev/null +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/update/12_operation.yaml @@ -0,0 +1,52 @@ +--- +"Update operation field": + + - do: + update: + index: test_1 + type: test + id: 1 + body: + doc: { foo: bar } + doc_as_upsert: true + + - match: { _version: 1 } + - match: { _operation: create } + + - do: + update: + index: test_1 + type: test + id: 1 + body: + doc: { foo: bar } + doc_as_upsert: true + + - match: { _version: 1 } + - match: { _operation: noop } + + - do: + update: + index: test_1 + type: test + id: 1 + body: + doc: { foo: bar } + doc_as_upsert: true + detect_noop: false + + - match: { _version: 2 } + - match: { _operation: index } + + - do: + update: + index: test_1 + type: test + id: 1 + body: + doc: { foo: baz } + doc_as_upsert: true + detect_noop: true + + - match: { _version: 3 } + - match: { _operation: index } diff --git a/test/framework/src/main/java/org/elasticsearch/test/junit/listeners/ReproduceInfoPrinter.java b/test/framework/src/main/java/org/elasticsearch/test/junit/listeners/ReproduceInfoPrinter.java index d5c14935ecd..92433649553 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/junit/listeners/ReproduceInfoPrinter.java +++ b/test/framework/src/main/java/org/elasticsearch/test/junit/listeners/ReproduceInfoPrinter.java @@ -24,7 +24,7 @@ import org.elasticsearch.common.logging.ESLogger; import org.elasticsearch.common.logging.Loggers; import org.elasticsearch.test.ESIntegTestCase; import org.elasticsearch.test.ESTestCase; -import org.elasticsearch.test.rest.ESClientYamlSuiteTestCase; +import org.elasticsearch.test.rest.yaml.ESClientYamlSuiteTestCase; import org.junit.internal.AssumptionViolatedException; import org.junit.runner.Description; import org.junit.runner.notification.Failure; @@ -37,9 +37,9 @@ import static com.carrotsearch.randomizedtesting.SysGlobals.SYSPROP_ITERATIONS; import static com.carrotsearch.randomizedtesting.SysGlobals.SYSPROP_PREFIX; import static com.carrotsearch.randomizedtesting.SysGlobals.SYSPROP_TESTMETHOD; import static org.elasticsearch.test.ESIntegTestCase.TESTS_CLUSTER; -import static org.elasticsearch.test.rest.ESClientYamlSuiteTestCase.REST_TESTS_BLACKLIST; -import static org.elasticsearch.test.rest.ESClientYamlSuiteTestCase.REST_TESTS_SPEC; -import static org.elasticsearch.test.rest.ESClientYamlSuiteTestCase.REST_TESTS_SUITE; +import static org.elasticsearch.test.rest.yaml.ESClientYamlSuiteTestCase.REST_TESTS_BLACKLIST; +import static org.elasticsearch.test.rest.yaml.ESClientYamlSuiteTestCase.REST_TESTS_SPEC; +import static org.elasticsearch.test.rest.yaml.ESClientYamlSuiteTestCase.REST_TESTS_SUITE; /** * A {@link RunListener} that emits a command you can use to re-run a failing test with the failing random seed to diff --git a/test/framework/src/main/java/org/elasticsearch/test/rest/BlacklistedPathPatternMatcher.java b/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/BlacklistedPathPatternMatcher.java similarity index 98% rename from test/framework/src/main/java/org/elasticsearch/test/rest/BlacklistedPathPatternMatcher.java rename to test/framework/src/main/java/org/elasticsearch/test/rest/yaml/BlacklistedPathPatternMatcher.java index e5bb75955cf..f0e0802a6b2 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/rest/BlacklistedPathPatternMatcher.java +++ b/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/BlacklistedPathPatternMatcher.java @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.elasticsearch.test.rest; +package org.elasticsearch.test.rest.yaml; import java.util.regex.Pattern; diff --git a/test/framework/src/main/java/org/elasticsearch/test/rest/RestTestCandidate.java b/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/ClientYamlTestCandidate.java similarity index 67% rename from test/framework/src/main/java/org/elasticsearch/test/rest/RestTestCandidate.java rename to test/framework/src/main/java/org/elasticsearch/test/rest/yaml/ClientYamlTestCandidate.java index 57c7e1b1305..dd650a38ebb 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/rest/RestTestCandidate.java +++ b/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/ClientYamlTestCandidate.java @@ -16,23 +16,22 @@ * specific language governing permissions and limitations * under the License. */ -package org.elasticsearch.test.rest; +package org.elasticsearch.test.rest.yaml; -import org.elasticsearch.test.rest.section.RestTestSuite; -import org.elasticsearch.test.rest.section.SetupSection; -import org.elasticsearch.test.rest.section.TeardownSection; -import org.elasticsearch.test.rest.section.TestSection; +import org.elasticsearch.test.rest.yaml.section.ClientYamlTestSuite; +import org.elasticsearch.test.rest.yaml.section.SetupSection; +import org.elasticsearch.test.rest.yaml.section.TeardownSection; +import org.elasticsearch.test.rest.yaml.section.ClientYamlTestSection; /** - * Wraps {@link org.elasticsearch.test.rest.section.TestSection}s ready to be run. - * Each test section is associated to its {@link org.elasticsearch.test.rest.section.RestTestSuite}. + * Wraps {@link ClientYamlTestSection}s ready to be run. Each test section is associated to its {@link ClientYamlTestSuite}. */ -public class RestTestCandidate { +public class ClientYamlTestCandidate { - private final RestTestSuite restTestSuite; - private final TestSection testSection; + private final ClientYamlTestSuite restTestSuite; + private final ClientYamlTestSection testSection; - public RestTestCandidate(RestTestSuite restTestSuite, TestSection testSection) { + public ClientYamlTestCandidate(ClientYamlTestSuite restTestSuite, ClientYamlTestSection testSection) { this.restTestSuite = restTestSuite; this.testSection = testSection; } @@ -61,7 +60,7 @@ public class RestTestCandidate { return restTestSuite.getTeardownSection(); } - public TestSection getTestSection() { + public ClientYamlTestSection getTestSection() { return testSection; } diff --git a/test/framework/src/main/java/org/elasticsearch/test/rest/RestTestExecutionContext.java b/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/ClientYamlTestExecutionContext.java similarity index 79% rename from test/framework/src/main/java/org/elasticsearch/test/rest/RestTestExecutionContext.java rename to test/framework/src/main/java/org/elasticsearch/test/rest/yaml/ClientYamlTestExecutionContext.java index 59d45bc0a88..f99ee4be83f 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/rest/RestTestExecutionContext.java +++ b/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/ClientYamlTestExecutionContext.java @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.elasticsearch.test.rest; +package org.elasticsearch.test.rest.yaml; import org.apache.http.HttpHost; import org.elasticsearch.Version; @@ -24,10 +24,10 @@ import org.elasticsearch.client.RestClient; import org.elasticsearch.common.logging.ESLogger; import org.elasticsearch.common.logging.Loggers; import org.elasticsearch.common.xcontent.XContentFactory; -import org.elasticsearch.test.rest.client.RestTestClient; -import org.elasticsearch.test.rest.client.RestTestResponse; -import org.elasticsearch.test.rest.client.RestTestResponseException; -import org.elasticsearch.test.rest.spec.RestSpec; +import org.elasticsearch.test.rest.yaml.client.ClientYamlTestClient; +import org.elasticsearch.test.rest.yaml.client.ClientYamlTestResponse; +import org.elasticsearch.test.rest.yaml.client.ClientYamlTestResponseException; +import org.elasticsearch.test.rest.yaml.restspec.ClientYamlSuiteRestSpec; import java.io.IOException; import java.util.HashMap; @@ -40,19 +40,19 @@ import java.util.Map; * Caches the last obtained test response and allows to stash part of it within variables * that can be used as input values in following requests. */ -public class RestTestExecutionContext { +public class ClientYamlTestExecutionContext { - private static final ESLogger logger = Loggers.getLogger(RestTestExecutionContext.class); + private static final ESLogger logger = Loggers.getLogger(ClientYamlTestExecutionContext.class); private final Stash stash = new Stash(); - private final RestSpec restSpec; + private final ClientYamlSuiteRestSpec restSpec; - private RestTestClient restTestClient; + private ClientYamlTestClient restTestClient; - private RestTestResponse response; + private ClientYamlTestResponse response; - public RestTestExecutionContext(RestSpec restSpec) { + public ClientYamlTestExecutionContext(ClientYamlSuiteRestSpec restSpec) { this.restSpec = restSpec; } @@ -60,7 +60,7 @@ public class RestTestExecutionContext { * Calls an elasticsearch api with the parameters and request body provided as arguments. * Saves the obtained response in the execution context. */ - public RestTestResponse callApi(String apiName, Map params, List> bodies, + public ClientYamlTestResponse callApi(String apiName, Map params, List> bodies, Map headers) throws IOException { //makes a copy of the parameters before modifying them for this specific request HashMap requestParams = new HashMap<>(params); @@ -74,7 +74,7 @@ public class RestTestExecutionContext { try { response = callApiInternal(apiName, requestParams, body, headers); return response; - } catch(RestTestResponseException e) { + } catch(ClientYamlTestResponseException e) { response = e.getRestTestResponse(); throw e; } finally { @@ -103,7 +103,7 @@ public class RestTestExecutionContext { return XContentFactory.jsonBuilder().map(body).string(); } - private RestTestResponse callApiInternal(String apiName, Map params, String body, Map headers) + private ClientYamlTestResponse callApiInternal(String apiName, Map params, String body, Map headers) throws IOException { return restTestClient.callApi(apiName, params, body, headers); } @@ -119,7 +119,7 @@ public class RestTestExecutionContext { * Creates the embedded REST client when needed. Needs to be called before each test. */ public void initClient(RestClient client, List hosts) throws IOException { - restTestClient = new RestTestClient(restSpec, client, hosts); + restTestClient = new ClientYamlTestClient(restSpec, client, hosts); } /** diff --git a/test/framework/src/main/java/org/elasticsearch/test/rest/ESClientYamlSuiteTestCase.java b/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/ESClientYamlSuiteTestCase.java similarity index 83% rename from test/framework/src/main/java/org/elasticsearch/test/rest/ESClientYamlSuiteTestCase.java rename to test/framework/src/main/java/org/elasticsearch/test/rest/yaml/ESClientYamlSuiteTestCase.java index 2611e20d447..ae1853ccec3 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/rest/ESClientYamlSuiteTestCase.java +++ b/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/ESClientYamlSuiteTestCase.java @@ -17,7 +17,7 @@ * under the License. */ -package org.elasticsearch.test.rest; +package org.elasticsearch.test.rest.yaml; import com.carrotsearch.randomizedtesting.RandomizedTest; @@ -25,16 +25,17 @@ import org.apache.lucene.util.IOUtils; import org.elasticsearch.common.Strings; import org.elasticsearch.common.SuppressForbidden; import org.elasticsearch.common.xcontent.XContentHelper; -import org.elasticsearch.test.rest.parser.RestTestParseException; -import org.elasticsearch.test.rest.parser.RestTestSuiteParser; -import org.elasticsearch.test.rest.section.DoSection; -import org.elasticsearch.test.rest.section.ExecutableSection; -import org.elasticsearch.test.rest.section.RestTestSuite; -import org.elasticsearch.test.rest.section.SkipSection; -import org.elasticsearch.test.rest.section.TestSection; -import org.elasticsearch.test.rest.spec.RestApi; -import org.elasticsearch.test.rest.spec.RestSpec; -import org.elasticsearch.test.rest.support.FileUtils; +import org.elasticsearch.test.rest.ESRestTestCase; +import org.elasticsearch.test.rest.yaml.parser.ClientYamlTestParseException; +import org.elasticsearch.test.rest.yaml.parser.ClientYamlTestSuiteParser; +import org.elasticsearch.test.rest.yaml.restspec.ClientYamlSuiteRestApi; +import org.elasticsearch.test.rest.yaml.restspec.ClientYamlSuiteRestSpec; +import org.elasticsearch.test.rest.yaml.section.ClientYamlTestSuite; +import org.elasticsearch.test.rest.yaml.section.DoSection; +import org.elasticsearch.test.rest.yaml.section.ExecutableSection; +import org.elasticsearch.test.rest.yaml.section.SkipSection; +import org.elasticsearch.test.rest.yaml.section.ClientYamlTestSection; +import org.elasticsearch.test.rest.yaml.support.FileUtils; import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; @@ -97,12 +98,12 @@ public abstract class ESClientYamlSuiteTestCase extends ESRestTestCase { private static final String PATHS_SEPARATOR = "(? blacklistPathMatchers = new ArrayList<>(); - private static RestTestExecutionContext restTestExecutionContext; - private static RestTestExecutionContext adminExecutionContext; + private static ClientYamlTestExecutionContext restTestExecutionContext; + private static ClientYamlTestExecutionContext adminExecutionContext; - private final RestTestCandidate testCandidate; + private final ClientYamlTestCandidate testCandidate; - public ESClientYamlSuiteTestCase(RestTestCandidate testCandidate) { + public ESClientYamlSuiteTestCase(ClientYamlTestCandidate testCandidate) { this.testCandidate = testCandidate; String[] blacklist = resolvePathsProperty(REST_TESTS_BLACKLIST, null); for (String entry : blacklist) { @@ -117,34 +118,34 @@ public abstract class ESClientYamlSuiteTestCase extends ESRestTestCase { super.afterIfFailed(errors); } - public static Iterable createParameters(int id, int count) throws IOException, RestTestParseException { + public static Iterable createParameters(int id, int count) throws IOException, ClientYamlTestParseException { //parse tests only if rest test group is enabled, otherwise rest tests might not even be available on file system - List restTestCandidates = collectTestCandidates(id, count); + List restTestCandidates = collectTestCandidates(id, count); List objects = new ArrayList<>(); - for (RestTestCandidate restTestCandidate : restTestCandidates) { + for (ClientYamlTestCandidate restTestCandidate : restTestCandidates) { objects.add(new Object[]{restTestCandidate}); } return objects; } - private static List collectTestCandidates(int id, int count) throws RestTestParseException, IOException { - List testCandidates = new ArrayList<>(); + private static List collectTestCandidates(int id, int count) throws ClientYamlTestParseException, IOException { + List testCandidates = new ArrayList<>(); FileSystem fileSystem = getFileSystem(); // don't make a try-with, getFileSystem returns null // ... and you can't close() the default filesystem try { String[] paths = resolvePathsProperty(REST_TESTS_SUITE, DEFAULT_TESTS_PATH); Map> yamlSuites = FileUtils.findYamlSuites(fileSystem, DEFAULT_TESTS_PATH, paths); - RestTestSuiteParser restTestSuiteParser = new RestTestSuiteParser(); + ClientYamlTestSuiteParser restTestSuiteParser = new ClientYamlTestSuiteParser(); //yaml suites are grouped by directory (effectively by api) for (String api : yamlSuites.keySet()) { List yamlFiles = new ArrayList<>(yamlSuites.get(api)); for (Path yamlFile : yamlFiles) { String key = api + yamlFile.getFileName().toString(); if (mustExecute(key, id, count)) { - RestTestSuite restTestSuite = restTestSuiteParser.parse(api, yamlFile); - for (TestSection testSection : restTestSuite.getTestSections()) { - testCandidates.add(new RestTestCandidate(restTestSuite, testSection)); + ClientYamlTestSuite restTestSuite = restTestSuiteParser.parse(api, yamlFile); + for (ClientYamlTestSection testSection : restTestSuite.getTestSections()) { + testCandidates.add(new ClientYamlTestCandidate(restTestSuite, testSection)); } } } @@ -154,9 +155,9 @@ public abstract class ESClientYamlSuiteTestCase extends ESRestTestCase { } //sort the candidates so they will always be in the same order before being shuffled, for repeatability - Collections.sort(testCandidates, new Comparator() { + Collections.sort(testCandidates, new Comparator() { @Override - public int compare(RestTestCandidate o1, RestTestCandidate o2) { + public int compare(ClientYamlTestCandidate o1, ClientYamlTestCandidate o2) { return o1.getTestPath().compareTo(o2.getTestPath()); } }); @@ -209,29 +210,29 @@ public abstract class ESClientYamlSuiteTestCase extends ESRestTestCase { @BeforeClass public static void initExecutionContext() throws IOException { String[] specPaths = resolvePathsProperty(REST_TESTS_SPEC, DEFAULT_SPEC_PATH); - RestSpec restSpec = null; + ClientYamlSuiteRestSpec restSpec = null; FileSystem fileSystem = getFileSystem(); // don't make a try-with, getFileSystem returns null // ... and you can't close() the default filesystem try { - restSpec = RestSpec.parseFrom(fileSystem, DEFAULT_SPEC_PATH, specPaths); + restSpec = ClientYamlSuiteRestSpec.parseFrom(fileSystem, DEFAULT_SPEC_PATH, specPaths); } finally { IOUtils.close(fileSystem); } validateSpec(restSpec); - restTestExecutionContext = new RestTestExecutionContext(restSpec); - adminExecutionContext = new RestTestExecutionContext(restSpec); + restTestExecutionContext = new ClientYamlTestExecutionContext(restSpec); + adminExecutionContext = new ClientYamlTestExecutionContext(restSpec); } - protected RestTestExecutionContext getAdminExecutionContext() { + protected ClientYamlTestExecutionContext getAdminExecutionContext() { return adminExecutionContext; } - private static void validateSpec(RestSpec restSpec) { + private static void validateSpec(ClientYamlSuiteRestSpec restSpec) { boolean validateSpec = RandomizedTest.systemPropertyAsBoolean(REST_TESTS_VALIDATE_SPEC, true); if (validateSpec) { StringBuilder errorMessage = new StringBuilder(); - for (RestApi restApi : restSpec.getApis()) { + for (ClientYamlSuiteRestApi restApi : restSpec.getApis()) { if (restApi.getMethods().contains("GET") && restApi.isBodySupported()) { if (!restApi.getMethods().contains("POST")) { errorMessage.append("\n- ").append(restApi.getName()).append(" supports GET with a body but doesn't support POST"); diff --git a/test/framework/src/main/java/org/elasticsearch/test/rest/ObjectPath.java b/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/ObjectPath.java similarity index 99% rename from test/framework/src/main/java/org/elasticsearch/test/rest/ObjectPath.java rename to test/framework/src/main/java/org/elasticsearch/test/rest/yaml/ObjectPath.java index 8c492d279b0..6311944fdcb 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/rest/ObjectPath.java +++ b/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/ObjectPath.java @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.elasticsearch.test.rest; +package org.elasticsearch.test.rest.yaml; import org.elasticsearch.common.xcontent.XContent; import org.elasticsearch.common.xcontent.XContentParser; diff --git a/test/framework/src/main/java/org/elasticsearch/test/rest/Stash.java b/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/Stash.java similarity index 99% rename from test/framework/src/main/java/org/elasticsearch/test/rest/Stash.java rename to test/framework/src/main/java/org/elasticsearch/test/rest/yaml/Stash.java index f687f2b39bf..dff1e59762e 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/rest/Stash.java +++ b/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/Stash.java @@ -17,7 +17,7 @@ * under the License. */ -package org.elasticsearch.test.rest; +package org.elasticsearch.test.rest.yaml; import org.elasticsearch.common.Strings; import org.elasticsearch.common.logging.ESLogger; diff --git a/test/framework/src/main/java/org/elasticsearch/test/rest/client/RestTestClient.java b/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/client/ClientYamlTestClient.java similarity index 84% rename from test/framework/src/main/java/org/elasticsearch/test/rest/client/RestTestClient.java rename to test/framework/src/main/java/org/elasticsearch/test/rest/yaml/client/ClientYamlTestClient.java index 2fb0374d048..c21e905ed5c 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/rest/client/RestTestClient.java +++ b/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/client/ClientYamlTestClient.java @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.elasticsearch.test.rest.client; +package org.elasticsearch.test.rest.yaml.client; import com.carrotsearch.randomizedtesting.RandomizedTest; @@ -34,8 +34,10 @@ import org.elasticsearch.common.Strings; import org.elasticsearch.common.logging.ESLogger; import org.elasticsearch.common.logging.Loggers; import org.elasticsearch.common.util.set.Sets; -import org.elasticsearch.test.rest.spec.RestApi; -import org.elasticsearch.test.rest.spec.RestSpec; +import org.elasticsearch.test.rest.yaml.ESClientYamlSuiteTestCase; +import org.elasticsearch.test.rest.yaml.restspec.ClientYamlSuiteRestApi; +import org.elasticsearch.test.rest.yaml.restspec.ClientYamlSuiteRestPath; +import org.elasticsearch.test.rest.yaml.restspec.ClientYamlSuiteRestSpec; import java.io.IOException; import java.net.URI; @@ -49,20 +51,20 @@ import java.util.Objects; import java.util.Set; /** - * REST client used to test the elasticsearch REST layer. - * Wraps a {@link RestClient} instance used to send the REST requests. - * Holds the {@link RestSpec} used to translate api calls into REST calls + * Used by {@link ESClientYamlSuiteTestCase} to execute REST requests according to the tests written in yaml suite files. Wraps a + * {@link RestClient} instance used to send the REST requests. Holds the {@link ClientYamlSuiteRestSpec} used to translate api calls into + * REST calls. */ -public class RestTestClient { - private static final ESLogger logger = Loggers.getLogger(RestTestClient.class); +public class ClientYamlTestClient { + private static final ESLogger logger = Loggers.getLogger(ClientYamlTestClient.class); //query_string params that don't need to be declared in the spec, they are supported by default private static final Set ALWAYS_ACCEPTED_QUERY_STRING_PARAMS = Sets.newHashSet("pretty", "source", "filter_path"); - private final RestSpec restSpec; + private final ClientYamlSuiteRestSpec restSpec; private final RestClient restClient; private final Version esVersion; - public RestTestClient(RestSpec restSpec, RestClient restClient, List hosts) throws IOException { + public ClientYamlTestClient(ClientYamlSuiteRestSpec restSpec, RestClient restClient, List hosts) throws IOException { assert hosts.size() > 0; this.restSpec = restSpec; this.restClient = restClient; @@ -70,7 +72,7 @@ public class RestTestClient { } private Version readAndCheckVersion(List hosts) throws IOException { - RestApi restApi = restApi("info"); + ClientYamlSuiteRestApi restApi = restApi("info"); assert restApi.getPaths().size() == 1; assert restApi.getMethods().size() == 1; @@ -80,7 +82,7 @@ public class RestTestClient { String method = restApi.getMethods().get(0); String endpoint = restApi.getPaths().get(0); Response response = restClient.performRequest(method, endpoint); - RestTestResponse restTestResponse = new RestTestResponse(response); + ClientYamlTestResponse restTestResponse = new ClientYamlTestResponse(response); Object latestVersion = restTestResponse.evaluate("version.number"); if (latestVersion == null) { throw new RuntimeException("elasticsearch version not found in the response"); @@ -103,7 +105,7 @@ public class RestTestClient { /** * Calls an api with the provided parameters and body */ - public RestTestResponse callApi(String apiName, Map params, String body, Map headers) + public ClientYamlTestResponse callApi(String apiName, Map params, String body, Map headers) throws IOException { if ("raw".equals(apiName)) { @@ -118,9 +120,9 @@ public class RestTestClient { // And everything else is a url parameter! try { Response response = restClient.performRequest(method, path, queryStringParams, entity); - return new RestTestResponse(response); + return new ClientYamlTestResponse(response); } catch(ResponseException e) { - throw new RestTestResponseException(e); + throw new ClientYamlTestResponseException(e); } } @@ -146,7 +148,7 @@ public class RestTestClient { //create doesn't exist in the spec but is supported in the clients (index with op_type=create) boolean indexCreateApi = "create".equals(apiName); String api = indexCreateApi ? "index" : apiName; - RestApi restApi = restApi(api); + ClientYamlSuiteRestApi restApi = restApi(api); //divide params between ones that go within query string and ones that go within path Map pathParts = new HashMap<>(); @@ -192,7 +194,7 @@ public class RestTestClient { } //the rest path to use is randomized out of the matching ones (if more than one) - RestPath restPath = RandomizedTest.randomFrom(restApi.getFinalPaths(pathParts)); + ClientYamlSuiteRestPath restPath = RandomizedTest.randomFrom(restApi.getFinalPaths(pathParts)); //Encode rules for path and query string parameters are different. We use URI to encode the path. //We need to encode each path part separately, as each one might contain slashes that need to be escaped, which needs to //be done manually. @@ -225,17 +227,17 @@ public class RestTestClient { logger.debug("calling api [{}]", apiName); try { Response response = restClient.performRequest(requestMethod, requestPath, queryStringParams, requestBody, requestHeaders); - return new RestTestResponse(response); + return new ClientYamlTestResponse(response); } catch(ResponseException e) { if (ignores.contains(e.getResponse().getStatusLine().getStatusCode())) { - return new RestTestResponse(e.getResponse()); + return new ClientYamlTestResponse(e.getResponse()); } - throw new RestTestResponseException(e); + throw new ClientYamlTestResponseException(e); } } - private RestApi restApi(String apiName) { - RestApi restApi = restSpec.getApi(apiName); + private ClientYamlSuiteRestApi restApi(String apiName) { + ClientYamlSuiteRestApi restApi = restSpec.getApi(apiName); if (restApi == null) { throw new IllegalArgumentException("rest api [" + apiName + "] doesn't exist in the rest spec"); } diff --git a/test/framework/src/main/java/org/elasticsearch/test/rest/client/RestTestResponse.java b/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/client/ClientYamlTestResponse.java similarity index 94% rename from test/framework/src/main/java/org/elasticsearch/test/rest/client/RestTestResponse.java rename to test/framework/src/main/java/org/elasticsearch/test/rest/yaml/client/ClientYamlTestResponse.java index 9149824c33c..9ccdd89592f 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/rest/client/RestTestResponse.java +++ b/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/client/ClientYamlTestResponse.java @@ -16,14 +16,14 @@ * specific language governing permissions and limitations * under the License. */ -package org.elasticsearch.test.rest.client; +package org.elasticsearch.test.rest.yaml.client; import org.apache.http.client.methods.HttpHead; import org.apache.http.util.EntityUtils; import org.elasticsearch.client.Response; import org.elasticsearch.common.xcontent.XContentType; -import org.elasticsearch.test.rest.ObjectPath; -import org.elasticsearch.test.rest.Stash; +import org.elasticsearch.test.rest.yaml.ObjectPath; +import org.elasticsearch.test.rest.yaml.Stash; import java.io.IOException; import java.nio.charset.StandardCharsets; @@ -32,13 +32,13 @@ import java.nio.charset.StandardCharsets; * Response obtained from a REST call, eagerly reads the response body into a string for later optional parsing. * Supports parsing the response body when needed and returning specific values extracted from it. */ -public class RestTestResponse { +public class ClientYamlTestResponse { private final Response response; private final String body; private ObjectPath parsedResponse; - RestTestResponse(Response response) throws IOException { + ClientYamlTestResponse(Response response) throws IOException { this.response = response; if (response.getEntity() != null) { try { diff --git a/test/framework/src/main/java/org/elasticsearch/test/rest/client/RestTestResponseException.java b/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/client/ClientYamlTestResponseException.java similarity index 80% rename from test/framework/src/main/java/org/elasticsearch/test/rest/client/RestTestResponseException.java rename to test/framework/src/main/java/org/elasticsearch/test/rest/yaml/client/ClientYamlTestResponseException.java index 2fc93a91088..73719202c10 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/rest/client/RestTestResponseException.java +++ b/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/client/ClientYamlTestResponseException.java @@ -17,7 +17,7 @@ * under the License. */ -package org.elasticsearch.test.rest.client; +package org.elasticsearch.test.rest.yaml.client; import org.elasticsearch.client.ResponseException; @@ -27,21 +27,21 @@ import java.io.IOException; * Exception obtained from a REST call in case the response code indicated an error. Eagerly reads the response body into a string * for later optional parsing. Supports parsing the response body when needed and returning specific values extracted from it. */ -public class RestTestResponseException extends IOException { +public class ClientYamlTestResponseException extends IOException { - private final RestTestResponse restTestResponse; + private final ClientYamlTestResponse restTestResponse; private final ResponseException responseException; - RestTestResponseException(ResponseException responseException) throws IOException { + ClientYamlTestResponseException(ResponseException responseException) throws IOException { super(responseException); this.responseException = responseException; - this.restTestResponse = new RestTestResponse(responseException.getResponse()); + this.restTestResponse = new ClientYamlTestResponse(responseException.getResponse()); } /** * Exposes the obtained response body */ - public RestTestResponse getRestTestResponse() { + public ClientYamlTestResponse getRestTestResponse() { return restTestResponse; } diff --git a/test/framework/src/main/java/org/elasticsearch/test/rest/parser/RestTestFragmentParser.java b/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/parser/ClientYamlTestFragmentParser.java similarity index 76% rename from test/framework/src/main/java/org/elasticsearch/test/rest/parser/RestTestFragmentParser.java rename to test/framework/src/main/java/org/elasticsearch/test/rest/yaml/parser/ClientYamlTestFragmentParser.java index 8d2bd8be76f..390ac1ce366 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/rest/parser/RestTestFragmentParser.java +++ b/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/parser/ClientYamlTestFragmentParser.java @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.elasticsearch.test.rest.parser; +package org.elasticsearch.test.rest.yaml.parser; import java.io.IOException; @@ -24,10 +24,10 @@ import java.io.IOException; * Base parser for a REST test suite fragment * @param the test fragment's type that gets parsed and returned */ -public interface RestTestFragmentParser { +public interface ClientYamlTestFragmentParser { /** - * Parses a test fragment given the current {@link RestTestSuiteParseContext} + * Parses a test fragment given the current {@link ClientYamlTestSuiteParseContext} */ - T parse(RestTestSuiteParseContext parseContext) throws IOException, RestTestParseException; + T parse(ClientYamlTestSuiteParseContext parseContext) throws IOException, ClientYamlTestParseException; } diff --git a/test/framework/src/main/java/org/elasticsearch/test/rest/parser/RestTestParseException.java b/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/parser/ClientYamlTestParseException.java similarity index 80% rename from test/framework/src/main/java/org/elasticsearch/test/rest/parser/RestTestParseException.java rename to test/framework/src/main/java/org/elasticsearch/test/rest/yaml/parser/ClientYamlTestParseException.java index 3e1af2cd749..594f701c79a 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/rest/parser/RestTestParseException.java +++ b/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/parser/ClientYamlTestParseException.java @@ -16,18 +16,18 @@ * specific language governing permissions and limitations * under the License. */ -package org.elasticsearch.test.rest.parser; +package org.elasticsearch.test.rest.yaml.parser; /** * Exception thrown whenever there is a problem parsing any of the REST test suite fragment */ -public class RestTestParseException extends Exception { +public class ClientYamlTestParseException extends Exception { - RestTestParseException(String message) { + ClientYamlTestParseException(String message) { super(message); } - RestTestParseException(String message, Throwable cause) { + ClientYamlTestParseException(String message, Throwable cause) { super(message, cause); } } diff --git a/test/framework/src/main/java/org/elasticsearch/test/rest/parser/RestTestSectionParser.java b/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/parser/ClientYamlTestSectionParser.java similarity index 74% rename from test/framework/src/main/java/org/elasticsearch/test/rest/parser/RestTestSectionParser.java rename to test/framework/src/main/java/org/elasticsearch/test/rest/yaml/parser/ClientYamlTestSectionParser.java index e1d2011e231..b6e8ad6c0f4 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/rest/parser/RestTestSectionParser.java +++ b/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/parser/ClientYamlTestSectionParser.java @@ -16,23 +16,23 @@ * specific language governing permissions and limitations * under the License. */ -package org.elasticsearch.test.rest.parser; +package org.elasticsearch.test.rest.yaml.parser; import org.elasticsearch.common.xcontent.XContentParser; -import org.elasticsearch.test.rest.section.TestSection; +import org.elasticsearch.test.rest.yaml.section.ClientYamlTestSection; import java.io.IOException; /** * Parser for a complete test section */ -public class RestTestSectionParser implements RestTestFragmentParser { +public class ClientYamlTestSectionParser implements ClientYamlTestFragmentParser { @Override - public TestSection parse(RestTestSuiteParseContext parseContext) throws IOException, RestTestParseException { + public ClientYamlTestSection parse(ClientYamlTestSuiteParseContext parseContext) throws IOException, ClientYamlTestParseException { XContentParser parser = parseContext.parser(); parseContext.advanceToFieldName(); - TestSection testSection = new TestSection(parser.currentName()); + ClientYamlTestSection testSection = new ClientYamlTestSection(parser.currentName()); try { parser.nextToken(); testSection.setSkipSection(parseContext.parseSkipSection()); @@ -48,7 +48,7 @@ public class RestTestSectionParser implements RestTestFragmentParser> EXECUTABLE_SECTIONS_PARSERS = new HashMap<>(); + private static final Map> EXECUTABLE_SECTIONS_PARSERS = + new HashMap<>(); static { EXECUTABLE_SECTIONS_PARSERS.put("do", DO_SECTION_PARSER); EXECUTABLE_SECTIONS_PARSERS.put("set", new SetSectionParser()); @@ -62,7 +62,7 @@ public class RestTestSuiteParseContext { private final String suiteName; private final XContentParser parser; - public RestTestSuiteParseContext(String api, String suiteName, XContentParser parser) { + public ClientYamlTestSuiteParseContext(String api, String suiteName, XContentParser parser) { this.api = api; this.suiteName = suiteName; this.parser = parser; @@ -80,7 +80,7 @@ public class RestTestSuiteParseContext { return parser; } - public SetupSection parseSetupSection() throws IOException, RestTestParseException { + public SetupSection parseSetupSection() throws IOException, ClientYamlTestParseException { advanceToFieldName(); @@ -94,7 +94,7 @@ public class RestTestSuiteParseContext { return SetupSection.EMPTY; } - public TeardownSection parseTeardownSection() throws IOException, RestTestParseException { + public TeardownSection parseTeardownSection() throws IOException, ClientYamlTestParseException { advanceToFieldName(); if ("teardown".equals(parser.currentName())) { @@ -107,11 +107,11 @@ public class RestTestSuiteParseContext { return TeardownSection.EMPTY; } - public TestSection parseTestSection() throws IOException, RestTestParseException { + public ClientYamlTestSection parseTestSection() throws IOException, ClientYamlTestParseException { return TEST_SECTION_PARSER.parse(this); } - public SkipSection parseSkipSection() throws IOException, RestTestParseException { + public SkipSection parseSkipSection() throws IOException, ClientYamlTestParseException { advanceToFieldName(); @@ -124,12 +124,12 @@ public class RestTestSuiteParseContext { return SkipSection.EMPTY; } - public ExecutableSection parseExecutableSection() throws IOException, RestTestParseException { + public ExecutableSection parseExecutableSection() throws IOException, ClientYamlTestParseException { advanceToFieldName(); String section = parser.currentName(); - RestTestFragmentParser execSectionParser = EXECUTABLE_SECTIONS_PARSERS.get(section); + ClientYamlTestFragmentParser execSectionParser = EXECUTABLE_SECTIONS_PARSERS.get(section); if (execSectionParser == null) { - throw new RestTestParseException("no parser found for executable section [" + section + "]"); + throw new ClientYamlTestParseException("no parser found for executable section [" + section + "]"); } XContentLocation location = parser.getTokenLocation(); try { @@ -141,11 +141,11 @@ public class RestTestSuiteParseContext { } } - public DoSection parseDoSection() throws IOException, RestTestParseException { + public DoSection parseDoSection() throws IOException, ClientYamlTestParseException { return DO_SECTION_PARSER.parse(this); } - public void advanceToFieldName() throws IOException, RestTestParseException { + public void advanceToFieldName() throws IOException, ClientYamlTestParseException { XContentParser.Token token = parser.currentToken(); //we are in the beginning, haven't called nextToken yet if (token == null) { @@ -158,12 +158,12 @@ public class RestTestSuiteParseContext { token = parser.nextToken(); } if (token != XContentParser.Token.FIELD_NAME) { - throw new RestTestParseException("malformed test section: field name expected but found " + token + " at " + throw new ClientYamlTestParseException("malformed test section: field name expected but found " + token + " at " + parser.getTokenLocation()); } } - public String parseField() throws IOException, RestTestParseException { + public String parseField() throws IOException, ClientYamlTestParseException { parser.nextToken(); assert parser.currentToken().isValue(); String field = parser.text(); @@ -171,7 +171,7 @@ public class RestTestSuiteParseContext { return field; } - public Tuple parseTuple() throws IOException, RestTestParseException { + public Tuple parseTuple() throws IOException, ClientYamlTestParseException { parser.nextToken(); advanceToFieldName(); Map map = parser.map(); @@ -179,7 +179,7 @@ public class RestTestSuiteParseContext { parser.nextToken(); if (map.size() != 1) { - throw new RestTestParseException("expected key value pair but found " + map.size() + " "); + throw new ClientYamlTestParseException("expected key value pair but found " + map.size() + " "); } Map.Entry entry = map.entrySet().iterator().next(); diff --git a/test/framework/src/main/java/org/elasticsearch/test/rest/parser/RestTestSuiteParser.java b/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/parser/ClientYamlTestSuiteParser.java similarity index 72% rename from test/framework/src/main/java/org/elasticsearch/test/rest/parser/RestTestSuiteParser.java rename to test/framework/src/main/java/org/elasticsearch/test/rest/yaml/parser/ClientYamlTestSuiteParser.java index f22f0109594..65277888471 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/rest/parser/RestTestSuiteParser.java +++ b/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/parser/ClientYamlTestSuiteParser.java @@ -16,13 +16,12 @@ * specific language governing permissions and limitations * under the License. */ -package org.elasticsearch.test.rest.parser; +package org.elasticsearch.test.rest.yaml.parser; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.yaml.YamlXContent; -import org.elasticsearch.test.rest.section.RestTestSuite; -import org.elasticsearch.test.rest.section.TeardownSection; -import org.elasticsearch.test.rest.section.TestSection; +import org.elasticsearch.test.rest.yaml.section.ClientYamlTestSuite; +import org.elasticsearch.test.rest.yaml.section.ClientYamlTestSection; import java.io.IOException; import java.nio.ByteBuffer; @@ -34,9 +33,9 @@ import java.nio.file.StandardOpenOption; /** * Parser for a complete test suite (yaml file) */ -public class RestTestSuiteParser implements RestTestFragmentParser { +public class ClientYamlTestSuiteParser implements ClientYamlTestFragmentParser { - public RestTestSuite parse(String api, Path file) throws IOException, RestTestParseException { + public ClientYamlTestSuite parse(String api, Path file) throws IOException, ClientYamlTestParseException { if (!Files.isRegularFile(file)) { throw new IllegalArgumentException(file.toAbsolutePath() + " is not a file"); @@ -54,27 +53,27 @@ public class RestTestSuiteParser implements RestTestFragmentParser { +public class DoSectionParser implements ClientYamlTestFragmentParser { @Override - public DoSection parse(RestTestSuiteParseContext parseContext) throws IOException, RestTestParseException { + public DoSection parse(ClientYamlTestSuiteParseContext parseContext) throws IOException, ClientYamlTestParseException { XContentParser parser = parseContext.parser(); @@ -91,7 +91,7 @@ public class DoSectionParser implements RestTestFragmentParser { } try { if (apiCallSection == null) { - throw new RestTestParseException("client call section is mandatory within a do section"); + throw new ClientYamlTestParseException("client call section is mandatory within a do section"); } if (headers.isEmpty() == false) { apiCallSection.addHeaders(headers); diff --git a/test/framework/src/main/java/org/elasticsearch/test/rest/parser/GreaterThanEqualToParser.java b/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/parser/GreaterThanEqualToParser.java similarity index 70% rename from test/framework/src/main/java/org/elasticsearch/test/rest/parser/GreaterThanEqualToParser.java rename to test/framework/src/main/java/org/elasticsearch/test/rest/yaml/parser/GreaterThanEqualToParser.java index 7a4cd0f316a..1ed71075970 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/rest/parser/GreaterThanEqualToParser.java +++ b/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/parser/GreaterThanEqualToParser.java @@ -17,23 +17,23 @@ * under the License. */ -package org.elasticsearch.test.rest.parser; +package org.elasticsearch.test.rest.yaml.parser; import org.elasticsearch.common.collect.Tuple; -import org.elasticsearch.test.rest.section.GreaterThanEqualToAssertion; +import org.elasticsearch.test.rest.yaml.section.GreaterThanEqualToAssertion; import java.io.IOException; /** * Parser for gte assert sections */ -public class GreaterThanEqualToParser implements RestTestFragmentParser { - +public class GreaterThanEqualToParser implements ClientYamlTestFragmentParser { @Override - public GreaterThanEqualToAssertion parse(RestTestSuiteParseContext parseContext) throws IOException, RestTestParseException { + public GreaterThanEqualToAssertion parse(ClientYamlTestSuiteParseContext parseContext) + throws IOException, ClientYamlTestParseException { Tuple stringObjectTuple = parseContext.parseTuple(); if (! (stringObjectTuple.v2() instanceof Comparable) ) { - throw new RestTestParseException("gte section can only be used with objects that support natural ordering, found " + throw new ClientYamlTestParseException("gte section can only be used with objects that support natural ordering, found " + stringObjectTuple.v2().getClass().getSimpleName()); } return new GreaterThanEqualToAssertion(stringObjectTuple.v1(), stringObjectTuple.v2()); diff --git a/test/framework/src/main/java/org/elasticsearch/test/rest/parser/GreaterThanParser.java b/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/parser/GreaterThanParser.java similarity index 72% rename from test/framework/src/main/java/org/elasticsearch/test/rest/parser/GreaterThanParser.java rename to test/framework/src/main/java/org/elasticsearch/test/rest/yaml/parser/GreaterThanParser.java index 7e1ca1ece7f..ca76d486ab4 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/rest/parser/GreaterThanParser.java +++ b/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/parser/GreaterThanParser.java @@ -16,23 +16,23 @@ * specific language governing permissions and limitations * under the License. */ -package org.elasticsearch.test.rest.parser; +package org.elasticsearch.test.rest.yaml.parser; import org.elasticsearch.common.collect.Tuple; -import org.elasticsearch.test.rest.section.GreaterThanAssertion; +import org.elasticsearch.test.rest.yaml.section.GreaterThanAssertion; import java.io.IOException; /** * Parser for gt assert sections */ -public class GreaterThanParser implements RestTestFragmentParser { +public class GreaterThanParser implements ClientYamlTestFragmentParser { @Override - public GreaterThanAssertion parse(RestTestSuiteParseContext parseContext) throws IOException, RestTestParseException { + public GreaterThanAssertion parse(ClientYamlTestSuiteParseContext parseContext) throws IOException, ClientYamlTestParseException { Tuple stringObjectTuple = parseContext.parseTuple(); if (! (stringObjectTuple.v2() instanceof Comparable) ) { - throw new RestTestParseException("gt section can only be used with objects that support natural ordering, found " + throw new ClientYamlTestParseException("gt section can only be used with objects that support natural ordering, found " + stringObjectTuple.v2().getClass().getSimpleName()); } return new GreaterThanAssertion(stringObjectTuple.v1(), stringObjectTuple.v2()); diff --git a/test/framework/src/main/java/org/elasticsearch/test/rest/parser/IsFalseParser.java b/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/parser/IsFalseParser.java similarity index 74% rename from test/framework/src/main/java/org/elasticsearch/test/rest/parser/IsFalseParser.java rename to test/framework/src/main/java/org/elasticsearch/test/rest/yaml/parser/IsFalseParser.java index 81cade6d84b..8a41df99002 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/rest/parser/IsFalseParser.java +++ b/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/parser/IsFalseParser.java @@ -16,19 +16,19 @@ * specific language governing permissions and limitations * under the License. */ -package org.elasticsearch.test.rest.parser; +package org.elasticsearch.test.rest.yaml.parser; -import org.elasticsearch.test.rest.section.IsFalseAssertion; +import org.elasticsearch.test.rest.yaml.section.IsFalseAssertion; import java.io.IOException; /** * Parser for is_false assert sections */ -public class IsFalseParser implements RestTestFragmentParser { +public class IsFalseParser implements ClientYamlTestFragmentParser { @Override - public IsFalseAssertion parse(RestTestSuiteParseContext parseContext) throws IOException, RestTestParseException { + public IsFalseAssertion parse(ClientYamlTestSuiteParseContext parseContext) throws IOException, ClientYamlTestParseException { return new IsFalseAssertion(parseContext.parseField()); } } diff --git a/test/framework/src/main/java/org/elasticsearch/test/rest/parser/IsTrueParser.java b/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/parser/IsTrueParser.java similarity index 74% rename from test/framework/src/main/java/org/elasticsearch/test/rest/parser/IsTrueParser.java rename to test/framework/src/main/java/org/elasticsearch/test/rest/yaml/parser/IsTrueParser.java index 922629b47ef..228cc29c262 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/rest/parser/IsTrueParser.java +++ b/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/parser/IsTrueParser.java @@ -16,19 +16,19 @@ * specific language governing permissions and limitations * under the License. */ -package org.elasticsearch.test.rest.parser; +package org.elasticsearch.test.rest.yaml.parser; -import org.elasticsearch.test.rest.section.IsTrueAssertion; +import org.elasticsearch.test.rest.yaml.section.IsTrueAssertion; import java.io.IOException; /** * Parser for is_true assert sections */ -public class IsTrueParser implements RestTestFragmentParser { +public class IsTrueParser implements ClientYamlTestFragmentParser { @Override - public IsTrueAssertion parse(RestTestSuiteParseContext parseContext) throws IOException, RestTestParseException { + public IsTrueAssertion parse(ClientYamlTestSuiteParseContext parseContext) throws IOException, ClientYamlTestParseException { return new IsTrueAssertion(parseContext.parseField()); } } diff --git a/test/framework/src/main/java/org/elasticsearch/test/rest/parser/LengthParser.java b/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/parser/LengthParser.java similarity index 77% rename from test/framework/src/main/java/org/elasticsearch/test/rest/parser/LengthParser.java rename to test/framework/src/main/java/org/elasticsearch/test/rest/yaml/parser/LengthParser.java index 414be59f4cd..8a206130cb5 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/rest/parser/LengthParser.java +++ b/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/parser/LengthParser.java @@ -16,20 +16,20 @@ * specific language governing permissions and limitations * under the License. */ -package org.elasticsearch.test.rest.parser; +package org.elasticsearch.test.rest.yaml.parser; import org.elasticsearch.common.collect.Tuple; -import org.elasticsearch.test.rest.section.LengthAssertion; +import org.elasticsearch.test.rest.yaml.section.LengthAssertion; import java.io.IOException; /** * Parser for length assert sections */ -public class LengthParser implements RestTestFragmentParser { +public class LengthParser implements ClientYamlTestFragmentParser { @Override - public LengthAssertion parse(RestTestSuiteParseContext parseContext) throws IOException, RestTestParseException { + public LengthAssertion parse(ClientYamlTestSuiteParseContext parseContext) throws IOException, ClientYamlTestParseException { Tuple stringObjectTuple = parseContext.parseTuple(); assert stringObjectTuple.v2() != null; int value; @@ -39,7 +39,7 @@ public class LengthParser implements RestTestFragmentParser { try { value = Integer.valueOf(stringObjectTuple.v2().toString()); } catch(NumberFormatException e) { - throw new RestTestParseException("length is not a valid number", e); + throw new ClientYamlTestParseException("length is not a valid number", e); } } diff --git a/test/framework/src/main/java/org/elasticsearch/test/rest/parser/LessThanOrEqualToParser.java b/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/parser/LessThanOrEqualToParser.java similarity index 71% rename from test/framework/src/main/java/org/elasticsearch/test/rest/parser/LessThanOrEqualToParser.java rename to test/framework/src/main/java/org/elasticsearch/test/rest/yaml/parser/LessThanOrEqualToParser.java index a30979c6a3c..9fc43212548 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/rest/parser/LessThanOrEqualToParser.java +++ b/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/parser/LessThanOrEqualToParser.java @@ -17,23 +17,23 @@ * under the License. */ -package org.elasticsearch.test.rest.parser; +package org.elasticsearch.test.rest.yaml.parser; import org.elasticsearch.common.collect.Tuple; -import org.elasticsearch.test.rest.section.LessThanOrEqualToAssertion; +import org.elasticsearch.test.rest.yaml.section.LessThanOrEqualToAssertion; import java.io.IOException; /** * Parser for lte assert section */ -public class LessThanOrEqualToParser implements RestTestFragmentParser { +public class LessThanOrEqualToParser implements ClientYamlTestFragmentParser { @Override - public LessThanOrEqualToAssertion parse(RestTestSuiteParseContext parseContext) throws IOException, RestTestParseException { + public LessThanOrEqualToAssertion parse(ClientYamlTestSuiteParseContext parseContext) throws IOException, ClientYamlTestParseException { Tuple stringObjectTuple = parseContext.parseTuple(); if (! (stringObjectTuple.v2() instanceof Comparable) ) { - throw new RestTestParseException("lte section can only be used with objects that support natural ordering, found " + throw new ClientYamlTestParseException("lte section can only be used with objects that support natural ordering, found " + stringObjectTuple.v2().getClass().getSimpleName()); } return new LessThanOrEqualToAssertion(stringObjectTuple.v1(), stringObjectTuple.v2()); diff --git a/test/framework/src/main/java/org/elasticsearch/test/rest/parser/LessThanParser.java b/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/parser/LessThanParser.java similarity index 72% rename from test/framework/src/main/java/org/elasticsearch/test/rest/parser/LessThanParser.java rename to test/framework/src/main/java/org/elasticsearch/test/rest/yaml/parser/LessThanParser.java index fc31f221758..f244bd68f93 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/rest/parser/LessThanParser.java +++ b/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/parser/LessThanParser.java @@ -16,23 +16,23 @@ * specific language governing permissions and limitations * under the License. */ -package org.elasticsearch.test.rest.parser; +package org.elasticsearch.test.rest.yaml.parser; import org.elasticsearch.common.collect.Tuple; -import org.elasticsearch.test.rest.section.LessThanAssertion; +import org.elasticsearch.test.rest.yaml.section.LessThanAssertion; import java.io.IOException; /** * Parser for lt assert sections */ -public class LessThanParser implements RestTestFragmentParser { +public class LessThanParser implements ClientYamlTestFragmentParser { @Override - public LessThanAssertion parse(RestTestSuiteParseContext parseContext) throws IOException, RestTestParseException { + public LessThanAssertion parse(ClientYamlTestSuiteParseContext parseContext) throws IOException, ClientYamlTestParseException { Tuple stringObjectTuple = parseContext.parseTuple(); if (! (stringObjectTuple.v2() instanceof Comparable) ) { - throw new RestTestParseException("lt section can only be used with objects that support natural ordering, found " + throw new ClientYamlTestParseException("lt section can only be used with objects that support natural ordering, found " + stringObjectTuple.v2().getClass().getSimpleName()); } return new LessThanAssertion(stringObjectTuple.v1(), stringObjectTuple.v2()); diff --git a/test/framework/src/main/java/org/elasticsearch/test/rest/parser/MatchParser.java b/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/parser/MatchParser.java similarity index 77% rename from test/framework/src/main/java/org/elasticsearch/test/rest/parser/MatchParser.java rename to test/framework/src/main/java/org/elasticsearch/test/rest/yaml/parser/MatchParser.java index 30ee18a4e05..35f3fc160bf 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/rest/parser/MatchParser.java +++ b/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/parser/MatchParser.java @@ -16,20 +16,20 @@ * specific language governing permissions and limitations * under the License. */ -package org.elasticsearch.test.rest.parser; +package org.elasticsearch.test.rest.yaml.parser; import org.elasticsearch.common.collect.Tuple; -import org.elasticsearch.test.rest.section.MatchAssertion; +import org.elasticsearch.test.rest.yaml.section.MatchAssertion; import java.io.IOException; /** * Parser for match assert sections */ -public class MatchParser implements RestTestFragmentParser { +public class MatchParser implements ClientYamlTestFragmentParser { @Override - public MatchAssertion parse(RestTestSuiteParseContext parseContext) throws IOException, RestTestParseException { + public MatchAssertion parse(ClientYamlTestSuiteParseContext parseContext) throws IOException, ClientYamlTestParseException { Tuple stringObjectTuple = parseContext.parseTuple(); return new MatchAssertion(stringObjectTuple.v1(), stringObjectTuple.v2()); } diff --git a/test/framework/src/main/java/org/elasticsearch/test/rest/parser/SetSectionParser.java b/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/parser/SetSectionParser.java similarity index 79% rename from test/framework/src/main/java/org/elasticsearch/test/rest/parser/SetSectionParser.java rename to test/framework/src/main/java/org/elasticsearch/test/rest/yaml/parser/SetSectionParser.java index 8afafc09f7a..2686593e10a 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/rest/parser/SetSectionParser.java +++ b/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/parser/SetSectionParser.java @@ -16,20 +16,20 @@ * specific language governing permissions and limitations * under the License. */ -package org.elasticsearch.test.rest.parser; +package org.elasticsearch.test.rest.yaml.parser; import org.elasticsearch.common.xcontent.XContentParser; -import org.elasticsearch.test.rest.section.SetSection; +import org.elasticsearch.test.rest.yaml.section.SetSection; import java.io.IOException; /** * Parser for set sections */ -public class SetSectionParser implements RestTestFragmentParser { +public class SetSectionParser implements ClientYamlTestFragmentParser { @Override - public SetSection parse(RestTestSuiteParseContext parseContext) throws IOException, RestTestParseException { + public SetSection parse(ClientYamlTestSuiteParseContext parseContext) throws IOException, ClientYamlTestParseException { XContentParser parser = parseContext.parser(); @@ -49,7 +49,7 @@ public class SetSectionParser implements RestTestFragmentParser { parser.nextToken(); if (setSection.getStash().isEmpty()) { - throw new RestTestParseException("set section must set at least a value"); + throw new ClientYamlTestParseException("set section must set at least a value"); } return setSection; diff --git a/test/framework/src/main/java/org/elasticsearch/test/rest/parser/SetupSectionParser.java b/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/parser/SetupSectionParser.java similarity index 76% rename from test/framework/src/main/java/org/elasticsearch/test/rest/parser/SetupSectionParser.java rename to test/framework/src/main/java/org/elasticsearch/test/rest/yaml/parser/SetupSectionParser.java index 2a2e39ea744..e62b3af5251 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/rest/parser/SetupSectionParser.java +++ b/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/parser/SetupSectionParser.java @@ -16,20 +16,20 @@ * specific language governing permissions and limitations * under the License. */ -package org.elasticsearch.test.rest.parser; +package org.elasticsearch.test.rest.yaml.parser; import org.elasticsearch.common.xcontent.XContentParser; -import org.elasticsearch.test.rest.section.SetupSection; +import org.elasticsearch.test.rest.yaml.section.SetupSection; import java.io.IOException; /** * Parser for setup sections */ -public class SetupSectionParser implements RestTestFragmentParser { +public class SetupSectionParser implements ClientYamlTestFragmentParser { @Override - public SetupSection parse(RestTestSuiteParseContext parseContext) throws IOException, RestTestParseException { + public SetupSection parse(ClientYamlTestSuiteParseContext parseContext) throws IOException, ClientYamlTestParseException { XContentParser parser = parseContext.parser(); @@ -39,7 +39,7 @@ public class SetupSectionParser implements RestTestFragmentParser while (parser.currentToken() != XContentParser.Token.END_ARRAY) { parseContext.advanceToFieldName(); if (!"do".equals(parser.currentName())) { - throw new RestTestParseException("section [" + parser.currentName() + "] not supported within setup section"); + throw new ClientYamlTestParseException("section [" + parser.currentName() + "] not supported within setup section"); } parser.nextToken(); diff --git a/test/framework/src/main/java/org/elasticsearch/test/rest/parser/SkipSectionParser.java b/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/parser/SkipSectionParser.java similarity index 77% rename from test/framework/src/main/java/org/elasticsearch/test/rest/parser/SkipSectionParser.java rename to test/framework/src/main/java/org/elasticsearch/test/rest/yaml/parser/SkipSectionParser.java index 33733821019..31451dee247 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/rest/parser/SkipSectionParser.java +++ b/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/parser/SkipSectionParser.java @@ -16,11 +16,11 @@ * specific language governing permissions and limitations * under the License. */ -package org.elasticsearch.test.rest.parser; +package org.elasticsearch.test.rest.yaml.parser; import org.elasticsearch.common.Strings; import org.elasticsearch.common.xcontent.XContentParser; -import org.elasticsearch.test.rest.section.SkipSection; +import org.elasticsearch.test.rest.yaml.section.SkipSection; import java.io.IOException; import java.util.ArrayList; @@ -29,10 +29,10 @@ import java.util.List; /** * Parser for skip sections */ -public class SkipSectionParser implements RestTestFragmentParser { +public class SkipSectionParser implements ClientYamlTestFragmentParser { @Override - public SkipSection parse(RestTestSuiteParseContext parseContext) throws IOException, RestTestParseException { + public SkipSection parse(ClientYamlTestSuiteParseContext parseContext) throws IOException, ClientYamlTestParseException { XContentParser parser = parseContext.parser(); @@ -54,7 +54,7 @@ public class SkipSectionParser implements RestTestFragmentParser { features.add(parser.text()); } else { - throw new RestTestParseException("field " + currentFieldName + " not supported within skip section"); + throw new ClientYamlTestParseException("field " + currentFieldName + " not supported within skip section"); } } else if (token == XContentParser.Token.START_ARRAY) { if ("features".equals(currentFieldName)) { @@ -68,13 +68,13 @@ public class SkipSectionParser implements RestTestFragmentParser { parser.nextToken(); if (!Strings.hasLength(version) && features.isEmpty()) { - throw new RestTestParseException("version or features is mandatory within skip section"); + throw new ClientYamlTestParseException("version or features is mandatory within skip section"); } if (Strings.hasLength(version) && !features.isEmpty()) { - throw new RestTestParseException("version or features are mutually exclusive"); + throw new ClientYamlTestParseException("version or features are mutually exclusive"); } if (Strings.hasLength(version) && !Strings.hasLength(reason)) { - throw new RestTestParseException("reason is mandatory within skip version section"); + throw new ClientYamlTestParseException("reason is mandatory within skip version section"); } return new SkipSection(version, features, reason); diff --git a/test/framework/src/main/java/org/elasticsearch/test/rest/parser/TeardownSectionParser.java b/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/parser/TeardownSectionParser.java similarity index 76% rename from test/framework/src/main/java/org/elasticsearch/test/rest/parser/TeardownSectionParser.java rename to test/framework/src/main/java/org/elasticsearch/test/rest/yaml/parser/TeardownSectionParser.java index 428a21e2e06..ed1b42c3a9c 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/rest/parser/TeardownSectionParser.java +++ b/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/parser/TeardownSectionParser.java @@ -17,20 +17,20 @@ * under the License. */ -package org.elasticsearch.test.rest.parser; +package org.elasticsearch.test.rest.yaml.parser; import org.elasticsearch.common.xcontent.XContentParser; -import org.elasticsearch.test.rest.section.TeardownSection; +import org.elasticsearch.test.rest.yaml.section.TeardownSection; import java.io.IOException; /** * Parser for teardown section */ -public class TeardownSectionParser implements RestTestFragmentParser { +public class TeardownSectionParser implements ClientYamlTestFragmentParser { @Override - public TeardownSection parse(RestTestSuiteParseContext parseContext) throws IOException, RestTestParseException { + public TeardownSection parse(ClientYamlTestSuiteParseContext parseContext) throws IOException, ClientYamlTestParseException { XContentParser parser = parseContext.parser(); TeardownSection teardownSection = new TeardownSection(); @@ -39,7 +39,7 @@ public class TeardownSectionParser implements RestTestFragmentParser paths = new ArrayList<>(); private List pathParts = new ArrayList<>(); private List params = new ArrayList<>(); - private BODY body = BODY.NOT_SUPPORTED; + private Body body = Body.NOT_SUPPORTED; - public enum BODY { + public enum Body { NOT_SUPPORTED, OPTIONAL, REQUIRED } - RestApi(String location, String name) { + ClientYamlSuiteRestApi(String location, String name) { this.location = location; this.name = name; } @@ -116,34 +115,34 @@ public class RestApi { } void setBodyOptional() { - this.body = BODY.OPTIONAL; + this.body = Body.OPTIONAL; } void setBodyRequired() { - this.body = BODY.REQUIRED; + this.body = Body.REQUIRED; } public boolean isBodySupported() { - return body != BODY.NOT_SUPPORTED; + return body != Body.NOT_SUPPORTED; } public boolean isBodyRequired() { - return body == BODY.REQUIRED; + return body == Body.REQUIRED; } /** * Finds the best matching rest path given the current parameters and replaces * placeholders with their corresponding values received as arguments */ - public RestPath[] getFinalPaths(Map pathParams) { - List matchingRestPaths = findMatchingRestPaths(pathParams.keySet()); + public ClientYamlSuiteRestPath[] getFinalPaths(Map pathParams) { + List matchingRestPaths = findMatchingRestPaths(pathParams.keySet()); if (matchingRestPaths == null || matchingRestPaths.isEmpty()) { throw new IllegalArgumentException("unable to find matching rest path for api [" + name + "] and path params " + pathParams); } - RestPath[] restPaths = new RestPath[matchingRestPaths.size()]; + ClientYamlSuiteRestPath[] restPaths = new ClientYamlSuiteRestPath[matchingRestPaths.size()]; for (int i = 0; i < matchingRestPaths.size(); i++) { - RestPath restPath = matchingRestPaths.get(i); + ClientYamlSuiteRestPath restPath = matchingRestPaths.get(i); restPaths[i] = restPath.replacePlaceholders(pathParams); } return restPaths; @@ -155,11 +154,11 @@ public class RestApi { * The best path is the one that has exactly the same number of placeholders to replace * (e.g. /{index}/{type}/{id} when the path params are exactly index, type and id). */ - private List findMatchingRestPaths(Set restParams) { + private List findMatchingRestPaths(Set restParams) { - List matchingRestPaths = new ArrayList<>(); - RestPath[] restPaths = buildRestPaths(); - for (RestPath restPath : restPaths) { + List matchingRestPaths = new ArrayList<>(); + ClientYamlSuiteRestPath[] restPaths = buildRestPaths(); + for (ClientYamlSuiteRestPath restPath : restPaths) { if (restPath.matches(restParams)) { matchingRestPaths.add(restPath); } @@ -167,10 +166,10 @@ public class RestApi { return matchingRestPaths; } - private RestPath[] buildRestPaths() { - RestPath[] restPaths = new RestPath[paths.size()]; + private ClientYamlSuiteRestPath[] buildRestPaths() { + ClientYamlSuiteRestPath[] restPaths = new ClientYamlSuiteRestPath[paths.size()]; for (int i = 0; i < restPaths.length; i++) { - restPaths[i] = new RestPath(paths.get(i)); + restPaths[i] = new ClientYamlSuiteRestPath(paths.get(i)); } return restPaths; } diff --git a/test/framework/src/main/java/org/elasticsearch/test/rest/spec/RestApiParser.java b/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/restspec/ClientYamlSuiteRestApiParser.java similarity index 94% rename from test/framework/src/main/java/org/elasticsearch/test/rest/spec/RestApiParser.java rename to test/framework/src/main/java/org/elasticsearch/test/rest/yaml/restspec/ClientYamlSuiteRestApiParser.java index 95fe132471a..178fb9c5f34 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/rest/spec/RestApiParser.java +++ b/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/restspec/ClientYamlSuiteRestApiParser.java @@ -16,24 +16,24 @@ * specific language governing permissions and limitations * under the License. */ -package org.elasticsearch.test.rest.spec; +package org.elasticsearch.test.rest.yaml.restspec; import org.elasticsearch.common.xcontent.XContentParser; import java.io.IOException; /** - * Parser for a REST api spec (single json file) + * Parser for a {@link ClientYamlSuiteRestApi}. */ -public class RestApiParser { +public class ClientYamlSuiteRestApiParser { - public RestApi parse(String location, XContentParser parser) throws IOException { + public ClientYamlSuiteRestApi parse(String location, XContentParser parser) throws IOException { while ( parser.nextToken() != XContentParser.Token.FIELD_NAME ) { //move to first field name } - RestApi restApi = new RestApi(location, parser.currentName()); + ClientYamlSuiteRestApi restApi = new ClientYamlSuiteRestApi(location, parser.currentName()); int level = -1; while (parser.nextToken() != XContentParser.Token.END_OBJECT || level >= 0) { diff --git a/test/framework/src/main/java/org/elasticsearch/test/rest/client/RestPath.java b/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/restspec/ClientYamlSuiteRestPath.java similarity index 90% rename from test/framework/src/main/java/org/elasticsearch/test/rest/client/RestPath.java rename to test/framework/src/main/java/org/elasticsearch/test/rest/yaml/restspec/ClientYamlSuiteRestPath.java index ed1ce728c0b..f54994138e0 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/rest/client/RestPath.java +++ b/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/restspec/ClientYamlSuiteRestPath.java @@ -17,7 +17,7 @@ * under the License. */ -package org.elasticsearch.test.rest.client; +package org.elasticsearch.test.rest.yaml.restspec; import java.util.ArrayList; import java.util.Collections; @@ -25,11 +25,11 @@ import java.util.List; import java.util.Map; import java.util.Set; -public class RestPath { +public class ClientYamlSuiteRestPath { private final List parts; private final List placeholders; - public RestPath(List parts) { + public ClientYamlSuiteRestPath(List parts) { List pathParts = new ArrayList<>(parts.size()); for (String part : parts) { pathParts.add(new PathPart(part, false)); @@ -38,7 +38,7 @@ public class RestPath { this.placeholders = Collections.emptyList(); } - public RestPath(String path) { + public ClientYamlSuiteRestPath(String path) { String[] pathParts = path.split("/"); List placeholders = new ArrayList<>(); List parts = new ArrayList<>(); @@ -73,7 +73,7 @@ public class RestPath { return placeholders.size() == params.size() && placeholders.containsAll(params); } - public RestPath replacePlaceholders(Map params) { + public ClientYamlSuiteRestPath replacePlaceholders(Map params) { List finalPathParts = new ArrayList<>(parts.size()); for (PathPart pathPart : parts) { if (pathPart.isPlaceholder) { @@ -86,7 +86,7 @@ public class RestPath { finalPathParts.add(pathPart.pathPart); } } - return new RestPath(finalPathParts); + return new ClientYamlSuiteRestPath(finalPathParts); } private static class PathPart { diff --git a/test/framework/src/main/java/org/elasticsearch/test/rest/spec/RestSpec.java b/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/restspec/ClientYamlSuiteRestSpec.java similarity index 72% rename from test/framework/src/main/java/org/elasticsearch/test/rest/spec/RestSpec.java rename to test/framework/src/main/java/org/elasticsearch/test/rest/yaml/restspec/ClientYamlSuiteRestSpec.java index c6ea48fd6ef..d0cfc839fcc 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/rest/spec/RestSpec.java +++ b/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/restspec/ClientYamlSuiteRestSpec.java @@ -16,11 +16,11 @@ * specific language governing permissions and limitations * under the License. */ -package org.elasticsearch.test.rest.spec; +package org.elasticsearch.test.rest.yaml.restspec; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.json.JsonXContent; -import org.elasticsearch.test.rest.support.FileUtils; +import org.elasticsearch.test.rest.yaml.support.FileUtils; import java.io.IOException; import java.io.InputStream; @@ -32,41 +32,41 @@ import java.util.HashMap; import java.util.Map; /** - * Holds the elasticsearch REST spec + * Holds the specification used to turn {@code do} actions in the YAML suite into REST api calls. */ -public class RestSpec { - Map restApiMap = new HashMap<>(); +public class ClientYamlSuiteRestSpec { + Map restApiMap = new HashMap<>(); - private RestSpec() { + private ClientYamlSuiteRestSpec() { } - void addApi(RestApi restApi) { - RestApi previous = restApiMap.putIfAbsent(restApi.getName(), restApi); + void addApi(ClientYamlSuiteRestApi restApi) { + ClientYamlSuiteRestApi previous = restApiMap.putIfAbsent(restApi.getName(), restApi); if (previous != null) { throw new IllegalArgumentException("cannot register api [" + restApi.getName() + "] found in [" + restApi.getLocation() + "]. " + "api with same name was already found in [" + previous.getLocation() + "]"); } } - public RestApi getApi(String api) { + public ClientYamlSuiteRestApi getApi(String api) { return restApiMap.get(api); } - public Collection getApis() { + public Collection getApis() { return restApiMap.values(); } /** * Parses the complete set of REST spec available under the provided directories */ - public static RestSpec parseFrom(FileSystem fileSystem, String optionalPathPrefix, String... paths) throws IOException { - RestSpec restSpec = new RestSpec(); - RestApiParser restApiParser = new RestApiParser(); + public static ClientYamlSuiteRestSpec parseFrom(FileSystem fileSystem, String optionalPathPrefix, String... paths) throws IOException { + ClientYamlSuiteRestSpec restSpec = new ClientYamlSuiteRestSpec(); + ClientYamlSuiteRestApiParser restApiParser = new ClientYamlSuiteRestApiParser(); for (String path : paths) { for (Path jsonFile : FileUtils.findJsonSpec(fileSystem, optionalPathPrefix, path)) { try (InputStream stream = Files.newInputStream(jsonFile)) { try (XContentParser parser = JsonXContent.jsonXContent.createParser(stream)) { - RestApi restApi = restApiParser.parse(jsonFile.toString(), parser); + ClientYamlSuiteRestApi restApi = restApiParser.parse(jsonFile.toString(), parser); String filename = jsonFile.getFileName().toString(); String expectedApiName = filename.substring(0, filename.lastIndexOf('.')); if (restApi.getName().equals(expectedApiName) == false) { diff --git a/test/framework/src/main/java/org/elasticsearch/test/rest/section/ApiCallSection.java b/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/section/ApiCallSection.java similarity index 97% rename from test/framework/src/main/java/org/elasticsearch/test/rest/section/ApiCallSection.java rename to test/framework/src/main/java/org/elasticsearch/test/rest/yaml/section/ApiCallSection.java index 030469148ed..5d097f872b4 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/rest/section/ApiCallSection.java +++ b/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/section/ApiCallSection.java @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.elasticsearch.test.rest.section; +package org.elasticsearch.test.rest.yaml.section; import java.util.ArrayList; import java.util.Collections; diff --git a/test/framework/src/main/java/org/elasticsearch/test/rest/section/Assertion.java b/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/section/Assertion.java similarity index 86% rename from test/framework/src/main/java/org/elasticsearch/test/rest/section/Assertion.java rename to test/framework/src/main/java/org/elasticsearch/test/rest/yaml/section/Assertion.java index fbba9de163b..97ef2546074 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/rest/section/Assertion.java +++ b/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/section/Assertion.java @@ -16,9 +16,9 @@ * specific language governing permissions and limitations * under the License. */ -package org.elasticsearch.test.rest.section; +package org.elasticsearch.test.rest.yaml.section; -import org.elasticsearch.test.rest.RestTestExecutionContext; +import org.elasticsearch.test.rest.yaml.ClientYamlTestExecutionContext; import java.io.IOException; import java.util.Map; @@ -44,7 +44,7 @@ public abstract class Assertion implements ExecutableSection { return expectedValue; } - protected final Object resolveExpectedValue(RestTestExecutionContext executionContext) throws IOException { + protected final Object resolveExpectedValue(ClientYamlTestExecutionContext executionContext) throws IOException { if (expectedValue instanceof Map) { @SuppressWarnings("unchecked") Map map = (Map) expectedValue; @@ -57,7 +57,7 @@ public abstract class Assertion implements ExecutableSection { return expectedValue; } - protected final Object getActualValue(RestTestExecutionContext executionContext) throws IOException { + protected final Object getActualValue(ClientYamlTestExecutionContext executionContext) throws IOException { if (executionContext.stash().containsStashedValue(field)) { return executionContext.stash().getValue(field); } @@ -65,7 +65,7 @@ public abstract class Assertion implements ExecutableSection { } @Override - public final void execute(RestTestExecutionContext executionContext) throws IOException { + public final void execute(ClientYamlTestExecutionContext executionContext) throws IOException { doAssert(getActualValue(executionContext), resolveExpectedValue(executionContext)); } diff --git a/test/framework/src/main/java/org/elasticsearch/test/rest/section/TestSection.java b/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/section/ClientYamlTestSection.java similarity index 87% rename from test/framework/src/main/java/org/elasticsearch/test/rest/section/TestSection.java rename to test/framework/src/main/java/org/elasticsearch/test/rest/yaml/section/ClientYamlTestSection.java index 3f44e5ce767..4df126cba19 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/rest/section/TestSection.java +++ b/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/section/ClientYamlTestSection.java @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.elasticsearch.test.rest.section; +package org.elasticsearch.test.rest.yaml.section; import java.util.ArrayList; import java.util.List; @@ -24,12 +24,12 @@ import java.util.List; /** * Represents a test section, which is composed of a skip section and multiple executable sections. */ -public class TestSection implements Comparable { +public class ClientYamlTestSection implements Comparable { private final String name; private SkipSection skipSection; private final List executableSections; - public TestSection(String name) { + public ClientYamlTestSection(String name) { this.name = name; this.executableSections = new ArrayList<>(); } @@ -59,7 +59,7 @@ public class TestSection implements Comparable { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; - TestSection that = (TestSection) o; + ClientYamlTestSection that = (ClientYamlTestSection) o; if (name != null ? !name.equals(that.name) : that.name != null) return false; @@ -72,7 +72,7 @@ public class TestSection implements Comparable { } @Override - public int compareTo(TestSection o) { + public int compareTo(ClientYamlTestSection o) { return name.compareTo(o.getName()); } } diff --git a/test/framework/src/main/java/org/elasticsearch/test/rest/section/RestTestSuite.java b/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/section/ClientYamlTestSuite.java similarity index 81% rename from test/framework/src/main/java/org/elasticsearch/test/rest/section/RestTestSuite.java rename to test/framework/src/main/java/org/elasticsearch/test/rest/yaml/section/ClientYamlTestSuite.java index 5c093be3fa0..af3e1be0528 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/rest/section/RestTestSuite.java +++ b/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/section/ClientYamlTestSuite.java @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.elasticsearch.test.rest.section; +package org.elasticsearch.test.rest.yaml.section; import java.util.ArrayList; import java.util.List; @@ -27,7 +27,7 @@ import java.util.TreeSet; * Holds a REST test suite loaded from a specific yaml file. * Supports a setup section and multiple test sections. */ -public class RestTestSuite { +public class ClientYamlTestSuite { private final String api; private final String name; @@ -35,9 +35,9 @@ public class RestTestSuite { private SetupSection setupSection; private TeardownSection teardownSection; - private Set testSections = new TreeSet<>(); + private Set testSections = new TreeSet<>(); - public RestTestSuite(String api, String name) { + public ClientYamlTestSuite(String api, String name) { this.api = api; this.name = name; } @@ -71,14 +71,14 @@ public class RestTestSuite { } /** - * Adds a {@link org.elasticsearch.test.rest.section.TestSection} to the REST suite + * Adds a {@link org.elasticsearch.test.rest.yaml.section.ClientYamlTestSection} to the REST suite * @return true if the test section was not already present, false otherwise */ - public boolean addTestSection(TestSection testSection) { + public boolean addTestSection(ClientYamlTestSection testSection) { return this.testSections.add(testSection); } - public List getTestSections() { + public List getTestSections() { return new ArrayList<>(testSections); } } diff --git a/test/framework/src/main/java/org/elasticsearch/test/rest/section/DoSection.java b/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/section/DoSection.java similarity index 88% rename from test/framework/src/main/java/org/elasticsearch/test/rest/section/DoSection.java rename to test/framework/src/main/java/org/elasticsearch/test/rest/yaml/section/DoSection.java index 20b4f66f06c..78461130783 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/rest/section/DoSection.java +++ b/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/section/DoSection.java @@ -16,15 +16,15 @@ * specific language governing permissions and limitations * under the License. */ -package org.elasticsearch.test.rest.section; +package org.elasticsearch.test.rest.yaml.section; import org.elasticsearch.common.Strings; import org.elasticsearch.common.collect.Tuple; import org.elasticsearch.common.logging.ESLogger; import org.elasticsearch.common.logging.Loggers; -import org.elasticsearch.test.rest.RestTestExecutionContext; -import org.elasticsearch.test.rest.client.RestTestResponse; -import org.elasticsearch.test.rest.client.RestTestResponseException; +import org.elasticsearch.test.rest.yaml.ClientYamlTestExecutionContext; +import org.elasticsearch.test.rest.yaml.client.ClientYamlTestResponse; +import org.elasticsearch.test.rest.yaml.client.ClientYamlTestResponseException; import java.io.IOException; import java.util.HashMap; @@ -79,7 +79,7 @@ public class DoSection implements ExecutableSection { } @Override - public void execute(RestTestExecutionContext executionContext) throws IOException { + public void execute(ClientYamlTestExecutionContext executionContext) throws IOException { if ("param".equals(catchParam)) { //client should throw validation error before sending request @@ -89,7 +89,7 @@ public class DoSection implements ExecutableSection { } try { - RestTestResponse restTestResponse = executionContext.callApi(apiCallSection.getApi(), apiCallSection.getParams(), + ClientYamlTestResponse restTestResponse = executionContext.callApi(apiCallSection.getApi(), apiCallSection.getParams(), apiCallSection.getBodies(), apiCallSection.getHeaders()); if (Strings.hasLength(catchParam)) { String catchStatusCode; @@ -102,8 +102,8 @@ public class DoSection implements ExecutableSection { } fail(formatStatusCodeMessage(restTestResponse, catchStatusCode)); } - } catch(RestTestResponseException e) { - RestTestResponse restTestResponse = e.getRestTestResponse(); + } catch(ClientYamlTestResponseException e) { + ClientYamlTestResponse restTestResponse = e.getRestTestResponse(); if (!Strings.hasLength(catchParam)) { fail(formatStatusCodeMessage(restTestResponse, "2xx")); } else if (catches.containsKey(catchParam)) { @@ -124,13 +124,13 @@ public class DoSection implements ExecutableSection { } } - private void assertStatusCode(RestTestResponse restTestResponse) { + private void assertStatusCode(ClientYamlTestResponse restTestResponse) { Tuple> stringMatcherTuple = catches.get(catchParam); assertThat(formatStatusCodeMessage(restTestResponse, stringMatcherTuple.v1()), restTestResponse.getStatusCode(), stringMatcherTuple.v2()); } - private String formatStatusCodeMessage(RestTestResponse restTestResponse, String expected) { + private String formatStatusCodeMessage(ClientYamlTestResponse restTestResponse, String expected) { String api = apiCallSection.getApi(); if ("raw".equals(api)) { api += "[method=" + apiCallSection.getParams().get("method") + " path=" + apiCallSection.getParams().get("path") + "]"; diff --git a/test/framework/src/main/java/org/elasticsearch/test/rest/section/ExecutableSection.java b/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/section/ExecutableSection.java similarity index 83% rename from test/framework/src/main/java/org/elasticsearch/test/rest/section/ExecutableSection.java rename to test/framework/src/main/java/org/elasticsearch/test/rest/yaml/section/ExecutableSection.java index 669d82cdd78..dbf8f4c1a4a 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/rest/section/ExecutableSection.java +++ b/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/section/ExecutableSection.java @@ -16,9 +16,9 @@ * specific language governing permissions and limitations * under the License. */ -package org.elasticsearch.test.rest.section; +package org.elasticsearch.test.rest.yaml.section; -import org.elasticsearch.test.rest.RestTestExecutionContext; +import org.elasticsearch.test.rest.yaml.ClientYamlTestExecutionContext; import java.io.IOException; @@ -30,5 +30,5 @@ public interface ExecutableSection { /** * Executes the section passing in the execution context */ - void execute(RestTestExecutionContext executionContext) throws IOException; + void execute(ClientYamlTestExecutionContext executionContext) throws IOException; } diff --git a/test/framework/src/main/java/org/elasticsearch/test/rest/section/GreaterThanAssertion.java b/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/section/GreaterThanAssertion.java similarity index 97% rename from test/framework/src/main/java/org/elasticsearch/test/rest/section/GreaterThanAssertion.java rename to test/framework/src/main/java/org/elasticsearch/test/rest/yaml/section/GreaterThanAssertion.java index 63f69696653..9f2aa72ceda 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/rest/section/GreaterThanAssertion.java +++ b/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/section/GreaterThanAssertion.java @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.elasticsearch.test.rest.section; +package org.elasticsearch.test.rest.yaml.section; import org.elasticsearch.common.logging.ESLogger; import org.elasticsearch.common.logging.Loggers; diff --git a/test/framework/src/main/java/org/elasticsearch/test/rest/section/GreaterThanEqualToAssertion.java b/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/section/GreaterThanEqualToAssertion.java similarity index 97% rename from test/framework/src/main/java/org/elasticsearch/test/rest/section/GreaterThanEqualToAssertion.java rename to test/framework/src/main/java/org/elasticsearch/test/rest/yaml/section/GreaterThanEqualToAssertion.java index 297eecf2d2a..5c1ff6c9008 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/rest/section/GreaterThanEqualToAssertion.java +++ b/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/section/GreaterThanEqualToAssertion.java @@ -17,7 +17,7 @@ * under the License. */ -package org.elasticsearch.test.rest.section; +package org.elasticsearch.test.rest.yaml.section; import org.elasticsearch.common.logging.ESLogger; import org.elasticsearch.common.logging.Loggers; diff --git a/test/framework/src/main/java/org/elasticsearch/test/rest/section/IsFalseAssertion.java b/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/section/IsFalseAssertion.java similarity index 97% rename from test/framework/src/main/java/org/elasticsearch/test/rest/section/IsFalseAssertion.java rename to test/framework/src/main/java/org/elasticsearch/test/rest/yaml/section/IsFalseAssertion.java index 3d5e21e5146..3c7bc9f3ce9 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/rest/section/IsFalseAssertion.java +++ b/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/section/IsFalseAssertion.java @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.elasticsearch.test.rest.section; +package org.elasticsearch.test.rest.yaml.section; import org.elasticsearch.common.logging.ESLogger; import org.elasticsearch.common.logging.Loggers; diff --git a/test/framework/src/main/java/org/elasticsearch/test/rest/section/IsTrueAssertion.java b/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/section/IsTrueAssertion.java similarity index 97% rename from test/framework/src/main/java/org/elasticsearch/test/rest/section/IsTrueAssertion.java rename to test/framework/src/main/java/org/elasticsearch/test/rest/yaml/section/IsTrueAssertion.java index 1a899c3cc2b..2a6b9431ad5 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/rest/section/IsTrueAssertion.java +++ b/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/section/IsTrueAssertion.java @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.elasticsearch.test.rest.section; +package org.elasticsearch.test.rest.yaml.section; import org.elasticsearch.common.logging.ESLogger; import org.elasticsearch.common.logging.Loggers; diff --git a/test/framework/src/main/java/org/elasticsearch/test/rest/section/LengthAssertion.java b/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/section/LengthAssertion.java similarity index 98% rename from test/framework/src/main/java/org/elasticsearch/test/rest/section/LengthAssertion.java rename to test/framework/src/main/java/org/elasticsearch/test/rest/yaml/section/LengthAssertion.java index eb28ba01a94..396e6464774 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/rest/section/LengthAssertion.java +++ b/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/section/LengthAssertion.java @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.elasticsearch.test.rest.section; +package org.elasticsearch.test.rest.yaml.section; import org.elasticsearch.common.logging.ESLogger; import org.elasticsearch.common.logging.Loggers; diff --git a/test/framework/src/main/java/org/elasticsearch/test/rest/section/LessThanAssertion.java b/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/section/LessThanAssertion.java similarity index 97% rename from test/framework/src/main/java/org/elasticsearch/test/rest/section/LessThanAssertion.java rename to test/framework/src/main/java/org/elasticsearch/test/rest/yaml/section/LessThanAssertion.java index 153a7824569..0493da1f016 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/rest/section/LessThanAssertion.java +++ b/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/section/LessThanAssertion.java @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.elasticsearch.test.rest.section; +package org.elasticsearch.test.rest.yaml.section; import org.elasticsearch.common.logging.ESLogger; import org.elasticsearch.common.logging.Loggers; diff --git a/test/framework/src/main/java/org/elasticsearch/test/rest/section/LessThanOrEqualToAssertion.java b/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/section/LessThanOrEqualToAssertion.java similarity index 97% rename from test/framework/src/main/java/org/elasticsearch/test/rest/section/LessThanOrEqualToAssertion.java rename to test/framework/src/main/java/org/elasticsearch/test/rest/yaml/section/LessThanOrEqualToAssertion.java index 1eb3a9fc2b2..f46a357bfe0 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/rest/section/LessThanOrEqualToAssertion.java +++ b/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/section/LessThanOrEqualToAssertion.java @@ -17,7 +17,7 @@ * under the License. */ -package org.elasticsearch.test.rest.section; +package org.elasticsearch.test.rest.yaml.section; import org.elasticsearch.common.logging.ESLogger; import org.elasticsearch.common.logging.Loggers; diff --git a/test/framework/src/main/java/org/elasticsearch/test/rest/section/MatchAssertion.java b/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/section/MatchAssertion.java similarity index 99% rename from test/framework/src/main/java/org/elasticsearch/test/rest/section/MatchAssertion.java rename to test/framework/src/main/java/org/elasticsearch/test/rest/yaml/section/MatchAssertion.java index 3a96d4532a0..c0ec9ffca0b 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/rest/section/MatchAssertion.java +++ b/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/section/MatchAssertion.java @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.elasticsearch.test.rest.section; +package org.elasticsearch.test.rest.yaml.section; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.logging.ESLogger; diff --git a/test/framework/src/main/java/org/elasticsearch/test/rest/section/SetSection.java b/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/section/SetSection.java similarity index 87% rename from test/framework/src/main/java/org/elasticsearch/test/rest/section/SetSection.java rename to test/framework/src/main/java/org/elasticsearch/test/rest/yaml/section/SetSection.java index 940664b4ee9..6372b7c9a0d 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/rest/section/SetSection.java +++ b/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/section/SetSection.java @@ -16,9 +16,9 @@ * specific language governing permissions and limitations * under the License. */ -package org.elasticsearch.test.rest.section; +package org.elasticsearch.test.rest.yaml.section; -import org.elasticsearch.test.rest.RestTestExecutionContext; +import org.elasticsearch.test.rest.yaml.ClientYamlTestExecutionContext; import java.io.IOException; import java.util.HashMap; @@ -43,7 +43,7 @@ public class SetSection implements ExecutableSection { } @Override - public void execute(RestTestExecutionContext executionContext) throws IOException { + public void execute(ClientYamlTestExecutionContext executionContext) throws IOException { for (Map.Entry entry : stash.entrySet()) { Object actualValue = executionContext.response(entry.getKey()); executionContext.stash().stashValue(entry.getValue(), actualValue); diff --git a/test/framework/src/main/java/org/elasticsearch/test/rest/section/SetupSection.java b/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/section/SetupSection.java similarity index 97% rename from test/framework/src/main/java/org/elasticsearch/test/rest/section/SetupSection.java rename to test/framework/src/main/java/org/elasticsearch/test/rest/yaml/section/SetupSection.java index 45c66fbad4f..c2bcaa3ecd1 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/rest/section/SetupSection.java +++ b/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/section/SetupSection.java @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.elasticsearch.test.rest.section; +package org.elasticsearch.test.rest.yaml.section; import java.util.ArrayList; import java.util.List; diff --git a/test/framework/src/main/java/org/elasticsearch/test/rest/section/SkipSection.java b/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/section/SkipSection.java similarity index 97% rename from test/framework/src/main/java/org/elasticsearch/test/rest/section/SkipSection.java rename to test/framework/src/main/java/org/elasticsearch/test/rest/yaml/section/SkipSection.java index 179d0a1e868..c9b6ead4aa8 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/rest/section/SkipSection.java +++ b/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/section/SkipSection.java @@ -16,11 +16,11 @@ * specific language governing permissions and limitations * under the License. */ -package org.elasticsearch.test.rest.section; +package org.elasticsearch.test.rest.yaml.section; import org.elasticsearch.Version; import org.elasticsearch.test.VersionUtils; -import org.elasticsearch.test.rest.support.Features; +import org.elasticsearch.test.rest.yaml.support.Features; import java.util.ArrayList; import java.util.List; diff --git a/test/framework/src/main/java/org/elasticsearch/test/rest/section/TeardownSection.java b/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/section/TeardownSection.java similarity index 96% rename from test/framework/src/main/java/org/elasticsearch/test/rest/section/TeardownSection.java rename to test/framework/src/main/java/org/elasticsearch/test/rest/yaml/section/TeardownSection.java index b3709472be5..1e49f8b5037 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/rest/section/TeardownSection.java +++ b/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/section/TeardownSection.java @@ -17,7 +17,7 @@ * under the License. */ -package org.elasticsearch.test.rest.section; +package org.elasticsearch.test.rest.yaml.section; import java.util.ArrayList; import java.util.List; diff --git a/test/framework/src/main/java/org/elasticsearch/test/rest/support/Features.java b/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/support/Features.java similarity index 97% rename from test/framework/src/main/java/org/elasticsearch/test/rest/support/Features.java rename to test/framework/src/main/java/org/elasticsearch/test/rest/yaml/support/Features.java index 98bce54082f..8d7a5a58e16 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/rest/support/Features.java +++ b/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/support/Features.java @@ -17,7 +17,7 @@ * under the License. */ -package org.elasticsearch.test.rest.support; +package org.elasticsearch.test.rest.yaml.support; import org.elasticsearch.test.ESIntegTestCase; diff --git a/test/framework/src/main/java/org/elasticsearch/test/rest/support/FileUtils.java b/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/support/FileUtils.java similarity index 99% rename from test/framework/src/main/java/org/elasticsearch/test/rest/support/FileUtils.java rename to test/framework/src/main/java/org/elasticsearch/test/rest/yaml/support/FileUtils.java index b32308f8cd8..783f0f9dcc1 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/rest/support/FileUtils.java +++ b/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/support/FileUtils.java @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.elasticsearch.test.rest.support; +package org.elasticsearch.test.rest.yaml.support; import org.elasticsearch.common.Strings; import org.elasticsearch.common.io.PathUtils; diff --git a/test/framework/src/main/java/org/elasticsearch/transport/AbstractSimpleTransportTestCase.java b/test/framework/src/main/java/org/elasticsearch/transport/AbstractSimpleTransportTestCase.java index 58cc45a75a1..eb4dbb8bca5 100644 --- a/test/framework/src/main/java/org/elasticsearch/transport/AbstractSimpleTransportTestCase.java +++ b/test/framework/src/main/java/org/elasticsearch/transport/AbstractSimpleTransportTestCase.java @@ -32,6 +32,7 @@ import org.elasticsearch.common.transport.TransportAddress; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.util.concurrent.AbstractRunnable; import org.elasticsearch.common.util.concurrent.ConcurrentCollections; +import org.elasticsearch.node.Node; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.test.junit.annotations.TestLogging; import org.elasticsearch.test.transport.MockTransportService; @@ -127,7 +128,7 @@ public abstract class AbstractSimpleTransportTestCase extends ESTestCase { private MockTransportService buildService(final String name, final Version version) { MockTransportService service = build( Settings.builder() - .put("name", name) + .put(Node.NODE_NAME_SETTING.getKey(), name) .put(TransportService.TRACE_LOG_INCLUDE_SETTING.getKey(), "") .put(TransportService.TRACE_LOG_EXCLUDE_SETTING.getKey(), "NOTHING") .build(), @@ -488,7 +489,9 @@ public abstract class AbstractSimpleTransportTestCase extends ESTestCase { assertThat(latch.await(5, TimeUnit.SECONDS), equalTo(true)); } - @TestLogging("transport:DEBUG") + @TestLogging("transport:DEBUG,transport.tracer:TRACE") + // boaz is on this + @AwaitsFix(bugUrl = "https://elasticsearch-ci.elastic.co/job/elastic+elasticsearch+master+multijob-os-compatibility/os=oraclelinux/835") public void testConcurrentSendRespondAndDisconnect() throws BrokenBarrierException, InterruptedException { Set sendingErrors = ConcurrentCollections.newConcurrentSet(); Set responseErrors = ConcurrentCollections.newConcurrentSet(); @@ -506,7 +509,7 @@ public abstract class AbstractSimpleTransportTestCase extends ESTestCase { channel.sendResponse(new TestResponse()); } catch (Exception e) { // we don't really care what's going on B, we're testing through A - logger.trace("caught exception while res ponding from node B", e); + logger.trace("caught exception while responding from node B", e); } }; serviceB.registerRequestHandler("test", TestRequest::new, ThreadPool.Names.SAME, ignoringRequestHandler); @@ -587,10 +590,10 @@ public abstract class AbstractSimpleTransportTestCase extends ESTestCase { if (i % 3 == 0) { // simulate restart of nodeB serviceB.close(); - MockTransportService newService = buildService("TS_B", version1); + MockTransportService newService = buildService("TS_B_" + i, version1); newService.registerRequestHandler("test", TestRequest::new, ThreadPool.Names.SAME, ignoringRequestHandler); serviceB = newService; - nodeB = new DiscoveryNode("TS_B", serviceB.boundAddress().publishAddress(), emptyMap(), emptySet(), version1); + nodeB = new DiscoveryNode("TS_B_" + i, "TS_B", serviceB.boundAddress().publishAddress(), emptyMap(), emptySet(), version1); serviceB.connectToNode(nodeA); serviceA.connectToNode(nodeB); } else if (serviceA.nodeConnected(nodeB)) { @@ -787,7 +790,7 @@ public abstract class AbstractSimpleTransportTestCase extends ESTestCase { assertTrue(inFlight.tryAcquire(Integer.MAX_VALUE, 10, TimeUnit.SECONDS)); } - @TestLogging(value = "test. transport.tracer:TRACE") + @TestLogging(value = "test.transport.tracer:TRACE") public void testTracerLog() throws InterruptedException { TransportRequestHandler handler = new TransportRequestHandler() { @Override diff --git a/test/framework/src/main/java/org/elasticsearch/transport/MockTcpTransport.java b/test/framework/src/main/java/org/elasticsearch/transport/MockTcpTransport.java index 44a2bbd2166..c128ee49022 100644 --- a/test/framework/src/main/java/org/elasticsearch/transport/MockTcpTransport.java +++ b/test/framework/src/main/java/org/elasticsearch/transport/MockTcpTransport.java @@ -43,7 +43,6 @@ import java.io.BufferedOutputStream; import java.io.Closeable; import java.io.IOException; import java.io.OutputStream; -import java.io.UncheckedIOException; import java.net.InetSocketAddress; import java.net.ServerSocket; import java.net.Socket; diff --git a/test/framework/src/test/java/org/elasticsearch/test/rest/BlacklistedPathPatternMatcherTests.java b/test/framework/src/test/java/org/elasticsearch/test/rest/yaml/BlacklistedPathPatternMatcherTests.java similarity index 97% rename from test/framework/src/test/java/org/elasticsearch/test/rest/BlacklistedPathPatternMatcherTests.java rename to test/framework/src/test/java/org/elasticsearch/test/rest/yaml/BlacklistedPathPatternMatcherTests.java index 9414a2219cf..a58a70111c2 100644 --- a/test/framework/src/test/java/org/elasticsearch/test/rest/BlacklistedPathPatternMatcherTests.java +++ b/test/framework/src/test/java/org/elasticsearch/test/rest/yaml/BlacklistedPathPatternMatcherTests.java @@ -16,10 +16,11 @@ * specific language governing permissions and limitations * under the License. */ -package org.elasticsearch.test.rest; +package org.elasticsearch.test.rest.yaml; import org.elasticsearch.test.ESTestCase; +import org.elasticsearch.test.rest.yaml.BlacklistedPathPatternMatcher; public class BlacklistedPathPatternMatcherTests extends ESTestCase { diff --git a/test/framework/src/test/java/org/elasticsearch/test/rest/test/ObjectPathTests.java b/test/framework/src/test/java/org/elasticsearch/test/rest/yaml/ObjectPathTests.java similarity index 98% rename from test/framework/src/test/java/org/elasticsearch/test/rest/test/ObjectPathTests.java rename to test/framework/src/test/java/org/elasticsearch/test/rest/yaml/ObjectPathTests.java index 1d99a73c767..5559fd3f385 100644 --- a/test/framework/src/test/java/org/elasticsearch/test/rest/test/ObjectPathTests.java +++ b/test/framework/src/test/java/org/elasticsearch/test/rest/yaml/ObjectPathTests.java @@ -16,14 +16,14 @@ * specific language governing permissions and limitations * under the License. */ -package org.elasticsearch.test.rest.test; +package org.elasticsearch.test.rest.yaml; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.test.ESTestCase; -import org.elasticsearch.test.rest.ObjectPath; -import org.elasticsearch.test.rest.Stash; +import org.elasticsearch.test.rest.yaml.ObjectPath; +import org.elasticsearch.test.rest.yaml.Stash; import java.io.IOException; import java.util.HashMap; diff --git a/test/framework/src/test/java/org/elasticsearch/test/rest/test/StashTests.java b/test/framework/src/test/java/org/elasticsearch/test/rest/yaml/StashTests.java similarity index 94% rename from test/framework/src/test/java/org/elasticsearch/test/rest/test/StashTests.java rename to test/framework/src/test/java/org/elasticsearch/test/rest/yaml/StashTests.java index 7d0c0598f09..a8d32a316ac 100644 --- a/test/framework/src/test/java/org/elasticsearch/test/rest/test/StashTests.java +++ b/test/framework/src/test/java/org/elasticsearch/test/rest/yaml/StashTests.java @@ -17,10 +17,10 @@ * under the License. */ -package org.elasticsearch.test.rest.test; +package org.elasticsearch.test.rest.yaml; import org.elasticsearch.test.ESTestCase; -import org.elasticsearch.test.rest.Stash; +import org.elasticsearch.test.rest.yaml.Stash; import java.io.IOException; import java.util.HashMap; diff --git a/test/framework/src/test/java/org/elasticsearch/test/rest/test/AbstractParserTestCase.java b/test/framework/src/test/java/org/elasticsearch/test/rest/yaml/parser/AbstractParserTestCase.java similarity index 96% rename from test/framework/src/test/java/org/elasticsearch/test/rest/test/AbstractParserTestCase.java rename to test/framework/src/test/java/org/elasticsearch/test/rest/yaml/parser/AbstractParserTestCase.java index 2a925dd2586..7d32389ddba 100644 --- a/test/framework/src/test/java/org/elasticsearch/test/rest/test/AbstractParserTestCase.java +++ b/test/framework/src/test/java/org/elasticsearch/test/rest/yaml/parser/AbstractParserTestCase.java @@ -17,7 +17,7 @@ * under the License. */ -package org.elasticsearch.test.rest.test; +package org.elasticsearch.test.rest.yaml.parser; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.test.ESTestCase; diff --git a/test/framework/src/test/java/org/elasticsearch/test/rest/test/AssertionParsersTests.java b/test/framework/src/test/java/org/elasticsearch/test/rest/yaml/parser/AssertionParsersTests.java similarity index 78% rename from test/framework/src/test/java/org/elasticsearch/test/rest/test/AssertionParsersTests.java rename to test/framework/src/test/java/org/elasticsearch/test/rest/yaml/parser/AssertionParsersTests.java index 68b84b99639..4e382fb7b09 100644 --- a/test/framework/src/test/java/org/elasticsearch/test/rest/test/AssertionParsersTests.java +++ b/test/framework/src/test/java/org/elasticsearch/test/rest/yaml/parser/AssertionParsersTests.java @@ -16,22 +16,22 @@ * specific language governing permissions and limitations * under the License. */ -package org.elasticsearch.test.rest.test; +package org.elasticsearch.test.rest.yaml.parser; import org.elasticsearch.common.xcontent.yaml.YamlXContent; -import org.elasticsearch.test.rest.parser.GreaterThanParser; -import org.elasticsearch.test.rest.parser.IsFalseParser; -import org.elasticsearch.test.rest.parser.IsTrueParser; -import org.elasticsearch.test.rest.parser.LengthParser; -import org.elasticsearch.test.rest.parser.LessThanParser; -import org.elasticsearch.test.rest.parser.MatchParser; -import org.elasticsearch.test.rest.parser.RestTestSuiteParseContext; -import org.elasticsearch.test.rest.section.GreaterThanAssertion; -import org.elasticsearch.test.rest.section.IsFalseAssertion; -import org.elasticsearch.test.rest.section.IsTrueAssertion; -import org.elasticsearch.test.rest.section.LengthAssertion; -import org.elasticsearch.test.rest.section.LessThanAssertion; -import org.elasticsearch.test.rest.section.MatchAssertion; +import org.elasticsearch.test.rest.yaml.parser.GreaterThanParser; +import org.elasticsearch.test.rest.yaml.parser.IsFalseParser; +import org.elasticsearch.test.rest.yaml.parser.IsTrueParser; +import org.elasticsearch.test.rest.yaml.parser.LengthParser; +import org.elasticsearch.test.rest.yaml.parser.LessThanParser; +import org.elasticsearch.test.rest.yaml.parser.MatchParser; +import org.elasticsearch.test.rest.yaml.parser.ClientYamlTestSuiteParseContext; +import org.elasticsearch.test.rest.yaml.section.GreaterThanAssertion; +import org.elasticsearch.test.rest.yaml.section.IsFalseAssertion; +import org.elasticsearch.test.rest.yaml.section.IsTrueAssertion; +import org.elasticsearch.test.rest.yaml.section.LengthAssertion; +import org.elasticsearch.test.rest.yaml.section.LessThanAssertion; +import org.elasticsearch.test.rest.yaml.section.MatchAssertion; import java.util.List; import java.util.Map; @@ -47,7 +47,7 @@ public class AssertionParsersTests extends AbstractParserTestCase { ); IsTrueParser isTrueParser = new IsTrueParser(); - IsTrueAssertion trueAssertion = isTrueParser.parse(new RestTestSuiteParseContext("api", "suite", parser)); + IsTrueAssertion trueAssertion = isTrueParser.parse(new ClientYamlTestSuiteParseContext("api", "suite", parser)); assertThat(trueAssertion, notNullValue()); assertThat(trueAssertion.getField(), equalTo("get.fields._timestamp")); @@ -59,7 +59,7 @@ public class AssertionParsersTests extends AbstractParserTestCase { ); IsFalseParser isFalseParser = new IsFalseParser(); - IsFalseAssertion falseAssertion = isFalseParser.parse(new RestTestSuiteParseContext("api", "suite", parser)); + IsFalseAssertion falseAssertion = isFalseParser.parse(new ClientYamlTestSuiteParseContext("api", "suite", parser)); assertThat(falseAssertion, notNullValue()); assertThat(falseAssertion.getField(), equalTo("docs.1._source")); @@ -71,7 +71,7 @@ public class AssertionParsersTests extends AbstractParserTestCase { ); GreaterThanParser greaterThanParser = new GreaterThanParser(); - GreaterThanAssertion greaterThanAssertion = greaterThanParser.parse(new RestTestSuiteParseContext("api", "suite", parser)); + GreaterThanAssertion greaterThanAssertion = greaterThanParser.parse(new ClientYamlTestSuiteParseContext("api", "suite", parser)); assertThat(greaterThanAssertion, notNullValue()); assertThat(greaterThanAssertion.getField(), equalTo("field")); assertThat(greaterThanAssertion.getExpectedValue(), instanceOf(Integer.class)); @@ -84,7 +84,7 @@ public class AssertionParsersTests extends AbstractParserTestCase { ); LessThanParser lessThanParser = new LessThanParser(); - LessThanAssertion lessThanAssertion = lessThanParser.parse(new RestTestSuiteParseContext("api", "suite", parser)); + LessThanAssertion lessThanAssertion = lessThanParser.parse(new ClientYamlTestSuiteParseContext("api", "suite", parser)); assertThat(lessThanAssertion, notNullValue()); assertThat(lessThanAssertion.getField(), equalTo("field")); assertThat(lessThanAssertion.getExpectedValue(), instanceOf(Integer.class)); @@ -97,7 +97,7 @@ public class AssertionParsersTests extends AbstractParserTestCase { ); LengthParser lengthParser = new LengthParser(); - LengthAssertion lengthAssertion = lengthParser.parse(new RestTestSuiteParseContext("api", "suite", parser)); + LengthAssertion lengthAssertion = lengthParser.parse(new ClientYamlTestSuiteParseContext("api", "suite", parser)); assertThat(lengthAssertion, notNullValue()); assertThat(lengthAssertion.getField(), equalTo("_id")); assertThat(lengthAssertion.getExpectedValue(), instanceOf(Integer.class)); @@ -110,7 +110,7 @@ public class AssertionParsersTests extends AbstractParserTestCase { ); MatchParser matchParser = new MatchParser(); - MatchAssertion matchAssertion = matchParser.parse(new RestTestSuiteParseContext("api", "suite", parser)); + MatchAssertion matchAssertion = matchParser.parse(new ClientYamlTestSuiteParseContext("api", "suite", parser)); assertThat(matchAssertion, notNullValue()); assertThat(matchAssertion.getField(), equalTo("field")); @@ -124,7 +124,7 @@ public class AssertionParsersTests extends AbstractParserTestCase { ); MatchParser matchParser = new MatchParser(); - MatchAssertion matchAssertion = matchParser.parse(new RestTestSuiteParseContext("api", "suite", parser)); + MatchAssertion matchAssertion = matchParser.parse(new ClientYamlTestSuiteParseContext("api", "suite", parser)); assertThat(matchAssertion, notNullValue()); assertThat(matchAssertion.getField(), equalTo("foo")); @@ -138,7 +138,7 @@ public class AssertionParsersTests extends AbstractParserTestCase { ); MatchParser matchParser = new MatchParser(); - MatchAssertion matchAssertion = matchParser.parse(new RestTestSuiteParseContext("api", "suite", parser)); + MatchAssertion matchAssertion = matchParser.parse(new ClientYamlTestSuiteParseContext("api", "suite", parser)); assertThat(matchAssertion, notNullValue()); assertThat(matchAssertion.getField(), equalTo("matches")); @@ -156,7 +156,7 @@ public class AssertionParsersTests extends AbstractParserTestCase { ); MatchParser matchParser = new MatchParser(); - MatchAssertion matchAssertion = matchParser.parse(new RestTestSuiteParseContext("api", "suite", parser)); + MatchAssertion matchAssertion = matchParser.parse(new ClientYamlTestSuiteParseContext("api", "suite", parser)); assertThat(matchAssertion, notNullValue()); assertThat(matchAssertion.getField(), equalTo("_source")); diff --git a/test/framework/src/test/java/org/elasticsearch/test/rest/test/RestTestParserTests.java b/test/framework/src/test/java/org/elasticsearch/test/rest/yaml/parser/ClientYamlSuiteTestParserTests.java similarity index 94% rename from test/framework/src/test/java/org/elasticsearch/test/rest/test/RestTestParserTests.java rename to test/framework/src/test/java/org/elasticsearch/test/rest/yaml/parser/ClientYamlSuiteTestParserTests.java index 6b5cc3defb7..3b7313ec221 100644 --- a/test/framework/src/test/java/org/elasticsearch/test/rest/test/RestTestParserTests.java +++ b/test/framework/src/test/java/org/elasticsearch/test/rest/yaml/parser/ClientYamlSuiteTestParserTests.java @@ -16,19 +16,19 @@ * specific language governing permissions and limitations * under the License. */ -package org.elasticsearch.test.rest.test; +package org.elasticsearch.test.rest.yaml.parser; import org.elasticsearch.Version; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.yaml.YamlXContent; import org.elasticsearch.test.ESTestCase; -import org.elasticsearch.test.rest.parser.RestTestParseException; -import org.elasticsearch.test.rest.parser.RestTestSuiteParseContext; -import org.elasticsearch.test.rest.parser.RestTestSuiteParser; -import org.elasticsearch.test.rest.section.DoSection; -import org.elasticsearch.test.rest.section.IsTrueAssertion; -import org.elasticsearch.test.rest.section.MatchAssertion; -import org.elasticsearch.test.rest.section.RestTestSuite; +import org.elasticsearch.test.rest.yaml.parser.ClientYamlTestParseException; +import org.elasticsearch.test.rest.yaml.parser.ClientYamlTestSuiteParseContext; +import org.elasticsearch.test.rest.yaml.parser.ClientYamlTestSuiteParser; +import org.elasticsearch.test.rest.yaml.section.ClientYamlTestSuite; +import org.elasticsearch.test.rest.yaml.section.DoSection; +import org.elasticsearch.test.rest.yaml.section.IsTrueAssertion; +import org.elasticsearch.test.rest.yaml.section.MatchAssertion; import org.junit.After; import java.util.Map; @@ -39,7 +39,7 @@ import static org.hamcrest.Matchers.instanceOf; import static org.hamcrest.Matchers.notNullValue; import static org.hamcrest.Matchers.nullValue; -public class RestTestParserTests extends ESTestCase { +public class ClientYamlSuiteTestParserTests extends ESTestCase { private XContentParser parser; @Override @@ -103,8 +103,8 @@ public class RestTestParserTests extends ESTestCase { " - match: {test_type.properties.text.analyzer: whitespace}\n" ); - RestTestSuiteParser testParser = new RestTestSuiteParser(); - RestTestSuite restTestSuite = testParser.parse(new RestTestSuiteParseContext("api", "suite", parser)); + ClientYamlTestSuiteParser testParser = new ClientYamlTestSuiteParser(); + ClientYamlTestSuite restTestSuite = testParser.parse(new ClientYamlTestSuiteParseContext("api", "suite", parser)); assertThat(restTestSuite, notNullValue()); assertThat(restTestSuite.getName(), equalTo("suite")); @@ -207,8 +207,8 @@ public class RestTestParserTests extends ESTestCase { " - match: { _source: { foo: bar }}" ); - RestTestSuiteParser testParser = new RestTestSuiteParser(); - RestTestSuite restTestSuite = testParser.parse(new RestTestSuiteParseContext("api", "suite", parser)); + ClientYamlTestSuiteParser testParser = new ClientYamlTestSuiteParser(); + ClientYamlTestSuite restTestSuite = testParser.parse(new ClientYamlTestSuiteParseContext("api", "suite", parser)); assertThat(restTestSuite, notNullValue()); assertThat(restTestSuite.getName(), equalTo("suite")); @@ -320,8 +320,8 @@ public class RestTestParserTests extends ESTestCase { " params: { bar: 'xxx' }\n" ); - RestTestSuiteParser testParser = new RestTestSuiteParser(); - RestTestSuite restTestSuite = testParser.parse(new RestTestSuiteParseContext("api", "suite", parser)); + ClientYamlTestSuiteParser testParser = new ClientYamlTestSuiteParser(); + ClientYamlTestSuite restTestSuite = testParser.parse(new ClientYamlTestSuiteParseContext("api", "suite", parser)); assertThat(restTestSuite, notNullValue()); assertThat(restTestSuite.getName(), equalTo("suite")); @@ -394,11 +394,11 @@ public class RestTestParserTests extends ESTestCase { "\n" ); - RestTestSuiteParser testParser = new RestTestSuiteParser(); + ClientYamlTestSuiteParser testParser = new ClientYamlTestSuiteParser(); try { - testParser.parse(new RestTestSuiteParseContext("api", "suite", parser)); + testParser.parse(new ClientYamlTestSuiteParseContext("api", "suite", parser)); fail("Expected RestTestParseException"); - } catch (RestTestParseException e) { + } catch (ClientYamlTestParseException e) { assertThat(e.getMessage(), containsString("duplicate test section")); } } diff --git a/test/framework/src/test/java/org/elasticsearch/test/rest/test/DoSectionParserTests.java b/test/framework/src/test/java/org/elasticsearch/test/rest/yaml/parser/DoSectionParserTests.java similarity index 89% rename from test/framework/src/test/java/org/elasticsearch/test/rest/test/DoSectionParserTests.java rename to test/framework/src/test/java/org/elasticsearch/test/rest/yaml/parser/DoSectionParserTests.java index 655d3071d63..5d79432155f 100644 --- a/test/framework/src/test/java/org/elasticsearch/test/rest/test/DoSectionParserTests.java +++ b/test/framework/src/test/java/org/elasticsearch/test/rest/yaml/parser/DoSectionParserTests.java @@ -16,16 +16,16 @@ * specific language governing permissions and limitations * under the License. */ -package org.elasticsearch.test.rest.test; +package org.elasticsearch.test.rest.yaml.parser; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.json.JsonXContent; import org.elasticsearch.common.xcontent.yaml.YamlXContent; -import org.elasticsearch.test.rest.parser.DoSectionParser; -import org.elasticsearch.test.rest.parser.RestTestParseException; -import org.elasticsearch.test.rest.parser.RestTestSuiteParseContext; -import org.elasticsearch.test.rest.section.ApiCallSection; -import org.elasticsearch.test.rest.section.DoSection; +import org.elasticsearch.test.rest.yaml.parser.DoSectionParser; +import org.elasticsearch.test.rest.yaml.parser.ClientYamlTestParseException; +import org.elasticsearch.test.rest.yaml.parser.ClientYamlTestSuiteParseContext; +import org.elasticsearch.test.rest.yaml.section.ApiCallSection; +import org.elasticsearch.test.rest.yaml.section.DoSection; import org.hamcrest.MatcherAssert; import java.io.IOException; @@ -46,7 +46,7 @@ public class DoSectionParserTests extends AbstractParserTestCase { ); DoSectionParser doSectionParser = new DoSectionParser(); - DoSection doSection = doSectionParser.parse(new RestTestSuiteParseContext("api", "suite", parser)); + DoSection doSection = doSectionParser.parse(new ClientYamlTestSuiteParseContext("api", "suite", parser)); ApiCallSection apiCallSection = doSection.getApiCallSection(); assertThat(apiCallSection, notNullValue()); @@ -64,7 +64,7 @@ public class DoSectionParserTests extends AbstractParserTestCase { ); DoSectionParser doSectionParser = new DoSectionParser(); - DoSection doSection = doSectionParser.parse(new RestTestSuiteParseContext("api", "suite", parser)); + DoSection doSection = doSectionParser.parse(new ClientYamlTestSuiteParseContext("api", "suite", parser)); ApiCallSection apiCallSection = doSection.getApiCallSection(); assertThat(apiCallSection, notNullValue()); @@ -84,7 +84,7 @@ public class DoSectionParserTests extends AbstractParserTestCase { ); DoSectionParser doSectionParser = new DoSectionParser(); - DoSection doSection = doSectionParser.parse(new RestTestSuiteParseContext("api", "suite", parser)); + DoSection doSection = doSectionParser.parse(new ClientYamlTestSuiteParseContext("api", "suite", parser)); ApiCallSection apiCallSection = doSection.getApiCallSection(); assertThat(apiCallSection, notNullValue()); @@ -116,7 +116,7 @@ public class DoSectionParserTests extends AbstractParserTestCase { ); DoSectionParser doSectionParser = new DoSectionParser(); - DoSection doSection = doSectionParser.parse(new RestTestSuiteParseContext("api", "suite", parser)); + DoSection doSection = doSectionParser.parse(new ClientYamlTestSuiteParseContext("api", "suite", parser)); ApiCallSection apiCallSection = doSection.getApiCallSection(); assertThat(apiCallSection, notNullValue()); @@ -142,7 +142,7 @@ public class DoSectionParserTests extends AbstractParserTestCase { ); DoSectionParser doSectionParser = new DoSectionParser(); - DoSection doSection = doSectionParser.parse(new RestTestSuiteParseContext("api", "suite", parser)); + DoSection doSection = doSectionParser.parse(new ClientYamlTestSuiteParseContext("api", "suite", parser)); ApiCallSection apiCallSection = doSection.getApiCallSection(); assertThat(apiCallSection, notNullValue()); @@ -166,7 +166,7 @@ public class DoSectionParserTests extends AbstractParserTestCase { String body = "{ \"_source\": [ \"include.field1\", \"include.field2\" ], \"query\": { \"match_all\": {} }}"; DoSectionParser doSectionParser = new DoSectionParser(); - DoSection doSection = doSectionParser.parse(new RestTestSuiteParseContext("api", "suite", parser)); + DoSection doSection = doSectionParser.parse(new ClientYamlTestSuiteParseContext("api", "suite", parser)); ApiCallSection apiCallSection = doSection.getApiCallSection(); assertThat(apiCallSection, notNullValue()); @@ -202,7 +202,7 @@ public class DoSectionParserTests extends AbstractParserTestCase { bodies[3] = "{ \"f1\":\"v2\", \"f2\": 47 }"; DoSectionParser doSectionParser = new DoSectionParser(); - DoSection doSection = doSectionParser.parse(new RestTestSuiteParseContext("api", "suite", parser)); + DoSection doSection = doSectionParser.parse(new ClientYamlTestSuiteParseContext("api", "suite", parser)); ApiCallSection apiCallSection = doSection.getApiCallSection(); assertThat(apiCallSection, notNullValue()); @@ -235,7 +235,7 @@ public class DoSectionParserTests extends AbstractParserTestCase { bodies[1] = "{ \"f1\":\"v1\", \"f2\": 42 }"; DoSectionParser doSectionParser = new DoSectionParser(); - DoSection doSection = doSectionParser.parse(new RestTestSuiteParseContext("api", "suite", parser)); + DoSection doSection = doSectionParser.parse(new ClientYamlTestSuiteParseContext("api", "suite", parser)); ApiCallSection apiCallSection = doSection.getApiCallSection(); assertThat(apiCallSection, notNullValue()); @@ -264,7 +264,7 @@ public class DoSectionParserTests extends AbstractParserTestCase { "]}"; DoSectionParser doSectionParser = new DoSectionParser(); - DoSection doSection = doSectionParser.parse(new RestTestSuiteParseContext("api", "suite", parser)); + DoSection doSection = doSectionParser.parse(new ClientYamlTestSuiteParseContext("api", "suite", parser)); ApiCallSection apiCallSection = doSection.getApiCallSection(); assertThat(apiCallSection, notNullValue()); @@ -285,7 +285,7 @@ public class DoSectionParserTests extends AbstractParserTestCase { ); DoSectionParser doSectionParser = new DoSectionParser(); - DoSection doSection = doSectionParser.parse(new RestTestSuiteParseContext("api", "suite", parser)); + DoSection doSection = doSectionParser.parse(new ClientYamlTestSuiteParseContext("api", "suite", parser)); ApiCallSection apiCallSection = doSection.getApiCallSection(); assertThat(apiCallSection, notNullValue()); @@ -311,7 +311,7 @@ public class DoSectionParserTests extends AbstractParserTestCase { String body = "{ \"size\": 100, \"query\": { \"match_all\": {} } }"; DoSectionParser doSectionParser = new DoSectionParser(); - DoSection doSection = doSectionParser.parse(new RestTestSuiteParseContext("api", "suite", parser)); + DoSection doSection = doSectionParser.parse(new ClientYamlTestSuiteParseContext("api", "suite", parser)); ApiCallSection apiCallSection = doSection.getApiCallSection(); assertThat(apiCallSection.getApi(), equalTo("index")); @@ -332,7 +332,7 @@ public class DoSectionParserTests extends AbstractParserTestCase { ); DoSectionParser doSectionParser = new DoSectionParser(); - DoSection doSection = doSectionParser.parse(new RestTestSuiteParseContext("api", "suite", parser)); + DoSection doSection = doSectionParser.parse(new ClientYamlTestSuiteParseContext("api", "suite", parser)); assertThat(doSection.getCatch(), equalTo("missing")); assertThat(doSection.getApiCallSection(), notNullValue()); @@ -352,7 +352,7 @@ public class DoSectionParserTests extends AbstractParserTestCase { ); DoSectionParser doSectionParser = new DoSectionParser(); - DoSection doSection = doSectionParser.parse(new RestTestSuiteParseContext("api", "suite", parser)); + DoSection doSection = doSectionParser.parse(new ClientYamlTestSuiteParseContext("api", "suite", parser)); assertThat(doSection.getApiCallSection(), notNullValue()); assertThat(doSection.getApiCallSection().getApi(), equalTo("indices.get_warmer")); @@ -371,9 +371,9 @@ public class DoSectionParserTests extends AbstractParserTestCase { DoSectionParser doSectionParser = new DoSectionParser(); try { - doSectionParser.parse(new RestTestSuiteParseContext("api", "suite", parser)); + doSectionParser.parse(new ClientYamlTestSuiteParseContext("api", "suite", parser)); fail("Expected RestTestParseException"); - } catch (RestTestParseException e) { + } catch (ClientYamlTestParseException e) { assertThat(e.getMessage(), is("client call section is mandatory within a do section")); } } @@ -387,7 +387,7 @@ public class DoSectionParserTests extends AbstractParserTestCase { ); DoSectionParser doSectionParser = new DoSectionParser(); - DoSection doSection = doSectionParser.parse(new RestTestSuiteParseContext("api", "suite", parser)); + DoSection doSection = doSectionParser.parse(new ClientYamlTestSuiteParseContext("api", "suite", parser)); assertThat(doSection.getCatch(), nullValue()); assertThat(doSection.getApiCallSection(), notNullValue()); diff --git a/test/framework/src/test/java/org/elasticsearch/test/rest/test/SetSectionParserTests.java b/test/framework/src/test/java/org/elasticsearch/test/rest/yaml/parser/SetSectionParserTests.java similarity index 78% rename from test/framework/src/test/java/org/elasticsearch/test/rest/test/SetSectionParserTests.java rename to test/framework/src/test/java/org/elasticsearch/test/rest/yaml/parser/SetSectionParserTests.java index c2b66375664..386cdd6deb4 100644 --- a/test/framework/src/test/java/org/elasticsearch/test/rest/test/SetSectionParserTests.java +++ b/test/framework/src/test/java/org/elasticsearch/test/rest/yaml/parser/SetSectionParserTests.java @@ -16,13 +16,13 @@ * specific language governing permissions and limitations * under the License. */ -package org.elasticsearch.test.rest.test; +package org.elasticsearch.test.rest.yaml.parser; import org.elasticsearch.common.xcontent.yaml.YamlXContent; -import org.elasticsearch.test.rest.parser.RestTestParseException; -import org.elasticsearch.test.rest.parser.RestTestSuiteParseContext; -import org.elasticsearch.test.rest.parser.SetSectionParser; -import org.elasticsearch.test.rest.section.SetSection; +import org.elasticsearch.test.rest.yaml.parser.ClientYamlTestParseException; +import org.elasticsearch.test.rest.yaml.parser.ClientYamlTestSuiteParseContext; +import org.elasticsearch.test.rest.yaml.parser.SetSectionParser; +import org.elasticsearch.test.rest.yaml.section.SetSection; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.is; @@ -36,7 +36,7 @@ public class SetSectionParserTests extends AbstractParserTestCase { SetSectionParser setSectionParser = new SetSectionParser(); - SetSection setSection = setSectionParser.parse(new RestTestSuiteParseContext("api", "suite", parser)); + SetSection setSection = setSectionParser.parse(new ClientYamlTestSuiteParseContext("api", "suite", parser)); assertThat(setSection, notNullValue()); assertThat(setSection.getStash(), notNullValue()); @@ -51,7 +51,7 @@ public class SetSectionParserTests extends AbstractParserTestCase { SetSectionParser setSectionParser = new SetSectionParser(); - SetSection setSection = setSectionParser.parse(new RestTestSuiteParseContext("api", "suite", parser)); + SetSection setSection = setSectionParser.parse(new ClientYamlTestSuiteParseContext("api", "suite", parser)); assertThat(setSection, notNullValue()); assertThat(setSection.getStash(), notNullValue()); @@ -68,9 +68,9 @@ public class SetSectionParserTests extends AbstractParserTestCase { SetSectionParser setSectionParser = new SetSectionParser(); try { - setSectionParser.parse(new RestTestSuiteParseContext("api", "suite", parser)); + setSectionParser.parse(new ClientYamlTestSuiteParseContext("api", "suite", parser)); fail("Expected RestTestParseException"); - } catch (RestTestParseException e) { + } catch (ClientYamlTestParseException e) { assertThat(e.getMessage(), is("set section must set at least a value")); } } diff --git a/test/framework/src/test/java/org/elasticsearch/test/rest/test/SetupSectionParserTests.java b/test/framework/src/test/java/org/elasticsearch/test/rest/yaml/parser/SetupSectionParserTests.java similarity index 92% rename from test/framework/src/test/java/org/elasticsearch/test/rest/test/SetupSectionParserTests.java rename to test/framework/src/test/java/org/elasticsearch/test/rest/yaml/parser/SetupSectionParserTests.java index b3fe1f0f23b..fa7c34eecde 100644 --- a/test/framework/src/test/java/org/elasticsearch/test/rest/test/SetupSectionParserTests.java +++ b/test/framework/src/test/java/org/elasticsearch/test/rest/yaml/parser/SetupSectionParserTests.java @@ -16,13 +16,13 @@ * specific language governing permissions and limitations * under the License. */ -package org.elasticsearch.test.rest.test; +package org.elasticsearch.test.rest.yaml.parser; import org.elasticsearch.Version; import org.elasticsearch.common.xcontent.yaml.YamlXContent; -import org.elasticsearch.test.rest.parser.RestTestSuiteParseContext; -import org.elasticsearch.test.rest.parser.SetupSectionParser; -import org.elasticsearch.test.rest.section.SetupSection; +import org.elasticsearch.test.rest.yaml.parser.ClientYamlTestSuiteParseContext; +import org.elasticsearch.test.rest.yaml.parser.SetupSectionParser; +import org.elasticsearch.test.rest.yaml.section.SetupSection; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.notNullValue; @@ -45,7 +45,7 @@ public class SetupSectionParserTests extends AbstractParserTestCase { ); SetupSectionParser setupSectionParser = new SetupSectionParser(); - SetupSection setupSection = setupSectionParser.parse(new RestTestSuiteParseContext("api", "suite", parser)); + SetupSection setupSection = setupSectionParser.parse(new ClientYamlTestSuiteParseContext("api", "suite", parser)); assertThat(setupSection, notNullValue()); assertThat(setupSection.getSkipSection().isEmpty(), equalTo(true)); @@ -74,7 +74,7 @@ public class SetupSectionParserTests extends AbstractParserTestCase { ); SetupSectionParser setupSectionParser = new SetupSectionParser(); - SetupSection setupSection = setupSectionParser.parse(new RestTestSuiteParseContext("api", "suite", parser)); + SetupSection setupSection = setupSectionParser.parse(new ClientYamlTestSuiteParseContext("api", "suite", parser)); assertThat(setupSection, notNullValue()); assertThat(setupSection.getSkipSection().isEmpty(), equalTo(false)); diff --git a/test/framework/src/test/java/org/elasticsearch/test/rest/test/SkipSectionParserTests.java b/test/framework/src/test/java/org/elasticsearch/test/rest/yaml/parser/SkipSectionParserTests.java similarity index 80% rename from test/framework/src/test/java/org/elasticsearch/test/rest/test/SkipSectionParserTests.java rename to test/framework/src/test/java/org/elasticsearch/test/rest/yaml/parser/SkipSectionParserTests.java index 39b0f284b5e..f5d46cdd3d6 100644 --- a/test/framework/src/test/java/org/elasticsearch/test/rest/test/SkipSectionParserTests.java +++ b/test/framework/src/test/java/org/elasticsearch/test/rest/yaml/parser/SkipSectionParserTests.java @@ -16,15 +16,15 @@ * specific language governing permissions and limitations * under the License. */ -package org.elasticsearch.test.rest.test; +package org.elasticsearch.test.rest.yaml.parser; import org.elasticsearch.Version; import org.elasticsearch.common.xcontent.yaml.YamlXContent; import org.elasticsearch.test.VersionUtils; -import org.elasticsearch.test.rest.parser.RestTestParseException; -import org.elasticsearch.test.rest.parser.RestTestSuiteParseContext; -import org.elasticsearch.test.rest.parser.SkipSectionParser; -import org.elasticsearch.test.rest.section.SkipSection; +import org.elasticsearch.test.rest.yaml.parser.ClientYamlTestParseException; +import org.elasticsearch.test.rest.yaml.parser.ClientYamlTestSuiteParseContext; +import org.elasticsearch.test.rest.yaml.parser.SkipSectionParser; +import org.elasticsearch.test.rest.yaml.section.SkipSection; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.is; @@ -40,7 +40,7 @@ public class SkipSectionParserTests extends AbstractParserTestCase { SkipSectionParser skipSectionParser = new SkipSectionParser(); - SkipSection skipSection = skipSectionParser.parse(new RestTestSuiteParseContext("api", "suite", parser)); + SkipSection skipSection = skipSectionParser.parse(new ClientYamlTestSuiteParseContext("api", "suite", parser)); assertThat(skipSection, notNullValue()); assertThat(skipSection.getLowerVersion(), equalTo(VersionUtils.getFirstVersion())); @@ -57,7 +57,7 @@ public class SkipSectionParserTests extends AbstractParserTestCase { SkipSectionParser skipSectionParser = new SkipSectionParser(); - SkipSection skipSection = skipSectionParser.parse(new RestTestSuiteParseContext("api", "suite", parser)); + SkipSection skipSection = skipSectionParser.parse(new ClientYamlTestSuiteParseContext("api", "suite", parser)); assertThat(skipSection, notNullValue()); assertThat(skipSection.getLowerVersion(), equalTo(VersionUtils.getFirstVersion())); @@ -73,7 +73,7 @@ public class SkipSectionParserTests extends AbstractParserTestCase { SkipSectionParser skipSectionParser = new SkipSectionParser(); - SkipSection skipSection = skipSectionParser.parse(new RestTestSuiteParseContext("api", "suite", parser)); + SkipSection skipSection = skipSectionParser.parse(new ClientYamlTestSuiteParseContext("api", "suite", parser)); assertThat(skipSection, notNullValue()); assertThat(skipSection.isVersionCheck(), equalTo(false)); @@ -89,7 +89,7 @@ public class SkipSectionParserTests extends AbstractParserTestCase { SkipSectionParser skipSectionParser = new SkipSectionParser(); - SkipSection skipSection = skipSectionParser.parse(new RestTestSuiteParseContext("api", "suite", parser)); + SkipSection skipSection = skipSectionParser.parse(new ClientYamlTestSuiteParseContext("api", "suite", parser)); assertThat(skipSection, notNullValue()); assertThat(skipSection.isVersionCheck(), equalTo(false)); @@ -110,9 +110,9 @@ public class SkipSectionParserTests extends AbstractParserTestCase { SkipSectionParser skipSectionParser = new SkipSectionParser(); try { - skipSectionParser.parse(new RestTestSuiteParseContext("api", "suite", parser)); + skipSectionParser.parse(new ClientYamlTestSuiteParseContext("api", "suite", parser)); fail("Expected RestTestParseException"); - } catch (RestTestParseException e) { + } catch (ClientYamlTestParseException e) { assertThat(e.getMessage(), is("version or features are mutually exclusive")); } } @@ -124,9 +124,9 @@ public class SkipSectionParserTests extends AbstractParserTestCase { SkipSectionParser skipSectionParser = new SkipSectionParser(); try { - skipSectionParser.parse(new RestTestSuiteParseContext("api", "suite", parser)); + skipSectionParser.parse(new ClientYamlTestSuiteParseContext("api", "suite", parser)); fail("Expected RestTestParseException"); - } catch (RestTestParseException e) { + } catch (ClientYamlTestParseException e) { assertThat(e.getMessage(), is("reason is mandatory within skip version section")); } } @@ -138,9 +138,9 @@ public class SkipSectionParserTests extends AbstractParserTestCase { SkipSectionParser skipSectionParser = new SkipSectionParser(); try { - skipSectionParser.parse(new RestTestSuiteParseContext("api", "suite", parser)); + skipSectionParser.parse(new ClientYamlTestSuiteParseContext("api", "suite", parser)); fail("Expected RestTestParseException"); - } catch (RestTestParseException e) { + } catch (ClientYamlTestParseException e) { assertThat(e.getMessage(), is("version or features is mandatory within skip section")); } } diff --git a/test/framework/src/test/java/org/elasticsearch/test/rest/test/TeardownSectionParserTests.java b/test/framework/src/test/java/org/elasticsearch/test/rest/yaml/parser/TeardownSectionParserTests.java similarity index 90% rename from test/framework/src/test/java/org/elasticsearch/test/rest/test/TeardownSectionParserTests.java rename to test/framework/src/test/java/org/elasticsearch/test/rest/yaml/parser/TeardownSectionParserTests.java index eeccea5f5e5..4ad47e35e48 100644 --- a/test/framework/src/test/java/org/elasticsearch/test/rest/test/TeardownSectionParserTests.java +++ b/test/framework/src/test/java/org/elasticsearch/test/rest/yaml/parser/TeardownSectionParserTests.java @@ -17,13 +17,13 @@ * under the License. */ -package org.elasticsearch.test.rest.test; +package org.elasticsearch.test.rest.yaml.parser; import org.elasticsearch.Version; import org.elasticsearch.common.xcontent.yaml.YamlXContent; -import org.elasticsearch.test.rest.parser.RestTestSuiteParseContext; -import org.elasticsearch.test.rest.parser.TeardownSectionParser; -import org.elasticsearch.test.rest.section.TeardownSection; +import org.elasticsearch.test.rest.yaml.parser.ClientYamlTestSuiteParseContext; +import org.elasticsearch.test.rest.yaml.parser.TeardownSectionParser; +import org.elasticsearch.test.rest.yaml.section.TeardownSection; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.notNullValue; @@ -50,7 +50,7 @@ public class TeardownSectionParserTests extends AbstractParserTestCase { ); TeardownSectionParser teardownSectionParser = new TeardownSectionParser(); - TeardownSection section = teardownSectionParser.parse(new RestTestSuiteParseContext("api", "suite", parser)); + TeardownSection section = teardownSectionParser.parse(new ClientYamlTestSuiteParseContext("api", "suite", parser)); assertThat(section, notNullValue()); assertThat(section.getSkipSection().isEmpty(), equalTo(true)); @@ -79,7 +79,7 @@ public class TeardownSectionParserTests extends AbstractParserTestCase { ); TeardownSectionParser teardownSectionParser = new TeardownSectionParser(); - TeardownSection section = teardownSectionParser.parse(new RestTestSuiteParseContext("api", "suite", parser)); + TeardownSection section = teardownSectionParser.parse(new ClientYamlTestSuiteParseContext("api", "suite", parser)); assertThat(section, notNullValue()); assertThat(section.getSkipSection().isEmpty(), equalTo(false)); diff --git a/test/framework/src/test/java/org/elasticsearch/test/rest/test/TestSectionParserTests.java b/test/framework/src/test/java/org/elasticsearch/test/rest/yaml/parser/TestSectionParserTests.java similarity index 85% rename from test/framework/src/test/java/org/elasticsearch/test/rest/test/TestSectionParserTests.java rename to test/framework/src/test/java/org/elasticsearch/test/rest/yaml/parser/TestSectionParserTests.java index d034ae56a71..aa23cabe07b 100644 --- a/test/framework/src/test/java/org/elasticsearch/test/rest/test/TestSectionParserTests.java +++ b/test/framework/src/test/java/org/elasticsearch/test/rest/yaml/parser/TestSectionParserTests.java @@ -16,22 +16,22 @@ * specific language governing permissions and limitations * under the License. */ -package org.elasticsearch.test.rest.test; +package org.elasticsearch.test.rest.yaml.parser; import org.elasticsearch.Version; import org.elasticsearch.common.xcontent.yaml.YamlXContent; -import org.elasticsearch.test.rest.parser.RestTestSectionParser; -import org.elasticsearch.test.rest.parser.RestTestSuiteParseContext; -import org.elasticsearch.test.rest.section.DoSection; -import org.elasticsearch.test.rest.section.GreaterThanAssertion; -import org.elasticsearch.test.rest.section.IsFalseAssertion; -import org.elasticsearch.test.rest.section.IsTrueAssertion; -import org.elasticsearch.test.rest.section.LengthAssertion; -import org.elasticsearch.test.rest.section.LessThanAssertion; -import org.elasticsearch.test.rest.section.MatchAssertion; -import org.elasticsearch.test.rest.section.SetSection; -import org.elasticsearch.test.rest.section.SkipSection; -import org.elasticsearch.test.rest.section.TestSection; +import org.elasticsearch.test.rest.yaml.parser.ClientYamlTestSectionParser; +import org.elasticsearch.test.rest.yaml.parser.ClientYamlTestSuiteParseContext; +import org.elasticsearch.test.rest.yaml.section.DoSection; +import org.elasticsearch.test.rest.yaml.section.GreaterThanAssertion; +import org.elasticsearch.test.rest.yaml.section.IsFalseAssertion; +import org.elasticsearch.test.rest.yaml.section.IsTrueAssertion; +import org.elasticsearch.test.rest.yaml.section.LengthAssertion; +import org.elasticsearch.test.rest.yaml.section.LessThanAssertion; +import org.elasticsearch.test.rest.yaml.section.MatchAssertion; +import org.elasticsearch.test.rest.yaml.section.SetSection; +import org.elasticsearch.test.rest.yaml.section.SkipSection; +import org.elasticsearch.test.rest.yaml.section.ClientYamlTestSection; import java.util.Map; @@ -51,8 +51,8 @@ public class TestSectionParserTests extends AbstractParserTestCase { " name: test_warmer" ); - RestTestSectionParser testSectionParser = new RestTestSectionParser(); - TestSection testSection = testSectionParser.parse(new RestTestSuiteParseContext("api", "suite", parser)); + ClientYamlTestSectionParser testSectionParser = new ClientYamlTestSectionParser(); + ClientYamlTestSection testSection = testSectionParser.parse(new ClientYamlTestSuiteParseContext("api", "suite", parser)); assertThat(testSection, notNullValue()); assertThat(testSection.getName(), equalTo("First test section")); @@ -80,9 +80,9 @@ public class TestSectionParserTests extends AbstractParserTestCase { " - set: {_scroll_id: scroll_id}"; - RestTestSectionParser testSectionParser = new RestTestSectionParser(); + ClientYamlTestSectionParser testSectionParser = new ClientYamlTestSectionParser(); parser = YamlXContent.yamlXContent.createParser(yaml); - TestSection testSection = testSectionParser.parse(new RestTestSuiteParseContext("api", "suite", parser)); + ClientYamlTestSection testSection = testSectionParser.parse(new ClientYamlTestSuiteParseContext("api", "suite", parser)); assertThat(testSection, notNullValue()); assertThat(testSection.getName(), equalTo("First test section")); @@ -119,8 +119,8 @@ public class TestSectionParserTests extends AbstractParserTestCase { " id: 中文" ); - RestTestSectionParser testSectionParser = new RestTestSectionParser(); - TestSection testSection = testSectionParser.parse(new RestTestSuiteParseContext("api", "suite", parser)); + ClientYamlTestSectionParser testSectionParser = new ClientYamlTestSectionParser(); + ClientYamlTestSection testSection = testSectionParser.parse(new ClientYamlTestSuiteParseContext("api", "suite", parser)); assertThat(testSection, notNullValue()); assertThat(testSection.getName(), equalTo("Basic")); @@ -172,8 +172,8 @@ public class TestSectionParserTests extends AbstractParserTestCase { " - lt: { size: 10 }" ); - RestTestSectionParser testSectionParser = new RestTestSectionParser(); - TestSection testSection = testSectionParser.parse(new RestTestSuiteParseContext("api", "suite", parser)); + ClientYamlTestSectionParser testSectionParser = new ClientYamlTestSectionParser(); + ClientYamlTestSection testSection = testSectionParser.parse(new ClientYamlTestSuiteParseContext("api", "suite", parser)); assertThat(testSection, notNullValue()); assertThat(testSection.getName(), equalTo("Basic")); @@ -242,8 +242,8 @@ public class TestSectionParserTests extends AbstractParserTestCase { " \n" + " - is_true: nodes\n" + " - is_true: cluster_name\n"); - RestTestSectionParser testSectionParser = new RestTestSectionParser(); - TestSection testSection = testSectionParser.parse(new RestTestSuiteParseContext("api", "suite", parser)); + ClientYamlTestSectionParser testSectionParser = new ClientYamlTestSectionParser(); + ClientYamlTestSection testSection = testSectionParser.parse(new ClientYamlTestSuiteParseContext("api", "suite", parser)); assertThat(testSection, notNullValue()); assertThat(testSection.getName(), equalTo("node_info test")); assertThat(testSection.getExecutableSections().size(), equalTo(3)); diff --git a/test/framework/src/test/java/org/elasticsearch/test/rest/test/RestApiParserFailingTests.java b/test/framework/src/test/java/org/elasticsearch/test/rest/yaml/restspec/ClientYamlSuiteRestApiParserFailingTests.java similarity index 89% rename from test/framework/src/test/java/org/elasticsearch/test/rest/test/RestApiParserFailingTests.java rename to test/framework/src/test/java/org/elasticsearch/test/rest/yaml/restspec/ClientYamlSuiteRestApiParserFailingTests.java index 0cd8ee31398..f2219816462 100644 --- a/test/framework/src/test/java/org/elasticsearch/test/rest/test/RestApiParserFailingTests.java +++ b/test/framework/src/test/java/org/elasticsearch/test/rest/yaml/restspec/ClientYamlSuiteRestApiParserFailingTests.java @@ -16,21 +16,22 @@ * specific language governing permissions and limitations * under the License. */ -package org.elasticsearch.test.rest.test; +package org.elasticsearch.test.rest.yaml.restspec; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.json.JsonXContent; import org.elasticsearch.test.ESTestCase; -import org.elasticsearch.test.rest.spec.RestApiParser; +import org.elasticsearch.test.rest.yaml.restspec.ClientYamlSuiteRestApiParser; import java.io.IOException; import static org.hamcrest.Matchers.containsString; /** - * These tests are not part of {@link RestApiParserTests} because the tested failures don't allow to consume the whole yaml stream + * These tests are not part of {@link ClientYamlSuiteRestApiParserTests} because the tested failures don't allow to consume the whole yaml + * stream */ -public class RestApiParserFailingTests extends ESTestCase { +public class ClientYamlSuiteRestApiParserFailingTests extends ESTestCase { public void testBrokenSpecShouldThrowUsefulExceptionWhenParsingFailsOnParams() throws Exception { parseAndExpectFailure(BROKEN_SPEC_PARAMS, "Expected params field in rest api definition to contain an object"); } @@ -42,7 +43,7 @@ public class RestApiParserFailingTests extends ESTestCase { private void parseAndExpectFailure(String brokenJson, String expectedErrorMessage) throws Exception { XContentParser parser = JsonXContent.jsonXContent.createParser(brokenJson); try { - new RestApiParser().parse("location", parser); + new ClientYamlSuiteRestApiParser().parse("location", parser); fail("Expected to fail parsing but did not happen"); } catch (IOException e) { assertThat(e.getMessage(), containsString(expectedErrorMessage)); diff --git a/test/framework/src/test/java/org/elasticsearch/test/rest/test/RestApiParserTests.java b/test/framework/src/test/java/org/elasticsearch/test/rest/yaml/restspec/ClientYamlSuiteRestApiParserTests.java similarity index 93% rename from test/framework/src/test/java/org/elasticsearch/test/rest/test/RestApiParserTests.java rename to test/framework/src/test/java/org/elasticsearch/test/rest/yaml/restspec/ClientYamlSuiteRestApiParserTests.java index d884b327f71..342f2bb4ed2 100644 --- a/test/framework/src/test/java/org/elasticsearch/test/rest/test/RestApiParserTests.java +++ b/test/framework/src/test/java/org/elasticsearch/test/rest/yaml/restspec/ClientYamlSuiteRestApiParserTests.java @@ -16,20 +16,21 @@ * specific language governing permissions and limitations * under the License. */ -package org.elasticsearch.test.rest.test; +package org.elasticsearch.test.rest.yaml.restspec; import org.elasticsearch.common.xcontent.json.JsonXContent; -import org.elasticsearch.test.rest.spec.RestApi; -import org.elasticsearch.test.rest.spec.RestApiParser; +import org.elasticsearch.test.rest.yaml.parser.AbstractParserTestCase; +import org.elasticsearch.test.rest.yaml.restspec.ClientYamlSuiteRestApi; +import org.elasticsearch.test.rest.yaml.restspec.ClientYamlSuiteRestApiParser; import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.notNullValue; -public class RestApiParserTests extends AbstractParserTestCase { +public class ClientYamlSuiteRestApiParserTests extends AbstractParserTestCase { public void testParseRestSpecIndexApi() throws Exception { parser = JsonXContent.jsonXContent.createParser(REST_SPEC_INDEX_API); - RestApi restApi = new RestApiParser().parse("location", parser); + ClientYamlSuiteRestApi restApi = new ClientYamlSuiteRestApiParser().parse("location", parser); assertThat(restApi, notNullValue()); assertThat(restApi.getName(), equalTo("index")); @@ -51,7 +52,7 @@ public class RestApiParserTests extends AbstractParserTestCase { public void testParseRestSpecGetTemplateApi() throws Exception { parser = JsonXContent.jsonXContent.createParser(REST_SPEC_GET_TEMPLATE_API); - RestApi restApi = new RestApiParser().parse("location", parser); + ClientYamlSuiteRestApi restApi = new ClientYamlSuiteRestApiParser().parse("location", parser); assertThat(restApi, notNullValue()); assertThat(restApi.getName(), equalTo("indices.get_template")); assertThat(restApi.getMethods().size(), equalTo(1)); @@ -68,7 +69,7 @@ public class RestApiParserTests extends AbstractParserTestCase { public void testParseRestSpecCountApi() throws Exception { parser = JsonXContent.jsonXContent.createParser(REST_SPEC_COUNT_API); - RestApi restApi = new RestApiParser().parse("location", parser); + ClientYamlSuiteRestApi restApi = new ClientYamlSuiteRestApiParser().parse("location", parser); assertThat(restApi, notNullValue()); assertThat(restApi.getName(), equalTo("count")); assertThat(restApi.getMethods().size(), equalTo(2)); diff --git a/test/framework/src/test/java/org/elasticsearch/test/rest/test/FileUtilsTests.java b/test/framework/src/test/java/org/elasticsearch/test/rest/yaml/support/FileUtilsTests.java similarity index 98% rename from test/framework/src/test/java/org/elasticsearch/test/rest/test/FileUtilsTests.java rename to test/framework/src/test/java/org/elasticsearch/test/rest/yaml/support/FileUtilsTests.java index db41c42e16a..c02ca5d85d0 100644 --- a/test/framework/src/test/java/org/elasticsearch/test/rest/test/FileUtilsTests.java +++ b/test/framework/src/test/java/org/elasticsearch/test/rest/yaml/support/FileUtilsTests.java @@ -16,10 +16,10 @@ * specific language governing permissions and limitations * under the License. */ -package org.elasticsearch.test.rest.test; +package org.elasticsearch.test.rest.yaml.support; import org.elasticsearch.test.ESTestCase; -import org.elasticsearch.test.rest.support.FileUtils; +import org.elasticsearch.test.rest.yaml.support.FileUtils; import java.nio.file.Files; import java.nio.file.Path;