Test: Allow integ tests to exclude mock plugins

We currently randomly add a set of mock plugins to integ tests.
Sometimes it is necessary to omit this mock plugins, but other times you
may just want to suppress a particular mock plugin. For example, if you
have your own transport, you want to omit the asserting local transport
mock, since they would both try to set the transport.type.
This commit is contained in:
Ryan Ernst 2015-12-16 17:59:43 -08:00
parent b4fbe1e1b8
commit 17a806631d
7 changed files with 68 additions and 22 deletions

View File

@ -37,6 +37,7 @@ import org.elasticsearch.common.transport.TransportAddress;
import org.elasticsearch.discovery.MasterNotDiscoveredException; import org.elasticsearch.discovery.MasterNotDiscoveredException;
import org.elasticsearch.discovery.zen.ping.unicast.UnicastZenPing; import org.elasticsearch.discovery.zen.ping.unicast.UnicastZenPing;
import org.elasticsearch.node.Node; import org.elasticsearch.node.Node;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.test.ESIntegTestCase; import org.elasticsearch.test.ESIntegTestCase;
import org.elasticsearch.test.InternalTestCluster; import org.elasticsearch.test.InternalTestCluster;
import org.elasticsearch.test.NodeConfigurationSource; import org.elasticsearch.test.NodeConfigurationSource;
@ -47,6 +48,7 @@ import org.junit.BeforeClass;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.Map; import java.util.Map;
@ -79,6 +81,11 @@ public class TribeIT extends ESIntegTestCase {
return Settings.builder().put(Node.HTTP_ENABLED, false).build(); return Settings.builder().put(Node.HTTP_ENABLED, false).build();
} }
@Override
public Collection<Class<? extends Plugin>> nodePlugins() {
return Collections.emptyList();
}
@Override @Override
public Settings transportClientSettings() { public Settings transportClientSettings() {
return null; return null;
@ -86,7 +93,7 @@ public class TribeIT extends ESIntegTestCase {
}; };
cluster2 = new InternalTestCluster(InternalTestCluster.configuredNodeMode(), randomLong(), createTempDir(), 2, 2, cluster2 = new InternalTestCluster(InternalTestCluster.configuredNodeMode(), randomLong(), createTempDir(), 2, 2,
Strings.randomBase64UUID(getRandom()), nodeConfigurationSource, 0, false, SECOND_CLUSTER_NODE_PREFIX, true); Strings.randomBase64UUID(getRandom()), nodeConfigurationSource, 0, false, SECOND_CLUSTER_NODE_PREFIX, Collections.emptyList());
cluster2.beforeTest(getRandom(), 0.1); cluster2.beforeTest(getRandom(), 0.1);
cluster2.ensureAtLeastNumDataNodes(2); cluster2.ensureAtLeastNumDataNodes(2);

View File

@ -29,6 +29,7 @@ import org.elasticsearch.common.io.PathUtils;
import org.elasticsearch.common.network.NetworkModule; import org.elasticsearch.common.network.NetworkModule;
import org.elasticsearch.common.regex.Regex; import org.elasticsearch.common.regex.Regex;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.test.junit.annotations.TestLogging; import org.elasticsearch.test.junit.annotations.TestLogging;
import org.elasticsearch.test.junit.listeners.LoggingListener; import org.elasticsearch.test.junit.listeners.LoggingListener;
@ -40,6 +41,8 @@ import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target; import java.lang.annotation.Target;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.Collection;
import java.util.Collections;
import java.util.Map; import java.util.Map;
import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.is;
@ -175,6 +178,11 @@ public abstract class ESBackcompatTestCase extends ESIntegTestCase {
return externalNodeSettings(nodeOrdinal); return externalNodeSettings(nodeOrdinal);
} }
@Override
public Collection<Class<? extends Plugin>> nodePlugins() {
return Collections.emptyList();
}
@Override @Override
public Settings transportClientSettings() { public Settings transportClientSettings() {
return transportClientSettings(); return transportClientSettings();

View File

@ -95,6 +95,7 @@ import org.elasticsearch.discovery.zen.ZenDiscovery;
import org.elasticsearch.discovery.zen.elect.ElectMasterService; import org.elasticsearch.discovery.zen.elect.ElectMasterService;
import org.elasticsearch.env.Environment; import org.elasticsearch.env.Environment;
import org.elasticsearch.index.IndexService; import org.elasticsearch.index.IndexService;
import org.elasticsearch.index.MockEngineFactoryPlugin;
import org.elasticsearch.index.codec.CodecService; import org.elasticsearch.index.codec.CodecService;
import org.elasticsearch.index.mapper.DocumentMapper; import org.elasticsearch.index.mapper.DocumentMapper;
import org.elasticsearch.index.mapper.MappedFieldType; import org.elasticsearch.index.mapper.MappedFieldType;
@ -111,13 +112,18 @@ import org.elasticsearch.indices.cache.request.IndicesRequestCache;
import org.elasticsearch.indices.flush.SyncedFlushService; import org.elasticsearch.indices.flush.SyncedFlushService;
import org.elasticsearch.indices.store.IndicesStore; import org.elasticsearch.indices.store.IndicesStore;
import org.elasticsearch.node.Node; import org.elasticsearch.node.Node;
import org.elasticsearch.node.NodeMocksPlugin;
import org.elasticsearch.plugins.Plugin; import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.rest.RestStatus; import org.elasticsearch.rest.RestStatus;
import org.elasticsearch.search.MockSearchService;
import org.elasticsearch.search.SearchHit; import org.elasticsearch.search.SearchHit;
import org.elasticsearch.search.SearchService; import org.elasticsearch.search.SearchService;
import org.elasticsearch.test.client.RandomizingClient; import org.elasticsearch.test.client.RandomizingClient;
import org.elasticsearch.test.disruption.ServiceDisruptionScheme; import org.elasticsearch.test.disruption.ServiceDisruptionScheme;
import org.elasticsearch.test.rest.client.http.HttpRequestBuilder; import org.elasticsearch.test.rest.client.http.HttpRequestBuilder;
import org.elasticsearch.test.store.MockFSIndexStore;
import org.elasticsearch.test.transport.AssertingLocalTransport;
import org.elasticsearch.test.transport.MockTransportService;
import org.hamcrest.Matchers; import org.hamcrest.Matchers;
import org.joda.time.DateTimeZone; import org.joda.time.DateTimeZone;
import org.junit.After; import org.junit.After;
@ -128,6 +134,7 @@ import org.junit.BeforeClass;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.lang.annotation.Annotation; import java.lang.annotation.Annotation;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType; import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited; import java.lang.annotation.Inherited;
import java.lang.annotation.Retention; import java.lang.annotation.Retention;
@ -1806,14 +1813,21 @@ public abstract class ESIntegTestCase extends ESTestCase {
nodeMode = "local"; nodeMode = "local";
} }
boolean enableMockModules = enableMockModules(); Collection<Class<? extends Plugin>> mockPlugins = getMockPlugins();
return new InternalTestCluster(nodeMode, seed, createTempDir(), minNumDataNodes, maxNumDataNodes, return new InternalTestCluster(nodeMode, seed, createTempDir(), minNumDataNodes, maxNumDataNodes,
InternalTestCluster.clusterName(scope.name(), seed) + "-cluster", nodeConfigurationSource, getNumClientNodes(), InternalTestCluster.clusterName(scope.name(), seed) + "-cluster", nodeConfigurationSource, getNumClientNodes(),
InternalTestCluster.DEFAULT_ENABLE_HTTP_PIPELINING, nodePrefix, enableMockModules); InternalTestCluster.DEFAULT_ENABLE_HTTP_PIPELINING, nodePrefix, mockPlugins);
} }
protected boolean enableMockModules() { /** Return the mock plugins the cluster should use. These may be randomly omitted based on the cluster seed. */
return RandomizedTest.systemPropertyAsBoolean(TESTS_ENABLE_MOCK_MODULES, true); protected Collection<Class<? extends Plugin>> getMockPlugins() {
return pluginList(MockTransportService.TestPlugin.class,
MockFSIndexStore.TestPlugin.class,
NodeMocksPlugin.class,
MockEngineFactoryPlugin.class,
MockSearchService.TestPlugin.class,
AssertingLocalTransport.TestPlugin.class);
} }
/** /**

View File

@ -199,7 +199,7 @@ public final class InternalTestCluster extends TestCluster {
private final ExecutorService executor; private final ExecutorService executor;
private final boolean enableMockModules; private final Collection<Class<? extends Plugin>> mockPlugins;
/** /**
* All nodes started by the cluster will have their name set to nodePrefix followed by a positive number * All nodes started by the cluster will have their name set to nodePrefix followed by a positive number
@ -212,7 +212,7 @@ public final class InternalTestCluster extends TestCluster {
public InternalTestCluster(String nodeMode, long clusterSeed, Path baseDir, public InternalTestCluster(String nodeMode, long clusterSeed, Path baseDir,
int minNumDataNodes, int maxNumDataNodes, String clusterName, NodeConfigurationSource nodeConfigurationSource, int numClientNodes, int minNumDataNodes, int maxNumDataNodes, String clusterName, NodeConfigurationSource nodeConfigurationSource, int numClientNodes,
boolean enableHttpPipelining, String nodePrefix, boolean enableMockModules) { boolean enableHttpPipelining, String nodePrefix, Collection<Class<? extends Plugin>> mockPlugins) {
super(clusterSeed); super(clusterSeed);
if ("network".equals(nodeMode) == false && "local".equals(nodeMode) == false) { if ("network".equals(nodeMode) == false && "local".equals(nodeMode) == false) {
throw new IllegalArgumentException("Unknown nodeMode: " + nodeMode); throw new IllegalArgumentException("Unknown nodeMode: " + nodeMode);
@ -248,7 +248,7 @@ public final class InternalTestCluster extends TestCluster {
this.nodePrefix = nodePrefix; this.nodePrefix = nodePrefix;
assert nodePrefix != null; assert nodePrefix != null;
this.enableMockModules = enableMockModules; this.mockPlugins = mockPlugins;
/* /*
* TODO * TODO
@ -359,16 +359,10 @@ public final class InternalTestCluster extends TestCluster {
private Collection<Class<? extends Plugin>> getPlugins(long seed) { private Collection<Class<? extends Plugin>> getPlugins(long seed) {
Set<Class<? extends Plugin>> plugins = new HashSet<>(nodeConfigurationSource.nodePlugins()); Set<Class<? extends Plugin>> plugins = new HashSet<>(nodeConfigurationSource.nodePlugins());
Random random = new Random(seed); plugins.addAll(mockPlugins);
if (enableMockModules && usually(random)) { if (isLocalTransportConfigured() == false) {
plugins.add(MockTransportService.TestPlugin.class); // this is crazy we must do this here...we should really just always be using local transport...
plugins.add(MockFSIndexStore.TestPlugin.class); plugins.remove(AssertingLocalTransport.TestPlugin.class);
plugins.add(NodeMocksPlugin.class);
plugins.add(MockEngineFactoryPlugin.class);
plugins.add(MockSearchService.TestPlugin.class);
if (isLocalTransportConfigured()) {
plugins.add(AssertingLocalTransport.TestPlugin.class);
}
} }
return plugins; return plugins;
} }

View File

@ -19,10 +19,18 @@
package org.elasticsearch.test; package org.elasticsearch.test;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.MockEngineFactoryPlugin;
import org.elasticsearch.node.NodeMocksPlugin;
import org.elasticsearch.plugins.Plugin; import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.search.MockSearchService;
import org.elasticsearch.test.store.MockFSIndexStore;
import org.elasticsearch.test.transport.AssertingLocalTransport;
import org.elasticsearch.test.transport.MockTransportService;
import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.List;
public abstract class NodeConfigurationSource { public abstract class NodeConfigurationSource {
@ -43,6 +51,18 @@ public abstract class NodeConfigurationSource {
*/ */
public abstract Settings nodeSettings(int nodeOrdinal); public abstract Settings nodeSettings(int nodeOrdinal);
/** Plugins that will be randomly added to the node */
public Collection<Class<? extends Plugin>> mockPlugins() {
List<Class<? extends Plugin>> plugins = new ArrayList<>();
plugins.add(MockTransportService.TestPlugin.class);
plugins.add(MockFSIndexStore.TestPlugin.class);
plugins.add(NodeMocksPlugin.class);
plugins.add(MockEngineFactoryPlugin.class);
plugins.add(MockSearchService.TestPlugin.class);
plugins.add(AssertingLocalTransport.TestPlugin.class);
return plugins;
}
/** Returns plugins that should be loaded on the node */ /** Returns plugins that should be loaded on the node */
public Collection<Class<? extends Plugin>> nodePlugins() { public Collection<Class<? extends Plugin>> nodePlugins() {
return Collections.emptyList(); return Collections.emptyList();

View File

@ -24,12 +24,15 @@ import org.elasticsearch.common.SuppressForbidden;
import org.elasticsearch.common.network.NetworkUtils; import org.elasticsearch.common.network.NetworkUtils;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.util.CollectionUtils; import org.elasticsearch.common.util.CollectionUtils;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.test.InternalTestCluster; import org.elasticsearch.test.InternalTestCluster;
import org.elasticsearch.test.NodeConfigurationSource; import org.elasticsearch.test.NodeConfigurationSource;
import java.io.IOException; import java.io.IOException;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.net.ServerSocket; import java.net.ServerSocket;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;

View File

@ -52,8 +52,8 @@ public class InternalTestClusterTests extends ESTestCase {
String nodePrefix = randomRealisticUnicodeOfCodepointLengthBetween(1, 10); String nodePrefix = randomRealisticUnicodeOfCodepointLengthBetween(1, 10);
Path baseDir = createTempDir(); Path baseDir = createTempDir();
InternalTestCluster cluster0 = new InternalTestCluster("local", clusterSeed, baseDir, minNumDataNodes, maxNumDataNodes, clusterName, nodeConfigurationSource, numClientNodes, enableHttpPipelining, nodePrefix, true); InternalTestCluster cluster0 = new InternalTestCluster("local", clusterSeed, baseDir, minNumDataNodes, maxNumDataNodes, clusterName, nodeConfigurationSource, numClientNodes, enableHttpPipelining, nodePrefix, Collections.emptyList());
InternalTestCluster cluster1 = new InternalTestCluster("local", clusterSeed, baseDir, minNumDataNodes, maxNumDataNodes, clusterName, nodeConfigurationSource, numClientNodes, enableHttpPipelining, nodePrefix, true); InternalTestCluster cluster1 = new InternalTestCluster("local", clusterSeed, baseDir, minNumDataNodes, maxNumDataNodes, clusterName, nodeConfigurationSource, numClientNodes, enableHttpPipelining, nodePrefix, Collections.emptyList());
// TODO: this is not ideal - we should have a way to make sure ports are initialized in the same way // TODO: this is not ideal - we should have a way to make sure ports are initialized in the same way
assertClusters(cluster0, cluster1, false); assertClusters(cluster0, cluster1, false);
@ -110,8 +110,8 @@ public class InternalTestClusterTests extends ESTestCase {
String nodePrefix = "foobar"; String nodePrefix = "foobar";
Path baseDir = createTempDir(); Path baseDir = createTempDir();
InternalTestCluster cluster0 = new InternalTestCluster("local", clusterSeed, baseDir, minNumDataNodes, maxNumDataNodes, clusterName1, nodeConfigurationSource, numClientNodes, enableHttpPipelining, nodePrefix, true); InternalTestCluster cluster0 = new InternalTestCluster("local", clusterSeed, baseDir, minNumDataNodes, maxNumDataNodes, clusterName1, nodeConfigurationSource, numClientNodes, enableHttpPipelining, nodePrefix, Collections.emptyList());
InternalTestCluster cluster1 = new InternalTestCluster("local", clusterSeed, baseDir, minNumDataNodes, maxNumDataNodes, clusterName2, nodeConfigurationSource, numClientNodes, enableHttpPipelining, nodePrefix, true); InternalTestCluster cluster1 = new InternalTestCluster("local", clusterSeed, baseDir, minNumDataNodes, maxNumDataNodes, clusterName2, nodeConfigurationSource, numClientNodes, enableHttpPipelining, nodePrefix, Collections.emptyList());
assertClusters(cluster0, cluster1, false); assertClusters(cluster0, cluster1, false);
long seed = randomLong(); long seed = randomLong();