diff --git a/pom.xml b/pom.xml
index 4ee18629961..410e69be730 100644
--- a/pom.xml
+++ b/pom.xml
@@ -34,6 +34,7 @@
1
true
onerror
+ 0.0
INFO
@@ -389,6 +390,7 @@
${tests.showSuccess}
${tests.integration}
${tests.cluster_seed}
+ ${tests.client.ratio}
${env.ES_TEST_LOCAL}
${es.node.mode}
${es.logger.level}
diff --git a/src/test/java/org/elasticsearch/index/store/mock/MockDirectoryHelper.java b/src/test/java/org/elasticsearch/index/store/mock/MockDirectoryHelper.java
index 1bd729b96ee..0d230c90454 100644
--- a/src/test/java/org/elasticsearch/index/store/mock/MockDirectoryHelper.java
+++ b/src/test/java/org/elasticsearch/index/store/mock/MockDirectoryHelper.java
@@ -36,7 +36,7 @@ import org.elasticsearch.index.store.fs.NioFsDirectoryService;
import org.elasticsearch.index.store.fs.SimpleFsDirectoryService;
import org.elasticsearch.index.store.memory.ByteBufferDirectoryService;
import org.elasticsearch.index.store.ram.RamDirectoryService;
-import org.elasticsearch.test.ElasticSearchTestCase;
+import org.elasticsearch.test.AbstractIntegrationTest;
import java.util.Random;
import java.util.Set;
@@ -58,7 +58,7 @@ public class MockDirectoryHelper {
public MockDirectoryHelper(ShardId shardId, Settings indexSettings, ESLogger logger) {
randomIOExceptionRate = indexSettings.getAsDouble(RANDOM_IO_EXCEPTION_RATE, 0.0d);
randomIOExceptionRateOnOpen = indexSettings.getAsDouble(RANDOM_IO_EXCEPTION_RATE_ON_OPEN, 0.0d);
- final long seed = indexSettings.getAsLong(ElasticSearchTestCase.INDEX_SEED_SETTING, 0l);
+ final long seed = indexSettings.getAsLong(AbstractIntegrationTest.INDEX_SEED_SETTING, 0l);
random = new Random(seed);
random.nextInt(shardId.getId() + 1); // some randomness per shard
throttle = Throttling.valueOf(indexSettings.get(RANDOM_THROTTLE, random.nextDouble() < 0.1 ? "SOMETIMES" : "NEVER"));
diff --git a/src/test/java/org/elasticsearch/junit/listeners/ReproduceInfoPrinter.java b/src/test/java/org/elasticsearch/junit/listeners/ReproduceInfoPrinter.java
index a168b1b2b27..0f6585e8c86 100644
--- a/src/test/java/org/elasticsearch/junit/listeners/ReproduceInfoPrinter.java
+++ b/src/test/java/org/elasticsearch/junit/listeners/ReproduceInfoPrinter.java
@@ -1,14 +1,13 @@
package org.elasticsearch.junit.listeners;
-import org.elasticsearch.test.AbstractIntegrationTest;
-import org.elasticsearch.test.ElasticSearchTestCase;
-
import com.carrotsearch.randomizedtesting.RandomizedContext;
import com.carrotsearch.randomizedtesting.ReproduceErrorMessageBuilder;
import com.carrotsearch.randomizedtesting.SeedUtils;
import com.carrotsearch.randomizedtesting.TraceFormatting;
import org.elasticsearch.common.logging.ESLogger;
import org.elasticsearch.common.logging.Loggers;
+import org.elasticsearch.test.AbstractIntegrationTest;
+import org.elasticsearch.test.ElasticSearchTestCase;
import org.junit.internal.AssumptionViolatedException;
import org.junit.runner.Description;
import org.junit.runner.notification.Failure;
@@ -47,7 +46,7 @@ public class ReproduceInfoPrinter extends RunListener {
b.append("REPRODUCE WITH : mvn test");
ReproduceErrorMessageBuilder builder = new MavenMessageBuilder(b).appendAllOpts(failure.getDescription());
if (AbstractIntegrationTest.class.isAssignableFrom(failure.getDescription().getTestClass())) {
- builder.appendOpt("tests.cluster_seed", SeedUtils.formatSeed(ElasticSearchTestCase.SHARED_CLUSTER_SEED));
+ builder.appendOpt("tests.cluster_seed", SeedUtils.formatSeed(AbstractIntegrationTest.SHARED_CLUSTER_SEED));
}
b.append("\n");
diff --git a/src/test/java/org/elasticsearch/test/AbstractIntegrationTest.java b/src/test/java/org/elasticsearch/test/AbstractIntegrationTest.java
index 78a21e2576d..23eeda62cf9 100644
--- a/src/test/java/org/elasticsearch/test/AbstractIntegrationTest.java
+++ b/src/test/java/org/elasticsearch/test/AbstractIntegrationTest.java
@@ -18,6 +18,7 @@
*/
package org.elasticsearch.test;
+import com.carrotsearch.randomizedtesting.SeedUtils;
import com.google.common.base.Joiner;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableMap.Builder;
@@ -101,9 +102,17 @@ import static org.hamcrest.Matchers.equalTo;
@Ignore
@IntegrationTests
public abstract class AbstractIntegrationTest extends ElasticSearchTestCase {
+
+ public static final String INDEX_SEED_SETTING = "index.tests.seed";
+
+ public static final long SHARED_CLUSTER_SEED = clusterSeed();
+
+ private static final double TRANSPORT_CLIENT_RATIO = transportClientRatio();
private static final TestCluster globalCluster = new TestCluster(SHARED_CLUSTER_SEED, TestCluster.clusterName("shared", ElasticSearchTestCase.CHILD_VM_ID, SHARED_CLUSTER_SEED));
+
private static TestCluster currentCluster;
+
private static final Map, TestCluster> clusters = new IdentityHashMap, TestCluster>();
@Before
@@ -122,9 +131,8 @@ public abstract class AbstractIntegrationTest extends ElasticSearchTestCase {
break;
default:
assert false : "Unknonw Scope: [" + currentClusterScope + "]";
-
}
- currentCluster.beforeTest(getRandom());
+ currentCluster.beforeTest(getRandom(), Double.isNaN(TRANSPORT_CLIENT_RATIO) ? randomDouble() : TRANSPORT_CLIENT_RATIO);
wipeIndices();
wipeTemplates();
randomIndexTemplate();
@@ -601,5 +609,21 @@ public abstract class AbstractIntegrationTest extends ElasticSearchTestCase {
Scope scope() default Scope.GLOBAL;
int numNodes() default -1;
}
+
+ private static long clusterSeed() {
+ String property = System.getProperty("tests.cluster_seed");
+ if (property == null || property.isEmpty()) {
+ return System.nanoTime();
+ }
+ return SeedUtils.parseSeed(property);
+ }
+
+ private static double transportClientRatio() {
+ String property = System.getProperty("tests.client.ratio");
+ if (property == null || property.isEmpty()) {
+ return Double.NaN;
+ }
+ return Double.parseDouble(property);
+ }
}
diff --git a/src/test/java/org/elasticsearch/test/ElasticSearchTestCase.java b/src/test/java/org/elasticsearch/test/ElasticSearchTestCase.java
index cdf51e05dc5..cd5aed83b1a 100644
--- a/src/test/java/org/elasticsearch/test/ElasticSearchTestCase.java
+++ b/src/test/java/org/elasticsearch/test/ElasticSearchTestCase.java
@@ -18,7 +18,6 @@
*/
package org.elasticsearch.test;
-import com.carrotsearch.randomizedtesting.SeedUtils;
import com.carrotsearch.randomizedtesting.annotations.*;
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakScope.Scope;
import com.google.common.base.Predicate;
@@ -50,18 +49,6 @@ public abstract class ElasticSearchTestCase extends AbstractRandomizedTest {
public static final String CHILD_VM_ID = System.getProperty("junit4.childvm.id", "" + System.currentTimeMillis());
- public static final long SHARED_CLUSTER_SEED = clusterSeed();
- public static final String INDEX_SEED_SETTING = "index.tests.seed";
-
- private static long clusterSeed() {
- String property = System.getProperty("tests.cluster_seed");
- if (property == null || property.isEmpty()) {
- return System.nanoTime();
- }
- return SeedUtils.parseSeed(property);
-
- }
-
public boolean awaitBusy(Predicate> breakPredicate) throws InterruptedException {
return awaitBusy(breakPredicate, 10, TimeUnit.SECONDS);
}
diff --git a/src/test/java/org/elasticsearch/test/TestCluster.java b/src/test/java/org/elasticsearch/test/TestCluster.java
index 97adb644200..8de8380e1fe 100644
--- a/src/test/java/org/elasticsearch/test/TestCluster.java
+++ b/src/test/java/org/elasticsearch/test/TestCluster.java
@@ -89,6 +89,8 @@ public class TestCluster implements Closeable, Iterable {
* this is important if a node is randomly shut down in a test since the next test relies on a
* fully shared cluster to be more reproducible */
private final long[] sharedNodesSeeds;
+
+ private double transportClientRatio = 0.0;
private final Map perNodeSettingsMap;
private static final Map EMPTY = Collections.emptyMap();
@@ -418,31 +420,29 @@ public class TestCluster implements Closeable, Iterable {
@Override
public Client client(Node node, String clusterName, Random random) {
- switch (random.nextInt(10)) {
- case 5: // disabled for now - will re-enable once tests stabelize
-// if (logger.isDebugEnabled()) {
-// logger.debug("Using transport client for node [{}] sniff: [{}]", node.settings().get("name"), false);
-// }
-// return TransportClientFactory.NO_SNIFF_CLIENT_FACTORY.client(node, clusterName, random);
- case 3:
-// if (logger.isDebugEnabled()) {
-// logger.debug("Using transport client for node [{}] sniff: [{}]", node.settings().get("name"), true);
-// }
-// return TransportClientFactory.SNIFF_CLIENT_FACTORY.client(node, clusterName, random);
- default:
- if (logger.isDebugEnabled()) {
- logger.debug("Using node client for node [{}]", node.settings().get("name"));
- }
- return node.client();
+ double nextDouble = random.nextDouble();
+ if (nextDouble < transportClientRatio) {
+ if (logger.isDebugEnabled()) {
+ logger.debug("Using transport client for node [{}] sniff: [{}]", node.settings().get("name"), false);
+ }
+ /* 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 TransportClientFactory.NO_SNIFF_CLIENT_FACTORY.client(node, clusterName, random);
+ } else {
+ return node.client();
}
}
}
- public synchronized void beforeTest(Random random) {
- reset(random, true);
+ public synchronized void beforeTest(Random random, double transportClientRatio) {
+ reset(random, true, transportClientRatio);
}
- private synchronized void reset(Random random, boolean wipeData) {
+ private synchronized void reset(Random random, boolean wipeData, double transportClientRatio) {
+ assert transportClientRatio >= 0.0 && transportClientRatio <= 1.0;
+ logger.debug("Reset test cluster with transport client ratio: [{}]", transportClientRatio);
+ this.transportClientRatio = transportClientRatio;
this.random = new Random(random.nextLong());
resetClients(); /* reset all clients - each test gets it's own client based on the Random instance created above. */
if (wipeData) {
@@ -586,6 +586,7 @@ public class TestCluster implements Closeable, Iterable {
}
}
+
public synchronized void stopCurrentMasterNode() {
ensureOpen();
assert numNodes() > 0;
@@ -695,7 +696,7 @@ public class TestCluster implements Closeable, Iterable {
}
public void closeNonSharedNodes(boolean wipeData) {
- reset(random, wipeData);
+ reset(random, wipeData, transportClientRatio);
}
diff --git a/src/test/java/org/elasticsearch/test/engine/MockRobinEngine.java b/src/test/java/org/elasticsearch/test/engine/MockRobinEngine.java
index 5f101f78280..732a3f2ec0f 100644
--- a/src/test/java/org/elasticsearch/test/engine/MockRobinEngine.java
+++ b/src/test/java/org/elasticsearch/test/engine/MockRobinEngine.java
@@ -43,7 +43,7 @@ import org.elasticsearch.index.similarity.SimilarityService;
import org.elasticsearch.index.store.Store;
import org.elasticsearch.index.translog.Translog;
import org.elasticsearch.indices.warmer.IndicesWarmer;
-import org.elasticsearch.test.ElasticSearchTestCase;
+import org.elasticsearch.test.AbstractIntegrationTest;
import org.elasticsearch.threadpool.ThreadPool;
import java.util.Map.Entry;
@@ -63,8 +63,8 @@ public final class MockRobinEngine extends RobinEngine implements Engine {
CodecService codecService) throws EngineException {
super(shardId, indexSettings, threadPool, indexSettingsService, indexingService, warmer, store,
deletionPolicy, translog, mergePolicyProvider, mergeScheduler, analysisService, similarityService, codecService);
- final long seed = indexSettings.getAsLong(ElasticSearchTestCase.INDEX_SEED_SETTING, 0l);
- if (logger.isTraceEnabled()) {
+ final long seed = indexSettings.getAsLong(AbstractIntegrationTest.INDEX_SEED_SETTING, 0l);
+ if (logger.isTraceEnabled()){
logger.trace("Using [{}] for shard [{}] seed: [{}]", this.getClass().getName(), shardId, seed);
}
random = new Random(seed);