From 89e1a0fb7dd6227fb1d74d51644da7a52c3f7055 Mon Sep 17 00:00:00 2001 From: Ryan Ernst Date: Sat, 22 Aug 2015 00:21:13 -0700 Subject: [PATCH 1/2] Plugins: Removed plugin.types The setting `plugin.types` is currently used to load plugins from the classpath. This is necessary in tests, as well as the transport client. This change removes the setting, and replaces it with the ability to directly add plugins when building a transport client, as well as infrastructure in the integration tests to specify which plugin classes should be loaded on each node. --- core/pom.xml | 1 + .../client/transport/TransportClient.java | 13 +- .../java/org/elasticsearch/node/Node.java | 31 ++- .../elasticsearch/plugins/PluginsService.java | 51 ++--- .../transport/TransportModule.java | 2 +- .../action/IndicesRequestIT.java | 20 +- .../expression/ScriptComparisonBenchmark.java | 15 +- .../score/ScriptsConstantScoreBenchmark.java | 12 +- .../scripts/score/ScriptsScoreBenchmark.java | 13 +- .../ScriptsScorePayloadSumBenchmark.java | 13 +- .../TransportClientHeadersTests.java | 20 +- .../cluster/ClusterInfoServiceIT.java | 8 +- .../cluster/ClusterServiceIT.java | 6 +- .../allocation/decider/MockDiskUsagesIT.java | 10 +- .../cluster/settings/SettingsFilteringIT.java | 7 +- .../DiscoveryWithServiceDisruptionsIT.java | 9 +- .../discovery/ZenUnicastDiscoveryIT.java | 2 +- .../index/IndexWithShadowReplicasIT.java | 8 +- .../index/TransportIndexFailuresIT.java | 8 +- .../ExternalValuesMapperIntegrationIT.java | 11 +- .../query/plugin/CustomQueryParserIT.java | 8 +- .../index/store/CorruptedFileIT.java | 7 +- .../index/store/CorruptedTranslogIT.java | 12 +- .../index/store/ExceptionRetryIT.java | 9 +- .../PreBuiltAnalyzerIntegrationIT.java | 9 +- .../RandomExceptionCircuitBreakerIT.java | 7 +- .../indices/recovery/IndexRecoveryIT.java | 7 +- .../store/IndicesStoreIntegrationIT.java | 8 +- .../template/IndexTemplateFilteringIT.java | 9 +- .../java/org/elasticsearch/node/MockNode.java | 54 +++++ .../nodesinfo/SimpleNodesInfoIT.java | 4 +- .../plugins/PluggableTransportModuleIT.java | 14 +- .../elasticsearch/plugins/PluginTestCase.java | 56 ----- .../plugins/PluginsServiceTests.java | 16 +- .../plugins/ResponseHeaderPluginIT.java | 8 +- .../elasticsearch/recovery/RelocationIT.java | 8 +- .../recovery/TruncatedRecoveryIT.java | 9 +- .../script/CustomScriptContextIT.java | 8 +- .../elasticsearch/script/ScriptFieldIT.java | 5 +- .../SignificantTermsSignificanceScoreIT.java | 6 +- .../basic/SearchWithRandomExceptionsIT.java | 173 +--------------- .../basic/SearchWithRandomIOExceptionsIT.java | 191 ++++++++++++++++++ .../search/fetch/FetchSubPhasePluginIT.java | 8 +- .../functionscore/ExplainableScriptIT.java | 9 +- .../functionscore/FunctionScorePluginIT.java | 9 +- .../highlight/CustomHighlighterSearchIT.java | 9 +- .../suggest/CustomSuggesterSearchIT.java | 6 +- .../AbstractSnapshotIntegTestCase.java | 9 +- .../DedicatedClusterSnapshotRestoreIT.java | 11 +- .../test/ESBackcompatTestCase.java | 9 +- .../elasticsearch/test/ESIntegTestCase.java | 59 +++++- .../org/elasticsearch/test/ExternalNode.java | 14 +- .../test/InternalTestCluster.java | 69 ++++--- ...urce.java => NodeConfigurationSource.java} | 26 ++- .../ClusterDiscoveryConfiguration.java | 15 +- .../test/disruption/NetworkPartitionIT.java | 10 +- .../test/test/InternalTestClusterTests.java | 14 +- .../ContextAndHeaderTransportIT.java | 6 +- .../transport/netty/NettyTransportIT.java | 12 +- .../update/UpdateByNativeScriptIT.java | 8 +- docs/plugins/authors.asciidoc | 18 +- .../testing/testing-framework.asciidoc | 8 +- .../cloud/aws/AbstractAwsTest.java | 8 +- .../discovery/ec2/Ec2DiscoveryITest.java | 9 +- .../ec2/Ec2DiscoveryUpdateSettingsITest.java | 9 +- .../s3/AbstractS3SnapshotRestoreTest.java | 8 +- .../AbstractAzureComputeServiceTest.java | 15 +- .../AbstractAzureRepositoryServiceTest.java | 7 +- .../cloud/azure/AbstractAzureTest.java | 9 +- .../azure/AzureMinimumMasterNodesTest.java | 2 +- .../discovery/azure/AzureSimpleTest.java | 2 +- .../azure/AzureTwoStartedNodesTest.java | 2 +- .../index/store/AbstractAzureFsTest.java | 9 +- .../deletebyquery/DeleteByQueryTests.java | 12 +- .../index/mapper/size/SizeMappingIT.java | 9 +- 75 files changed, 797 insertions(+), 521 deletions(-) create mode 100644 core/src/test/java/org/elasticsearch/node/MockNode.java delete mode 100644 core/src/test/java/org/elasticsearch/plugins/PluginTestCase.java create mode 100644 core/src/test/java/org/elasticsearch/search/basic/SearchWithRandomIOExceptionsIT.java rename core/src/test/java/org/elasticsearch/test/{SettingsSource.java => NodeConfigurationSource.java} (57%) diff --git a/core/pom.xml b/core/pom.xml index 3186718248f..c9f8656eacb 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -314,6 +314,7 @@ org/elasticsearch/common/util/MockBigArrays.class org/elasticsearch/common/util/MockBigArrays$*.class org/elasticsearch/node/NodeMocksPlugin.class + org/elasticsearch/node/MockNode.class diff --git a/core/src/main/java/org/elasticsearch/client/transport/TransportClient.java b/core/src/main/java/org/elasticsearch/client/transport/TransportClient.java index 5ae074a1027..08157fe20ff 100644 --- a/core/src/main/java/org/elasticsearch/client/transport/TransportClient.java +++ b/core/src/main/java/org/elasticsearch/client/transport/TransportClient.java @@ -45,6 +45,7 @@ import org.elasticsearch.env.EnvironmentModule; import org.elasticsearch.indices.breaker.CircuitBreakerModule; import org.elasticsearch.monitor.MonitorService; import org.elasticsearch.node.internal.InternalSettingsPreparer; +import org.elasticsearch.plugins.Plugin; import org.elasticsearch.plugins.PluginsModule; import org.elasticsearch.plugins.PluginsService; import org.elasticsearch.search.SearchModule; @@ -54,6 +55,7 @@ import org.elasticsearch.transport.TransportModule; import org.elasticsearch.transport.TransportService; import org.elasticsearch.transport.netty.NettyTransport; +import java.util.ArrayList; import java.util.List; import java.util.concurrent.TimeUnit; @@ -81,6 +83,7 @@ public class TransportClient extends AbstractClient { public static class Builder { private Settings settings = Settings.EMPTY; + private List> pluginClasses = new ArrayList<>(); private boolean loadConfigSettings = true; /** @@ -107,6 +110,14 @@ public class TransportClient extends AbstractClient { return this; } + /** + * Add the given plugin to the client when it is created. + */ + public Builder addPlugin(Class pluginClass) { + pluginClasses.add(pluginClass); + return this; + } + /** * Builds a new instance of the transport client. */ @@ -121,7 +132,7 @@ public class TransportClient extends AbstractClient { .build(); Environment environment = tuple.v2(); - PluginsService pluginsService = new PluginsService(settings, tuple.v2()); + PluginsService pluginsService = new PluginsService(settings, tuple.v2(), pluginClasses); this.settings = pluginsService.updatedSettings(); Version version = Version.CURRENT; diff --git a/core/src/main/java/org/elasticsearch/node/Node.java b/core/src/main/java/org/elasticsearch/node/Node.java index 45e5522a22c..2b82a58d518 100644 --- a/core/src/main/java/org/elasticsearch/node/Node.java +++ b/core/src/main/java/org/elasticsearch/node/Node.java @@ -72,6 +72,7 @@ import org.elasticsearch.node.internal.InternalSettingsPreparer; import org.elasticsearch.node.settings.NodeSettingsService; import org.elasticsearch.percolator.PercolatorModule; import org.elasticsearch.percolator.PercolatorService; +import org.elasticsearch.plugins.Plugin; import org.elasticsearch.plugins.PluginsModule; import org.elasticsearch.plugins.PluginsService; import org.elasticsearch.repositories.RepositoriesModule; @@ -94,6 +95,8 @@ import org.elasticsearch.watcher.ResourceWatcherService; import java.io.IOException; import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; import java.util.concurrent.TimeUnit; import static org.elasticsearch.common.settings.Settings.settingsBuilder; @@ -116,19 +119,22 @@ public class Node implements Releasable { private final PluginsService pluginsService; private final Client client; - public Node() { - this(Settings.Builder.EMPTY_SETTINGS, true); + /** + * Constructs a node with the given settings. + * + * @param preparedSettings Base settings to configure the node with + * @param loadConfigSettings true if settings should also be loaded and merged from configuration files + */ + public Node(Settings preparedSettings, boolean loadConfigSettings) { + this(preparedSettings, loadConfigSettings, Version.CURRENT, Collections.>emptyList()); } - public Node(Settings preparedSettings, boolean loadConfigSettings) { + Node(Settings preparedSettings, boolean loadConfigSettings, Version version, Collection> classpathPlugins) { final Settings pSettings = settingsBuilder().put(preparedSettings) .put(Client.CLIENT_TYPE_SETTING, CLIENT_TYPE).build(); Tuple tuple = InternalSettingsPreparer.prepareSettings(pSettings, loadConfigSettings); tuple = new Tuple<>(TribeService.processSettings(tuple.v1()), tuple.v2()); - // The only place we can actually fake the version a node is running on: - Version version = pSettings.getAsVersion("tests.mock.version", Version.CURRENT); - ESLogger logger = Loggers.getLogger(Node.class, tuple.v1().get("name")); logger.info("version[{}], pid[{}], build[{}/{}]", version, JvmInfo.jvmInfo().pid(), Build.CURRENT.hashShort(), Build.CURRENT.timestamp()); @@ -140,7 +146,7 @@ public class Node implements Releasable { env.configFile(), Arrays.toString(env.dataFiles()), env.logsFile(), env.pluginsFile()); } - this.pluginsService = new PluginsService(tuple.v1(), tuple.v2()); + this.pluginsService = new PluginsService(tuple.v1(), tuple.v2(), classpathPlugins); this.settings = pluginsService.updatedSettings(); // create the environment based on the finalized (processed) view of the settings this.environment = new Environment(this.settings()); @@ -413,15 +419,4 @@ public class Node implements Releasable { public Injector injector() { return this.injector; } - - public static void main(String[] args) throws Exception { - final Node node = new Node(); - node.start(); - Runtime.getRuntime().addShutdownHook(new Thread() { - @Override - public void run() { - node.close(); - } - }); - } } diff --git a/core/src/main/java/org/elasticsearch/plugins/PluginsService.java b/core/src/main/java/org/elasticsearch/plugins/PluginsService.java index 8b3488ef4da..84b640e4c1b 100644 --- a/core/src/main/java/org/elasticsearch/plugins/PluginsService.java +++ b/core/src/main/java/org/elasticsearch/plugins/PluginsService.java @@ -70,10 +70,10 @@ public class PluginsService extends AbstractComponent { /** * We keep around a list of plugins */ - private final ImmutableList> plugins; + private final List> plugins; private final PluginsInfo info; - private final ImmutableMap> onModuleReferences; + private final Map> onModuleReferences; static class OnModuleReference { public final Class moduleClass; @@ -89,20 +89,19 @@ public class PluginsService extends AbstractComponent { * Constructs a new PluginService * @param settings The settings of the system * @param environment The environment of the system + * @param classpathPlugins Plugins that exist in the classpath which should be loaded */ - public PluginsService(Settings settings, Environment environment) { + public PluginsService(Settings settings, Environment environment, Collection> classpathPlugins) { super(settings); - ImmutableList.Builder> tupleBuilder = ImmutableList.builder(); + List> tupleBuilder = new ArrayList<>(); - // first we load specified plugins via 'plugin.types' settings parameter. - // this is a hack for what is between unit and integration tests... - String[] defaultPluginsClasses = settings.getAsArray("plugin.types"); - for (String pluginClass : defaultPluginsClasses) { - Plugin plugin = loadPlugin(pluginClass, settings, getClass().getClassLoader()); - PluginInfo pluginInfo = new PluginInfo(plugin.name(), plugin.description(), false, "NA", true, pluginClass, false); + // first we load plugins that are on the classpath. this is for tests and transport clients + for (Class pluginClass : classpathPlugins) { + Plugin plugin = loadPlugin(pluginClass, settings); + PluginInfo pluginInfo = new PluginInfo(plugin.name(), plugin.description(), false, "NA", true, pluginClass.getName(), false); if (logger.isTraceEnabled()) { - logger.trace("plugin loaded from settings [{}]", pluginInfo); + logger.trace("plugin loaded from classpath [{}]", pluginInfo); } tupleBuilder.add(new Tuple<>(pluginInfo, plugin)); } @@ -115,7 +114,7 @@ public class PluginsService extends AbstractComponent { throw new IllegalStateException("Unable to initialize plugins", ex); } - plugins = tupleBuilder.build(); + plugins = Collections.unmodifiableList(tupleBuilder); info = new PluginsInfo(); for (Tuple tuple : plugins) { info.add(tuple.v1()); @@ -128,7 +127,7 @@ public class PluginsService extends AbstractComponent { for (Tuple tuple : plugins) { PluginInfo info = tuple.v1(); if (info.isJvm()) { - jvmPlugins.put(tuple.v2().name(), tuple.v2()); + jvmPlugins.put(info.getName(), tuple.v2()); } if (info.isSite()) { sitePlugins.add(info.getName()); @@ -151,7 +150,7 @@ public class PluginsService extends AbstractComponent { logger.info("loaded {}, sites {}", jvmPlugins.keySet(), sitePlugins); - MapBuilder> onModuleReferences = MapBuilder.newMapBuilder(); + Map> onModuleReferences = new HashMap<>(); for (Plugin plugin : jvmPlugins.values()) { List list = new ArrayList<>(); for (Method method : plugin.getClass().getMethods()) { @@ -173,10 +172,10 @@ public class PluginsService extends AbstractComponent { onModuleReferences.put(plugin, list); } } - this.onModuleReferences = onModuleReferences.immutableMap(); + this.onModuleReferences = Collections.unmodifiableMap(onModuleReferences); } - public ImmutableList> plugins() { + public List> plugins() { return plugins; } @@ -355,7 +354,8 @@ public class PluginsService extends AbstractComponent { if (pluginInfo.isJvm()) { // reload lucene SPI with any new services from the plugin reloadLuceneSPI(loader); - plugin = loadPlugin(pluginInfo.getClassname(), settings, loader); + Class pluginClass = loadPluginClass(pluginInfo.getClassname(), loader); + plugin = loadPlugin(pluginClass, settings); } else { plugin = new SitePlugin(pluginInfo.getName(), pluginInfo.getDescription()); } @@ -384,10 +384,16 @@ public class PluginsService extends AbstractComponent { TokenizerFactory.reloadTokenizers(loader); } - private Plugin loadPlugin(String className, Settings settings, ClassLoader loader) { + private Class loadPluginClass(String className, ClassLoader loader) { try { - Class pluginClass = loader.loadClass(className).asSubclass(Plugin.class); + return loader.loadClass(className).asSubclass(Plugin.class); + } catch (ClassNotFoundException e) { + throw new ElasticsearchException("Could not find plugin class [" + className + "]", e); + } + } + private Plugin loadPlugin(Class pluginClass, Settings settings) { + try { try { return pluginClass.getConstructor(Settings.class).newInstance(settings); } catch (NoSuchMethodException e) { @@ -395,13 +401,12 @@ public class PluginsService extends AbstractComponent { return pluginClass.getConstructor().newInstance(); } catch (NoSuchMethodException e1) { throw new ElasticsearchException("No constructor for [" + pluginClass + "]. A plugin class must " + - "have either an empty default constructor or a single argument constructor accepting a " + - "Settings instance"); + "have either an empty default constructor or a single argument constructor accepting a " + + "Settings instance"); } } - } catch (Throwable e) { - throw new ElasticsearchException("Failed to load plugin class [" + className + "]", e); + throw new ElasticsearchException("Failed to load plugin class [" + pluginClass.getName() + "]", e); } } } diff --git a/core/src/main/java/org/elasticsearch/transport/TransportModule.java b/core/src/main/java/org/elasticsearch/transport/TransportModule.java index 0be84037700..0c8dbcdc118 100644 --- a/core/src/main/java/org/elasticsearch/transport/TransportModule.java +++ b/core/src/main/java/org/elasticsearch/transport/TransportModule.java @@ -85,7 +85,7 @@ public class TransportModule extends AbstractModule { bind(TransportService.class).asEagerSingleton(); } else { if (transportServices.containsKey(typeName) == false) { - throw new IllegalArgumentException("Unknown TransportService [" + typeName + "]"); + throw new IllegalArgumentException("Unknown TransportService type [" + typeName + "], known types are: " + transportServices.keySet()); } bind(TransportService.class).to(transportServices.get(typeName)).asEagerSingleton(); } diff --git a/core/src/test/java/org/elasticsearch/action/IndicesRequestIT.java b/core/src/test/java/org/elasticsearch/action/IndicesRequestIT.java index 10b34493334..dd31d4f352f 100644 --- a/core/src/test/java/org/elasticsearch/action/IndicesRequestIT.java +++ b/core/src/test/java/org/elasticsearch/action/IndicesRequestIT.java @@ -95,6 +95,7 @@ import org.elasticsearch.search.action.SearchServiceTransportAction; import org.elasticsearch.test.ESIntegTestCase; import org.elasticsearch.test.ESIntegTestCase.ClusterScope; import org.elasticsearch.test.ESIntegTestCase.Scope; +import org.elasticsearch.test.transport.MockTransportService; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.Transport; import org.elasticsearch.transport.TransportChannel; @@ -107,6 +108,7 @@ import org.junit.Before; import org.junit.Test; import java.util.ArrayList; +import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; @@ -141,11 +143,15 @@ public class IndicesRequestIT extends ESIntegTestCase { } @Override - protected Settings nodeSettings(int nodeOrdinal) { - return Settings.settingsBuilder() - .put(super.nodeSettings(nodeOrdinal)) - .extendArray("plugin.types", InterceptingTransportService.TestPlugin.class.getName()) - .build(); + protected Settings nodeSettings(int ordinal) { + // must set this independently of the plugin so it overrides MockTransportService + return Settings.builder().put(super.nodeSettings(ordinal)) + .put(TransportModule.TRANSPORT_SERVICE_TYPE_KEY, "intercepting").build(); + } + + @Override + protected Collection> nodePlugins() { + return pluginList(InterceptingTransportService.TestPlugin.class); } @Before @@ -856,10 +862,6 @@ public class IndicesRequestIT extends ESIntegTestCase { public void onModule(TransportModule transportModule) { transportModule.addTransportService("intercepting", InterceptingTransportService.class); } - @Override - public Settings additionalSettings() { - return Settings.builder().put(TransportModule.TRANSPORT_SERVICE_TYPE_KEY, "intercepting").build(); - } } private final Set actions = new HashSet<>(); diff --git a/core/src/test/java/org/elasticsearch/benchmark/scripts/expression/ScriptComparisonBenchmark.java b/core/src/test/java/org/elasticsearch/benchmark/scripts/expression/ScriptComparisonBenchmark.java index d0f534327a1..6581cd2e98e 100644 --- a/core/src/test/java/org/elasticsearch/benchmark/scripts/expression/ScriptComparisonBenchmark.java +++ b/core/src/test/java/org/elasticsearch/benchmark/scripts/expression/ScriptComparisonBenchmark.java @@ -20,6 +20,7 @@ package org.elasticsearch.benchmark.scripts.expression; import org.elasticsearch.ElasticsearchException; +import org.elasticsearch.Version; import org.elasticsearch.action.bulk.BulkRequestBuilder; import org.elasticsearch.action.search.SearchRequestBuilder; import org.elasticsearch.client.Client; @@ -28,13 +29,18 @@ import org.elasticsearch.common.StopWatch; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.index.query.QueryBuilders; +import org.elasticsearch.node.MockNode; import org.elasticsearch.node.Node; +import org.elasticsearch.plugins.Plugin; import org.elasticsearch.script.Script; import org.elasticsearch.script.ScriptService.ScriptType; import org.elasticsearch.search.sort.ScriptSortBuilder; import org.elasticsearch.search.sort.SortBuilders; import org.joda.time.PeriodType; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; import java.util.Random; import static org.elasticsearch.common.settings.Settings.settingsBuilder; @@ -102,10 +108,11 @@ public class ScriptComparisonBenchmark { static Client setupIndex() throws Exception { // create cluster - Settings settings = settingsBuilder().put("plugin.types", NativeScriptPlugin.class.getName()) - .put("name", "node1") - .build(); - Node node1 = nodeBuilder().clusterName(clusterName).settings(settings).node(); + Settings settings = settingsBuilder().put("name", "node1") + .put("cluster.name", clusterName).build(); + Collection> plugins = Collections.>singletonList(NativeScriptPlugin.class); + Node node1 = new MockNode(settings, true, Version.CURRENT, plugins); + node1.start(); Client client = node1.client(); client.admin().cluster().prepareHealth(indexName).setWaitForGreenStatus().setTimeout("10s").execute().actionGet(); diff --git a/core/src/test/java/org/elasticsearch/benchmark/scripts/score/ScriptsConstantScoreBenchmark.java b/core/src/test/java/org/elasticsearch/benchmark/scripts/score/ScriptsConstantScoreBenchmark.java index 23da127ba8b..7ad1837c215 100644 --- a/core/src/test/java/org/elasticsearch/benchmark/scripts/score/ScriptsConstantScoreBenchmark.java +++ b/core/src/test/java/org/elasticsearch/benchmark/scripts/score/ScriptsConstantScoreBenchmark.java @@ -18,14 +18,19 @@ */ package org.elasticsearch.benchmark.scripts.score; +import org.elasticsearch.Version; import org.elasticsearch.benchmark.scripts.score.plugin.NativeScriptExamplesPlugin; import org.elasticsearch.benchmark.scripts.score.script.NativeConstantForLoopScoreScript; import org.elasticsearch.benchmark.scripts.score.script.NativeConstantScoreScript; import org.elasticsearch.client.Client; import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.node.MockNode; import org.elasticsearch.node.Node; +import org.elasticsearch.plugins.Plugin; import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; import java.util.List; import java.util.Map.Entry; @@ -46,10 +51,13 @@ public class ScriptsConstantScoreBenchmark extends BasicScriptBenchmark { init(maxTerms); List allResults = new ArrayList<>(); - Settings settings = settingsBuilder().put("plugin.types", NativeScriptExamplesPlugin.class.getName()).build(); String clusterName = ScriptsConstantScoreBenchmark.class.getSimpleName(); - Node node1 = nodeBuilder().clusterName(clusterName).settings(settingsBuilder().put(settings).put("name", "node1")).node(); + Settings settings = settingsBuilder().put("name", "node1") + .put("cluster.name", clusterName).build(); + Collection> plugins = Collections.>singletonList(NativeScriptExamplesPlugin.class); + Node node1 = new MockNode(settings, true, Version.CURRENT, plugins); + node1.start(); Client client = node1.client(); client.admin().cluster().prepareHealth("test").setWaitForGreenStatus().setTimeout("10s").execute().actionGet(); diff --git a/core/src/test/java/org/elasticsearch/benchmark/scripts/score/ScriptsScoreBenchmark.java b/core/src/test/java/org/elasticsearch/benchmark/scripts/score/ScriptsScoreBenchmark.java index 889a45c4589..712b6130488 100644 --- a/core/src/test/java/org/elasticsearch/benchmark/scripts/score/ScriptsScoreBenchmark.java +++ b/core/src/test/java/org/elasticsearch/benchmark/scripts/score/ScriptsScoreBenchmark.java @@ -18,13 +18,18 @@ */ package org.elasticsearch.benchmark.scripts.score; +import org.elasticsearch.Version; import org.elasticsearch.benchmark.scripts.score.plugin.NativeScriptExamplesPlugin; import org.elasticsearch.benchmark.scripts.score.script.NativeNaiveTFIDFScoreScript; import org.elasticsearch.client.Client; import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.node.MockNode; import org.elasticsearch.node.Node; +import org.elasticsearch.plugins.Plugin; import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; import java.util.List; import java.util.Map.Entry; @@ -46,10 +51,12 @@ public class ScriptsScoreBenchmark extends BasicScriptBenchmark { boolean runMVEL = false; init(maxTerms); List allResults = new ArrayList<>(); - Settings settings = settingsBuilder().put("plugin.types", NativeScriptExamplesPlugin.class.getName()).build(); - String clusterName = ScriptsScoreBenchmark.class.getSimpleName(); - Node node1 = nodeBuilder().clusterName(clusterName).settings(settingsBuilder().put(settings).put("name", "node1")).node(); + Settings settings = settingsBuilder().put("name", "node1") + .put("cluster.name", clusterName).build(); + Collection> plugins = Collections.>singletonList(NativeScriptExamplesPlugin.class); + Node node1 = new MockNode(settings, true, Version.CURRENT, plugins); + node1.start(); Client client = node1.client(); client.admin().cluster().prepareHealth("test").setWaitForGreenStatus().setTimeout("10s").execute().actionGet(); diff --git a/core/src/test/java/org/elasticsearch/benchmark/scripts/score/ScriptsScorePayloadSumBenchmark.java b/core/src/test/java/org/elasticsearch/benchmark/scripts/score/ScriptsScorePayloadSumBenchmark.java index 786f943b2e5..556c224f1f3 100644 --- a/core/src/test/java/org/elasticsearch/benchmark/scripts/score/ScriptsScorePayloadSumBenchmark.java +++ b/core/src/test/java/org/elasticsearch/benchmark/scripts/score/ScriptsScorePayloadSumBenchmark.java @@ -18,14 +18,19 @@ */ package org.elasticsearch.benchmark.scripts.score; +import org.elasticsearch.Version; import org.elasticsearch.benchmark.scripts.score.plugin.NativeScriptExamplesPlugin; import org.elasticsearch.benchmark.scripts.score.script.NativePayloadSumNoRecordScoreScript; import org.elasticsearch.benchmark.scripts.score.script.NativePayloadSumScoreScript; import org.elasticsearch.client.Client; import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.node.MockNode; import org.elasticsearch.node.Node; +import org.elasticsearch.plugins.Plugin; import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; import java.util.List; import java.util.Map.Entry; @@ -46,10 +51,12 @@ public class ScriptsScorePayloadSumBenchmark extends BasicScriptBenchmark { init(maxTerms); List allResults = new ArrayList<>(); - Settings settings = settingsBuilder().put("plugin.types", NativeScriptExamplesPlugin.class.getName()).build(); - String clusterName = ScriptsScoreBenchmark.class.getSimpleName(); - Node node1 = nodeBuilder().clusterName(clusterName).settings(settingsBuilder().put(settings).put("name", "node1")).node(); + Settings settings = settingsBuilder().put("name", "node1") + .put("cluster.name", clusterName).build(); + Collection> plugins = Collections.>singletonList(NativeScriptExamplesPlugin.class); + Node node1 = new MockNode(settings, true, Version.CURRENT, plugins); + node1.start(); Client client = node1.client(); client.admin().cluster().prepareHealth("test").setWaitForGreenStatus().setTimeout("10s").execute().actionGet(); diff --git a/core/src/test/java/org/elasticsearch/client/transport/TransportClientHeadersTests.java b/core/src/test/java/org/elasticsearch/client/transport/TransportClientHeadersTests.java index 20d14f33dd4..631b2d18839 100644 --- a/core/src/test/java/org/elasticsearch/client/transport/TransportClientHeadersTests.java +++ b/core/src/test/java/org/elasticsearch/client/transport/TransportClientHeadersTests.java @@ -48,6 +48,7 @@ import org.elasticsearch.transport.TransportResponseHandler; import org.elasticsearch.transport.TransportService; import org.junit.Test; +import java.util.Collection; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; @@ -63,12 +64,13 @@ public class TransportClientHeadersTests extends AbstractClientHeadersTests { @Override protected Client buildClient(Settings headersSettings, GenericAction[] testedActions) { - TransportClient client = TransportClient.builder().settings(Settings.builder() + TransportClient client = TransportClient.builder() + .settings(Settings.builder() .put("client.transport.sniff", false) .put("node.name", "transport_client_" + this.getTestName()) - .put("plugin.types", InternalTransportService.TestPlugin.class.getName()) .put(headersSettings) - .build()).build(); + .build()) + .addPlugin(InternalTransportService.TestPlugin.class).build(); client.addTransportAddress(address); return client; @@ -76,15 +78,17 @@ public class TransportClientHeadersTests extends AbstractClientHeadersTests { @Test public void testWithSniffing() throws Exception { - TransportClient client = TransportClient.builder().settings(Settings.builder() + TransportClient client = TransportClient.builder() + .settings(Settings.builder() .put("client.transport.sniff", true) .put("cluster.name", "cluster1") .put("node.name", "transport_client_" + this.getTestName() + "_1") - .put("client.transport.nodes_sampler_interval", "1s") - .put("plugin.types", InternalTransportService.TestPlugin.class.getName()) + .put("client.transport.nodes_sampler_interval", "1s") .put(HEADER_SETTINGS) - .put("path.home", createTempDir().toString()) - .build()).build(); + .put("path.home", createTempDir().toString()).build()) + .addPlugin(InternalTransportService.TestPlugin.class) + .build(); + try { client.addTransportAddress(address); diff --git a/core/src/test/java/org/elasticsearch/cluster/ClusterInfoServiceIT.java b/core/src/test/java/org/elasticsearch/cluster/ClusterInfoServiceIT.java index 6368e5aa1d9..8805b895a00 100644 --- a/core/src/test/java/org/elasticsearch/cluster/ClusterInfoServiceIT.java +++ b/core/src/test/java/org/elasticsearch/cluster/ClusterInfoServiceIT.java @@ -47,6 +47,7 @@ import org.hamcrest.Matchers; import org.junit.Test; import java.io.IOException; +import java.util.Collection; import java.util.Map; import java.util.Set; import java.util.concurrent.CountDownLatch; @@ -146,10 +147,15 @@ public class ClusterInfoServiceIT extends ESIntegTestCase { return Settings.builder() // manual collection or upon cluster forming. .put(InternalClusterInfoService.INTERNAL_CLUSTER_INFO_TIMEOUT, "1s") - .putArray("plugin.types", TestPlugin.class.getName(), MockTransportService.TestPlugin.class.getName()) .build(); } + @Override + protected Collection> nodePlugins() { + return pluginList(TestPlugin.class, + MockTransportService.TestPlugin.class); + } + @Test public void testClusterInfoServiceCollectsInformation() throws Exception { internalCluster().startNodesAsync(2, diff --git a/core/src/test/java/org/elasticsearch/cluster/ClusterServiceIT.java b/core/src/test/java/org/elasticsearch/cluster/ClusterServiceIT.java index 9776f667dc9..5c3d0d966c2 100644 --- a/core/src/test/java/org/elasticsearch/cluster/ClusterServiceIT.java +++ b/core/src/test/java/org/elasticsearch/cluster/ClusterServiceIT.java @@ -69,6 +69,11 @@ import static org.hamcrest.Matchers.notNullValue; @ESIntegTestCase.SuppressLocalMode public class ClusterServiceIT extends ESIntegTestCase { + @Override + protected Collection> nodePlugins() { + return pluginList(TestPlugin.class); + } + @Test public void testTimeoutUpdateTask() throws Exception { Settings settings = settingsBuilder() @@ -637,7 +642,6 @@ public class ClusterServiceIT extends ESIntegTestCase { .put("discovery.zen.minimum_master_nodes", 1) .put("discovery.zen.ping_timeout", "400ms") .put("discovery.initial_state_timeout", "500ms") - .put("plugin.types", TestPlugin.class.getName()) .build(); String node_0 = internalCluster().startNode(settings); diff --git a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/decider/MockDiskUsagesIT.java b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/decider/MockDiskUsagesIT.java index 35b5ffefae3..8df9117a03e 100644 --- a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/decider/MockDiskUsagesIT.java +++ b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/decider/MockDiskUsagesIT.java @@ -29,9 +29,11 @@ import org.elasticsearch.cluster.routing.RoutingNode; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.transport.DummyTransportAddress; import org.elasticsearch.monitor.fs.FsInfo; +import org.elasticsearch.plugins.Plugin; import org.elasticsearch.test.ESIntegTestCase; import org.junit.Test; +import java.util.Collection; import java.util.Iterator; import java.util.List; import java.util.Map; @@ -50,13 +52,17 @@ public class MockDiskUsagesIT extends ESIntegTestCase { protected Settings nodeSettings(int nodeOrdinal) { return Settings.builder() .put(super.nodeSettings(nodeOrdinal)) - // Use the mock internal cluster info service, which has fake-able disk usages - .extendArray("plugin.types", MockInternalClusterInfoService.TestPlugin.class.getName()) // Update more frequently .put(InternalClusterInfoService.INTERNAL_CLUSTER_INFO_UPDATE_INTERVAL, "1s") .build(); } + @Override + protected Collection> nodePlugins() { + // Use the mock internal cluster info service, which has fake-able disk usages + return pluginList(MockInternalClusterInfoService.TestPlugin.class); + } + @Test //@TestLogging("org.elasticsearch.cluster:TRACE,org.elasticsearch.cluster.routing.allocation.decider:TRACE") public void testRerouteOccursOnDiskPassingHighWatermark() throws Exception { diff --git a/core/src/test/java/org/elasticsearch/cluster/settings/SettingsFilteringIT.java b/core/src/test/java/org/elasticsearch/cluster/settings/SettingsFilteringIT.java index 32551a4fe58..9c2d02617dc 100644 --- a/core/src/test/java/org/elasticsearch/cluster/settings/SettingsFilteringIT.java +++ b/core/src/test/java/org/elasticsearch/cluster/settings/SettingsFilteringIT.java @@ -43,11 +43,8 @@ import static org.hamcrest.Matchers.nullValue; public class SettingsFilteringIT extends ESIntegTestCase { @Override - protected Settings nodeSettings(int nodeOrdinal) { - return Settings.settingsBuilder() - .put(super.nodeSettings(nodeOrdinal)) - .put("plugin.types", SettingsFilteringPlugin.class.getName()) - .build(); + protected Collection> nodePlugins() { + return pluginList(SettingsFilteringPlugin.class); } public static class SettingsFilteringPlugin extends Plugin { diff --git a/core/src/test/java/org/elasticsearch/discovery/DiscoveryWithServiceDisruptionsIT.java b/core/src/test/java/org/elasticsearch/discovery/DiscoveryWithServiceDisruptionsIT.java index 02173a0c0b6..a884dac9854 100644 --- a/core/src/test/java/org/elasticsearch/discovery/DiscoveryWithServiceDisruptionsIT.java +++ b/core/src/test/java/org/elasticsearch/discovery/DiscoveryWithServiceDisruptionsIT.java @@ -48,6 +48,7 @@ import org.elasticsearch.discovery.zen.ping.ZenPing; import org.elasticsearch.discovery.zen.ping.ZenPingService; import org.elasticsearch.discovery.zen.ping.unicast.UnicastZenPing; import org.elasticsearch.discovery.zen.publish.PublishClusterStateAction; +import org.elasticsearch.plugins.Plugin; import org.elasticsearch.test.ESIntegTestCase; import org.elasticsearch.test.InternalTestCluster; import org.elasticsearch.test.discovery.ClusterDiscoveryConfiguration; @@ -82,7 +83,7 @@ public class DiscoveryWithServiceDisruptionsIT extends ESIntegTestCase { @Override protected Settings nodeSettings(int nodeOrdinal) { - return discoveryConfig.node(nodeOrdinal); + return discoveryConfig.nodeSettings(nodeOrdinal); } @Before @@ -134,9 +135,13 @@ public class DiscoveryWithServiceDisruptionsIT extends ESIntegTestCase { .put("transport.bind_host", "127.0.0.1") .put("transport.publish_host", "127.0.0.1") .put("gateway.local.list_timeout", "10s") // still long to induce failures but to long so test won't time out - .put("plugin.types", MockTransportService.TestPlugin.class.getName()) .build(); + @Override + protected Collection> nodePlugins() { + return pluginList(MockTransportService.TestPlugin.class); + } + private void configureUnicastCluster(int numberOfNodes, @Nullable int[] unicastHostsOrdinals, int minimumMasterNode) throws ExecutionException, InterruptedException { if (minimumMasterNode < 0) { minimumMasterNode = numberOfNodes / 2 + 1; diff --git a/core/src/test/java/org/elasticsearch/discovery/ZenUnicastDiscoveryIT.java b/core/src/test/java/org/elasticsearch/discovery/ZenUnicastDiscoveryIT.java index 87c1204b8b6..b233d4c0c95 100644 --- a/core/src/test/java/org/elasticsearch/discovery/ZenUnicastDiscoveryIT.java +++ b/core/src/test/java/org/elasticsearch/discovery/ZenUnicastDiscoveryIT.java @@ -42,7 +42,7 @@ public class ZenUnicastDiscoveryIT extends ESIntegTestCase { @Override protected Settings nodeSettings(int nodeOrdinal) { - return discoveryConfig.node(nodeOrdinal); + return discoveryConfig.nodeSettings(nodeOrdinal); } @Before diff --git a/core/src/test/java/org/elasticsearch/index/IndexWithShadowReplicasIT.java b/core/src/test/java/org/elasticsearch/index/IndexWithShadowReplicasIT.java index ee85af93215..09512433784 100644 --- a/core/src/test/java/org/elasticsearch/index/IndexWithShadowReplicasIT.java +++ b/core/src/test/java/org/elasticsearch/index/IndexWithShadowReplicasIT.java @@ -38,6 +38,7 @@ import org.elasticsearch.index.shard.IndexShard; import org.elasticsearch.index.shard.ShadowIndexShard; import org.elasticsearch.indices.IndicesService; import org.elasticsearch.indices.recovery.RecoveryTarget; +import org.elasticsearch.plugins.Plugin; import org.elasticsearch.search.SearchHit; import org.elasticsearch.search.sort.SortOrder; import org.elasticsearch.snapshots.SnapshotState; @@ -49,6 +50,7 @@ import org.junit.Test; import java.io.IOException; import java.nio.file.Path; +import java.util.Collection; import java.util.List; import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.CountDownLatch; @@ -80,6 +82,11 @@ public class IndexWithShadowReplicasIT extends ESIntegTestCase { .build(); } + @Override + protected Collection> nodePlugins() { + return pluginList(MockTransportService.TestPlugin.class); + } + public void testCannotCreateWithBadPath() throws Exception { Settings nodeSettings = nodeSettings("/badpath"); internalCluster().startNodesAsync(1, nodeSettings).get(); @@ -416,7 +423,6 @@ public class IndexWithShadowReplicasIT extends ESIntegTestCase { Path dataPath = createTempDir(); Settings nodeSettings = Settings.builder() .put("node.add_id_to_custom_path", false) - .put("plugin.types", MockTransportService.TestPlugin.class.getName()) .put("path.shared_data", dataPath) .build(); diff --git a/core/src/test/java/org/elasticsearch/index/TransportIndexFailuresIT.java b/core/src/test/java/org/elasticsearch/index/TransportIndexFailuresIT.java index bdbcd45c7e4..c5cab481fae 100644 --- a/core/src/test/java/org/elasticsearch/index/TransportIndexFailuresIT.java +++ b/core/src/test/java/org/elasticsearch/index/TransportIndexFailuresIT.java @@ -33,12 +33,14 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.discovery.Discovery; import org.elasticsearch.discovery.DiscoverySettings; import org.elasticsearch.discovery.zen.fd.FaultDetection; +import org.elasticsearch.plugins.Plugin; import org.elasticsearch.test.ESIntegTestCase; import org.elasticsearch.test.transport.MockTransportService; import org.elasticsearch.transport.TransportModule; import org.elasticsearch.transport.TransportService; import org.junit.Test; +import java.util.Collection; import java.util.List; import static org.elasticsearch.cluster.routing.ShardRoutingState.*; @@ -57,9 +59,13 @@ public class TransportIndexFailuresIT extends ESIntegTestCase { .put(FaultDetection.SETTING_PING_RETRIES, "1") // <-- for hitting simulated network failures quickly .put(DiscoverySettings.PUBLISH_TIMEOUT, "1s") // <-- for hitting simulated network failures quickly .put("discovery.zen.minimum_master_nodes", 1) - .put("plugin.types", MockTransportService.TestPlugin.class.getName()) .build(); + @Override + protected Collection> nodePlugins() { + return pluginList(MockTransportService.TestPlugin.class); + } + @Override protected int numberOfShards() { return 1; diff --git a/core/src/test/java/org/elasticsearch/index/mapper/externalvalues/ExternalValuesMapperIntegrationIT.java b/core/src/test/java/org/elasticsearch/index/mapper/externalvalues/ExternalValuesMapperIntegrationIT.java index 101b3d6b16b..42a9df6632e 100644 --- a/core/src/test/java/org/elasticsearch/index/mapper/externalvalues/ExternalValuesMapperIntegrationIT.java +++ b/core/src/test/java/org/elasticsearch/index/mapper/externalvalues/ExternalValuesMapperIntegrationIT.java @@ -25,19 +25,20 @@ import org.elasticsearch.common.geo.builders.ShapeBuilder; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.index.query.QueryBuilders; +import org.elasticsearch.plugins.Plugin; import org.elasticsearch.test.ESIntegTestCase; import org.junit.Test; +import java.util.Arrays; +import java.util.Collection; + import static org.hamcrest.Matchers.equalTo; public class ExternalValuesMapperIntegrationIT extends ESIntegTestCase { @Override - protected Settings nodeSettings(int nodeOrdinal) { - return Settings.settingsBuilder() - .put(super.nodeSettings(nodeOrdinal)) - .put("plugin.types", ExternalMapperPlugin.class.getName()) - .build(); + protected Collection> nodePlugins() { + return pluginList(ExternalMapperPlugin.class); } @Test diff --git a/core/src/test/java/org/elasticsearch/index/query/plugin/CustomQueryParserIT.java b/core/src/test/java/org/elasticsearch/index/query/plugin/CustomQueryParserIT.java index e4d345e80b0..1f0743abd96 100644 --- a/core/src/test/java/org/elasticsearch/index/query/plugin/CustomQueryParserIT.java +++ b/core/src/test/java/org/elasticsearch/index/query/plugin/CustomQueryParserIT.java @@ -27,10 +27,13 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.query.BoolQueryBuilder; import org.elasticsearch.index.query.IndexQueryParserService; import org.elasticsearch.indices.IndicesService; +import org.elasticsearch.plugins.Plugin; import org.elasticsearch.test.ESIntegTestCase; import org.junit.Before; import org.junit.Test; +import java.util.Collection; + import static org.elasticsearch.index.query.QueryBuilders.boolQuery; import static org.elasticsearch.index.query.QueryBuilders.constantScoreQuery; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitCount; @@ -39,9 +42,8 @@ import static org.hamcrest.Matchers.instanceOf; public class CustomQueryParserIT extends ESIntegTestCase { @Override - protected Settings nodeSettings(int nodeOrdinal) { - return Settings.builder().put(super.nodeSettings(nodeOrdinal)) - .put("plugin.types", DummyQueryParserPlugin.class.getName()).build(); + protected Collection> nodePlugins() { + return pluginList(DummyQueryParserPlugin.class); } @Before 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 b9d00741720..667174fe210 100644 --- a/core/src/test/java/org/elasticsearch/index/store/CorruptedFileIT.java +++ b/core/src/test/java/org/elasticsearch/index/store/CorruptedFileIT.java @@ -61,6 +61,7 @@ import org.elasticsearch.indices.recovery.RecoveryFileChunkRequest; import org.elasticsearch.indices.recovery.RecoverySettings; import org.elasticsearch.indices.recovery.RecoveryTarget; import org.elasticsearch.monitor.fs.FsInfo; +import org.elasticsearch.plugins.Plugin; import org.elasticsearch.snapshots.SnapshotState; import org.elasticsearch.test.ESIntegTestCase; import org.elasticsearch.test.InternalTestCluster; @@ -98,7 +99,6 @@ public class CorruptedFileIT extends ESIntegTestCase { // we really need local GW here since this also checks for corruption etc. // and we need to make sure primaries are not just trashed if we don't have replicas .put(super.nodeSettings(nodeOrdinal)) - .extendArray("plugin.types", MockTransportService.TestPlugin.class.getName()) // speed up recoveries .put(RecoverySettings.INDICES_RECOVERY_CONCURRENT_STREAMS, 10) .put(RecoverySettings.INDICES_RECOVERY_CONCURRENT_SMALL_FILE_STREAMS, 10) @@ -106,6 +106,11 @@ public class CorruptedFileIT extends ESIntegTestCase { .build(); } + @Override + protected Collection> nodePlugins() { + return pluginList(MockTransportService.TestPlugin.class); + } + /** * Tests that we can actually recover from a corruption on the primary given that we have replica shards around. */ diff --git a/core/src/test/java/org/elasticsearch/index/store/CorruptedTranslogIT.java b/core/src/test/java/org/elasticsearch/index/store/CorruptedTranslogIT.java index 04b0ed38742..70fcfd4b180 100644 --- a/core/src/test/java/org/elasticsearch/index/store/CorruptedTranslogIT.java +++ b/core/src/test/java/org/elasticsearch/index/store/CorruptedTranslogIT.java @@ -34,6 +34,7 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.shard.IndexShard; import org.elasticsearch.index.translog.TranslogConfig; 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.junit.annotations.TestLogging; @@ -46,6 +47,7 @@ import java.nio.ByteBuffer; import java.nio.channels.FileChannel; import java.nio.file.*; import java.util.Arrays; +import java.util.Collection; import java.util.List; import java.util.Set; import java.util.TreeSet; @@ -61,12 +63,10 @@ import static org.hamcrest.Matchers.notNullValue; public class CorruptedTranslogIT extends ESIntegTestCase { @Override - protected Settings nodeSettings(int nodeOrdinal) { - return Settings.builder() - // we really need local GW here since this also checks for corruption etc. - // and we need to make sure primaries are not just trashed if we don't have replicas - .put(super.nodeSettings(nodeOrdinal)) - .extendArray("plugin.types", MockTransportService.TestPlugin.class.getName()).build(); + protected Collection> nodePlugins() { + // we really need local GW here since this also checks for corruption etc. + // and we need to make sure primaries are not just trashed if we don't have replicas + return pluginList(MockTransportService.TestPlugin.class); } @Test diff --git a/core/src/test/java/org/elasticsearch/index/store/ExceptionRetryIT.java b/core/src/test/java/org/elasticsearch/index/store/ExceptionRetryIT.java index 9fe2a0fd629..91d17f45038 100644 --- a/core/src/test/java/org/elasticsearch/index/store/ExceptionRetryIT.java +++ b/core/src/test/java/org/elasticsearch/index/store/ExceptionRetryIT.java @@ -29,6 +29,7 @@ import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.discovery.Discovery; +import org.elasticsearch.plugins.Plugin; import org.elasticsearch.search.SearchHit; import org.elasticsearch.test.ESIntegTestCase; import org.elasticsearch.test.transport.MockTransportService; @@ -36,6 +37,7 @@ import org.elasticsearch.transport.*; import org.junit.Test; import java.io.IOException; +import java.util.Collection; import java.util.HashSet; import java.util.Set; import java.util.concurrent.ExecutionException; @@ -51,11 +53,8 @@ import static org.hamcrest.Matchers.greaterThan; public class ExceptionRetryIT extends ESIntegTestCase { @Override - protected Settings nodeSettings(int nodeOrdinal) { - return Settings.builder() - .put(super.nodeSettings(nodeOrdinal)) - .extendArray("plugin.types", MockTransportService.TestPlugin.class.getName()) - .build(); + protected Collection> nodePlugins() { + return pluginList(MockTransportService.TestPlugin.class); } @Override diff --git a/core/src/test/java/org/elasticsearch/indices/analysis/PreBuiltAnalyzerIntegrationIT.java b/core/src/test/java/org/elasticsearch/indices/analysis/PreBuiltAnalyzerIntegrationIT.java index 839fc598d01..8f27e679db8 100644 --- a/core/src/test/java/org/elasticsearch/indices/analysis/PreBuiltAnalyzerIntegrationIT.java +++ b/core/src/test/java/org/elasticsearch/indices/analysis/PreBuiltAnalyzerIntegrationIT.java @@ -25,11 +25,13 @@ import org.apache.lucene.analysis.Analyzer; import org.elasticsearch.Version; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentBuilder; +import org.elasticsearch.plugins.Plugin; import org.elasticsearch.test.ESBackcompatTestCase; import org.elasticsearch.test.ESIntegTestCase; import org.junit.Test; import java.lang.reflect.Field; +import java.util.Collection; import java.util.List; import java.util.Locale; import java.util.Map; @@ -44,11 +46,8 @@ import static org.hamcrest.Matchers.notNullValue; public class PreBuiltAnalyzerIntegrationIT extends ESIntegTestCase { @Override - protected Settings nodeSettings(int nodeOrdinal) { - return Settings.settingsBuilder() - .put(super.nodeSettings(nodeOrdinal)) - .put("plugin.types", DummyAnalysisPlugin.class.getName()) - .build(); + protected Collection> nodePlugins() { + return pluginList(DummyAnalysisPlugin.class); } @Test diff --git a/core/src/test/java/org/elasticsearch/indices/memory/breaker/RandomExceptionCircuitBreakerIT.java b/core/src/test/java/org/elasticsearch/indices/memory/breaker/RandomExceptionCircuitBreakerIT.java index 6ff35daf55a..234f3eada9a 100644 --- a/core/src/test/java/org/elasticsearch/indices/memory/breaker/RandomExceptionCircuitBreakerIT.java +++ b/core/src/test/java/org/elasticsearch/indices/memory/breaker/RandomExceptionCircuitBreakerIT.java @@ -45,6 +45,7 @@ import org.junit.Test; import java.io.IOException; import java.util.Arrays; +import java.util.Collection; import java.util.Random; import java.util.concurrent.ExecutionException; @@ -57,6 +58,11 @@ import static org.hamcrest.Matchers.equalTo; */ public class RandomExceptionCircuitBreakerIT extends ESIntegTestCase { + @Override + protected Collection> nodePlugins() { + return pluginList(RandomExceptionDirectoryReaderWrapper.TestPlugin.class); + } + @Test public void testBreakerWithRandomExceptions() throws IOException, InterruptedException, ExecutionException { for (NodeStats node : client().admin().cluster().prepareNodesStats() @@ -107,7 +113,6 @@ public class RandomExceptionCircuitBreakerIT extends ESIntegTestCase { Settings.Builder settings = settingsBuilder() .put(indexSettings()) - .extendArray("plugin.types", RandomExceptionDirectoryReaderWrapper.TestPlugin.class.getName()) .put(EXCEPTION_TOP_LEVEL_RATIO_KEY, topLevelRate) .put(EXCEPTION_LOW_LEVEL_RATIO_KEY, lowLevelRate) .put(MockEngineSupport.WRAP_READER_RATIO, 1.0d); diff --git a/core/src/test/java/org/elasticsearch/indices/recovery/IndexRecoveryIT.java b/core/src/test/java/org/elasticsearch/indices/recovery/IndexRecoveryIT.java index c2860c75033..8f8b12d741c 100644 --- a/core/src/test/java/org/elasticsearch/indices/recovery/IndexRecoveryIT.java +++ b/core/src/test/java/org/elasticsearch/indices/recovery/IndexRecoveryIT.java @@ -47,6 +47,7 @@ import org.elasticsearch.index.store.Store; import org.elasticsearch.indices.IndicesService; import org.elasticsearch.indices.recovery.RecoveryState.Stage; import org.elasticsearch.indices.recovery.RecoveryState.Type; +import org.elasticsearch.plugins.Plugin; import org.elasticsearch.snapshots.SnapshotState; import org.elasticsearch.test.ESIntegTestCase; import org.elasticsearch.test.ESIntegTestCase.ClusterScope; @@ -58,6 +59,7 @@ import org.junit.Test; import java.io.IOException; import java.util.ArrayList; +import java.util.Collection; import java.util.List; import java.util.Map; import java.util.concurrent.CountDownLatch; @@ -85,6 +87,10 @@ public class IndexRecoveryIT extends ESIntegTestCase { private static final int SHARD_COUNT = 1; private static final int REPLICA_COUNT = 0; + @Override + protected Collection> nodePlugins() { + return pluginList(MockTransportService.TestPlugin.class); + } private void assertRecoveryStateWithoutStage(RecoveryState state, int shardId, Type type, String sourceNode, String targetNode, boolean hasRestoreSource) { @@ -519,7 +525,6 @@ public class IndexRecoveryIT extends ESIntegTestCase { final Settings nodeSettings = Settings.builder() .put(RecoverySettings.INDICES_RECOVERY_RETRY_DELAY_NETWORK, "100ms") .put(RecoverySettings.INDICES_RECOVERY_INTERNAL_ACTION_TIMEOUT, "1s") - .put("plugin.types", MockTransportService.TestPlugin.class.getName()) .put(MockFSDirectoryService.RANDOM_PREVENT_DOUBLE_WRITE, false) // restarted recoveries will delete temp files and write them again .build(); // start a master node diff --git a/core/src/test/java/org/elasticsearch/indices/store/IndicesStoreIntegrationIT.java b/core/src/test/java/org/elasticsearch/indices/store/IndicesStoreIntegrationIT.java index 898415152ca..a287bcb4f54 100644 --- a/core/src/test/java/org/elasticsearch/indices/store/IndicesStoreIntegrationIT.java +++ b/core/src/test/java/org/elasticsearch/indices/store/IndicesStoreIntegrationIT.java @@ -47,6 +47,7 @@ import org.elasticsearch.index.Index; import org.elasticsearch.index.shard.ShardId; import org.elasticsearch.indices.IndicesService; import org.elasticsearch.indices.recovery.RecoverySource; +import org.elasticsearch.plugins.Plugin; import org.elasticsearch.test.ESIntegTestCase; import org.elasticsearch.test.ESIntegTestCase.ClusterScope; import org.elasticsearch.test.InternalTestCluster; @@ -63,6 +64,7 @@ import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.util.Arrays; +import java.util.Collection; import java.util.List; import java.util.concurrent.CountDownLatch; import java.util.concurrent.Future; @@ -87,10 +89,14 @@ public class IndicesStoreIntegrationIT extends ESIntegTestCase { // which is between 1 and 2 sec can cause each of the shard deletion requests to timeout. // to prevent this we are setting the timeout here to something highish ie. the default in practice .put(IndicesStore.INDICES_STORE_DELETE_SHARD_TIMEOUT, new TimeValue(30, TimeUnit.SECONDS)) - .extendArray("plugin.types", MockTransportService.TestPlugin.class.getName()) .build(); } + @Override + protected Collection> nodePlugins() { + return pluginList(MockTransportService.TestPlugin.class); + } + @Override protected void ensureClusterStateConsistency() throws IOException { // testShardActiveElseWhere might change the state of a non-master node diff --git a/core/src/test/java/org/elasticsearch/indices/template/IndexTemplateFilteringIT.java b/core/src/test/java/org/elasticsearch/indices/template/IndexTemplateFilteringIT.java index e441a952f21..f67e12095f3 100644 --- a/core/src/test/java/org/elasticsearch/indices/template/IndexTemplateFilteringIT.java +++ b/core/src/test/java/org/elasticsearch/indices/template/IndexTemplateFilteringIT.java @@ -33,6 +33,8 @@ import org.elasticsearch.test.ESIntegTestCase.ClusterScope; import org.elasticsearch.test.ESIntegTestCase.Scope; import org.junit.Test; +import java.util.Collection; + import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; import static org.hamcrest.Matchers.is; import static org.hamcrest.core.IsNull.notNullValue; @@ -41,11 +43,8 @@ import static org.hamcrest.core.IsNull.notNullValue; public class IndexTemplateFilteringIT extends ESIntegTestCase { @Override - protected Settings nodeSettings(int nodeOrdinal) { - return Settings.builder() - .put(super.nodeSettings(nodeOrdinal)) - .put("plugin.types", TestPlugin.class.getName()) - .build(); + protected Collection> nodePlugins() { + return pluginList(TestPlugin.class); } @Test diff --git a/core/src/test/java/org/elasticsearch/node/MockNode.java b/core/src/test/java/org/elasticsearch/node/MockNode.java new file mode 100644 index 00000000000..04762641f00 --- /dev/null +++ b/core/src/test/java/org/elasticsearch/node/MockNode.java @@ -0,0 +1,54 @@ +/* + * 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.node; + +import org.elasticsearch.Version; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.plugins.Plugin; + +import java.util.Collection; + +/** + * A node for testing which allows: + *
    + *
  • Overriding Version.CURRENT
  • + *
  • Adding test plugins that exist on the classpath
  • + *
+ */ +public class MockNode extends Node { + + // these are kept here so a copy of this MockNode can be created, since Node does not store them + private Version version; + private Collection> plugins; + + public MockNode(Settings settings, boolean loadConfigSettings, Version version, Collection> classpathPlugins) { + super(settings, loadConfigSettings, version, classpathPlugins); + this.version = version; + this.plugins = classpathPlugins; + } + + public Collection> getPlugins() { + return plugins; + } + + public Version getVersion() { + return version; + } +} diff --git a/core/src/test/java/org/elasticsearch/nodesinfo/SimpleNodesInfoIT.java b/core/src/test/java/org/elasticsearch/nodesinfo/SimpleNodesInfoIT.java index 86b1a6a4cc3..406cf68a98e 100644 --- a/core/src/test/java/org/elasticsearch/nodesinfo/SimpleNodesInfoIT.java +++ b/core/src/test/java/org/elasticsearch/nodesinfo/SimpleNodesInfoIT.java @@ -22,7 +22,7 @@ package org.elasticsearch.nodesinfo; import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse; import org.elasticsearch.action.admin.cluster.node.info.NodesInfoResponse; import org.elasticsearch.cluster.ClusterService; -import org.elasticsearch.plugins.PluginTestCase; +import org.elasticsearch.test.ESIntegTestCase; import org.elasticsearch.test.ESIntegTestCase.ClusterScope; import org.junit.Test; @@ -36,7 +36,7 @@ import static org.hamcrest.Matchers.*; * */ @ClusterScope(scope= Scope.TEST, numDataNodes =0) -public class SimpleNodesInfoIT extends PluginTestCase { +public class SimpleNodesInfoIT extends ESIntegTestCase { static final class Fields { static final String SITE_PLUGIN = "dummy"; diff --git a/core/src/test/java/org/elasticsearch/plugins/PluggableTransportModuleIT.java b/core/src/test/java/org/elasticsearch/plugins/PluggableTransportModuleIT.java index bbeeac122f9..a6ac6bf1c69 100644 --- a/core/src/test/java/org/elasticsearch/plugins/PluggableTransportModuleIT.java +++ b/core/src/test/java/org/elasticsearch/plugins/PluggableTransportModuleIT.java @@ -31,6 +31,7 @@ import org.elasticsearch.transport.*; import org.junit.Test; import java.io.IOException; +import java.util.Collection; import java.util.concurrent.atomic.AtomicInteger; import static org.elasticsearch.common.settings.Settings.settingsBuilder; @@ -51,16 +52,17 @@ public class PluggableTransportModuleIT extends ESIntegTestCase { return settingsBuilder() .put(super.nodeSettings(nodeOrdinal)) .put(DiscoveryModule.DISCOVERY_TYPE_KEY, "local") - .put("plugin.types", CountingSentRequestsPlugin.class.getName()) .build(); } @Override - protected Settings transportClientSettings() { - return settingsBuilder() - .put("plugin.types", CountingSentRequestsPlugin.class.getName()) - .put(super.transportClientSettings()) - .build(); + protected Collection> nodePlugins() { + return pluginList(CountingSentRequestsPlugin.class); + } + + @Override + protected Collection> transportClientPlugins() { + return pluginList(CountingSentRequestsPlugin.class); } @Test diff --git a/core/src/test/java/org/elasticsearch/plugins/PluginTestCase.java b/core/src/test/java/org/elasticsearch/plugins/PluginTestCase.java deleted file mode 100644 index dffcba6e69f..00000000000 --- a/core/src/test/java/org/elasticsearch/plugins/PluginTestCase.java +++ /dev/null @@ -1,56 +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.plugins; - -import org.elasticsearch.cluster.ClusterService; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.test.ESIntegTestCase; - -import java.net.URISyntaxException; -import java.net.URL; - -import static org.elasticsearch.client.Requests.clusterHealthRequest; -import static org.elasticsearch.common.settings.Settings.settingsBuilder; - -/** - * Base class that lets you start a node with plugins. - */ -public abstract class PluginTestCase extends ESIntegTestCase { - - public String startNodeWithPlugins(Settings nodeSettings, String pluginDir, String ... pluginClassNames) throws URISyntaxException { - URL resource = getClass().getResource(pluginDir); - Settings.Builder settings = settingsBuilder(); - settings.put(nodeSettings); - if (resource != null) { - settings.put("path.plugins", getDataPath(pluginDir).toAbsolutePath()); - } - - if (pluginClassNames.length > 0) { - settings.putArray("plugin.types", pluginClassNames); - } - - String nodeName = internalCluster().startNode(settings); - - // We wait for a Green status - client().admin().cluster().health(clusterHealthRequest().waitForGreenStatus()).actionGet(); - - return internalCluster().getInstance(ClusterService.class, nodeName).state().nodes().localNodeId(); - } -} diff --git a/core/src/test/java/org/elasticsearch/plugins/PluginsServiceTests.java b/core/src/test/java/org/elasticsearch/plugins/PluginsServiceTests.java index 6ac34c2297e..c497c1ab6cc 100644 --- a/core/src/test/java/org/elasticsearch/plugins/PluginsServiceTests.java +++ b/core/src/test/java/org/elasticsearch/plugins/PluginsServiceTests.java @@ -24,6 +24,8 @@ import org.elasticsearch.env.Environment; import org.elasticsearch.index.store.IndexStoreModule; import org.elasticsearch.test.ESTestCase; +import java.util.Arrays; + public class PluginsServiceTests extends ESTestCase { public static class AdditionalSettingsPlugin1 extends Plugin { @Override @@ -54,13 +56,16 @@ public class PluginsServiceTests extends ESTestCase { } } + static PluginsService newPluginsService(Settings settings, Class... classpathPlugins) { + return new PluginsService(settings, new Environment(settings), Arrays.asList(classpathPlugins)); + } + public void testAdditionalSettings() { Settings settings = Settings.builder() .put("path.home", createTempDir()) .put("my.setting", "test") - .put(IndexStoreModule.STORE_TYPE, IndexStoreModule.Type.SIMPLEFS.getSettingsKey()) - .putArray("plugin.types", AdditionalSettingsPlugin1.class.getName()).build(); - PluginsService service = new PluginsService(settings, new Environment(settings)); + .put(IndexStoreModule.STORE_TYPE, IndexStoreModule.Type.SIMPLEFS.getSettingsKey()).build(); + PluginsService service = newPluginsService(settings, AdditionalSettingsPlugin1.class); Settings newSettings = service.updatedSettings(); assertEquals("test", newSettings.get("my.setting")); // previous settings still exist assertEquals("1", newSettings.get("foo.bar")); // added setting exists @@ -69,9 +74,8 @@ public class PluginsServiceTests extends ESTestCase { public void testAdditionalSettingsClash() { Settings settings = Settings.builder() - .put("path.home", createTempDir()) - .putArray("plugin.types", AdditionalSettingsPlugin1.class.getName(), AdditionalSettingsPlugin2.class.getName()).build(); - PluginsService service = new PluginsService(settings, new Environment(settings)); + .put("path.home", createTempDir()).build(); + PluginsService service = newPluginsService(settings, AdditionalSettingsPlugin1.class, AdditionalSettingsPlugin2.class); try { service.updatedSettings(); fail("Expected exception when building updated settings"); diff --git a/core/src/test/java/org/elasticsearch/plugins/ResponseHeaderPluginIT.java b/core/src/test/java/org/elasticsearch/plugins/ResponseHeaderPluginIT.java index b171278d659..d9580854c14 100644 --- a/core/src/test/java/org/elasticsearch/plugins/ResponseHeaderPluginIT.java +++ b/core/src/test/java/org/elasticsearch/plugins/ResponseHeaderPluginIT.java @@ -25,6 +25,8 @@ import org.elasticsearch.test.ESIntegTestCase.ClusterScope; import org.elasticsearch.test.rest.client.http.HttpResponse; import org.junit.Test; +import java.util.Collection; + import static org.elasticsearch.rest.RestStatus.OK; import static org.elasticsearch.rest.RestStatus.UNAUTHORIZED; import static org.elasticsearch.test.ESIntegTestCase.Scope; @@ -41,11 +43,15 @@ public class ResponseHeaderPluginIT extends ESIntegTestCase { protected Settings nodeSettings(int nodeOrdinal) { return Settings.settingsBuilder() .put(super.nodeSettings(nodeOrdinal)) - .put("plugin.types", TestResponseHeaderPlugin.class.getName()) .put("force.http.enabled", true) .build(); } + @Override + protected Collection> nodePlugins() { + return pluginList(TestResponseHeaderPlugin.class); + } + @Test public void testThatSettingHeadersWorks() throws Exception { ensureGreen(); diff --git a/core/src/test/java/org/elasticsearch/recovery/RelocationIT.java b/core/src/test/java/org/elasticsearch/recovery/RelocationIT.java index 39622287ea2..11016ee1b4c 100644 --- a/core/src/test/java/org/elasticsearch/recovery/RelocationIT.java +++ b/core/src/test/java/org/elasticsearch/recovery/RelocationIT.java @@ -54,6 +54,7 @@ import org.elasticsearch.indices.IndicesLifecycle; import org.elasticsearch.indices.recovery.RecoveryFileChunkRequest; import org.elasticsearch.indices.recovery.RecoverySettings; import org.elasticsearch.indices.recovery.RecoveryTarget; +import org.elasticsearch.plugins.Plugin; import org.elasticsearch.search.SearchHit; import org.elasticsearch.search.SearchHits; import org.elasticsearch.test.BackgroundIndexer; @@ -76,6 +77,7 @@ import java.nio.file.Path; import java.nio.file.SimpleFileVisitor; import java.nio.file.attribute.BasicFileAttributes; import java.util.ArrayList; +import java.util.Collection; import java.util.List; import java.util.concurrent.CountDownLatch; import java.util.concurrent.Semaphore; @@ -100,12 +102,10 @@ public class RelocationIT extends ESIntegTestCase { private final TimeValue ACCEPTABLE_RELOCATION_TIME = new TimeValue(5, TimeUnit.MINUTES); @Override - protected Settings nodeSettings(int nodeOrdinal) { - return Settings.builder() - .put("plugin.types", MockTransportService.TestPlugin.class.getName()).build(); + protected Collection> nodePlugins() { + return pluginList(MockTransportService.TestPlugin.class); } - @Test public void testSimpleRelocationNoIndexing() { logger.info("--> starting [node1] ..."); diff --git a/core/src/test/java/org/elasticsearch/recovery/TruncatedRecoveryIT.java b/core/src/test/java/org/elasticsearch/recovery/TruncatedRecoveryIT.java index 943a1485100..25347fa1fab 100644 --- a/core/src/test/java/org/elasticsearch/recovery/TruncatedRecoveryIT.java +++ b/core/src/test/java/org/elasticsearch/recovery/TruncatedRecoveryIT.java @@ -34,6 +34,7 @@ import org.elasticsearch.index.query.QueryBuilders; import org.elasticsearch.indices.recovery.RecoveryFileChunkRequest; import org.elasticsearch.indices.recovery.RecoverySettings; import org.elasticsearch.indices.recovery.RecoveryTarget; +import org.elasticsearch.plugins.Plugin; import org.elasticsearch.test.ESIntegTestCase; import org.elasticsearch.test.transport.MockTransportService; import org.elasticsearch.transport.*; @@ -41,6 +42,7 @@ import org.junit.Test; import java.io.IOException; import java.util.ArrayList; +import java.util.Collection; import java.util.Collections; import java.util.List; import java.util.concurrent.CountDownLatch; @@ -55,14 +57,19 @@ import static org.hamcrest.Matchers.greaterThanOrEqualTo; @SuppressCodecs("*") // test relies on exact file extensions public class TruncatedRecoveryIT extends ESIntegTestCase { + @Override protected Settings nodeSettings(int nodeOrdinal) { Settings.Builder builder = Settings.builder() .put(super.nodeSettings(nodeOrdinal)) - .extendArray("plugin.types", MockTransportService.TestPlugin.class.getName()) .put(RecoverySettings.INDICES_RECOVERY_FILE_CHUNK_SIZE, new ByteSizeValue(randomIntBetween(50, 300), ByteSizeUnit.BYTES)); return builder.build(); } + @Override + protected Collection> nodePlugins() { + return pluginList(MockTransportService.TestPlugin.class); + } + /** * This test tries to truncate some of larger files in the index to trigger leftovers on the recovery * target. This happens during recovery when the last chunk of the file is transferred to the replica diff --git a/core/src/test/java/org/elasticsearch/script/CustomScriptContextIT.java b/core/src/test/java/org/elasticsearch/script/CustomScriptContextIT.java index efac975fcc3..8f4a71dce08 100644 --- a/core/src/test/java/org/elasticsearch/script/CustomScriptContextIT.java +++ b/core/src/test/java/org/elasticsearch/script/CustomScriptContextIT.java @@ -28,6 +28,8 @@ import org.elasticsearch.script.mustache.MustacheScriptEngineService; import org.elasticsearch.test.ESIntegTestCase; import org.junit.Test; +import java.util.Collection; + import static org.hamcrest.CoreMatchers.containsString; import static org.hamcrest.CoreMatchers.notNullValue; @@ -40,12 +42,16 @@ public class CustomScriptContextIT extends ESIntegTestCase { @Override protected Settings nodeSettings(int nodeOrdinal) { return Settings.builder().put(super.nodeSettings(nodeOrdinal)) - .put("plugin.types", CustomScriptContextPlugin.class.getName()) .put("script." + PLUGIN_NAME + "_custom_globally_disabled_op", "off") .put("script.engine.expression.inline." + PLUGIN_NAME + "_custom_exp_disabled_op", "off") .build(); } + @Override + protected Collection> nodePlugins() { + return pluginList(CustomScriptContextPlugin.class); + } + @Test public void testCustomScriptContextsSettings() { ScriptService scriptService = internalCluster().getInstance(ScriptService.class); diff --git a/core/src/test/java/org/elasticsearch/script/ScriptFieldIT.java b/core/src/test/java/org/elasticsearch/script/ScriptFieldIT.java index c9707f7bdbb..d3f0923b61c 100644 --- a/core/src/test/java/org/elasticsearch/script/ScriptFieldIT.java +++ b/core/src/test/java/org/elasticsearch/script/ScriptFieldIT.java @@ -30,6 +30,7 @@ import org.elasticsearch.test.ESIntegTestCase; import org.elasticsearch.test.ESIntegTestCase.ClusterScope; import org.elasticsearch.test.ESIntegTestCase.Scope; +import java.util.Collection; import java.util.Map; import java.util.concurrent.ExecutionException; @@ -40,8 +41,8 @@ import static org.hamcrest.Matchers.equalTo; public class ScriptFieldIT extends ESIntegTestCase { @Override - protected Settings nodeSettings(int nodeOrdinal) { - return settingsBuilder().put(super.nodeSettings(nodeOrdinal)).put("plugin.types", CustomScriptPlugin.class.getName()).build(); + protected Collection> nodePlugins() { + return pluginList(CustomScriptPlugin.class); } static int[] intArray = { Integer.MAX_VALUE, Integer.MIN_VALUE, 3 }; diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/bucket/SignificantTermsSignificanceScoreIT.java b/core/src/test/java/org/elasticsearch/search/aggregations/bucket/SignificantTermsSignificanceScoreIT.java index c3780e98064..526c39a3b28 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/bucket/SignificantTermsSignificanceScoreIT.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/bucket/SignificantTermsSignificanceScoreIT.java @@ -93,11 +93,15 @@ public class SignificantTermsSignificanceScoreIT extends ESIntegTestCase { public Settings nodeSettings(int nodeOrdinal) { return settingsBuilder() .put(super.nodeSettings(nodeOrdinal)) - .put("plugin.types", CustomSignificanceHeuristicPlugin.class.getName()) .put("path.conf", this.getDataPath("config")) .build(); } + @Override + protected Collection> nodePlugins() { + return pluginList(CustomSignificanceHeuristicPlugin.class); + } + public String randomExecutionHint() { return randomBoolean() ? null : randomFrom(SignificantTermsAggregatorFactory.ExecutionMode.values()).toString(); } diff --git a/core/src/test/java/org/elasticsearch/search/basic/SearchWithRandomExceptionsIT.java b/core/src/test/java/org/elasticsearch/search/basic/SearchWithRandomExceptionsIT.java index 76e24467049..556bf136c30 100644 --- a/core/src/test/java/org/elasticsearch/search/basic/SearchWithRandomExceptionsIT.java +++ b/core/src/test/java/org/elasticsearch/search/basic/SearchWithRandomExceptionsIT.java @@ -24,199 +24,37 @@ import org.apache.lucene.index.FilterDirectoryReader; import org.apache.lucene.index.LeafReader; import org.apache.lucene.util.English; import org.elasticsearch.ElasticsearchException; -import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse; import org.elasticsearch.action.admin.indices.refresh.RefreshResponse; import org.elasticsearch.action.index.IndexResponse; import org.elasticsearch.action.search.SearchPhaseExecutionException; import org.elasticsearch.action.search.SearchResponse; -import org.elasticsearch.client.Requests; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings.Builder; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.index.query.QueryBuilders; import org.elasticsearch.plugins.Plugin; -import org.elasticsearch.search.SearchHit; import org.elasticsearch.search.sort.SortOrder; import org.elasticsearch.test.ESIntegTestCase; import org.elasticsearch.test.engine.MockEngineSupport; import org.elasticsearch.test.engine.MockEngineSupportModule; import org.elasticsearch.test.engine.ThrowingLeafReaderWrapper; -import org.elasticsearch.test.junit.annotations.TestLogging; -import org.elasticsearch.test.store.MockFSDirectoryService; -import org.junit.Test; import java.io.IOException; +import java.util.Collection; import java.util.Random; import java.util.concurrent.ExecutionException; import static org.elasticsearch.common.settings.Settings.settingsBuilder; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; -import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitCount; -import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoFailures; public class SearchWithRandomExceptionsIT extends ESIntegTestCase { - @Test - @TestLogging("action.search.type:TRACE,index.shard:TRACE") - public void testRandomDirectoryIOExceptions() throws IOException, InterruptedException, ExecutionException { - String mapping = XContentFactory.jsonBuilder(). - startObject(). - startObject("type"). - startObject("properties"). - startObject("test") - .field("type", "string") - .field("index", "not_analyzed") - .endObject(). - endObject(). - endObject() - .endObject().string(); - final double exceptionRate; - final double exceptionOnOpenRate; - if (frequently()) { - if (randomBoolean()) { - if (randomBoolean()) { - exceptionOnOpenRate = 1.0 / between(5, 100); - exceptionRate = 0.0d; - } else { - exceptionRate = 1.0 / between(5, 100); - exceptionOnOpenRate = 0.0d; - } - } else { - exceptionOnOpenRate = 1.0 / between(5, 100); - exceptionRate = 1.0 / between(5, 100); - } - } else { - // rarely no exception - exceptionRate = 0d; - exceptionOnOpenRate = 0d; - } - final boolean createIndexWithoutErrors = randomBoolean(); - int numInitialDocs = 0; - - if (createIndexWithoutErrors) { - Builder settings = settingsBuilder() - .put("index.number_of_replicas", numberOfReplicas()); - logger.info("creating index: [test] using settings: [{}]", settings.build().getAsMap()); - client().admin().indices().prepareCreate("test") - .setSettings(settings) - .addMapping("type", mapping).execute().actionGet(); - numInitialDocs = between(10, 100); - ensureGreen(); - for (int i = 0; i < numInitialDocs; i++) { - client().prepareIndex("test", "type", "init" + i).setSource("test", "init").get(); - } - client().admin().indices().prepareRefresh("test").execute().get(); - client().admin().indices().prepareFlush("test").setWaitIfOngoing(true).execute().get(); - client().admin().indices().prepareClose("test").execute().get(); - client().admin().indices().prepareUpdateSettings("test").setSettings(settingsBuilder() - .put(MockFSDirectoryService.RANDOM_IO_EXCEPTION_RATE, exceptionRate) - .put(MockFSDirectoryService.RANDOM_IO_EXCEPTION_RATE_ON_OPEN, exceptionOnOpenRate)); - client().admin().indices().prepareOpen("test").execute().get(); - } else { - Builder settings = settingsBuilder() - .put("index.number_of_replicas", randomIntBetween(0, 1)) - .put(MockFSDirectoryService.CHECK_INDEX_ON_CLOSE, false) - .put(MockFSDirectoryService.RANDOM_IO_EXCEPTION_RATE, exceptionRate) - .put(MockFSDirectoryService.RANDOM_IO_EXCEPTION_RATE_ON_OPEN, exceptionOnOpenRate); // we cannot expect that the index will be valid - logger.info("creating index: [test] using settings: [{}]", settings.build().getAsMap()); - client().admin().indices().prepareCreate("test") - .setSettings(settings) - .addMapping("type", mapping).execute().actionGet(); - } - ClusterHealthResponse clusterHealthResponse = client().admin().cluster() - .health(Requests.clusterHealthRequest().waitForYellowStatus().timeout(TimeValue.timeValueSeconds(5))).get(); // it's OK to timeout here - final int numDocs; - final boolean expectAllShardsFailed; - if (clusterHealthResponse.isTimedOut()) { - /* some seeds just won't let you create the index at all and we enter a ping-pong mode - * trying one node after another etc. that is ok but we need to make sure we don't wait - * forever when indexing documents so we set numDocs = 1 and expecte all shards to fail - * when we search below.*/ - logger.info("ClusterHealth timed out - only index one doc and expect searches to fail"); - numDocs = 1; - expectAllShardsFailed = true; - } else { - numDocs = between(10, 100); - expectAllShardsFailed = false; - } - int numCreated = 0; - boolean[] added = new boolean[numDocs]; - for (int i = 0; i < numDocs; i++) { - added[i] = false; - try { - IndexResponse indexResponse = client().prepareIndex("test", "type", Integer.toString(i)).setTimeout(TimeValue.timeValueSeconds(1)).setSource("test", English.intToEnglish(i)).get(); - if (indexResponse.isCreated()) { - numCreated++; - added[i] = true; - } - } catch (ElasticsearchException ex) { - } - - } - NumShards numShards = getNumShards("test"); - logger.info("Start Refresh"); - final RefreshResponse refreshResponse = client().admin().indices().prepareRefresh("test").execute().get(); // don't assert on failures here - final boolean refreshFailed = refreshResponse.getShardFailures().length != 0 || refreshResponse.getFailedShards() != 0; - logger.info("Refresh failed [{}] numShardsFailed: [{}], shardFailuresLength: [{}], successfulShards: [{}], totalShards: [{}] ", refreshFailed, refreshResponse.getFailedShards(), refreshResponse.getShardFailures().length, refreshResponse.getSuccessfulShards(), refreshResponse.getTotalShards()); - final int numSearches = scaledRandomIntBetween(10, 20); - // we don't check anything here really just making sure we don't leave any open files or a broken index behind. - for (int i = 0; i < numSearches; i++) { - try { - int docToQuery = between(0, numDocs - 1); - int expectedResults = added[docToQuery] ? 1 : 0; - logger.info("Searching for [test:{}]", English.intToEnglish(docToQuery)); - SearchResponse searchResponse = client().prepareSearch().setTypes("type").setQuery(QueryBuilders.matchQuery("test", English.intToEnglish(docToQuery))) - .setSize(expectedResults).get(); - logger.info("Successful shards: [{}] numShards: [{}]", searchResponse.getSuccessfulShards(), numShards.numPrimaries); - if (searchResponse.getSuccessfulShards() == numShards.numPrimaries && !refreshFailed) { - assertResultsAndLogOnFailure(expectedResults, searchResponse); - } - // check match all - searchResponse = client().prepareSearch().setTypes("type").setQuery(QueryBuilders.matchAllQuery()) - .setSize(numCreated + numInitialDocs).addSort("_uid", SortOrder.ASC).get(); - logger.info("Match all Successful shards: [{}] numShards: [{}]", searchResponse.getSuccessfulShards(), numShards.numPrimaries); - if (searchResponse.getSuccessfulShards() == numShards.numPrimaries && !refreshFailed) { - assertResultsAndLogOnFailure(numCreated + numInitialDocs, searchResponse); - } - } catch (SearchPhaseExecutionException ex) { - logger.info("SearchPhaseException: [{}]", ex.getMessage()); - // if a scheduled refresh or flush fails all shards we see all shards failed here - if (!(expectAllShardsFailed || refreshResponse.getSuccessfulShards() == 0 || ex.getMessage().contains("all shards failed"))) { - throw ex; - } - } - } - - if (createIndexWithoutErrors) { - // check the index still contains the records that we indexed without errors - client().admin().indices().prepareClose("test").execute().get(); - client().admin().indices().prepareUpdateSettings("test").setSettings(settingsBuilder() - .put(MockFSDirectoryService.RANDOM_IO_EXCEPTION_RATE, 0) - .put(MockFSDirectoryService.RANDOM_IO_EXCEPTION_RATE_ON_OPEN, 0)); - client().admin().indices().prepareOpen("test").execute().get(); - ensureGreen(); - SearchResponse searchResponse = client().prepareSearch().setTypes("type").setQuery(QueryBuilders.matchQuery("test", "init")).get(); - assertNoFailures(searchResponse); - assertHitCount(searchResponse, numInitialDocs); - } + @Override + protected Collection> nodePlugins() { + return pluginList(RandomExceptionDirectoryReaderWrapper.TestPlugin.class); } - private void assertResultsAndLogOnFailure(long expectedResults, SearchResponse searchResponse) { - if (searchResponse.getHits().getTotalHits() != expectedResults) { - StringBuilder sb = new StringBuilder("search result contains ["); - sb.append(searchResponse.getHits().getTotalHits()).append("] results. expected [").append(expectedResults).append("]"); - String failMsg = sb.toString(); - for (SearchHit hit : searchResponse.getHits().getHits()) { - sb.append("\n-> _index: [").append(hit.getIndex()).append("] type [").append(hit.getType()) - .append("] id [").append(hit.id()).append("]"); - } - logger.warn(sb.toString()); - fail(failMsg); - } - } - - @Test public void testRandomExceptions() throws IOException, InterruptedException, ExecutionException { String mapping = XContentFactory.jsonBuilder(). startObject(). @@ -252,10 +90,9 @@ public class SearchWithRandomExceptionsIT extends ESIntegTestCase { Builder settings = settingsBuilder() .put(indexSettings()) - .extendArray("plugin.types", RandomExceptionDirectoryReaderWrapper.TestPlugin.class.getName()) .put(EXCEPTION_TOP_LEVEL_RATIO_KEY, topLevelRate) .put(EXCEPTION_LOW_LEVEL_RATIO_KEY, lowLevelRate) - .put(MockEngineSupport.WRAP_READER_RATIO, 1.0d); + .put(MockEngineSupport.WRAP_READER_RATIO, 1.0d); logger.info("creating index: [test] using settings: [{}]", settings.build().getAsMap()); assertAcked(prepareCreate("test") .setSettings(settings) diff --git a/core/src/test/java/org/elasticsearch/search/basic/SearchWithRandomIOExceptionsIT.java b/core/src/test/java/org/elasticsearch/search/basic/SearchWithRandomIOExceptionsIT.java new file mode 100644 index 00000000000..457f63d54e5 --- /dev/null +++ b/core/src/test/java/org/elasticsearch/search/basic/SearchWithRandomIOExceptionsIT.java @@ -0,0 +1,191 @@ +/* + * 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.search.basic; + +import org.apache.lucene.util.English; +import org.elasticsearch.ElasticsearchException; +import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse; +import org.elasticsearch.action.admin.indices.refresh.RefreshResponse; +import org.elasticsearch.action.index.IndexResponse; +import org.elasticsearch.action.search.SearchPhaseExecutionException; +import org.elasticsearch.action.search.SearchResponse; +import org.elasticsearch.client.Requests; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.unit.TimeValue; +import org.elasticsearch.common.xcontent.XContentFactory; +import org.elasticsearch.index.query.QueryBuilders; +import org.elasticsearch.search.sort.SortOrder; +import org.elasticsearch.test.ESIntegTestCase; +import org.elasticsearch.test.junit.annotations.TestLogging; +import org.elasticsearch.test.store.MockFSDirectoryService; + +import java.io.IOException; +import java.util.concurrent.ExecutionException; + +import static org.elasticsearch.common.settings.Settings.settingsBuilder; +import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitCount; +import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoFailures; + +public class SearchWithRandomIOExceptionsIT extends ESIntegTestCase { + + @TestLogging("action.search.type:TRACE,index.shard:TRACE") + public void testRandomDirectoryIOExceptions() throws IOException, InterruptedException, ExecutionException { + String mapping = XContentFactory.jsonBuilder(). + startObject(). + startObject("type"). + startObject("properties"). + startObject("test") + .field("type", "string") + .field("index", "not_analyzed") + .endObject(). + endObject(). + endObject() + .endObject().string(); + final double exceptionRate; + final double exceptionOnOpenRate; + if (frequently()) { + if (randomBoolean()) { + if (randomBoolean()) { + exceptionOnOpenRate = 1.0 / between(5, 100); + exceptionRate = 0.0d; + } else { + exceptionRate = 1.0 / between(5, 100); + exceptionOnOpenRate = 0.0d; + } + } else { + exceptionOnOpenRate = 1.0 / between(5, 100); + exceptionRate = 1.0 / between(5, 100); + } + } else { + // rarely no exception + exceptionRate = 0d; + exceptionOnOpenRate = 0d; + } + final boolean createIndexWithoutErrors = randomBoolean(); + int numInitialDocs = 0; + + if (createIndexWithoutErrors) { + Settings.Builder settings = settingsBuilder() + .put("index.number_of_replicas", numberOfReplicas()); + logger.info("creating index: [test] using settings: [{}]", settings.build().getAsMap()); + client().admin().indices().prepareCreate("test") + .setSettings(settings) + .addMapping("type", mapping).execute().actionGet(); + numInitialDocs = between(10, 100); + ensureGreen(); + for (int i = 0; i < numInitialDocs; i++) { + client().prepareIndex("test", "type", "init" + i).setSource("test", "init").get(); + } + client().admin().indices().prepareRefresh("test").execute().get(); + client().admin().indices().prepareFlush("test").setWaitIfOngoing(true).execute().get(); + client().admin().indices().prepareClose("test").execute().get(); + client().admin().indices().prepareUpdateSettings("test").setSettings(settingsBuilder() + .put(MockFSDirectoryService.RANDOM_IO_EXCEPTION_RATE, exceptionRate) + .put(MockFSDirectoryService.RANDOM_IO_EXCEPTION_RATE_ON_OPEN, exceptionOnOpenRate)); + client().admin().indices().prepareOpen("test").execute().get(); + } else { + Settings.Builder settings = settingsBuilder() + .put("index.number_of_replicas", randomIntBetween(0, 1)) + .put(MockFSDirectoryService.CHECK_INDEX_ON_CLOSE, false) + .put(MockFSDirectoryService.RANDOM_IO_EXCEPTION_RATE, exceptionRate) + .put(MockFSDirectoryService.RANDOM_IO_EXCEPTION_RATE_ON_OPEN, exceptionOnOpenRate); // we cannot expect that the index will be valid + logger.info("creating index: [test] using settings: [{}]", settings.build().getAsMap()); + client().admin().indices().prepareCreate("test") + .setSettings(settings) + .addMapping("type", mapping).execute().actionGet(); + } + ClusterHealthResponse clusterHealthResponse = client().admin().cluster() + .health(Requests.clusterHealthRequest().waitForYellowStatus().timeout(TimeValue.timeValueSeconds(5))).get(); // it's OK to timeout here + final int numDocs; + final boolean expectAllShardsFailed; + if (clusterHealthResponse.isTimedOut()) { + /* some seeds just won't let you create the index at all and we enter a ping-pong mode + * trying one node after another etc. that is ok but we need to make sure we don't wait + * forever when indexing documents so we set numDocs = 1 and expecte all shards to fail + * when we search below.*/ + logger.info("ClusterHealth timed out - only index one doc and expect searches to fail"); + numDocs = 1; + expectAllShardsFailed = true; + } else { + numDocs = between(10, 100); + expectAllShardsFailed = false; + } + int numCreated = 0; + boolean[] added = new boolean[numDocs]; + for (int i = 0; i < numDocs; i++) { + added[i] = false; + try { + IndexResponse indexResponse = client().prepareIndex("test", "type", Integer.toString(i)).setTimeout(TimeValue.timeValueSeconds(1)).setSource("test", English.intToEnglish(i)).get(); + if (indexResponse.isCreated()) { + numCreated++; + added[i] = true; + } + } catch (ElasticsearchException ex) { + } + + } + ESIntegTestCase.NumShards numShards = getNumShards("test"); + logger.info("Start Refresh"); + final RefreshResponse refreshResponse = client().admin().indices().prepareRefresh("test").execute().get(); // don't assert on failures here + final boolean refreshFailed = refreshResponse.getShardFailures().length != 0 || refreshResponse.getFailedShards() != 0; + logger.info("Refresh failed [{}] numShardsFailed: [{}], shardFailuresLength: [{}], successfulShards: [{}], totalShards: [{}] ", refreshFailed, refreshResponse.getFailedShards(), refreshResponse.getShardFailures().length, refreshResponse.getSuccessfulShards(), refreshResponse.getTotalShards()); + final int numSearches = scaledRandomIntBetween(10, 20); + // we don't check anything here really just making sure we don't leave any open files or a broken index behind. + for (int i = 0; i < numSearches; i++) { + try { + int docToQuery = between(0, numDocs - 1); + int expectedResults = added[docToQuery] ? 1 : 0; + logger.info("Searching for [test:{}]", English.intToEnglish(docToQuery)); + SearchResponse searchResponse = client().prepareSearch().setTypes("type").setQuery(QueryBuilders.matchQuery("test", English.intToEnglish(docToQuery))) + .setSize(expectedResults).get(); + logger.info("Successful shards: [{}] numShards: [{}]", searchResponse.getSuccessfulShards(), numShards.numPrimaries); + if (searchResponse.getSuccessfulShards() == numShards.numPrimaries && !refreshFailed) { + assertResultsAndLogOnFailure(expectedResults, searchResponse); + } + // check match all + searchResponse = client().prepareSearch().setTypes("type").setQuery(QueryBuilders.matchAllQuery()) + .setSize(numCreated + numInitialDocs).addSort("_uid", SortOrder.ASC).get(); + logger.info("Match all Successful shards: [{}] numShards: [{}]", searchResponse.getSuccessfulShards(), numShards.numPrimaries); + if (searchResponse.getSuccessfulShards() == numShards.numPrimaries && !refreshFailed) { + assertResultsAndLogOnFailure(numCreated + numInitialDocs, searchResponse); + } + } catch (SearchPhaseExecutionException ex) { + logger.info("SearchPhaseException: [{}]", ex.getMessage()); + // if a scheduled refresh or flush fails all shards we see all shards failed here + if (!(expectAllShardsFailed || refreshResponse.getSuccessfulShards() == 0 || ex.getMessage().contains("all shards failed"))) { + throw ex; + } + } + } + + if (createIndexWithoutErrors) { + // check the index still contains the records that we indexed without errors + client().admin().indices().prepareClose("test").execute().get(); + client().admin().indices().prepareUpdateSettings("test").setSettings(settingsBuilder() + .put(MockFSDirectoryService.RANDOM_IO_EXCEPTION_RATE, 0) + .put(MockFSDirectoryService.RANDOM_IO_EXCEPTION_RATE_ON_OPEN, 0)); + client().admin().indices().prepareOpen("test").execute().get(); + ensureGreen(); + SearchResponse searchResponse = client().prepareSearch().setTypes("type").setQuery(QueryBuilders.matchQuery("test", "init")).get(); + assertNoFailures(searchResponse); + assertHitCount(searchResponse, numInitialDocs); + } + } +} diff --git a/core/src/test/java/org/elasticsearch/search/fetch/FetchSubPhasePluginIT.java b/core/src/test/java/org/elasticsearch/search/fetch/FetchSubPhasePluginIT.java index 58ec58bfdf3..ca98047a590 100644 --- a/core/src/test/java/org/elasticsearch/search/fetch/FetchSubPhasePluginIT.java +++ b/core/src/test/java/org/elasticsearch/search/fetch/FetchSubPhasePluginIT.java @@ -43,6 +43,7 @@ import org.junit.Test; import java.io.IOException; import java.util.ArrayList; +import java.util.Collection; import java.util.HashMap; import java.util.Map; @@ -59,11 +60,8 @@ import static org.hamcrest.Matchers.equalTo; public class FetchSubPhasePluginIT extends ESIntegTestCase { @Override - protected Settings nodeSettings(int nodeOrdinal) { - return settingsBuilder() - .put(super.nodeSettings(nodeOrdinal)) - .put("plugin.types", FetchTermVectorsPlugin.class.getName()) - .build(); + protected Collection> nodePlugins() { + return pluginList(FetchTermVectorsPlugin.class); } @Test diff --git a/core/src/test/java/org/elasticsearch/search/functionscore/ExplainableScriptIT.java b/core/src/test/java/org/elasticsearch/search/functionscore/ExplainableScriptIT.java index 44b7ea75494..ad9c0af267b 100644 --- a/core/src/test/java/org/elasticsearch/search/functionscore/ExplainableScriptIT.java +++ b/core/src/test/java/org/elasticsearch/search/functionscore/ExplainableScriptIT.java @@ -26,6 +26,7 @@ import org.elasticsearch.action.search.SearchType; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.fielddata.ScriptDocValues; +import org.elasticsearch.plugins.Plugin; import org.elasticsearch.script.AbstractDoubleSearchScript; import org.elasticsearch.script.ExecutableScript; import org.elasticsearch.script.ExplainableSearchScript; @@ -42,6 +43,7 @@ import org.junit.Test; import java.io.IOException; import java.util.ArrayList; +import java.util.Collection; import java.util.List; import java.util.Map; import java.util.concurrent.ExecutionException; @@ -60,11 +62,8 @@ import static org.hamcrest.Matchers.equalTo; public class ExplainableScriptIT extends ESIntegTestCase { @Override - protected Settings nodeSettings(int nodeOrdinal) { - return settingsBuilder() - .put(super.nodeSettings(nodeOrdinal)) - .put("plugin.types", ExplainableScriptPlugin.class.getName()) - .build(); + protected Collection> nodePlugins() { + return pluginList(ExplainableScriptPlugin.class); } @Test diff --git a/core/src/test/java/org/elasticsearch/search/functionscore/FunctionScorePluginIT.java b/core/src/test/java/org/elasticsearch/search/functionscore/FunctionScorePluginIT.java index d1dd06d8d82..946fb593bd1 100644 --- a/core/src/test/java/org/elasticsearch/search/functionscore/FunctionScorePluginIT.java +++ b/core/src/test/java/org/elasticsearch/search/functionscore/FunctionScorePluginIT.java @@ -37,6 +37,8 @@ import org.elasticsearch.test.ESIntegTestCase.Scope; import org.elasticsearch.test.hamcrest.ElasticsearchAssertions; import org.junit.Test; +import java.util.Collection; + import static org.elasticsearch.client.Requests.indexRequest; import static org.elasticsearch.client.Requests.searchRequest; import static org.elasticsearch.common.settings.Settings.settingsBuilder; @@ -53,11 +55,8 @@ import static org.hamcrest.Matchers.equalTo; public class FunctionScorePluginIT extends ESIntegTestCase { @Override - protected Settings nodeSettings(int nodeOrdinal) { - return settingsBuilder() - .put(super.nodeSettings(nodeOrdinal)) - .put("plugin.types", CustomDistanceScorePlugin.class.getName()) - .build(); + protected Collection> nodePlugins() { + return pluginList(CustomDistanceScorePlugin.class); } @Test diff --git a/core/src/test/java/org/elasticsearch/search/highlight/CustomHighlighterSearchIT.java b/core/src/test/java/org/elasticsearch/search/highlight/CustomHighlighterSearchIT.java index e254b4a0808..152a66218e2 100644 --- a/core/src/test/java/org/elasticsearch/search/highlight/CustomHighlighterSearchIT.java +++ b/core/src/test/java/org/elasticsearch/search/highlight/CustomHighlighterSearchIT.java @@ -22,6 +22,7 @@ import com.google.common.collect.Maps; import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.query.QueryBuilders; +import org.elasticsearch.plugins.Plugin; import org.elasticsearch.test.ESIntegTestCase; import org.elasticsearch.test.ESIntegTestCase.ClusterScope; import org.elasticsearch.test.ESIntegTestCase.Scope; @@ -29,6 +30,7 @@ import org.junit.Before; import org.junit.Test; import java.io.IOException; +import java.util.Collection; import java.util.Map; import static org.elasticsearch.common.settings.Settings.settingsBuilder; @@ -42,11 +44,8 @@ import static org.hamcrest.Matchers.equalTo; public class CustomHighlighterSearchIT extends ESIntegTestCase { @Override - protected Settings nodeSettings(int nodeOrdinal) { - return settingsBuilder() - .put(super.nodeSettings(nodeOrdinal)) - .put("plugin.types", CustomHighlighterPlugin.class.getName()) - .build(); + protected Collection> nodePlugins() { + return pluginList(CustomHighlighterPlugin.class); } @Before diff --git a/core/src/test/java/org/elasticsearch/search/suggest/CustomSuggesterSearchIT.java b/core/src/test/java/org/elasticsearch/search/suggest/CustomSuggesterSearchIT.java index 1d7ad858321..3447fbdeacb 100644 --- a/core/src/test/java/org/elasticsearch/search/suggest/CustomSuggesterSearchIT.java +++ b/core/src/test/java/org/elasticsearch/search/suggest/CustomSuggesterSearchIT.java @@ -23,10 +23,12 @@ import org.elasticsearch.action.search.SearchRequestBuilder; import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentBuilder; +import org.elasticsearch.plugins.Plugin; import org.elasticsearch.test.ESIntegTestCase; import org.elasticsearch.test.ESIntegTestCase.ClusterScope; import org.junit.Test; +import java.util.Collection; import java.util.List; import java.util.Locale; @@ -42,8 +44,8 @@ import static org.hamcrest.Matchers.is; public class CustomSuggesterSearchIT extends ESIntegTestCase { @Override - protected Settings nodeSettings(int nodeOrdinal) { - return Settings.settingsBuilder().put(super.nodeSettings(nodeOrdinal)).put("plugin.types", CustomSuggesterPlugin.class.getName()).build(); + protected Collection> nodePlugins() { + return pluginList(CustomSuggesterPlugin.class); } @Test diff --git a/core/src/test/java/org/elasticsearch/snapshots/AbstractSnapshotIntegTestCase.java b/core/src/test/java/org/elasticsearch/snapshots/AbstractSnapshotIntegTestCase.java index 4e30e3ca770..8000fc6d9d9 100644 --- a/core/src/test/java/org/elasticsearch/snapshots/AbstractSnapshotIntegTestCase.java +++ b/core/src/test/java/org/elasticsearch/snapshots/AbstractSnapshotIntegTestCase.java @@ -33,6 +33,7 @@ import org.elasticsearch.cluster.service.PendingClusterTask; import org.elasticsearch.common.Priority; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.TimeValue; +import org.elasticsearch.plugins.Plugin; import org.elasticsearch.repositories.RepositoriesService; import org.elasticsearch.snapshots.mockstore.MockRepository; import org.elasticsearch.test.ESIntegTestCase; @@ -43,6 +44,7 @@ import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.SimpleFileVisitor; import java.nio.file.attribute.BasicFileAttributes; +import java.util.Collection; import java.util.List; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; @@ -60,7 +62,12 @@ public abstract class AbstractSnapshotIntegTestCase extends ESIntegTestCase { // Rebalancing is causing some checks after restore to randomly fail // due to https://github.com/elastic/elasticsearch/issues/9421 .put(EnableAllocationDecider.CLUSTER_ROUTING_REBALANCE_ENABLE, EnableAllocationDecider.Rebalance.NONE) - .extendArray("plugin.types", MockRepository.Plugin.class.getName()).build(); + .build(); + } + + @Override + protected Collection> nodePlugins() { + return pluginList(MockRepository.Plugin.class); } public static long getFailureCount(String repository) { diff --git a/core/src/test/java/org/elasticsearch/snapshots/DedicatedClusterSnapshotRestoreIT.java b/core/src/test/java/org/elasticsearch/snapshots/DedicatedClusterSnapshotRestoreIT.java index 75c72162ab9..715eda0176f 100644 --- a/core/src/test/java/org/elasticsearch/snapshots/DedicatedClusterSnapshotRestoreIT.java +++ b/core/src/test/java/org/elasticsearch/snapshots/DedicatedClusterSnapshotRestoreIT.java @@ -56,6 +56,7 @@ import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.discovery.zen.elect.ElectMasterService; import org.elasticsearch.index.store.IndexStore; import org.elasticsearch.indices.ttl.IndicesTTLService; +import org.elasticsearch.plugins.Plugin; import org.elasticsearch.repositories.RepositoryMissingException; import org.elasticsearch.rest.RestChannel; import org.elasticsearch.rest.RestRequest; @@ -72,6 +73,7 @@ import org.junit.Test; import java.io.IOException; import java.nio.file.Path; import java.util.ArrayList; +import java.util.Collection; import java.util.EnumSet; import java.util.List; import java.util.concurrent.CopyOnWriteArrayList; @@ -102,6 +104,11 @@ import static org.hamcrest.Matchers.nullValue; @ESIntegTestCase.SuppressLocalMode // TODO only restorePersistentSettingsTest needs this maybe factor out? public class DedicatedClusterSnapshotRestoreIT extends AbstractSnapshotIntegTestCase { + @Override + protected Collection> nodePlugins() { + return pluginList(MockRepository.Plugin.class); + } + @Test public void restorePersistentSettingsTest() throws Exception { logger.info("--> start 2 nodes"); @@ -617,7 +624,7 @@ public class DedicatedClusterSnapshotRestoreIT extends AbstractSnapshotIntegTest @Test public void registrationFailureTest() { logger.info("--> start first node"); - internalCluster().startNode(settingsBuilder().put("plugin.types", MockRepository.Plugin.class.getName())); + internalCluster().startNode(); logger.info("--> start second node"); // Make sure the first node is elected as master internalCluster().startNode(settingsBuilder().put("node.master", false)); @@ -636,7 +643,7 @@ public class DedicatedClusterSnapshotRestoreIT extends AbstractSnapshotIntegTest @Test public void testThatSensitiveRepositorySettingsAreNotExposed() throws Exception { - Settings nodeSettings = settingsBuilder().put("plugin.types", MockRepository.Plugin.class.getName()).build(); + Settings nodeSettings = settingsBuilder().put().build(); logger.info("--> start two nodes"); internalCluster().startNodesAsync(2, nodeSettings).get(); // Register mock repositories diff --git a/core/src/test/java/org/elasticsearch/test/ESBackcompatTestCase.java b/core/src/test/java/org/elasticsearch/test/ESBackcompatTestCase.java index 39780db1026..47e163a6291 100644 --- a/core/src/test/java/org/elasticsearch/test/ESBackcompatTestCase.java +++ b/core/src/test/java/org/elasticsearch/test/ESBackcompatTestCase.java @@ -29,6 +29,7 @@ import org.elasticsearch.common.io.PathUtils; import org.elasticsearch.common.regex.Regex; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.indices.recovery.RecoverySettings; +import org.elasticsearch.plugins.Plugin; import org.elasticsearch.test.junit.annotations.TestLogging; import org.elasticsearch.test.junit.listeners.LoggingListener; import org.elasticsearch.transport.Transport; @@ -42,6 +43,8 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; import java.nio.file.Files; import java.nio.file.Path; +import java.util.Collection; +import java.util.Collections; import java.util.Map; import java.util.Random; @@ -182,14 +185,14 @@ public abstract class ESBackcompatTestCase extends ESIntegTestCase { @Override protected TestCluster buildTestCluster(Scope scope, long seed) throws IOException { TestCluster cluster = super.buildTestCluster(scope, seed); - ExternalNode externalNode = new ExternalNode(backwardsCompatibilityPath(), randomLong(), new SettingsSource() { + ExternalNode externalNode = new ExternalNode(backwardsCompatibilityPath(), randomLong(), new NodeConfigurationSource() { @Override - public Settings node(int nodeOrdinal) { + public Settings nodeSettings(int nodeOrdinal) { return externalNodeSettings(nodeOrdinal); } @Override - public Settings transportClient() { + public Settings transportClientSettings() { return transportClientSettings(); } }); diff --git a/core/src/test/java/org/elasticsearch/test/ESIntegTestCase.java b/core/src/test/java/org/elasticsearch/test/ESIntegTestCase.java index faaab9a4c44..b232133eabe 100644 --- a/core/src/test/java/org/elasticsearch/test/ESIntegTestCase.java +++ b/core/src/test/java/org/elasticsearch/test/ESIntegTestCase.java @@ -29,6 +29,7 @@ import com.google.common.base.Predicate; import com.google.common.collect.Lists; import org.apache.http.impl.client.HttpClients; +import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.cluster.routing.UnassignedInfo; import org.elasticsearch.cluster.routing.allocation.decider.EnableAllocationDecider; @@ -113,12 +114,13 @@ import org.elasticsearch.indices.flush.IndicesSyncedFlushResult; import org.elasticsearch.indices.flush.SyncedFlushService; import org.elasticsearch.indices.store.IndicesStore; import org.elasticsearch.node.Node; +import org.elasticsearch.plugins.Plugin; import org.elasticsearch.rest.RestStatus; +import org.elasticsearch.search.SearchHit; import org.elasticsearch.search.SearchService; import org.elasticsearch.test.client.RandomizingClient; import org.elasticsearch.test.disruption.ServiceDisruptionScheme; import org.elasticsearch.test.rest.client.http.HttpRequestBuilder; -import org.elasticsearch.transport.TransportModule; import org.hamcrest.Matchers; import org.joda.time.DateTimeZone; import org.junit.*; @@ -835,6 +837,21 @@ public abstract class ESIntegTestCase extends ESTestCase { } } + /** Ensures the result counts are as expected, and logs the results if different */ + public void assertResultsAndLogOnFailure(long expectedResults, SearchResponse searchResponse) { + if (searchResponse.getHits().getTotalHits() != expectedResults) { + StringBuilder sb = new StringBuilder("search result contains ["); + sb.append(searchResponse.getHits().getTotalHits()).append("] results. expected [").append(expectedResults).append("]"); + String failMsg = sb.toString(); + for (SearchHit hit : searchResponse.getHits().getHits()) { + sb.append("\n-> _index: [").append(hit.getIndex()).append("] type [").append(hit.getType()) + .append("] id [").append(hit.id()).append("]"); + } + logger.warn(sb.toString()); + fail(failMsg); + } + } + /** * Restricts the given index to be allocated on n nodes using the allocation deciders. * Yet if the shards can't be allocated on any other node shards for this index will remain allocated on @@ -1619,6 +1636,25 @@ public abstract class ESIntegTestCase extends ESTestCase { return builder.build(); } + /** + * Returns a collection of plugins that should be loaded on each node. + */ + protected Collection> nodePlugins() { + return Collections.emptyList(); + } + + /** + * Returns a collection of plugins that should be loaded when creating a transport client. + */ + protected Collection> transportClientPlugins() { + return Collections.emptyList(); + } + + /** Helper method to create list of plugins without specifying generic types. */ + protected static Collection> pluginList(Class... plugins) { + return Arrays.asList(plugins); + } + /** * This method is used to obtain additional settings for clients created by the internal cluster. * These settings will be applied on the client in addition to some randomized settings defined in @@ -1671,16 +1707,23 @@ public abstract class ESIntegTestCase extends ESTestCase { default: throw new ElasticsearchException("Scope not supported: " + scope); } - SettingsSource settingsSource = new SettingsSource() { + NodeConfigurationSource nodeConfigurationSource = new NodeConfigurationSource() { @Override - public Settings node(int nodeOrdinal) { + public Settings nodeSettings(int nodeOrdinal) { return Settings.builder().put(Node.HTTP_ENABLED, false). - put(nodeSettings(nodeOrdinal)).build(); + put(ESIntegTestCase.this.nodeSettings(nodeOrdinal)).build(); } - @Override - public Settings transportClient() { - return transportClientSettings(); + public Collection> nodePlugins() { + return ESIntegTestCase.this.nodePlugins(); + } + @Override + public Settings transportClientSettings() { + return ESIntegTestCase.this.transportClientSettings(); + } + @Override + public Collection> transportClientPlugins() { + return ESIntegTestCase.this.transportClientPlugins(); } }; @@ -1705,7 +1748,7 @@ public abstract class ESIntegTestCase extends ESTestCase { } return new InternalTestCluster(nodeMode, seed, createTempDir(), minNumDataNodes, maxNumDataNodes, - InternalTestCluster.clusterName(scope.name(), seed) + "-cluster", settingsSource, getNumClientNodes(), + InternalTestCluster.clusterName(scope.name(), seed) + "-cluster", nodeConfigurationSource, getNumClientNodes(), InternalTestCluster.DEFAULT_ENABLE_HTTP_PIPELINING, nodePrefix); } diff --git a/core/src/test/java/org/elasticsearch/test/ExternalNode.java b/core/src/test/java/org/elasticsearch/test/ExternalNode.java index 0d969db234b..88e5cf29ad0 100644 --- a/core/src/test/java/org/elasticsearch/test/ExternalNode.java +++ b/core/src/test/java/org/elasticsearch/test/ExternalNode.java @@ -60,7 +60,7 @@ final class ExternalNode implements Closeable { private final Path path; private final Random random; - private final SettingsSource settingsSource; + private final NodeConfigurationSource nodeConfigurationSource; private Process process; private NodeInfo nodeInfo; private final String clusterName; @@ -70,23 +70,23 @@ final class ExternalNode implements Closeable { private Settings externalNodeSettings; - ExternalNode(Path path, long seed, SettingsSource settingsSource) { - this(path, null, seed, settingsSource); + ExternalNode(Path path, long seed, NodeConfigurationSource nodeConfigurationSource) { + this(path, null, seed, nodeConfigurationSource); } - ExternalNode(Path path, String clusterName, long seed, SettingsSource settingsSource) { + ExternalNode(Path path, String clusterName, long seed, NodeConfigurationSource nodeConfigurationSource) { if (!Files.isDirectory(path)) { throw new IllegalArgumentException("path must be a directory"); } this.path = path; this.clusterName = clusterName; this.random = new Random(seed); - this.settingsSource = settingsSource; + this.nodeConfigurationSource = nodeConfigurationSource; } synchronized ExternalNode start(Client localNode, Settings defaultSettings, String nodeName, String clusterName, int nodeOrdinal) throws IOException, InterruptedException { - ExternalNode externalNode = new ExternalNode(path, clusterName, random.nextLong(), settingsSource); - Settings settings = Settings.builder().put(defaultSettings).put(settingsSource.node(nodeOrdinal)).build(); + ExternalNode externalNode = new ExternalNode(path, clusterName, random.nextLong(), nodeConfigurationSource); + Settings settings = Settings.builder().put(defaultSettings).put(nodeConfigurationSource.nodeSettings(nodeOrdinal)).build(); externalNode.startInternal(localNode, settings, nodeName, clusterName); return externalNode; } diff --git a/core/src/test/java/org/elasticsearch/test/InternalTestCluster.java b/core/src/test/java/org/elasticsearch/test/InternalTestCluster.java index 783021a0429..a7b858a6c14 100644 --- a/core/src/test/java/org/elasticsearch/test/InternalTestCluster.java +++ b/core/src/test/java/org/elasticsearch/test/InternalTestCluster.java @@ -63,7 +63,6 @@ import org.elasticsearch.common.io.FileSystemUtils; import org.elasticsearch.common.lease.Releasables; import org.elasticsearch.common.logging.ESLogger; import org.elasticsearch.common.logging.Loggers; -import org.elasticsearch.common.network.NetworkUtils; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings.Builder; import org.elasticsearch.common.transport.InetSocketTransportAddress; @@ -89,10 +88,12 @@ import org.elasticsearch.indices.cache.request.IndicesRequestCache; import org.elasticsearch.indices.fielddata.cache.IndicesFieldDataCache; import org.elasticsearch.indices.recovery.RecoverySettings; import org.elasticsearch.indices.store.IndicesStore; +import org.elasticsearch.node.MockNode; import org.elasticsearch.node.Node; import org.elasticsearch.node.NodeMocksPlugin; import org.elasticsearch.node.internal.InternalSettingsPreparer; import org.elasticsearch.node.service.NodeService; +import org.elasticsearch.plugins.Plugin; import org.elasticsearch.script.ScriptService; import org.elasticsearch.search.SearchService; import org.elasticsearch.test.disruption.ServiceDisruptionScheme; @@ -108,7 +109,6 @@ import org.junit.Assert; import java.io.Closeable; import java.io.IOException; -import java.net.InetAddress; import java.net.InetSocketAddress; import java.nio.file.Path; import java.util.ArrayList; @@ -134,7 +134,6 @@ import static org.apache.lucene.util.LuceneTestCase.TEST_NIGHTLY; import static org.apache.lucene.util.LuceneTestCase.rarely; import static org.apache.lucene.util.LuceneTestCase.usually; import static org.elasticsearch.common.settings.Settings.settingsBuilder; -import static org.elasticsearch.node.NodeBuilder.nodeBuilder; import static org.elasticsearch.test.ESTestCase.assertBusy; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoTimeout; import static org.hamcrest.Matchers.equalTo; @@ -157,7 +156,7 @@ public final class InternalTestCluster extends TestCluster { private final ESLogger logger = Loggers.getLogger(getClass()); - static SettingsSource DEFAULT_SETTINGS_SOURCE = SettingsSource.EMPTY; + static NodeConfigurationSource DEFAULT_SETTINGS_SOURCE = NodeConfigurationSource.EMPTY; /** * A boolean value to enable or disable mock modules. This is useful to test the @@ -214,7 +213,7 @@ public final class InternalTestCluster extends TestCluster { private final int numSharedClientNodes; - private final SettingsSource settingsSource; + private final NodeConfigurationSource nodeConfigurationSource; private final ExecutorService executor; @@ -233,7 +232,7 @@ public final class InternalTestCluster extends TestCluster { } public InternalTestCluster(String nodeMode, long clusterSeed, Path baseDir, - int minNumDataNodes, int maxNumDataNodes, String clusterName, SettingsSource settingsSource, int numClientNodes, + int minNumDataNodes, int maxNumDataNodes, String clusterName, NodeConfigurationSource nodeConfigurationSource, int numClientNodes, boolean enableHttpPipelining, String nodePrefix) { super(clusterSeed); if ("network".equals(nodeMode) == false && "local".equals(nodeMode) == false) { @@ -284,7 +283,7 @@ public final class InternalTestCluster extends TestCluster { } logger.info("Setup InternalTestCluster [{}] with seed [{}] using [{}] data nodes and [{}] client nodes", clusterName, SeedUtils.formatSeed(clusterSeed), numSharedDataNodes, numSharedClientNodes); - this.settingsSource = settingsSource; + this.nodeConfigurationSource = nodeConfigurationSource; Builder builder = Settings.settingsBuilder(); if (random.nextInt(5) == 0) { // sometimes set this // randomize (multi/single) data path, special case for 0, don't set it at all... @@ -364,7 +363,7 @@ public final class InternalTestCluster extends TestCluster { private Settings getSettings(int nodeOrdinal, long nodeSeed, Settings others) { Builder builder = Settings.settingsBuilder().put(defaultSettings) .put(getRandomNodeSettings(nodeSeed)); - Settings settings = settingsSource.node(nodeOrdinal); + Settings settings = nodeConfigurationSource.nodeSettings(nodeOrdinal); if (settings != null) { if (settings.get(ClusterName.SETTING) != null) { throw new IllegalStateException("Tests must not set a '" + ClusterName.SETTING + "' as a node setting set '" + ClusterName.SETTING + "': [" + settings.get(ClusterName.SETTING) + "]"); @@ -378,21 +377,27 @@ public final class InternalTestCluster extends TestCluster { return builder.build(); } + private Collection> getPlugins(long seed) { + Set> plugins = new HashSet<>(nodeConfigurationSource.nodePlugins()); + Random random = new Random(seed); + if (ENABLE_MOCK_MODULES && usually(random)) { + plugins.add(MockTransportService.TestPlugin.class); + plugins.add(MockFSIndexStore.TestPlugin.class); + plugins.add(NodeMocksPlugin.class); + plugins.add(MockEngineFactoryPlugin.class); + plugins.add(MockSearchService.TestPlugin.class); + } + if (isLocalTransportConfigured()) { + plugins.add(AssertingLocalTransport.TestPlugin.class); + } + return plugins; + } + private Settings getRandomNodeSettings(long seed) { Random random = new Random(seed); Builder builder = Settings.settingsBuilder() .put(SETTING_CLUSTER_NODE_SEED, seed); - if (ENABLE_MOCK_MODULES && usually(random)) { - builder.extendArray("plugin.types", - MockTransportService.TestPlugin.class.getName(), - MockFSIndexStore.TestPlugin.class.getName(), - NodeMocksPlugin.class.getName(), - MockEngineFactoryPlugin.class.getName(), - MockSearchService.TestPlugin.class.getName()); - } - if (isLocalTransportConfigured()) { - builder.extendArray("plugin.types", AssertingLocalTransport.TestPlugin.class.getName()); - } else { + if (isLocalTransportConfigured() == false) { builder.put(Transport.TransportSettings.TRANSPORT_TCP_COMPRESS, rarely(random)); } if (random.nextBoolean()) { @@ -621,6 +626,7 @@ public final class InternalTestCluster extends TestCluster { assert Thread.holdsLock(this); ensureOpen(); settings = getSettings(nodeId, seed, settings); + Collection> plugins = getPlugins(seed); String name = buildNodeName(nodeId); assert !nodes.containsKey(name); Settings finalSettings = settingsBuilder() @@ -628,9 +634,8 @@ public final class InternalTestCluster extends TestCluster { .put(settings) .put("name", name) .put("discovery.id.seed", seed) - .put("tests.mock.version", version) .build(); - Node node = nodeBuilder().settings(finalSettings).build(); + MockNode node = new MockNode(finalSettings, true, version, plugins); return new NodeAndClient(name, node); } @@ -787,13 +792,13 @@ public final class InternalTestCluster extends TestCluster { } private final class NodeAndClient implements Closeable { - private Node node; + private MockNode node; private Client nodeClient; private Client transportClient; private final AtomicBoolean closed = new AtomicBoolean(false); private final String name; - NodeAndClient(String name, Node node) { + NodeAndClient(String name, MockNode node) { this.node = node; this.name = name; } @@ -848,7 +853,7 @@ public final class InternalTestCluster extends TestCluster { /* no sniff client for now - doesn't work will all tests since it might throw NoNodeAvailableException if nodes are shut down. * we first need support of transportClientRatio as annotations or so */ - return transportClient = new TransportClientFactory(false, settingsSource.transportClient(), baseDir, nodeMode).client(node, clusterName); + return transportClient = new TransportClientFactory(false, nodeConfigurationSource.transportClientSettings(), baseDir, nodeMode, nodeConfigurationSource.transportClientPlugins()).client(node, clusterName); } void resetClient() throws IOException { @@ -880,7 +885,11 @@ public final class InternalTestCluster extends TestCluster { IOUtils.rm(nodeEnv.nodeDataPaths()); } } - node = nodeBuilder().settings(node.settings()).settings(newSettings).node(); + Settings finalSettings = Settings.builder().put(node.settings()).put(newSettings).build(); + Collection> plugins = node.getPlugins(); + Version version = node.getVersion(); + node = new MockNode(finalSettings, true, version, plugins); + node.start(); } void registerDataPath() { @@ -906,12 +915,14 @@ public final class InternalTestCluster extends TestCluster { private final Settings settings; private final Path baseDir; private final String nodeMode; + private final Collection> plugins; - TransportClientFactory(boolean sniff, Settings settings, Path baseDir, String nodeMode) { + TransportClientFactory(boolean sniff, Settings settings, Path baseDir, String nodeMode, Collection> plugins) { this.sniff = sniff; this.settings = settings != null ? settings : Settings.EMPTY; this.baseDir = baseDir; this.nodeMode = nodeMode; + this.plugins = plugins; } public Client client(Node node, String clusterName) { @@ -929,7 +940,11 @@ public final class InternalTestCluster extends TestCluster { .put(InternalSettingsPreparer.IGNORE_SYSTEM_PROPERTIES_SETTING, true) .put(settings); - TransportClient client = TransportClient.builder().settings(builder.build()).build(); + TransportClient.Builder clientBuilder = TransportClient.builder().settings(builder.build()); + for (Class plugin : plugins) { + clientBuilder.addPlugin(plugin); + } + TransportClient client = clientBuilder.build(); client.addTransportAddress(addr); return client; } diff --git a/core/src/test/java/org/elasticsearch/test/SettingsSource.java b/core/src/test/java/org/elasticsearch/test/NodeConfigurationSource.java similarity index 57% rename from core/src/test/java/org/elasticsearch/test/SettingsSource.java rename to core/src/test/java/org/elasticsearch/test/NodeConfigurationSource.java index 6341d842d67..e04e840e525 100644 --- a/core/src/test/java/org/elasticsearch/test/SettingsSource.java +++ b/core/src/test/java/org/elasticsearch/test/NodeConfigurationSource.java @@ -19,17 +19,21 @@ package org.elasticsearch.test; import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.plugins.Plugin; -public abstract class SettingsSource { +import java.util.Collection; +import java.util.Collections; - public static final SettingsSource EMPTY = new SettingsSource() { +public abstract class NodeConfigurationSource { + + public static final NodeConfigurationSource EMPTY = new NodeConfigurationSource() { @Override - public Settings node(int nodeOrdinal) { + public Settings nodeSettings(int nodeOrdinal) { return null; } @Override - public Settings transportClient() { + public Settings transportClientSettings() { return null; } }; @@ -37,8 +41,18 @@ public abstract class SettingsSource { /** * @return the settings for the node represented by the given ordinal, or {@code null} if there are no settings defined */ - public abstract Settings node(int nodeOrdinal); + public abstract Settings nodeSettings(int nodeOrdinal); - public abstract Settings transportClient(); + /** Returns plugins that should be loaded on the node */ + public Collection> nodePlugins() { + return Collections.emptyList(); + } + + public abstract Settings transportClientSettings(); + + /** Returns plugins that should be loaded in the transport client */ + public Collection> transportClientPlugins() { + return Collections.emptyList(); + } } diff --git a/core/src/test/java/org/elasticsearch/test/discovery/ClusterDiscoveryConfiguration.java b/core/src/test/java/org/elasticsearch/test/discovery/ClusterDiscoveryConfiguration.java index b7d0c2dd930..49b567bda64 100644 --- a/core/src/test/java/org/elasticsearch/test/discovery/ClusterDiscoveryConfiguration.java +++ b/core/src/test/java/org/elasticsearch/test/discovery/ClusterDiscoveryConfiguration.java @@ -25,18 +25,15 @@ import org.elasticsearch.common.SuppressForbidden; import org.elasticsearch.common.network.NetworkUtils; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.test.InternalTestCluster; -import org.elasticsearch.test.SettingsSource; -import org.elasticsearch.transport.local.LocalTransport; +import org.elasticsearch.test.NodeConfigurationSource; import java.io.IOException; -import java.net.Inet4Address; -import java.net.InetAddress; import java.net.InetSocketAddress; import java.net.ServerSocket; import java.util.HashSet; import java.util.Set; -public class ClusterDiscoveryConfiguration extends SettingsSource { +public class ClusterDiscoveryConfiguration extends NodeConfigurationSource { static Settings DEFAULT_NODE_SETTINGS = Settings.settingsBuilder().put("discovery.type", "zen").build(); private static final String IP_ADDR = "127.0.0.1"; @@ -52,12 +49,12 @@ public class ClusterDiscoveryConfiguration extends SettingsSource { } @Override - public Settings node(int nodeOrdinal) { + public Settings nodeSettings(int nodeOrdinal) { return nodeSettings; } @Override - public Settings transportClient() { + public Settings transportClientSettings() { return transportClientSettings; } @@ -107,7 +104,7 @@ public class ClusterDiscoveryConfiguration extends SettingsSource { } @Override - public Settings node(int nodeOrdinal) { + public Settings nodeSettings(int nodeOrdinal) { Settings.Builder builder = Settings.builder(); String[] unicastHosts = new String[unicastHostOrdinals.length]; @@ -125,7 +122,7 @@ public class ClusterDiscoveryConfiguration extends SettingsSource { } } builder.putArray("discovery.zen.ping.unicast.hosts", unicastHosts); - return builder.put(super.node(nodeOrdinal)).build(); + return builder.put(super.nodeSettings(nodeOrdinal)).build(); } @SuppressForbidden(reason = "we know we pass a IP address") diff --git a/core/src/test/java/org/elasticsearch/test/disruption/NetworkPartitionIT.java b/core/src/test/java/org/elasticsearch/test/disruption/NetworkPartitionIT.java index e0cbfa5ed90..fc2b9469a73 100644 --- a/core/src/test/java/org/elasticsearch/test/disruption/NetworkPartitionIT.java +++ b/core/src/test/java/org/elasticsearch/test/disruption/NetworkPartitionIT.java @@ -21,22 +21,20 @@ package org.elasticsearch.test.disruption; -import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.plugins.Plugin; import org.elasticsearch.test.ESIntegTestCase; import org.elasticsearch.test.InternalTestCluster; import org.elasticsearch.test.transport.MockTransportService; -import org.elasticsearch.transport.TransportModule; import org.junit.Test; import java.io.IOException; +import java.util.Collection; public class NetworkPartitionIT extends ESIntegTestCase { @Override - protected Settings nodeSettings(int nodeOrdinal) { - return Settings.builder() - .put("plugin.types", MockTransportService.TestPlugin.class.getName()) - .build(); + protected Collection> nodePlugins() { + return pluginList(MockTransportService.TestPlugin.class); } @Test diff --git a/core/src/test/java/org/elasticsearch/test/test/InternalTestClusterTests.java b/core/src/test/java/org/elasticsearch/test/test/InternalTestClusterTests.java index cf5c00e1575..cb724bfd9f0 100644 --- a/core/src/test/java/org/elasticsearch/test/test/InternalTestClusterTests.java +++ b/core/src/test/java/org/elasticsearch/test/test/InternalTestClusterTests.java @@ -26,7 +26,7 @@ import org.elasticsearch.cluster.ClusterName; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.test.InternalTestCluster; -import org.elasticsearch.test.SettingsSource; +import org.elasticsearch.test.NodeConfigurationSource; import java.io.IOException; import java.nio.file.Path; @@ -49,14 +49,14 @@ public class InternalTestClusterTests extends ESTestCase { int minNumDataNodes = randomIntBetween(0, 9); int maxNumDataNodes = randomIntBetween(minNumDataNodes, 10); String clusterName = randomRealisticUnicodeOfCodepointLengthBetween(1, 10); - SettingsSource settingsSource = SettingsSource.EMPTY; + NodeConfigurationSource nodeConfigurationSource = NodeConfigurationSource.EMPTY; int numClientNodes = randomIntBetween(0, 10); boolean enableHttpPipelining = randomBoolean(); String nodePrefix = randomRealisticUnicodeOfCodepointLengthBetween(1, 10); Path baseDir = createTempDir(); - InternalTestCluster cluster0 = new InternalTestCluster("local", clusterSeed, baseDir, minNumDataNodes, maxNumDataNodes, clusterName, settingsSource, numClientNodes, enableHttpPipelining, nodePrefix); - InternalTestCluster cluster1 = new InternalTestCluster("local", clusterSeed, baseDir, minNumDataNodes, maxNumDataNodes, clusterName, settingsSource, numClientNodes, enableHttpPipelining, nodePrefix); + InternalTestCluster cluster0 = new InternalTestCluster("local", clusterSeed, baseDir, minNumDataNodes, maxNumDataNodes, clusterName, nodeConfigurationSource, numClientNodes, enableHttpPipelining, nodePrefix); + InternalTestCluster cluster1 = new InternalTestCluster("local", clusterSeed, baseDir, minNumDataNodes, maxNumDataNodes, clusterName, nodeConfigurationSource, numClientNodes, enableHttpPipelining, nodePrefix); assertClusters(cluster0, cluster1, true); } @@ -92,15 +92,15 @@ public class InternalTestClusterTests extends ESTestCase { /*while (clusterName.equals(clusterName1)) { clusterName1 = clusterName("shared", Integer.toString(CHILD_JVM_ID), clusterSeed); // spin until the time changes }*/ - SettingsSource settingsSource = SettingsSource.EMPTY; + NodeConfigurationSource nodeConfigurationSource = NodeConfigurationSource.EMPTY; int numClientNodes = randomIntBetween(0, 2); boolean enableHttpPipelining = randomBoolean(); int jvmOrdinal = randomIntBetween(0, 10); String nodePrefix = "foobar"; Path baseDir = createTempDir(); - InternalTestCluster cluster0 = new InternalTestCluster("local", clusterSeed, baseDir, minNumDataNodes, maxNumDataNodes, clusterName1, settingsSource, numClientNodes, enableHttpPipelining, nodePrefix); - InternalTestCluster cluster1 = new InternalTestCluster("local", clusterSeed, baseDir, minNumDataNodes, maxNumDataNodes, clusterName2, settingsSource, numClientNodes, enableHttpPipelining, nodePrefix); + InternalTestCluster cluster0 = new InternalTestCluster("local", clusterSeed, baseDir, minNumDataNodes, maxNumDataNodes, clusterName1, nodeConfigurationSource, numClientNodes, enableHttpPipelining, nodePrefix); + InternalTestCluster cluster1 = new InternalTestCluster("local", clusterSeed, baseDir, minNumDataNodes, maxNumDataNodes, clusterName2, nodeConfigurationSource, numClientNodes, enableHttpPipelining, nodePrefix); assertClusters(cluster0, cluster1, false); long seed = randomLong(); diff --git a/core/src/test/java/org/elasticsearch/transport/ContextAndHeaderTransportIT.java b/core/src/test/java/org/elasticsearch/transport/ContextAndHeaderTransportIT.java index 811f6e5928d..917148cc91b 100644 --- a/core/src/test/java/org/elasticsearch/transport/ContextAndHeaderTransportIT.java +++ b/core/src/test/java/org/elasticsearch/transport/ContextAndHeaderTransportIT.java @@ -100,12 +100,16 @@ public class ContextAndHeaderTransportIT extends ESIntegTestCase { protected Settings nodeSettings(int nodeOrdinal) { return settingsBuilder() .put(super.nodeSettings(nodeOrdinal)) - .put("plugin.types", ActionLoggingPlugin.class.getName()) .put("script.indexed", "on") .put(HTTP_ENABLED, true) .build(); } + @Override + protected Collection> nodePlugins() { + return pluginList(ActionLoggingPlugin.class); + } + @Before public void createIndices() throws Exception { String mapping = jsonBuilder().startObject().startObject("type") diff --git a/core/src/test/java/org/elasticsearch/transport/netty/NettyTransportIT.java b/core/src/test/java/org/elasticsearch/transport/netty/NettyTransportIT.java index e26998cc0a6..28701248817 100644 --- a/core/src/test/java/org/elasticsearch/transport/netty/NettyTransportIT.java +++ b/core/src/test/java/org/elasticsearch/transport/netty/NettyTransportIT.java @@ -47,6 +47,7 @@ import org.junit.Test; import java.io.IOException; import java.net.InetSocketAddress; +import java.util.Collection; import static org.elasticsearch.common.settings.Settings.settingsBuilder; import static org.elasticsearch.test.ESIntegTestCase.ClusterScope; @@ -67,7 +68,12 @@ public class NettyTransportIT extends ESIntegTestCase { protected Settings nodeSettings(int nodeOrdinal) { return settingsBuilder().put(super.nodeSettings(nodeOrdinal)) .put("node.mode", "network") - .extendArray("plugin.types", ExceptionThrowingNettyTransport.TestPlugin.class.getName()).build(); + .put(TransportModule.TRANSPORT_TYPE_KEY, "exception-throwing").build(); + } + + @Override + protected Collection> nodePlugins() { + return pluginList(ExceptionThrowingNettyTransport.TestPlugin.class); } @Test @@ -99,10 +105,6 @@ public class NettyTransportIT extends ESIntegTestCase { public void onModule(TransportModule transportModule) { transportModule.addTransport("exception-throwing", ExceptionThrowingNettyTransport.class); } - @Override - public Settings additionalSettings() { - return Settings.builder().put(TransportModule.TRANSPORT_TYPE_KEY, "exception-throwing").build(); - } } @Inject diff --git a/core/src/test/java/org/elasticsearch/update/UpdateByNativeScriptIT.java b/core/src/test/java/org/elasticsearch/update/UpdateByNativeScriptIT.java index 2e2edb64bbb..8b5ec861a51 100644 --- a/core/src/test/java/org/elasticsearch/update/UpdateByNativeScriptIT.java +++ b/core/src/test/java/org/elasticsearch/update/UpdateByNativeScriptIT.java @@ -34,6 +34,7 @@ import org.elasticsearch.test.ESIntegTestCase.ClusterScope; import org.elasticsearch.test.ESIntegTestCase.Scope; import org.junit.Test; +import java.util.Collection; import java.util.Map; import static org.hamcrest.Matchers.hasKey; @@ -46,11 +47,8 @@ import static org.hamcrest.Matchers.is; public class UpdateByNativeScriptIT extends ESIntegTestCase { @Override - protected Settings nodeSettings(int nodeOrdinal) { - return Settings.settingsBuilder() - .put(super.nodeSettings(nodeOrdinal)) - .extendArray("plugin.types", CustomNativeScriptFactory.TestPlugin.class.getName()) - .build(); + protected Collection> nodePlugins() { + return pluginList(CustomNativeScriptFactory.TestPlugin.class); } @Test diff --git a/docs/plugins/authors.asciidoc b/docs/plugins/authors.asciidoc index 538b09ecfc1..048a2b76575 100644 --- a/docs/plugins/authors.asciidoc +++ b/docs/plugins/authors.asciidoc @@ -43,20 +43,14 @@ instance, see https://github.com/elastic/elasticsearch/blob/master/plugins/site-example/pom.xml[`plugins/site-example/pom.xml`]. [float] -=== Loading plugins from the classpath +=== Testing your plugin When testing a Java plugin, it will only be auto-loaded if it is in the -`plugins/` directory. If, instead, it is in your classpath, you can tell -Elasticsearch to load it with the `plugin.types` setting: +`plugins/` directory. Use `bin/plugin install file://path/to/your/plugin` +to install your plugin for testing. -[source,java] --------------------------- -settingsBuilder() - .put("cluster.name", cluster) - .put("path.home", getHome()) - .put("plugin.types", MyCustomPlugin.class.getName()) <1> - .build(); --------------------------- -<1> Tells Elasticsearch to load your plugin. +You may also load your plugin within the test framework for integration tests. +// nocommit +See INSERT-LINK-TO-TESTING-FRAMEWORK[[changing-node-configuration]] diff --git a/docs/reference/testing/testing-framework.asciidoc b/docs/reference/testing/testing-framework.asciidoc index aa73c582284..ecfd168c144 100644 --- a/docs/reference/testing/testing-framework.asciidoc +++ b/docs/reference/testing/testing-framework.asciidoc @@ -147,15 +147,13 @@ The above sample configures the test to use a new cluster for each test method. [[changing-node-configuration]] ==== Changing node configuration -As elasticsearch is using JUnit 4, using the `@Before` and `@After` annotations is not a problem. However you should keep in mind, that this does not have any effect in your cluster setup, as the cluster is already up and running when those methods are run. So in case you want to configure settings - like loading a plugin on node startup - before the node is actually running, you should overwrite the `nodeSettings()` method from the `ElasticsearchIntegrationTest` class and change the cluster scope to `SUITE`. +As elasticsearch is using JUnit 4, using the `@Before` and `@After` annotations is not a problem. However you should keep in mind, that this does not have any effect in your cluster setup, as the cluster is already up and running when those methods are run. So in case you want to configure settings - like loading a plugin on node startup - before the node is actually running, you should overwrite the `nodePlugins()` method from the `ESIntegTestCase` class and return the plugin classes each node should load. [source,java] ----------------------------------------- @Override -protected Settings nodeSettings(int nodeOrdinal) { - return Settings.settingsBuilder() - .put("plugin.types", CustomSuggesterPlugin.class.getName()) - .put(super.nodeSettings(nodeOrdinal)).build(); +protected Collection> nodePlugins() { + return pluginList(CustomSuggesterPlugin.class); } ----------------------------------------- diff --git a/plugins/cloud-aws/src/test/java/org/elasticsearch/cloud/aws/AbstractAwsTest.java b/plugins/cloud-aws/src/test/java/org/elasticsearch/cloud/aws/AbstractAwsTest.java index a44a0f46b3a..b66cd943b11 100644 --- a/plugins/cloud-aws/src/test/java/org/elasticsearch/cloud/aws/AbstractAwsTest.java +++ b/plugins/cloud-aws/src/test/java/org/elasticsearch/cloud/aws/AbstractAwsTest.java @@ -24,11 +24,13 @@ import org.elasticsearch.common.io.PathUtils; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.SettingsException; import org.elasticsearch.plugin.cloud.aws.CloudAwsPlugin; +import org.elasticsearch.plugins.Plugin; import org.elasticsearch.test.ESIntegTestCase; import org.elasticsearch.test.ESIntegTestCase.ThirdParty; import org.junit.After; import org.junit.Before; +import java.util.Collection; import java.util.HashMap; import java.util.Map; @@ -75,7 +77,6 @@ public abstract class AbstractAwsTest extends ESIntegTestCase { Settings.Builder settings = Settings.builder() .put(super.nodeSettings(nodeOrdinal)) .put("path.home", createTempDir()) - .extendArray("plugin.types", CloudAwsPlugin.class.getName(), TestAwsS3Service.TestPlugin.class.getName()) .put("cloud.aws.test.random", randomInt()) .put("cloud.aws.test.write_failures", 0.1) .put("cloud.aws.test.read_failures", 0.1); @@ -92,4 +93,9 @@ public abstract class AbstractAwsTest extends ESIntegTestCase { } return settings.build(); } + + @Override + protected Collection> nodePlugins() { + return pluginList(CloudAwsPlugin.class, TestAwsS3Service.TestPlugin.class); + } } diff --git a/plugins/cloud-aws/src/test/java/org/elasticsearch/discovery/ec2/Ec2DiscoveryITest.java b/plugins/cloud-aws/src/test/java/org/elasticsearch/discovery/ec2/Ec2DiscoveryITest.java index 463131522a2..9af9e4df62c 100644 --- a/plugins/cloud-aws/src/test/java/org/elasticsearch/discovery/ec2/Ec2DiscoveryITest.java +++ b/plugins/cloud-aws/src/test/java/org/elasticsearch/discovery/ec2/Ec2DiscoveryITest.java @@ -23,10 +23,13 @@ package org.elasticsearch.discovery.ec2; import org.elasticsearch.cloud.aws.AbstractAwsTest; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.plugin.cloud.aws.CloudAwsPlugin; +import org.elasticsearch.plugins.Plugin; import org.elasticsearch.test.ESIntegTestCase.ClusterScope; import org.elasticsearch.test.ESIntegTestCase.Scope; import org.junit.Test; +import java.util.Collection; + import static org.elasticsearch.common.settings.Settings.settingsBuilder; /** @@ -37,10 +40,14 @@ import static org.elasticsearch.common.settings.Settings.settingsBuilder; @ClusterScope(scope = Scope.TEST, numDataNodes = 0, numClientNodes = 0, transportClientRatio = 0.0) public class Ec2DiscoveryITest extends AbstractAwsTest { + @Override + protected Collection> nodePlugins() { + return pluginList(CloudAwsPlugin.class); + } + @Test public void testStart() { Settings nodeSettings = settingsBuilder() - .put("plugin.types", CloudAwsPlugin.class.getName()) .put("cloud.enabled", true) .put("discovery.type", "ec2") .build(); diff --git a/plugins/cloud-aws/src/test/java/org/elasticsearch/discovery/ec2/Ec2DiscoveryUpdateSettingsITest.java b/plugins/cloud-aws/src/test/java/org/elasticsearch/discovery/ec2/Ec2DiscoveryUpdateSettingsITest.java index 98576118206..7dbe7647da3 100644 --- a/plugins/cloud-aws/src/test/java/org/elasticsearch/discovery/ec2/Ec2DiscoveryUpdateSettingsITest.java +++ b/plugins/cloud-aws/src/test/java/org/elasticsearch/discovery/ec2/Ec2DiscoveryUpdateSettingsITest.java @@ -24,10 +24,13 @@ import org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsResp import org.elasticsearch.cloud.aws.AbstractAwsTest; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.plugin.cloud.aws.CloudAwsPlugin; +import org.elasticsearch.plugins.Plugin; import org.elasticsearch.test.ESIntegTestCase.ClusterScope; import org.elasticsearch.test.ESIntegTestCase.Scope; import org.junit.Test; +import java.util.Collection; + import static org.elasticsearch.common.settings.Settings.settingsBuilder; import static org.hamcrest.CoreMatchers.is; @@ -39,10 +42,14 @@ import static org.hamcrest.CoreMatchers.is; @ClusterScope(scope = Scope.TEST, numDataNodes = 0, numClientNodes = 0, transportClientRatio = 0.0) public class Ec2DiscoveryUpdateSettingsITest extends AbstractAwsTest { + @Override + protected Collection> nodePlugins() { + return pluginList(CloudAwsPlugin.class); + } + @Test public void testMinimumMasterNodesStart() { Settings nodeSettings = settingsBuilder() - .put("plugin.types", CloudAwsPlugin.class.getName()) .put("cloud.enabled", true) .put("discovery.type", "ec2") .build(); diff --git a/plugins/cloud-aws/src/test/java/org/elasticsearch/repositories/s3/AbstractS3SnapshotRestoreTest.java b/plugins/cloud-aws/src/test/java/org/elasticsearch/repositories/s3/AbstractS3SnapshotRestoreTest.java index 23441d5f509..393224105c0 100644 --- a/plugins/cloud-aws/src/test/java/org/elasticsearch/repositories/s3/AbstractS3SnapshotRestoreTest.java +++ b/plugins/cloud-aws/src/test/java/org/elasticsearch/repositories/s3/AbstractS3SnapshotRestoreTest.java @@ -34,6 +34,7 @@ import org.elasticsearch.cloud.aws.AwsS3Service; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.plugin.cloud.aws.CloudAwsPlugin; +import org.elasticsearch.plugins.Plugin; import org.elasticsearch.repositories.RepositoryMissingException; import org.elasticsearch.repositories.RepositoryVerificationException; import org.elasticsearch.snapshots.SnapshotMissingException; @@ -46,6 +47,7 @@ import org.junit.Before; import org.junit.Test; import java.util.ArrayList; +import java.util.Collection; import java.util.List; import static org.hamcrest.Matchers.*; @@ -63,11 +65,15 @@ abstract public class AbstractS3SnapshotRestoreTest extends AbstractAwsTest { .put(MockFSDirectoryService.RANDOM_PREVENT_DOUBLE_WRITE, false) .put(MockFSDirectoryService.RANDOM_NO_DELETE_OPEN_FILE, false) .put("cloud.enabled", true) - .put("plugin.types", CloudAwsPlugin.class.getName()) .put("repositories.s3.base_path", basePath) .build(); } + @Override + protected Collection> nodePlugins() { + return pluginList(CloudAwsPlugin.class); + } + private String basePath; @Before diff --git a/plugins/cloud-azure/src/test/java/org/elasticsearch/cloud/azure/AbstractAzureComputeServiceTest.java b/plugins/cloud-azure/src/test/java/org/elasticsearch/cloud/azure/AbstractAzureComputeServiceTest.java index 2dc5add0a3a..8df4df21470 100644 --- a/plugins/cloud-azure/src/test/java/org/elasticsearch/cloud/azure/AbstractAzureComputeServiceTest.java +++ b/plugins/cloud-azure/src/test/java/org/elasticsearch/cloud/azure/AbstractAzureComputeServiceTest.java @@ -24,13 +24,16 @@ import org.elasticsearch.cloud.azure.management.AzureComputeService.Discovery; import org.elasticsearch.cloud.azure.management.AzureComputeService.Management; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.plugin.cloud.azure.CloudAzurePlugin; +import org.elasticsearch.plugins.Plugin; import org.elasticsearch.test.ESIntegTestCase; +import java.util.Collection; + public abstract class AbstractAzureComputeServiceTest extends ESIntegTestCase { - private String mockPlugin; + private Class mockPlugin; - public AbstractAzureComputeServiceTest(String mockPlugin) { + public AbstractAzureComputeServiceTest(Class mockPlugin) { // We want to inject the Azure API Mock this.mockPlugin = mockPlugin; } @@ -41,8 +44,7 @@ public abstract class AbstractAzureComputeServiceTest extends ESIntegTestCase { .put(super.nodeSettings(nodeOrdinal)) .put("discovery.type", "azure") // We need the network to make the mock working - .put("node.mode", "network") - .extendArray("plugin.types", CloudAzurePlugin.class.getName(), mockPlugin); + .put("node.mode", "network"); // We add a fake subscription_id to start mock compute service builder.put(Management.SUBSCRIPTION_ID, "fake") @@ -53,6 +55,11 @@ public abstract class AbstractAzureComputeServiceTest extends ESIntegTestCase { return builder.build(); } + @Override + protected Collection> nodePlugins() { + return pluginList(CloudAzurePlugin.class, mockPlugin); + } + protected void checkNumberOfNodes(int expected) { NodesInfoResponse nodeInfos = client().admin().cluster().prepareNodesInfo().execute().actionGet(); assertNotNull(nodeInfos); diff --git a/plugins/cloud-azure/src/test/java/org/elasticsearch/cloud/azure/AbstractAzureRepositoryServiceTest.java b/plugins/cloud-azure/src/test/java/org/elasticsearch/cloud/azure/AbstractAzureRepositoryServiceTest.java index fa4131cf7d0..d4ae582c849 100644 --- a/plugins/cloud-azure/src/test/java/org/elasticsearch/cloud/azure/AbstractAzureRepositoryServiceTest.java +++ b/plugins/cloud-azure/src/test/java/org/elasticsearch/cloud/azure/AbstractAzureRepositoryServiceTest.java @@ -33,6 +33,7 @@ import org.junit.After; import org.junit.Before; import java.net.URISyntaxException; +import java.util.Collection; public abstract class AbstractAzureRepositoryServiceTest extends AbstractAzureTest { @@ -77,7 +78,6 @@ public abstract class AbstractAzureRepositoryServiceTest extends AbstractAzureTe @Override protected Settings nodeSettings(int nodeOrdinal) { Settings.Builder builder = Settings.settingsBuilder() - .extendArray("plugin.types", CloudAzurePlugin.class.getName(), TestPlugin.class.getName()) .put(Storage.API_IMPLEMENTATION, mock) .put(Storage.CONTAINER, "snapshots"); @@ -88,6 +88,11 @@ public abstract class AbstractAzureRepositoryServiceTest extends AbstractAzureTe return builder.build(); } + @Override + protected Collection> nodePlugins() { + return pluginList(CloudAzurePlugin.class, TestPlugin.class); + } + @Override public Settings indexSettings() { // During restore we frequently restore index to exactly the same state it was before, that might cause the same diff --git a/plugins/cloud-azure/src/test/java/org/elasticsearch/cloud/azure/AbstractAzureTest.java b/plugins/cloud-azure/src/test/java/org/elasticsearch/cloud/azure/AbstractAzureTest.java index 1263b4ba034..d99823b855c 100644 --- a/plugins/cloud-azure/src/test/java/org/elasticsearch/cloud/azure/AbstractAzureTest.java +++ b/plugins/cloud-azure/src/test/java/org/elasticsearch/cloud/azure/AbstractAzureTest.java @@ -24,9 +24,12 @@ import org.elasticsearch.common.io.PathUtils; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.SettingsException; import org.elasticsearch.plugin.cloud.azure.CloudAzurePlugin; +import org.elasticsearch.plugins.Plugin; import org.elasticsearch.test.ESIntegTestCase; import org.elasticsearch.test.ESIntegTestCase.ThirdParty; +import java.util.Collection; + /** * Base class for Azure tests that require credentials. *

@@ -40,11 +43,15 @@ public abstract class AbstractAzureTest extends ESIntegTestCase { protected Settings nodeSettings(int nodeOrdinal) { return Settings.builder() .put(super.nodeSettings(nodeOrdinal)) - .put("plugin.types", CloudAzurePlugin.class.getName()) .put(readSettingsFromFile()) .build(); } + @Override + protected Collection> nodePlugins() { + return pluginList(CloudAzurePlugin.class); + } + protected Settings readSettingsFromFile() { Settings.Builder settings = Settings.builder(); settings.put("path.home", createTempDir()); diff --git a/plugins/cloud-azure/src/test/java/org/elasticsearch/discovery/azure/AzureMinimumMasterNodesTest.java b/plugins/cloud-azure/src/test/java/org/elasticsearch/discovery/azure/AzureMinimumMasterNodesTest.java index 2cbdf4eaa3b..d2d559bc3ad 100644 --- a/plugins/cloud-azure/src/test/java/org/elasticsearch/discovery/azure/AzureMinimumMasterNodesTest.java +++ b/plugins/cloud-azure/src/test/java/org/elasticsearch/discovery/azure/AzureMinimumMasterNodesTest.java @@ -44,7 +44,7 @@ import static org.hamcrest.Matchers.nullValue; public class AzureMinimumMasterNodesTest extends AbstractAzureComputeServiceTest { public AzureMinimumMasterNodesTest() { - super(AzureComputeServiceTwoNodesMock.TestPlugin.class.getName()); + super(AzureComputeServiceTwoNodesMock.TestPlugin.class); } @Override diff --git a/plugins/cloud-azure/src/test/java/org/elasticsearch/discovery/azure/AzureSimpleTest.java b/plugins/cloud-azure/src/test/java/org/elasticsearch/discovery/azure/AzureSimpleTest.java index be69bde31ff..e46fadd7f03 100644 --- a/plugins/cloud-azure/src/test/java/org/elasticsearch/discovery/azure/AzureSimpleTest.java +++ b/plugins/cloud-azure/src/test/java/org/elasticsearch/discovery/azure/AzureSimpleTest.java @@ -36,7 +36,7 @@ import static org.hamcrest.Matchers.notNullValue; public class AzureSimpleTest extends AbstractAzureComputeServiceTest { public AzureSimpleTest() { - super(AzureComputeServiceSimpleMock.TestPlugin.class.getName()); + super(AzureComputeServiceSimpleMock.TestPlugin.class); } @Test diff --git a/plugins/cloud-azure/src/test/java/org/elasticsearch/discovery/azure/AzureTwoStartedNodesTest.java b/plugins/cloud-azure/src/test/java/org/elasticsearch/discovery/azure/AzureTwoStartedNodesTest.java index f5ec7427cfb..3b6287c65ce 100644 --- a/plugins/cloud-azure/src/test/java/org/elasticsearch/discovery/azure/AzureTwoStartedNodesTest.java +++ b/plugins/cloud-azure/src/test/java/org/elasticsearch/discovery/azure/AzureTwoStartedNodesTest.java @@ -36,7 +36,7 @@ import static org.hamcrest.Matchers.notNullValue; public class AzureTwoStartedNodesTest extends AbstractAzureComputeServiceTest { public AzureTwoStartedNodesTest() { - super(AzureComputeServiceTwoNodesMock.TestPlugin.class.getName()); + super(AzureComputeServiceTwoNodesMock.TestPlugin.class); } @Test diff --git a/plugins/cloud-azure/src/test/java/org/elasticsearch/index/store/AbstractAzureFsTest.java b/plugins/cloud-azure/src/test/java/org/elasticsearch/index/store/AbstractAzureFsTest.java index a335910e9f7..04407ce2d25 100644 --- a/plugins/cloud-azure/src/test/java/org/elasticsearch/index/store/AbstractAzureFsTest.java +++ b/plugins/cloud-azure/src/test/java/org/elasticsearch/index/store/AbstractAzureFsTest.java @@ -22,18 +22,19 @@ package org.elasticsearch.index.store; import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.plugin.cloud.azure.CloudAzurePlugin; +import org.elasticsearch.plugins.Plugin; import org.elasticsearch.test.ESIntegTestCase; import org.junit.Test; +import java.util.Collection; + import static org.hamcrest.Matchers.is; abstract public class AbstractAzureFsTest extends ESIntegTestCase { @Override - protected Settings nodeSettings(int nodeOrdinal) { - return Settings.settingsBuilder() - .put(super.nodeSettings(nodeOrdinal)) - .extendArray("plugin.types", CloudAzurePlugin.class.getName()).build(); + protected Collection> nodePlugins() { + return pluginList(CloudAzurePlugin.class); } @Test diff --git a/plugins/delete-by-query/src/test/java/org/elasticsearch/plugin/deletebyquery/DeleteByQueryTests.java b/plugins/delete-by-query/src/test/java/org/elasticsearch/plugin/deletebyquery/DeleteByQueryTests.java index 9d79a230b2f..7b0a88ce752 100644 --- a/plugins/delete-by-query/src/test/java/org/elasticsearch/plugin/deletebyquery/DeleteByQueryTests.java +++ b/plugins/delete-by-query/src/test/java/org/elasticsearch/plugin/deletebyquery/DeleteByQueryTests.java @@ -35,10 +35,12 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.IndexNotFoundException; import org.elasticsearch.index.query.MatchQueryBuilder; import org.elasticsearch.index.query.QueryBuilders; +import org.elasticsearch.plugins.Plugin; import org.elasticsearch.test.ESIntegTestCase; import org.elasticsearch.test.ESIntegTestCase.ClusterScope; import org.junit.Test; +import java.util.Collection; import java.util.concurrent.CountDownLatch; import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.atomic.AtomicReference; @@ -51,12 +53,10 @@ import static org.hamcrest.Matchers.nullValue; @ClusterScope(scope = SUITE, transportClientRatio = 0) public class DeleteByQueryTests extends ESIntegTestCase { - - protected Settings nodeSettings(int nodeOrdinal) { - Settings.Builder settings = Settings.builder() - .put(super.nodeSettings(nodeOrdinal)) - .put("plugin.types", DeleteByQueryPlugin.class.getName()); - return settings.build(); + + @Override + protected Collection> nodePlugins() { + return pluginList(DeleteByQueryPlugin.class); } @Test(expected = ActionRequestValidationException.class) diff --git a/plugins/mapper-size/src/test/java/org/elasticsearch/index/mapper/size/SizeMappingIT.java b/plugins/mapper-size/src/test/java/org/elasticsearch/index/mapper/size/SizeMappingIT.java index aa82c5a20ee..73f7a73547c 100644 --- a/plugins/mapper-size/src/test/java/org/elasticsearch/index/mapper/size/SizeMappingIT.java +++ b/plugins/mapper-size/src/test/java/org/elasticsearch/index/mapper/size/SizeMappingIT.java @@ -24,10 +24,12 @@ import org.elasticsearch.action.get.GetResponse; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.plugin.mapper.MapperSizePlugin; +import org.elasticsearch.plugins.Plugin; import org.elasticsearch.test.ESIntegTestCase; import org.junit.Test; import java.io.IOException; +import java.util.Collection; import java.util.Collections; import java.util.Locale; import java.util.Map; @@ -41,11 +43,8 @@ import static org.hamcrest.Matchers.notNullValue; public class SizeMappingIT extends ESIntegTestCase { @Override - protected Settings nodeSettings(int nodeOrdinal) { - return Settings.builder() - .put(super.nodeSettings(nodeOrdinal)) - .put("plugin.types", MapperSizePlugin.class.getName()) - .build(); + protected Collection> nodePlugins() { + return pluginList(MapperSizePlugin.class); } // issue 5053 From d06be0707caaf974b9efdadd68196859bc3bfff0 Mon Sep 17 00:00:00 2001 From: Ryan Ernst Date: Mon, 24 Aug 2015 12:05:00 -0700 Subject: [PATCH 2/2] Added link to test framework for plugin authors --- docs/plugins/authors.asciidoc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/docs/plugins/authors.asciidoc b/docs/plugins/authors.asciidoc index 048a2b76575..2ce05fdb1f9 100644 --- a/docs/plugins/authors.asciidoc +++ b/docs/plugins/authors.asciidoc @@ -50,7 +50,6 @@ When testing a Java plugin, it will only be auto-loaded if it is in the to install your plugin for testing. You may also load your plugin within the test framework for integration tests. -// nocommit -See INSERT-LINK-TO-TESTING-FRAMEWORK[[changing-node-configuration]] +Read more in {ref}/integration-tests.html#changing-node-configuration[Changing Node Configuration].