From 11c4218566baff8df436a0543b1846731f54695c Mon Sep 17 00:00:00 2001
From: Simon Willnauer
Date: Sun, 29 Dec 2013 00:50:10 +0100
Subject: [PATCH] Start Test nodes sometimes without mock modules
We are mocking out some functionality to add assertions etc. or
randomize store types. We should randomly run with our defaults to make
sure we don't hide any potential problems.
---
pom.xml | 1 +
.../test/ElasticsearchIntegrationTest.java | 2 ++
.../org/elasticsearch/test/TestCluster.java | 19 +++++++++++++++----
.../junit/listeners/ReproduceInfoPrinter.java | 3 ++-
4 files changed, 20 insertions(+), 5 deletions(-)
diff --git a/pom.xml b/pom.xml
index 19ddf997057..8a757e67d37 100644
--- a/pom.xml
+++ b/pom.xml
@@ -427,6 +427,7 @@
${tests.integration}
${tests.cluster_seed}
${tests.client.ratio}
+ ${tests.enable_mock_modules}
${tests.rest}
${tests.rest.suite}
${tests.rest.spec}
diff --git a/src/test/java/org/elasticsearch/test/ElasticsearchIntegrationTest.java b/src/test/java/org/elasticsearch/test/ElasticsearchIntegrationTest.java
index 7e573404a07..f2bb75dff79 100644
--- a/src/test/java/org/elasticsearch/test/ElasticsearchIntegrationTest.java
+++ b/src/test/java/org/elasticsearch/test/ElasticsearchIntegrationTest.java
@@ -125,6 +125,8 @@ import static org.hamcrest.Matchers.equalTo;
*
* - -D{@value #TESTS_CLIENT_RATIO} - a double value in the interval [0..1] which defines the ration between node and transport clients used
* - -D{@value TestCluster#TESTS_CLUSTER_SEED} - a random seed used to initialize the clusters random context.
+ *
- -D{@value TestCluster#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.
* - -D{@value #INDEX_SEED_SETTING} - a random seed used to initialize the index random context.
*
*
diff --git a/src/test/java/org/elasticsearch/test/TestCluster.java b/src/test/java/org/elasticsearch/test/TestCluster.java
index 8a9248b52b5..15092378d4d 100644
--- a/src/test/java/org/elasticsearch/test/TestCluster.java
+++ b/src/test/java/org/elasticsearch/test/TestCluster.java
@@ -62,7 +62,10 @@ import java.util.*;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
+import static com.carrotsearch.randomizedtesting.RandomizedTest.systemPropertyAsBoolean;
import static com.google.common.collect.Maps.newTreeMap;
+import static org.apache.lucene.util.LuceneTestCase.rarely;
+import static org.apache.lucene.util.LuceneTestCase.usually;
import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder;
import static org.elasticsearch.node.NodeBuilder.nodeBuilder;
@@ -91,6 +94,13 @@ public final class TestCluster implements Iterable {
*/
public static final String TESTS_CLUSTER_SEED = "tests.cluster_seed";
+ /**
+ * Key used to set the shared cluster random seed via the commandline -D{@value #TESTS_CLUSTER_SEED}
+ */
+ public static final String TESTS_ENABLE_MOCK_MODULES = "tests.enable_mock_modules";
+
+ private static final boolean ENABLE_MOCK_MODULES = systemPropertyAsBoolean(TESTS_ENABLE_MOCK_MODULES, true);
+
private static long clusterSeed() {
String property = System.getProperty(TESTS_CLUSTER_SEED);
if (!Strings.hasLength(property)) {
@@ -191,18 +201,19 @@ public final class TestCluster implements Iterable {
Builder builder = ImmutableSettings.settingsBuilder()
/* use RAM directories in 10% of the runs */
//.put("index.store.type", random.nextInt(10) == 0 ? MockRamIndexStoreModule.class.getName() : MockFSIndexStoreModule.class.getName())
- // TODO we should run without those mock modules once in a while to make sure we don't hide any bugs in the actual impl.
- .put("index.store.type", MockFSIndexStoreModule.class.getName()) // no RAM dir for now!
- .put(IndexEngineModule.EngineSettings.ENGINE_TYPE, MockEngineModule.class.getName())
.put("cluster.name", clusterName)
// decrease the routing schedule so new nodes will be added quickly - some random value between 30 and 80 ms
.put("cluster.routing.schedule", (30 + random.nextInt(50)) + "ms")
// default to non gateway
.put("gateway.type", "none");
+ if (ENABLE_MOCK_MODULES && usually(random)) {
+ builder.put("index.store.type", MockFSIndexStoreModule.class.getName()); // no RAM dir for now!
+ builder.put(IndexEngineModule.EngineSettings.ENGINE_TYPE, MockEngineModule.class.getName());
+ }
if (isLocalTransportConfigured()) {
builder.put(TransportModule.TRANSPORT_TYPE_KEY, AssertingLocalTransportModule.class.getName());
} else {
- builder.put(Transport.TransportSettings.TRANSPORT_TCP_COMPRESS, random.nextInt(10) == 0);
+ builder.put(Transport.TransportSettings.TRANSPORT_TCP_COMPRESS, rarely(random));
}
builder.put("type", RandomPicks.randomFrom(random, CacheRecycler.Type.values()));
return builder.build();
diff --git a/src/test/java/org/elasticsearch/test/junit/listeners/ReproduceInfoPrinter.java b/src/test/java/org/elasticsearch/test/junit/listeners/ReproduceInfoPrinter.java
index 56f2c231fc2..daefbfab208 100644
--- a/src/test/java/org/elasticsearch/test/junit/listeners/ReproduceInfoPrinter.java
+++ b/src/test/java/org/elasticsearch/test/junit/listeners/ReproduceInfoPrinter.java
@@ -9,6 +9,7 @@ import org.elasticsearch.common.logging.ESLogger;
import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.test.ElasticsearchIntegrationTest;
import org.elasticsearch.test.ElasticsearchTestCase;
+import org.elasticsearch.test.TestCluster;
import org.junit.internal.AssumptionViolatedException;
import org.junit.runner.Description;
import org.junit.runner.notification.Failure;
@@ -111,7 +112,7 @@ public class ReproduceInfoPrinter extends RunListener {
}
public ReproduceErrorMessageBuilder appendESProperties() {
- appendProperties("es.logger.level", "es.node.mode", "es.node.local");
+ appendProperties("es.logger.level", "es.node.mode", "es.node.local", TestCluster.TESTS_ENABLE_MOCK_MODULES);
if (System.getProperty("tests.jvm.argline") != null && !System.getProperty("tests.jvm.argline").isEmpty()) {
appendOpt("tests.jvm.argline", "\"" + System.getProperty("tests.jvm.argline") + "\"");