Merge pull request #13215 from martijnvg/tests/enable_mock_modules

Allow tests to override whether mock modules are used
This commit is contained in:
Martijn van Groningen 2015-08-31 21:11:34 +02:00
commit 51d052c32a
5 changed files with 31 additions and 25 deletions

View File

@ -218,7 +218,7 @@ import static org.hamcrest.Matchers.*;
* This class supports the following system properties (passed with -Dkey=value to the application)
* <ul>
* <li>-D{@value #TESTS_CLIENT_RATIO} - a double value in the interval [0..1] which defines the ration between node and transport clients used</li>
* <li>-D{@value InternalTestCluster#TESTS_ENABLE_MOCK_MODULES} - a boolean value to enable or disable mock modules. This is
* <li>-D{@value #TESTS_ENABLE_MOCK_MODULES} - a boolean value to enable or disable mock modules. This is
* useful to test the system without asserting modules that to make sure they don't hide any bugs in production.</li>
* <li> - a random seed used to initialize the index random context.
* </ul>
@ -268,6 +268,15 @@ public abstract class ESIntegTestCase extends ESTestCase {
*/
public static final String SETTING_INDEX_SEED = "index.tests.seed";
/**
* A boolean value to enable or disable mock modules. This is useful to test the
* system without asserting modules that to make sure they don't hide any bugs in
* production.
*
* @see ESIntegTestCase
*/
public static final String TESTS_ENABLE_MOCK_MODULES = "tests.enable_mock_modules";
/**
* Threshold at which indexing switches from frequently async to frequently bulk.
*/
@ -1806,9 +1815,14 @@ public abstract class ESIntegTestCase extends ESTestCase {
nodeMode = "local";
}
boolean enableMockModules = enableMockModules();
return new InternalTestCluster(nodeMode, seed, createTempDir(), minNumDataNodes, maxNumDataNodes,
InternalTestCluster.clusterName(scope.name(), seed) + "-cluster", nodeConfigurationSource, getNumClientNodes(),
InternalTestCluster.DEFAULT_ENABLE_HTTP_PIPELINING, nodePrefix);
InternalTestCluster.DEFAULT_ENABLE_HTTP_PIPELINING, nodePrefix, enableMockModules);
}
protected boolean enableMockModules() {
return RandomizedTest.systemPropertyAsBoolean(TESTS_ENABLE_MOCK_MODULES, true);
}
/**

View File

@ -153,15 +153,6 @@ public final class InternalTestCluster extends TestCluster {
static NodeConfigurationSource DEFAULT_SETTINGS_SOURCE = NodeConfigurationSource.EMPTY;
/**
* A boolean value to enable or disable mock modules. This is useful to test the
* system without asserting modules that to make sure they don't hide any bugs in
* production.
*
* @see ESIntegTestCase
*/
public static final String TESTS_ENABLE_MOCK_MODULES = "tests.enable_mock_modules";
/**
* A node level setting that holds a per node random seed that is consistent across node restarts
*/
@ -192,8 +183,6 @@ public final class InternalTestCluster extends TestCluster {
public final int HTTP_BASE_PORT = GLOBAL_HTTP_BASE_PORT + CLUSTER_BASE_PORT_OFFSET;
private static final boolean ENABLE_MOCK_MODULES = RandomizedTest.systemPropertyAsBoolean(TESTS_ENABLE_MOCK_MODULES, true);
static final int DEFAULT_MIN_NUM_DATA_NODES = 1;
static final int DEFAULT_MAX_NUM_DATA_NODES = TEST_NIGHTLY ? 6 : 3;
@ -229,6 +218,8 @@ public final class InternalTestCluster extends TestCluster {
private final ExecutorService executor;
private final boolean enableMockModules;
/**
* All nodes started by the cluster will have their name set to nodePrefix followed by a positive number
*/
@ -240,7 +231,7 @@ public final class InternalTestCluster extends TestCluster {
public InternalTestCluster(String nodeMode, long clusterSeed, Path baseDir,
int minNumDataNodes, int maxNumDataNodes, String clusterName, NodeConfigurationSource nodeConfigurationSource, int numClientNodes,
boolean enableHttpPipelining, String nodePrefix) {
boolean enableHttpPipelining, String nodePrefix, boolean enableMockModules) {
super(clusterSeed);
if ("network".equals(nodeMode) == false && "local".equals(nodeMode) == false) {
throw new IllegalArgumentException("Unknown nodeMode: " + nodeMode);
@ -276,6 +267,7 @@ public final class InternalTestCluster extends TestCluster {
this.nodePrefix = nodePrefix;
assert nodePrefix != null;
this.enableMockModules = enableMockModules;
/*
* TODO
@ -387,15 +379,15 @@ public final class InternalTestCluster extends TestCluster {
private Collection<Class<? extends Plugin>> getPlugins(long seed) {
Set<Class<? extends Plugin>> plugins = new HashSet<>(nodeConfigurationSource.nodePlugins());
Random random = new Random(seed);
if (ENABLE_MOCK_MODULES && usually(random)) {
if (enableMockModules && 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);
if (isLocalTransportConfigured()) {
plugins.add(AssertingLocalTransport.TestPlugin.class);
}
}
return plugins;
}

View File

@ -25,8 +25,8 @@ import com.carrotsearch.randomizedtesting.TraceFormatting;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.logging.ESLogger;
import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.test.ESIntegTestCase;
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.test.InternalTestCluster;
import org.junit.internal.AssumptionViolatedException;
import org.junit.runner.Description;
import org.junit.runner.notification.Failure;
@ -158,7 +158,7 @@ public class ReproduceInfoPrinter extends RunListener {
appendProperties("es.logger.level");
if (inVerifyPhase()) {
// these properties only make sense for integration tests
appendProperties("es.node.mode", "es.node.local", TESTS_CLUSTER, InternalTestCluster.TESTS_ENABLE_MOCK_MODULES);
appendProperties("es.node.mode", "es.node.local", TESTS_CLUSTER, ESIntegTestCase.TESTS_ENABLE_MOCK_MODULES);
}
appendProperties("tests.assertion.disabled", "tests.security.manager", "tests.nightly", "tests.jvms",
"tests.client.ratio", "tests.heap.size", "tests.bwc", "tests.bwc.version");

View File

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

View File

@ -76,7 +76,7 @@ public class TribeIT extends ESIntegTestCase {
public static void setupSecondCluster() throws Exception {
ESIntegTestCase.beforeClass();
cluster2 = new InternalTestCluster(InternalTestCluster.configuredNodeMode(), randomLong(), createTempDir(), 2, 2,
Strings.randomBase64UUID(getRandom()), NodeConfigurationSource.EMPTY, 0, false, SECOND_CLUSTER_NODE_PREFIX);
Strings.randomBase64UUID(getRandom()), NodeConfigurationSource.EMPTY, 0, false, SECOND_CLUSTER_NODE_PREFIX, true);
cluster2.beforeTest(getRandom(), 0.1);
cluster2.ensureAtLeastNumDataNodes(2);