Merge pull request #16070 from rjernst/rest_alone

Test: Make rest test framework accept http directly for the test cluster
This commit is contained in:
Ryan Ernst 2016-01-18 17:38:23 -08:00
commit 69e11d1e88
33 changed files with 103 additions and 294 deletions

View File

@ -46,9 +46,9 @@ class ClusterFormationTasks {
/**
* Adds dependent tasks to the given task to start and stop a cluster with the given configuration.
*
* Returns an object that will resolve at execution time of the given task to a uri for the cluster.
* Returns a NodeInfo object for the first node in the cluster.
*/
static Object setup(Project project, Task task, ClusterConfiguration config) {
static NodeInfo setup(Project project, Task task, ClusterConfiguration config) {
if (task.getEnabled() == false) {
// no need to add cluster formation tasks if the task won't run!
return
@ -66,7 +66,7 @@ class ClusterFormationTasks {
task.dependsOn(wait)
// delay the resolution of the uri by wrapping in a closure, so it is not used until read for tests
return "${-> nodes[0].transportUri()}"
return nodes[0]
}
/** Adds a dependency on the given distribution */

View File

@ -20,7 +20,6 @@ package org.elasticsearch.gradle.test
import com.carrotsearch.gradle.junit4.RandomizedTestingTask
import org.elasticsearch.gradle.BuildPlugin
import org.gradle.api.GradleException
import org.gradle.api.Task
import org.gradle.api.internal.tasks.options.Option
import org.gradle.api.plugins.JavaBasePlugin
@ -61,8 +60,12 @@ public class RestIntegTestTask extends RandomizedTestingTask {
// this must run after all projects have been configured, so we know any project
// references can be accessed as a fully configured
project.gradle.projectsEvaluated {
Object clusterUri = ClusterFormationTasks.setup(project, this, clusterConfig)
systemProperty('tests.cluster', clusterUri)
NodeInfo node = ClusterFormationTasks.setup(project, this, clusterConfig)
systemProperty('tests.rest.cluster', "localhost:${-> new URL('http://' + node.httpUri()).getPort()}")
// TODO: our "client" qa tests currently use the rest-test plugin. instead they should have their own plugin
// that sets up the test cluster and passes this transport uri instead of http uri. Until then, we pass
// both as separate sysprops
systemProperty('tests.cluster', "${-> node.transportUri()}")
}
}

View File

@ -21,21 +21,14 @@ package org.elasticsearch.script.expression;
import com.carrotsearch.randomizedtesting.annotations.Name;
import com.carrotsearch.randomizedtesting.annotations.ParametersFactory;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.test.rest.ESRestTestCase;
import org.elasticsearch.test.rest.RestTestCandidate;
import org.elasticsearch.test.rest.parser.RestTestParseException;
import java.io.IOException;
import java.util.Collection;
public class ExpressionRestIT extends ESRestTestCase {
@Override
protected Collection<Class<? extends Plugin>> nodePlugins() {
return pluginList(ExpressionPlugin.class);
}
public ExpressionRestIT(@Name("yaml") RestTestCandidate testCandidate) {
super(testCandidate);
}

View File

@ -21,21 +21,14 @@ package org.elasticsearch.script.groovy;
import com.carrotsearch.randomizedtesting.annotations.Name;
import com.carrotsearch.randomizedtesting.annotations.ParametersFactory;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.test.rest.ESRestTestCase;
import org.elasticsearch.test.rest.RestTestCandidate;
import org.elasticsearch.test.rest.parser.RestTestParseException;
import java.io.IOException;
import java.util.Collection;
public class GroovyRestIT extends ESRestTestCase {
@Override
protected Collection<Class<? extends Plugin>> nodePlugins() {
return pluginList(GroovyPlugin.class);
}
public GroovyRestIT(@Name("yaml") RestTestCandidate testCandidate) {
super(testCandidate);
}

View File

@ -21,21 +21,14 @@ package org.elasticsearch.script.mustache;
import com.carrotsearch.randomizedtesting.annotations.Name;
import com.carrotsearch.randomizedtesting.annotations.ParametersFactory;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.test.rest.ESRestTestCase;
import org.elasticsearch.test.rest.RestTestCandidate;
import org.elasticsearch.test.rest.parser.RestTestParseException;
import java.io.IOException;
import java.util.Collection;
public class MustacheRestIT extends ESRestTestCase {
@Override
protected Collection<Class<? extends Plugin>> nodePlugins() {
return pluginList(MustachePlugin.class);
}
public MustacheRestIT(@Name("yaml") RestTestCandidate testCandidate) {
super(testCandidate);
}

View File

@ -21,22 +21,14 @@ package org.elasticsearch.index.analysis;
import com.carrotsearch.randomizedtesting.annotations.Name;
import com.carrotsearch.randomizedtesting.annotations.ParametersFactory;
import org.elasticsearch.plugin.analysis.icu.AnalysisICUPlugin;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.test.rest.ESRestTestCase;
import org.elasticsearch.test.rest.RestTestCandidate;
import org.elasticsearch.test.rest.parser.RestTestParseException;
import java.io.IOException;
import java.util.Collection;
public class AnalysisICURestIT extends ESRestTestCase {
@Override
protected Collection<Class<? extends Plugin>> nodePlugins() {
return pluginList(AnalysisICUPlugin.class);
}
public AnalysisICURestIT(@Name("yaml") RestTestCandidate testCandidate) {
super(testCandidate);
}

View File

@ -21,23 +21,14 @@ package org.elasticsearch.index.analysis;
import com.carrotsearch.randomizedtesting.annotations.Name;
import com.carrotsearch.randomizedtesting.annotations.ParametersFactory;
import org.elasticsearch.plugin.analysis.kuromoji.AnalysisKuromojiPlugin;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.test.rest.ESRestTestCase;
import org.elasticsearch.test.rest.RestTestCandidate;
import org.elasticsearch.test.rest.parser.RestTestParseException;
import java.io.IOException;
import java.util.Collection;
public class AnalysisKuromojiRestIT extends ESRestTestCase {
@Override
protected Collection<Class<? extends Plugin>> nodePlugins() {
return pluginList(AnalysisKuromojiPlugin.class);
}
public AnalysisKuromojiRestIT(@Name("yaml") RestTestCandidate testCandidate) {
super(testCandidate);
}

View File

@ -21,22 +21,14 @@ package org.elasticsearch.index.analysis;
import com.carrotsearch.randomizedtesting.annotations.Name;
import com.carrotsearch.randomizedtesting.annotations.ParametersFactory;
import org.elasticsearch.plugin.analysis.AnalysisPhoneticPlugin;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.test.rest.ESRestTestCase;
import org.elasticsearch.test.rest.RestTestCandidate;
import org.elasticsearch.test.rest.parser.RestTestParseException;
import java.io.IOException;
import java.util.Collection;
public class AnalysisPhoneticRestIT extends ESRestTestCase {
@Override
protected Collection<Class<? extends Plugin>> nodePlugins() {
return pluginList(AnalysisPhoneticPlugin.class);
}
public AnalysisPhoneticRestIT(@Name("yaml") RestTestCandidate testCandidate) {
super(testCandidate);
}

View File

@ -21,22 +21,14 @@ package org.elasticsearch.index.analysis;
import com.carrotsearch.randomizedtesting.annotations.Name;
import com.carrotsearch.randomizedtesting.annotations.ParametersFactory;
import org.elasticsearch.plugin.analysis.smartcn.AnalysisSmartChinesePlugin;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.test.rest.ESRestTestCase;
import org.elasticsearch.test.rest.RestTestCandidate;
import org.elasticsearch.test.rest.parser.RestTestParseException;
import java.io.IOException;
import java.util.Collection;
public class AnalysisSmartChineseRestIT extends ESRestTestCase {
@Override
protected Collection<Class<? extends Plugin>> nodePlugins() {
return pluginList(AnalysisSmartChinesePlugin.class);
}
public AnalysisSmartChineseRestIT(@Name("yaml") RestTestCandidate testCandidate) {
super(testCandidate);
}

View File

@ -21,22 +21,14 @@ package org.elasticsearch.index.analysis;
import com.carrotsearch.randomizedtesting.annotations.Name;
import com.carrotsearch.randomizedtesting.annotations.ParametersFactory;
import org.elasticsearch.plugin.analysis.stempel.AnalysisStempelPlugin;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.test.rest.ESRestTestCase;
import org.elasticsearch.test.rest.RestTestCandidate;
import org.elasticsearch.test.rest.parser.RestTestParseException;
import java.io.IOException;
import java.util.Collection;
public class AnalysisPolishRestIT extends ESRestTestCase {
@Override
protected Collection<Class<? extends Plugin>> nodePlugins() {
return pluginList(AnalysisStempelPlugin.class);
}
public AnalysisPolishRestIT(@Name("yaml") RestTestCandidate testCandidate) {
super(testCandidate);
}

View File

@ -21,22 +21,14 @@ package org.elasticsearch.plugin.deletebyquery.test.rest;
import com.carrotsearch.randomizedtesting.annotations.Name;
import com.carrotsearch.randomizedtesting.annotations.ParametersFactory;
import org.elasticsearch.plugin.deletebyquery.DeleteByQueryPlugin;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.test.rest.ESRestTestCase;
import org.elasticsearch.test.rest.RestTestCandidate;
import org.elasticsearch.test.rest.parser.RestTestParseException;
import java.io.IOException;
import java.util.Collection;
public class DeleteByQueryRestIT extends ESRestTestCase {
@Override
protected Collection<Class<? extends Plugin>> nodePlugins() {
return pluginList(DeleteByQueryPlugin.class);
}
public DeleteByQueryRestIT(@Name("yaml") RestTestCandidate testCandidate) {
super(testCandidate);
}

View File

@ -21,22 +21,14 @@ package org.elasticsearch.discovery.azure;
import com.carrotsearch.randomizedtesting.annotations.Name;
import com.carrotsearch.randomizedtesting.annotations.ParametersFactory;
import org.elasticsearch.plugin.discovery.azure.AzureDiscoveryPlugin;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.test.rest.ESRestTestCase;
import org.elasticsearch.test.rest.RestTestCandidate;
import org.elasticsearch.test.rest.parser.RestTestParseException;
import java.io.IOException;
import java.util.Collection;
public class AzureDiscoveryRestIT extends ESRestTestCase {
@Override
protected Collection<Class<? extends Plugin>> nodePlugins() {
return pluginList(AzureDiscoveryPlugin.class);
}
public AzureDiscoveryRestIT(@Name("yaml") RestTestCandidate testCandidate) {
super(testCandidate);
}

View File

@ -21,22 +21,14 @@ package org.elasticsearch.cloud.aws;
import com.carrotsearch.randomizedtesting.annotations.Name;
import com.carrotsearch.randomizedtesting.annotations.ParametersFactory;
import org.elasticsearch.plugin.discovery.ec2.Ec2DiscoveryPlugin;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.test.rest.ESRestTestCase;
import org.elasticsearch.test.rest.RestTestCandidate;
import org.elasticsearch.test.rest.parser.RestTestParseException;
import java.io.IOException;
import java.util.Collection;
public class DiscoveryEc2RestIT extends ESRestTestCase {
@Override
protected Collection<Class<? extends Plugin>> nodePlugins() {
return pluginList(Ec2DiscoveryPlugin.class);
}
public DiscoveryEc2RestIT(@Name("yaml") RestTestCandidate testCandidate) {
super(testCandidate);
}

View File

@ -21,22 +21,14 @@ package org.elasticsearch.discovery.gce;
import com.carrotsearch.randomizedtesting.annotations.Name;
import com.carrotsearch.randomizedtesting.annotations.ParametersFactory;
import org.elasticsearch.plugin.discovery.gce.GceDiscoveryPlugin;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.test.rest.ESRestTestCase;
import org.elasticsearch.test.rest.RestTestCandidate;
import org.elasticsearch.test.rest.parser.RestTestParseException;
import java.io.IOException;
import java.util.Collection;
public class DiscoveryGCERestIT extends ESRestTestCase {
@Override
protected Collection<Class<? extends Plugin>> nodePlugins() {
return pluginList(GceDiscoveryPlugin.class);
}
public DiscoveryGCERestIT(@Name("yaml") RestTestCandidate testCandidate) {
super(testCandidate);
}

View File

@ -21,21 +21,14 @@ package org.elasticsearch.plugin.discovery.multicast;
import com.carrotsearch.randomizedtesting.annotations.Name;
import com.carrotsearch.randomizedtesting.annotations.ParametersFactory;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.test.rest.ESRestTestCase;
import org.elasticsearch.test.rest.RestTestCandidate;
import org.elasticsearch.test.rest.parser.RestTestParseException;
import java.io.IOException;
import java.util.Collection;
public class MulticastDiscoveryRestIT extends ESRestTestCase {
@Override
protected Collection<Class<? extends Plugin>> nodePlugins() {
return pluginList(MulticastDiscoveryPlugin.class);
}
public MulticastDiscoveryRestIT(@Name("yaml") RestTestCandidate testCandidate) {
super(testCandidate);
}

View File

@ -21,21 +21,14 @@ package org.elasticsearch.plugin.example;
import com.carrotsearch.randomizedtesting.annotations.Name;
import com.carrotsearch.randomizedtesting.annotations.ParametersFactory;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.test.rest.ESRestTestCase;
import org.elasticsearch.test.rest.RestTestCandidate;
import org.elasticsearch.test.rest.parser.RestTestParseException;
import java.io.IOException;
import java.util.Collection;
public class JvmExampleRestIT extends ESRestTestCase {
@Override
protected Collection<Class<? extends Plugin>> nodePlugins() {
return pluginList(JvmExamplePlugin.class);
}
public JvmExampleRestIT(@Name("yaml") RestTestCandidate testCandidate) {
super(testCandidate);
}

View File

@ -21,22 +21,14 @@ package org.elasticsearch.script.javascript;
import com.carrotsearch.randomizedtesting.annotations.Name;
import com.carrotsearch.randomizedtesting.annotations.ParametersFactory;
import org.elasticsearch.plugin.javascript.JavaScriptPlugin;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.test.rest.ESRestTestCase;
import org.elasticsearch.test.rest.RestTestCandidate;
import org.elasticsearch.test.rest.parser.RestTestParseException;
import java.io.IOException;
import java.util.Collection;
public class LangJavaScriptRestIT extends ESRestTestCase {
@Override
protected Collection<Class<? extends Plugin>> nodePlugins() {
return pluginList(JavaScriptPlugin.class);
}
public LangJavaScriptRestIT(@Name("yaml") RestTestCandidate testCandidate) {
super(testCandidate);
}

View File

@ -21,22 +21,15 @@ package org.elasticsearch.plan.a;
import com.carrotsearch.randomizedtesting.annotations.Name;
import com.carrotsearch.randomizedtesting.annotations.ParametersFactory;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.test.rest.ESRestTestCase;
import org.elasticsearch.test.rest.RestTestCandidate;
import org.elasticsearch.test.rest.parser.RestTestParseException;
import java.io.IOException;
import java.util.Collection;
/** Runs yaml rest tests */
public class PlanARestIT extends ESRestTestCase {
@Override
protected Collection<Class<? extends Plugin>> nodePlugins() {
return pluginList(PlanAPlugin.class);
}
public PlanARestIT(@Name("yaml") RestTestCandidate testCandidate) {
super(testCandidate);
}

View File

@ -21,22 +21,14 @@ package org.elasticsearch.script.python;
import com.carrotsearch.randomizedtesting.annotations.Name;
import com.carrotsearch.randomizedtesting.annotations.ParametersFactory;
import org.elasticsearch.plugin.python.PythonPlugin;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.test.rest.ESRestTestCase;
import org.elasticsearch.test.rest.RestTestCandidate;
import org.elasticsearch.test.rest.parser.RestTestParseException;
import java.io.IOException;
import java.util.Collection;
public class LangPythonScriptRestIT extends ESRestTestCase {
@Override
protected Collection<Class<? extends Plugin>> nodePlugins() {
return pluginList(PythonPlugin.class);
}
public LangPythonScriptRestIT(@Name("yaml") RestTestCandidate testCandidate) {
super(testCandidate);
}

View File

@ -21,7 +21,6 @@ package org.elasticsearch.mapper.attachments;
import com.carrotsearch.randomizedtesting.annotations.Name;
import com.carrotsearch.randomizedtesting.annotations.ParametersFactory;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.test.rest.ESRestTestCase;
import org.elasticsearch.test.rest.RestTestCandidate;
import org.elasticsearch.test.rest.parser.RestTestParseException;
@ -30,14 +29,6 @@ import java.io.IOException;
public class MapperAttachmentsRestIT extends ESRestTestCase {
@Override
protected Settings nodeSettings(int nodeOrdinal) {
return Settings.builder()
.put(super.nodeSettings(nodeOrdinal))
.put("plugin.types", MapperAttachmentsPlugin.class.getName())
.build();
}
public MapperAttachmentsRestIT(@Name("yaml") RestTestCandidate testCandidate) {
super(testCandidate);
}

View File

@ -21,22 +21,14 @@ package org.elasticsearch.index.mapper.murmur3;
import com.carrotsearch.randomizedtesting.annotations.Name;
import com.carrotsearch.randomizedtesting.annotations.ParametersFactory;
import org.elasticsearch.plugin.mapper.MapperMurmur3Plugin;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.test.rest.ESRestTestCase;
import org.elasticsearch.test.rest.RestTestCandidate;
import org.elasticsearch.test.rest.parser.RestTestParseException;
import java.io.IOException;
import java.util.Collection;
public class MapperMurmur3RestIT extends ESRestTestCase {
@Override
protected Collection<Class<? extends Plugin>> nodePlugins() {
return pluginList(MapperMurmur3Plugin.class);
}
public MapperMurmur3RestIT(@Name("yaml") RestTestCandidate testCandidate) {
super(testCandidate);
}

View File

@ -21,22 +21,14 @@ package org.elasticsearch.index.mapper.size;
import com.carrotsearch.randomizedtesting.annotations.Name;
import com.carrotsearch.randomizedtesting.annotations.ParametersFactory;
import org.elasticsearch.plugin.mapper.MapperSizePlugin;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.test.rest.ESRestTestCase;
import org.elasticsearch.test.rest.RestTestCandidate;
import org.elasticsearch.test.rest.parser.RestTestParseException;
import java.io.IOException;
import java.util.Collection;
public class MapperSizeRestIT extends ESRestTestCase {
@Override
protected Collection<Class<? extends Plugin>> nodePlugins() {
return pluginList(MapperSizePlugin.class);
}
public MapperSizeRestIT(@Name("yaml") RestTestCandidate testCandidate) {
super(testCandidate);
}

View File

@ -21,22 +21,14 @@ package org.elasticsearch.repositories.azure;
import com.carrotsearch.randomizedtesting.annotations.Name;
import com.carrotsearch.randomizedtesting.annotations.ParametersFactory;
import org.elasticsearch.plugin.repository.azure.AzureRepositoryPlugin;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.test.rest.ESRestTestCase;
import org.elasticsearch.test.rest.RestTestCandidate;
import org.elasticsearch.test.rest.parser.RestTestParseException;
import java.io.IOException;
import java.util.Collection;
public class AzureRepositoryRestIT extends ESRestTestCase {
@Override
protected Collection<Class<? extends Plugin>> nodePlugins() {
return pluginList(AzureRepositoryPlugin.class);
}
public AzureRepositoryRestIT(@Name("yaml") RestTestCandidate testCandidate) {
super(testCandidate);
}

View File

@ -19,24 +19,15 @@
package org.elasticsearch.repositories.hdfs;
import java.io.IOException;
import java.util.Collection;
import com.carrotsearch.randomizedtesting.annotations.Name;
import com.carrotsearch.randomizedtesting.annotations.ParametersFactory;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.repositories.hdfs.HdfsPlugin;
import org.elasticsearch.test.rest.ESRestTestCase;
import org.elasticsearch.test.rest.RestTestCandidate;
import org.elasticsearch.test.rest.parser.RestTestParseException;
public class HdfsRepositoryRestIT extends ESRestTestCase {
@Override
protected Collection<Class<? extends Plugin>> nodePlugins() {
return pluginList(HdfsPlugin.class);
}
public HdfsRepositoryRestIT(@Name("yaml") RestTestCandidate testCandidate) {
super(testCandidate);
}

View File

@ -21,22 +21,14 @@ package org.elasticsearch.repositories.s3;
import com.carrotsearch.randomizedtesting.annotations.Name;
import com.carrotsearch.randomizedtesting.annotations.ParametersFactory;
import org.elasticsearch.plugin.repository.s3.S3RepositoryPlugin;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.test.rest.ESRestTestCase;
import org.elasticsearch.test.rest.RestTestCandidate;
import org.elasticsearch.test.rest.parser.RestTestParseException;
import java.io.IOException;
import java.util.Collection;
public class RepositoryS3RestIT extends ESRestTestCase {
@Override
protected Collection<Class<? extends Plugin>> nodePlugins() {
return pluginList(S3RepositoryPlugin.class);
}
public RepositoryS3RestIT(@Name("yaml") RestTestCandidate testCandidate) {
super(testCandidate);
}

View File

@ -21,22 +21,14 @@ package org.elasticsearch.index.store;
import com.carrotsearch.randomizedtesting.annotations.Name;
import com.carrotsearch.randomizedtesting.annotations.ParametersFactory;
import org.elasticsearch.plugin.store.smb.SMBStorePlugin;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.test.rest.ESRestTestCase;
import org.elasticsearch.test.rest.RestTestCandidate;
import org.elasticsearch.test.rest.parser.RestTestParseException;
import java.io.IOException;
import java.util.Collection;
public class SMBStoreRestIT extends ESRestTestCase {
@Override
protected Collection<Class<? extends Plugin>> nodePlugins() {
return pluginList(SMBStorePlugin.class);
}
public SMBStoreRestIT(@Name("yaml") RestTestCandidate testCandidate) {
super(testCandidate);
}

View File

@ -67,11 +67,6 @@ public abstract class ESSmokeClientTestCase extends LuceneTestCase {
*/
public static final String TESTS_CLUSTER = "tests.cluster";
/**
* Defaults to localhost:9300
*/
public static final String TESTS_CLUSTER_DEFAULT = "localhost:9300";
protected static final ESLogger logger = ESLoggerFactory.getLogger(ESSmokeClientTestCase.class.getName());
private static final AtomicInteger counter = new AtomicInteger();
@ -131,11 +126,10 @@ public abstract class ESSmokeClientTestCase extends LuceneTestCase {
}
@BeforeClass
public static void initializeSettings() throws UnknownHostException {
public static void initializeSettings() {
clusterAddresses = System.getProperty(TESTS_CLUSTER);
if (clusterAddresses == null || clusterAddresses.isEmpty()) {
clusterAddresses = TESTS_CLUSTER_DEFAULT;
logger.info("[{}] not set. Falling back to [{}]", TESTS_CLUSTER, TESTS_CLUSTER_DEFAULT);
fail("Must specify " + TESTS_CLUSTER + " for smoke client test");
}
}

View File

@ -24,6 +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.ESRestTestCase;
import org.junit.internal.AssumptionViolatedException;
import org.junit.runner.Description;
import org.junit.runner.notification.Failure;
@ -39,7 +40,6 @@ import static org.elasticsearch.test.ESIntegTestCase.TESTS_CLUSTER;
import static org.elasticsearch.test.rest.ESRestTestCase.REST_TESTS_BLACKLIST;
import static org.elasticsearch.test.rest.ESRestTestCase.REST_TESTS_SPEC;
import static org.elasticsearch.test.rest.ESRestTestCase.REST_TESTS_SUITE;
import static org.elasticsearch.test.rest.ESRestTestCase.Rest;
/**
* A {@link RunListener} that emits to {@link System#err} a string with command
@ -82,7 +82,7 @@ public class ReproduceInfoPrinter extends RunListener {
gradleMessageBuilder.appendAllOpts(failure.getDescription());
//Rest tests are a special case as they allow for additional parameters
if (failure.getDescription().getTestClass().isAnnotationPresent(Rest.class)) {
if (ESRestTestCase.class.isAssignableFrom(failure.getDescription().getTestClass())) {
gradleMessageBuilder.appendRestTestsProperties();
}

View File

@ -20,20 +20,12 @@
package org.elasticsearch.test.rest;
import com.carrotsearch.randomizedtesting.RandomizedTest;
import com.carrotsearch.randomizedtesting.annotations.TestGroup;
import com.carrotsearch.randomizedtesting.annotations.TimeoutSuite;
import org.apache.lucene.util.IOUtils;
import org.apache.lucene.util.LuceneTestCase.SuppressCodecs;
import org.apache.lucene.util.LuceneTestCase.SuppressFsync;
import org.apache.lucene.util.TimeUnits;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.SuppressForbidden;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentHelper;
import org.elasticsearch.node.Node;
import org.elasticsearch.repositories.uri.URLRepository;
import org.elasticsearch.test.ESIntegTestCase;
import org.elasticsearch.test.ESIntegTestCase.ClusterScope;
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.test.rest.client.RestException;
import org.elasticsearch.test.rest.parser.RestTestParseException;
import org.elasticsearch.test.rest.parser.RestTestSuiteParser;
@ -45,17 +37,14 @@ 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.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import java.io.IOException;
import java.io.InputStream;
import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.net.InetSocketAddress;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
@ -67,6 +56,7 @@ import java.nio.file.StandardCopyOption;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
@ -74,27 +64,7 @@ import java.util.Set;
/**
* Runs the clients test suite against an elasticsearch cluster.
*/
@ESRestTestCase.Rest
@SuppressFsync // we aren't trying to test this here, and it can make the test slow
@SuppressCodecs("*") // requires custom completion postings format
@ClusterScope(randomDynamicTemplates = false)
@TimeoutSuite(millis = 40 * TimeUnits.MINUTE) // timeout the suite after 40min and fail the test.
public abstract class ESRestTestCase extends ESIntegTestCase {
/**
* Property that allows to control whether the REST tests are run (default) or not
*/
public static final String TESTS_REST = "tests.rest";
/**
* Annotation for REST tests
*/
@Inherited
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
@TestGroup(enabled = true, sysProperty = ESRestTestCase.TESTS_REST)
public @interface Rest {
}
public abstract class ESRestTestCase extends ESTestCase {
/**
* Property that allows to control which REST tests get run. Supports comma separated list of tests
@ -132,7 +102,9 @@ public abstract class ESRestTestCase extends ESIntegTestCase {
private static final String PATHS_SEPARATOR = "(?<!\\\\),";
private final List<BlacklistedPathPatternMatcher> blacklistPathMatchers = new ArrayList<>();
private final URL[] clusterUrls;
private static RestTestExecutionContext restTestExecutionContext;
private static RestTestExecutionContext adminExecutionContext;
private final RestTestCandidate testCandidate;
@ -142,6 +114,20 @@ public abstract class ESRestTestCase extends ESIntegTestCase {
for (String entry : blacklist) {
this.blacklistPathMatchers.add(new BlacklistedPathPatternMatcher(entry));
}
String cluster = System.getProperty("tests.rest.cluster");
if (cluster == null) {
throw new RuntimeException("Must specify tests.rest.cluster for rest tests");
}
String[] stringUrls = cluster.split(",");
clusterUrls = new URL[stringUrls.length];
int i = 0;
try {
for (String stringUrl : stringUrls) {
clusterUrls[i++] = new URL("http://" + stringUrl);
}
} catch (IOException e) {
throw new RuntimeException("Failed to parse cluster addresses for rest test", e);
}
}
@Override
@ -150,28 +136,7 @@ public abstract class ESRestTestCase extends ESIntegTestCase {
super.afterIfFailed(errors);
}
@Override
protected Settings nodeSettings(int nodeOrdinal) {
return Settings.builder()
.putArray(URLRepository.ALLOWED_URLS_SETTING, "http://snapshot.test*")
.put(Node.HTTP_ENABLED, true)
.put("node.testattr", "test")
.put(super.nodeSettings(nodeOrdinal)).build();
}
public static Iterable<Object[]> createParameters(int id, int count) throws IOException, RestTestParseException {
TestGroup testGroup = Rest.class.getAnnotation(TestGroup.class);
String sysProperty = TestGroup.Utilities.getSysProperty(Rest.class);
boolean enabled;
try {
enabled = RandomizedTest.systemPropertyAsBoolean(sysProperty, testGroup.enabled());
} catch (IllegalArgumentException e) {
// Ignore malformed system property, disable the group if malformed though.
enabled = false;
}
if (!enabled) {
return new ArrayList<>();
}
//parse tests only if rest test group is enabled, otherwise rest tests might not even be available on file system
List<RestTestCandidate> restTestCandidates = collectTestCandidates(id, count);
List<Object[]> objects = new ArrayList<>();
@ -274,6 +239,7 @@ public abstract class ESRestTestCase extends ESIntegTestCase {
}
validateSpec(restSpec);
restTestExecutionContext = new RestTestExecutionContext(restSpec);
adminExecutionContext = new RestTestExecutionContext(restSpec);
}
private static void validateSpec(RestSpec restSpec) {
@ -293,27 +259,42 @@ public abstract class ESRestTestCase extends ESIntegTestCase {
}
}
@After
public void wipeCluster() throws Exception {
// wipe indices
Map<String, String> deleteIndicesArgs = new HashMap<>();
deleteIndicesArgs.put("index", "*");
try {
adminExecutionContext.callApi("indices.delete", deleteIndicesArgs, Collections.emptyList(), Collections.emptyMap());
} catch (RestException e) {
// 404 here just means we had no indexes
if (e.statusCode() != 404) {
throw e;
}
}
// wipe index templates
Map<String, String> deleteTemplatesArgs = new HashMap<>();
deleteTemplatesArgs.put("name", "*");
adminExecutionContext.callApi("indices.delete_template", deleteTemplatesArgs, Collections.emptyList(), Collections.emptyMap());
// wipe snapshots
Map<String, String> deleteSnapshotsArgs = new HashMap<>();
deleteSnapshotsArgs.put("repository", "*");
adminExecutionContext.callApi("snapshot.delete_repository", deleteSnapshotsArgs, Collections.emptyList(), Collections.emptyMap());
}
@AfterClass
public static void close() {
if (restTestExecutionContext != null) {
restTestExecutionContext.close();
adminExecutionContext.close();
restTestExecutionContext = null;
adminExecutionContext = null;
}
}
@Override
protected int maximumNumberOfShards() {
return 3; // never go crazy in the REST tests
}
@Override
protected int maximumNumberOfReplicas() {
// hardcoded 1 since this is what clients also do and our tests must expect that we have only node
// with replicas set to 1 ie. the cluster won't be green
return 1;
}
/**
* Used to obtain settings for the REST client that is used to send REST requests.
*/
@ -321,15 +302,29 @@ public abstract class ESRestTestCase extends ESIntegTestCase {
return Settings.EMPTY;
}
/** Returns the REST client settings used for admin actions like cleaning up after the test has completed. */
protected Settings restAdminSettings() {
return restClientSettings(); // default to the same client settings
}
/** Returns the addresses the client uses to connect to the test cluster. */
protected URL[] getClusterUrls() {
return clusterUrls;
}
@Before
public void reset() throws IOException, RestException {
// admin context must be available for @After always, regardless of whether the test was blacklisted
adminExecutionContext.initClient(clusterUrls, restAdminSettings());
adminExecutionContext.clear();
//skip test if it matches one of the blacklist globs
for (BlacklistedPathPatternMatcher blacklistedPathMatcher : blacklistPathMatchers) {
String testPath = testCandidate.getSuitePath() + "/" + testCandidate.getTestSection().getName();
assumeFalse("[" + testCandidate.getTestPath() + "] skipped, reason: blacklisted", blacklistedPathMatcher.isSuffixMatch(testPath));
}
//The client needs non static info to get initialized, therefore it can't be initialized in the before class
restTestExecutionContext.initClient(cluster().httpAddresses(), restClientSettings());
restTestExecutionContext.initClient(clusterUrls, restClientSettings());
restTestExecutionContext.clear();
//skip test if the whole suite (yaml file) is disabled

View File

@ -31,6 +31,7 @@ import org.elasticsearch.test.rest.spec.RestSpec;
import java.io.Closeable;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.URL;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ -119,9 +120,9 @@ public class RestTestExecutionContext implements Closeable {
/**
* Creates the embedded REST client when needed. Needs to be called before each test.
*/
public void initClient(InetSocketAddress[] addresses, Settings settings) throws IOException, RestException {
public void initClient(URL[] urls, Settings settings) throws IOException, RestException {
if (restClient == null) {
restClient = new RestClient(restSpec, settings, addresses);
restClient = new RestClient(restSpec, settings, urls);
}
}

View File

@ -35,6 +35,7 @@ import org.elasticsearch.common.Strings;
import org.elasticsearch.common.io.PathUtils;
import org.elasticsearch.common.logging.ESLogger;
import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.common.network.InetAddresses;
import org.elasticsearch.common.network.NetworkAddress;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.util.set.Sets;
@ -48,6 +49,7 @@ import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.net.InetSocketAddress;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.security.KeyManagementException;
@ -80,18 +82,18 @@ public class RestClient implements Closeable {
private final RestSpec restSpec;
private final CloseableHttpClient httpClient;
private final Headers headers;
private final InetSocketAddress[] addresses;
private final URL[] urls;
private final Version esVersion;
public RestClient(RestSpec restSpec, Settings settings, InetSocketAddress[] addresses) throws IOException, RestException {
assert addresses.length > 0;
public RestClient(RestSpec restSpec, Settings settings, URL[] urls) throws IOException, RestException {
assert urls.length > 0;
this.restSpec = restSpec;
this.headers = new Headers(settings);
this.protocol = settings.get(PROTOCOL, "http");
this.httpClient = createHttpClient(settings);
this.addresses = addresses;
this.urls = urls;
this.esVersion = readAndCheckVersion();
logger.info("REST client initialized {}, elasticsearch version: [{}]", addresses, esVersion);
logger.info("REST client initialized {}, elasticsearch version: [{}]", urls, esVersion);
}
private Version readAndCheckVersion() throws IOException, RestException {
@ -102,8 +104,8 @@ public class RestClient implements Closeable {
assert restApi.getMethods().size() == 1;
String version = null;
for (InetSocketAddress address : addresses) {
RestResponse restResponse = new RestResponse(httpRequestBuilder(address)
for (URL url : urls) {
RestResponse restResponse = new RestResponse(httpRequestBuilder(url)
.path(restApi.getPaths().get(0))
.method(restApi.getMethods().get(0)).execute());
checkStatusCode(restResponse);
@ -152,6 +154,8 @@ public class RestClient implements Closeable {
HttpRequestBuilder httpRequestBuilder = callApiBuilder(apiName, requestParams, body);
for (Map.Entry<String, String> header : headers.entrySet()) {
logger.error("Adding header " + header.getKey());
logger.error(" with value " + header.getValue());
httpRequestBuilder.addHeader(header.getKey(), header.getValue());
}
logger.debug("calling api [{}]", apiName);
@ -246,17 +250,18 @@ public class RestClient implements Closeable {
return restApi;
}
protected HttpRequestBuilder httpRequestBuilder(InetSocketAddress address) {
protected HttpRequestBuilder httpRequestBuilder(URL url) {
return new HttpRequestBuilder(httpClient)
.addHeaders(headers)
.protocol(protocol)
.host(NetworkAddress.formatAddress(address.getAddress())).port(address.getPort());
.host(url.getHost())
.port(url.getPort());
}
protected HttpRequestBuilder httpRequestBuilder() {
//the address used is randomized between the available ones
InetSocketAddress address = RandomizedTest.randomFrom(addresses);
return httpRequestBuilder(address);
URL url = RandomizedTest.randomFrom(urls);
return httpRequestBuilder(url);
}
protected CloseableHttpClient createHttpClient(Settings settings) throws IOException {

View File

@ -136,7 +136,7 @@ public class RestTestSuiteParseContext {
token = parser.nextToken();
}
if (token != XContentParser.Token.FIELD_NAME) {
throw new RestTestParseException("malformed test section: field name expected but found " + token);
throw new RestTestParseException("malformed test section: field name expected but found " + token + " at " + parser.getTokenLocation());
}
}

View File

@ -18,11 +18,6 @@
*/
package org.elasticsearch.test.rest.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.TestSection;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
@ -30,6 +25,11 @@ import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;
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.TestSection;
/**
* Parser for a complete test suite (yaml file)
*/