diff --git a/src/test/java/org/elasticsearch/cluster/ack/AckClusterUpdateSettingsTests.java b/src/test/java/org/elasticsearch/cluster/ack/AckClusterUpdateSettingsTests.java
index 10f3a39e1fa..f546586446b 100644
--- a/src/test/java/org/elasticsearch/cluster/ack/AckClusterUpdateSettingsTests.java
+++ b/src/test/java/org/elasticsearch/cluster/ack/AckClusterUpdateSettingsTests.java
@@ -37,6 +37,7 @@ import org.junit.Test;
import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder;
import static org.elasticsearch.test.ElasticsearchIntegrationTest.ClusterScope;
import static org.elasticsearch.test.ElasticsearchIntegrationTest.Scope.TEST;
+import static org.elasticsearch.test.TestCluster.DEFAULT_MAX_NUM_SHARDS;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
import static org.hamcrest.Matchers.equalTo;
diff --git a/src/test/java/org/elasticsearch/cluster/ack/AckTests.java b/src/test/java/org/elasticsearch/cluster/ack/AckTests.java
index 0b8dd275477..6431247f2ba 100644
--- a/src/test/java/org/elasticsearch/cluster/ack/AckTests.java
+++ b/src/test/java/org/elasticsearch/cluster/ack/AckTests.java
@@ -53,6 +53,7 @@ import static org.elasticsearch.cluster.metadata.IndexMetaData.*;
import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder;
import static org.elasticsearch.test.ElasticsearchIntegrationTest.ClusterScope;
import static org.elasticsearch.test.ElasticsearchIntegrationTest.Scope.SUITE;
+import static org.elasticsearch.test.TestCluster.DEFAULT_MAX_NUM_SHARDS;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
import static org.hamcrest.Matchers.*;
diff --git a/src/test/java/org/elasticsearch/document/DocumentActionsTests.java b/src/test/java/org/elasticsearch/document/DocumentActionsTests.java
index 3ada713a95c..61ff48f753d 100644
--- a/src/test/java/org/elasticsearch/document/DocumentActionsTests.java
+++ b/src/test/java/org/elasticsearch/document/DocumentActionsTests.java
@@ -53,7 +53,7 @@ import static org.hamcrest.Matchers.nullValue;
public class DocumentActionsTests extends ElasticsearchIntegrationTest {
protected void createIndex() {
- wipeIndices(getConcreteIndexName());
+ cluster().wipeIndices(getConcreteIndexName());
createIndex(getConcreteIndexName());
}
diff --git a/src/test/java/org/elasticsearch/indices/fielddata/breaker/RandomExceptionCircuitBreakerTests.java b/src/test/java/org/elasticsearch/indices/fielddata/breaker/RandomExceptionCircuitBreakerTests.java
index f5728fad494..07ba6830c78 100644
--- a/src/test/java/org/elasticsearch/indices/fielddata/breaker/RandomExceptionCircuitBreakerTests.java
+++ b/src/test/java/org/elasticsearch/indices/fielddata/breaker/RandomExceptionCircuitBreakerTests.java
@@ -36,6 +36,7 @@ import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.search.sort.SortOrder;
import org.elasticsearch.test.ElasticsearchIntegrationTest;
+import org.elasticsearch.test.TestCluster;
import org.elasticsearch.test.engine.MockInternalEngine;
import org.elasticsearch.test.engine.ThrowingAtomicReaderWrapper;
import org.junit.Test;
@@ -199,7 +200,7 @@ public class RandomExceptionCircuitBreakerTests extends ElasticsearchIntegration
private final double lowLevelRatio;
ThrowingSubReaderWrapper(Settings settings) {
- final long seed = settings.getAsLong(ElasticsearchIntegrationTest.INDEX_SEED_SETTING, 0l);
+ final long seed = settings.getAsLong(TestCluster.SETTING_INDEX_SEED, 0l);
this.topLevelRatio = settings.getAsDouble(EXCEPTION_TOP_LEVEL_RATIO_KEY, 0.1d);
this.lowLevelRatio = settings.getAsDouble(EXCEPTION_LOW_LEVEL_RATIO_KEY, 0.1d);
this.random = new Random(seed);
diff --git a/src/test/java/org/elasticsearch/indices/mapping/ConcurrentDynamicTemplateTests.java b/src/test/java/org/elasticsearch/indices/mapping/ConcurrentDynamicTemplateTests.java
index 9f3efdc4566..0bac5b307a1 100644
--- a/src/test/java/org/elasticsearch/indices/mapping/ConcurrentDynamicTemplateTests.java
+++ b/src/test/java/org/elasticsearch/indices/mapping/ConcurrentDynamicTemplateTests.java
@@ -52,7 +52,7 @@ public class ConcurrentDynamicTemplateTests extends ElasticsearchIntegrationTest
int iters = scaledRandomIntBetween(5, 15);
for (int i = 0; i < iters; i++) {
- wipeIndices("test");
+ cluster().wipeIndices("test");
assertAcked(prepareCreate("test")
.addMapping(mappingType, mapping));
ensureYellow();
diff --git a/src/test/java/org/elasticsearch/indices/store/SimpleDistributorTests.java b/src/test/java/org/elasticsearch/indices/store/SimpleDistributorTests.java
index 49f933b99a1..cd7ca17666b 100644
--- a/src/test/java/org/elasticsearch/indices/store/SimpleDistributorTests.java
+++ b/src/test/java/org/elasticsearch/indices/store/SimpleDistributorTests.java
@@ -108,7 +108,7 @@ public class SimpleDistributorTests extends ElasticsearchIntegrationTest {
}
private void createIndexWithStoreType(String index, String storeType, String distributor) {
- wipeIndices(index);
+ cluster().wipeIndices(index);
client().admin().indices().prepareCreate(index)
.setSettings(settingsBuilder()
.put("index.store.distributor", distributor)
@@ -121,7 +121,7 @@ public class SimpleDistributorTests extends ElasticsearchIntegrationTest {
}
private void createIndexWithoutRateLimitingStoreType(String index, String storeType, String distributor) {
- wipeIndices(index);
+ cluster().wipeIndices(index);
client().admin().indices().prepareCreate(index)
.setSettings(settingsBuilder()
.put("index.store.distributor", distributor)
diff --git a/src/test/java/org/elasticsearch/mget/SimpleMgetTests.java b/src/test/java/org/elasticsearch/mget/SimpleMgetTests.java
index e7b6660f2ef..9ffe400cdad 100644
--- a/src/test/java/org/elasticsearch/mget/SimpleMgetTests.java
+++ b/src/test/java/org/elasticsearch/mget/SimpleMgetTests.java
@@ -33,6 +33,7 @@ import java.io.IOException;
import java.util.Map;
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
+import static org.elasticsearch.test.TestCluster.DEFAULT_MAX_NUM_SHARDS;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
import static org.hamcrest.Matchers.*;
diff --git a/src/test/java/org/elasticsearch/nested/SimpleNestedTests.java b/src/test/java/org/elasticsearch/nested/SimpleNestedTests.java
index f4255465d43..dac7ea3e3f4 100644
--- a/src/test/java/org/elasticsearch/nested/SimpleNestedTests.java
+++ b/src/test/java/org/elasticsearch/nested/SimpleNestedTests.java
@@ -46,6 +46,7 @@ import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilde
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
import static org.elasticsearch.index.query.FilterBuilders.*;
import static org.elasticsearch.index.query.QueryBuilders.*;
+import static org.elasticsearch.test.TestCluster.DEFAULT_MAX_NUM_SHARDS;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.*;
import static org.hamcrest.Matchers.*;
diff --git a/src/test/java/org/elasticsearch/percolator/PercolatorTests.java b/src/test/java/org/elasticsearch/percolator/PercolatorTests.java
index 3ff1822b931..9eb241a9244 100644
--- a/src/test/java/org/elasticsearch/percolator/PercolatorTests.java
+++ b/src/test/java/org/elasticsearch/percolator/PercolatorTests.java
@@ -287,7 +287,7 @@ public class PercolatorTests extends ElasticsearchIntegrationTest {
.setRefresh(true)
.execute().actionGet();
- wipeIndices("test");
+ cluster().wipeIndices("test");
createIndex("test");
ensureGreen();
diff --git a/src/test/java/org/elasticsearch/search/aggregations/RandomTests.java b/src/test/java/org/elasticsearch/search/aggregations/RandomTests.java
index 79c8a0c793a..93a2ebe1ba1 100644
--- a/src/test/java/org/elasticsearch/search/aggregations/RandomTests.java
+++ b/src/test/java/org/elasticsearch/search/aggregations/RandomTests.java
@@ -146,7 +146,7 @@ public class RandomTests extends ElasticsearchIntegrationTest {
final int maxNumTerms = randomIntBetween(10, 100000);
final IntOpenHashSet valuesSet = new IntOpenHashSet();
- wipeIndices("idx");
+ cluster().wipeIndices("idx");
prepareCreate("idx").addMapping("type", jsonBuilder().startObject()
.startObject("type")
.startObject("properties")
diff --git a/src/test/java/org/elasticsearch/search/basic/SearchWhileCreatingIndexTests.java b/src/test/java/org/elasticsearch/search/basic/SearchWhileCreatingIndexTests.java
index d9726098402..2fcb6aebea8 100644
--- a/src/test/java/org/elasticsearch/search/basic/SearchWhileCreatingIndexTests.java
+++ b/src/test/java/org/elasticsearch/search/basic/SearchWhileCreatingIndexTests.java
@@ -101,7 +101,7 @@ public class SearchWhileCreatingIndexTests extends ElasticsearchIntegrationTest
status = client().admin().cluster().prepareHealth("test").get().getStatus();
cluster().ensureAtLeastNumNodes(numberOfReplicas + 1);
}
- wipeIndices("test");
+ cluster().wipeIndices("test");
}
}
}
\ No newline at end of file
diff --git a/src/test/java/org/elasticsearch/search/basic/SearchWithRandomExceptionsTests.java b/src/test/java/org/elasticsearch/search/basic/SearchWithRandomExceptionsTests.java
index 98d7db4a943..11f24e3eafb 100644
--- a/src/test/java/org/elasticsearch/search/basic/SearchWithRandomExceptionsTests.java
+++ b/src/test/java/org/elasticsearch/search/basic/SearchWithRandomExceptionsTests.java
@@ -35,6 +35,7 @@ import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.test.ElasticsearchIntegrationTest;
+import org.elasticsearch.test.TestCluster;
import org.elasticsearch.test.engine.MockInternalEngine;
import org.elasticsearch.test.engine.ThrowingAtomicReaderWrapper;
import org.elasticsearch.test.store.MockDirectoryHelper;
@@ -287,7 +288,7 @@ public class SearchWithRandomExceptionsTests extends ElasticsearchIntegrationTes
private final double lowLevelRatio;
ThrowingSubReaderWrapper(Settings settings) {
- final long seed = settings.getAsLong(ElasticsearchIntegrationTest.INDEX_SEED_SETTING, 0l);
+ final long seed = settings.getAsLong(TestCluster.SETTING_INDEX_SEED, 0l);
this.topLevelRatio = settings.getAsDouble(EXCEPTION_TOP_LEVEL_RATIO_KEY, 0.1d);
this.lowLevelRatio = settings.getAsDouble(EXCEPTION_LOW_LEVEL_RATIO_KEY, 0.1d);
this.random = new Random(seed);
diff --git a/src/test/java/org/elasticsearch/search/child/SimpleChildQuerySearchTests.java b/src/test/java/org/elasticsearch/search/child/SimpleChildQuerySearchTests.java
index 0badde6e1fd..5f391325cc0 100644
--- a/src/test/java/org/elasticsearch/search/child/SimpleChildQuerySearchTests.java
+++ b/src/test/java/org/elasticsearch/search/child/SimpleChildQuerySearchTests.java
@@ -58,8 +58,8 @@ import static org.elasticsearch.index.query.FilterBuilders.*;
import static org.elasticsearch.index.query.QueryBuilders.*;
import static org.elasticsearch.index.query.functionscore.ScoreFunctionBuilders.scriptFunction;
import static org.elasticsearch.search.facet.FacetBuilders.termsFacet;
+import static org.elasticsearch.test.TestCluster.DEFAULT_MAX_NUM_SHARDS;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.*;
-import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoFailures;
import static org.hamcrest.Matchers.*;
/**
diff --git a/src/test/java/org/elasticsearch/search/query/SimpleQueryTests.java b/src/test/java/org/elasticsearch/search/query/SimpleQueryTests.java
index 78f4f4e7a65..7bea353a1e3 100644
--- a/src/test/java/org/elasticsearch/search/query/SimpleQueryTests.java
+++ b/src/test/java/org/elasticsearch/search/query/SimpleQueryTests.java
@@ -58,6 +58,7 @@ import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
import static org.elasticsearch.index.query.FilterBuilders.*;
import static org.elasticsearch.index.query.QueryBuilders.*;
import static org.elasticsearch.index.query.functionscore.ScoreFunctionBuilders.scriptFunction;
+import static org.elasticsearch.test.TestCluster.DEFAULT_MAX_NUM_SHARDS;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.*;
import static org.hamcrest.Matchers.*;
@@ -81,7 +82,7 @@ public class SimpleQueryTests extends ElasticsearchIntegrationTest {
SearchHit[] hits = searchResponse.getHits().hits();
assertThat(hits.length, equalTo(3));
assertThat(hits[0].score(), allOf(equalTo(hits[1].getScore()), equalTo(hits[2].getScore())));
- wipeIndices("test");
+ cluster().wipeIndices("test");
createIndex("test");
indexRandom(true, client().prepareIndex("test", "type1", "1").setSource("field1", "the quick brown fox jumps"),
@@ -375,7 +376,7 @@ public class SimpleQueryTests extends ElasticsearchIntegrationTest {
} catch (SearchPhaseExecutionException e) {
assertTrue(e.getMessage().endsWith("IllegalStateException[field \"field1\" was indexed without position data; cannot run PhraseQuery (term=quick)]; }"));
}
- wipeIndices("test");
+ cluster().wipeIndices("test");
} catch (MapperParsingException ex) {
assertThat(version.toString(), version.onOrAfter(Version.V_1_0_0_RC2), equalTo(true));
assertThat(ex.getCause().getMessage(), equalTo("'omit_term_freq_and_positions' is not supported anymore - use ['index_options' : 'DOCS_ONLY'] instead"));
diff --git a/src/test/java/org/elasticsearch/snapshots/DedicatedClusterSnapshotRestoreTests.java b/src/test/java/org/elasticsearch/snapshots/DedicatedClusterSnapshotRestoreTests.java
index 7728007d67b..0913f8f8bde 100644
--- a/src/test/java/org/elasticsearch/snapshots/DedicatedClusterSnapshotRestoreTests.java
+++ b/src/test/java/org/elasticsearch/snapshots/DedicatedClusterSnapshotRestoreTests.java
@@ -137,7 +137,7 @@ public class DedicatedClusterSnapshotRestoreTests extends AbstractSnapshotTests
logger.info("--> start 2 nodes");
cluster().startNode(settingsBuilder().put("gateway.type", "local"));
cluster().startNode(settingsBuilder().put("gateway.type", "local"));
- wipeIndices("_all");
+ cluster().wipeIndices("_all");
assertAcked(prepareCreate("test-idx-1", 2, settingsBuilder().put("number_of_shards", 6)
.put("number_of_replicas", 0)
diff --git a/src/test/java/org/elasticsearch/snapshots/SharedClusterSnapshotRestoreTests.java b/src/test/java/org/elasticsearch/snapshots/SharedClusterSnapshotRestoreTests.java
index 24433dd53e7..4565543ec61 100644
--- a/src/test/java/org/elasticsearch/snapshots/SharedClusterSnapshotRestoreTests.java
+++ b/src/test/java/org/elasticsearch/snapshots/SharedClusterSnapshotRestoreTests.java
@@ -130,7 +130,7 @@ public class SharedClusterSnapshotRestoreTests extends AbstractSnapshotTests {
// Test restore after index deletion
logger.info("--> delete indices");
- wipeIndices("test-idx-1", "test-idx-2");
+ cluster().wipeIndices("test-idx-1", "test-idx-2");
logger.info("--> restore one index after deletion");
restoreSnapshotResponse = client.admin().cluster().prepareRestoreSnapshot("test-repo", "test-snap").setWaitForCompletion(true).setIndices("test-idx-*", "-test-idx-2").execute().actionGet();
assertThat(restoreSnapshotResponse.getRestoreInfo().totalShards(), greaterThan(0));
@@ -167,7 +167,7 @@ public class SharedClusterSnapshotRestoreTests extends AbstractSnapshotTests {
assertThat(createSnapshotResponse.getSnapshotInfo().successfulShards(), equalTo(createSnapshotResponse.getSnapshotInfo().totalShards()));
logger.info("--> delete the index and recreate it with bar type");
- wipeIndices("test-idx");
+ cluster().wipeIndices("test-idx");
assertAcked(prepareCreate("test-idx", 2, ImmutableSettings.builder()
.put(SETTING_NUMBER_OF_SHARDS, numShards.numPrimaries).put(SETTING_NUMBER_OF_REPLICAS, between(0, 1)).put("refresh_interval", 5)));
assertAcked(client().admin().indices().preparePutMapping("test-idx").setType("bar").setSource("baz", "type=string"));
@@ -265,7 +265,7 @@ public class SharedClusterSnapshotRestoreTests extends AbstractSnapshotTests {
assertThat(client.admin().cluster().prepareGetSnapshots("test-repo").setSnapshots("test-snap-with-global-state").get().getSnapshots().get(0).state(), equalTo(SnapshotState.SUCCESS));
logger.info("--> delete test template");
- wipeTemplates("test-template");
+ cluster().wipeTemplates("test-template");
ClusterStateResponse clusterStateResponse = client.admin().cluster().prepareState().setRoutingTable(false).setNodes(false).setIndexTemplates("test-template").setIndices().get();
assertThat(clusterStateResponse.getState().getMetaData().templates().containsKey("test-template"), equalTo(false));
@@ -302,8 +302,8 @@ public class SharedClusterSnapshotRestoreTests extends AbstractSnapshotTests {
assertThat(client.admin().cluster().prepareGetSnapshots("test-repo").setSnapshots("test-snap-no-global-state-with-index").get().getSnapshots().get(0).state(), equalTo(SnapshotState.SUCCESS));
logger.info("--> delete test template and index ");
- wipeIndices("test-idx");
- wipeTemplates("test-template");
+ cluster().wipeIndices("test-idx");
+ cluster().wipeTemplates("test-template");
clusterStateResponse = client.admin().cluster().prepareState().setRoutingTable(false).setNodes(false).setIndexTemplates("test-template").setIndices().get();
assertThat(clusterStateResponse.getState().getMetaData().templates().containsKey("test-template"), equalTo(false));
@@ -469,7 +469,7 @@ public class SharedClusterSnapshotRestoreTests extends AbstractSnapshotTests {
// Test restore after index deletion
logger.info("--> delete index");
- wipeIndices("test-idx");
+ cluster().wipeIndices("test-idx");
logger.info("--> restore index after deletion");
RestoreSnapshotResponse restoreSnapshotResponse = client.admin().cluster().prepareRestoreSnapshot("test-repo", "test-snap").setWaitForCompletion(true).execute().actionGet();
assertThat(restoreSnapshotResponse.getRestoreInfo().totalShards(), greaterThan(0));
@@ -514,7 +514,7 @@ public class SharedClusterSnapshotRestoreTests extends AbstractSnapshotTests {
// Test restore after index deletion
logger.info("--> delete index");
- wipeIndices("test-idx");
+ cluster().wipeIndices("test-idx");
logger.info("--> restore index after deletion");
ListenableActionFuture restoreSnapshotResponseFuture =
client.admin().cluster().prepareRestoreSnapshot("test-repo", "test-snap").setWaitForCompletion(true).execute();
@@ -524,7 +524,7 @@ public class SharedClusterSnapshotRestoreTests extends AbstractSnapshotTests {
assertThat(waitForIndex("test-idx", TimeValue.timeValueSeconds(10)), equalTo(true));
logger.info("--> delete index");
- wipeIndices("test-idx");
+ cluster().wipeIndices("test-idx");
logger.info("--> get restore results");
// Now read restore results and make sure it failed
RestoreSnapshotResponse restoreSnapshotResponse = restoreSnapshotResponseFuture.actionGet(TimeValue.timeValueSeconds(10));
@@ -608,7 +608,7 @@ public class SharedClusterSnapshotRestoreTests extends AbstractSnapshotTests {
assertThat(numberOfFilesAfterDeletion, lessThan(numberOfFilesBeforeDeletion));
logger.info("--> delete index");
- wipeIndices("test-idx");
+ cluster().wipeIndices("test-idx");
logger.info("--> restore index");
String lastSnapshot = "test-snap-" + (numberOfSnapshots - 1);
@@ -782,7 +782,7 @@ public class SharedClusterSnapshotRestoreTests extends AbstractSnapshotTests {
assertThat(snapshotInfos.get(0).shardFailures().size(), equalTo(0));
logger.info("--> delete index");
- wipeIndices("test-idx");
+ cluster().wipeIndices("test-idx");
logger.info("--> replace mock repository with real one at the same location");
assertAcked(client.admin().cluster().preparePutRepository("test-repo")
@@ -867,7 +867,7 @@ public class SharedClusterSnapshotRestoreTests extends AbstractSnapshotTests {
assertThat(snapshotInfos.get(0).shardFailures().size(), equalTo(0));
logger.info("--> delete index");
- wipeIndices("test-idx");
+ cluster().wipeIndices("test-idx");
logger.info("--> replace mock repository with real one at the same location");
assertAcked(client.admin().cluster().preparePutRepository("test-repo")
@@ -911,7 +911,7 @@ public class SharedClusterSnapshotRestoreTests extends AbstractSnapshotTests {
assertThat(client.admin().cluster().prepareGetSnapshots("test-repo").setSnapshots("test-snap").get().getSnapshots().get(0).state(), equalTo(SnapshotState.SUCCESS));
logger.info("--> delete index");
- wipeIndices("test-idx");
+ cluster().wipeIndices("test-idx");
logger.info("--> create read-only URL repository");
assertAcked(client.admin().cluster().preparePutRepository("url-repo")
@@ -971,7 +971,7 @@ public class SharedClusterSnapshotRestoreTests extends AbstractSnapshotTests {
assertThat(createSnapshotResponse.getSnapshotInfo().successfulShards(), equalTo(createSnapshotResponse.getSnapshotInfo().totalShards()));
logger.info("--> delete index");
- wipeIndices("test-idx");
+ cluster().wipeIndices("test-idx");
logger.info("--> restore index");
RestoreSnapshotResponse restoreSnapshotResponse = client.admin().cluster().prepareRestoreSnapshot("test-repo", "test-snap").setWaitForCompletion(true).execute().actionGet();
diff --git a/src/test/java/org/elasticsearch/test/ElasticsearchIntegrationTest.java b/src/test/java/org/elasticsearch/test/ElasticsearchIntegrationTest.java
index 2ee300fe937..23d177cfbd3 100644
--- a/src/test/java/org/elasticsearch/test/ElasticsearchIntegrationTest.java
+++ b/src/test/java/org/elasticsearch/test/ElasticsearchIntegrationTest.java
@@ -18,22 +18,17 @@
*/
package org.elasticsearch.test;
-import com.carrotsearch.hppc.ObjectArrayList;
import com.carrotsearch.randomizedtesting.RandomizedContext;
import com.carrotsearch.randomizedtesting.SeedUtils;
import com.google.common.base.Joiner;
import com.google.common.collect.Lists;
import org.apache.lucene.util.AbstractRandomizedTest;
-import org.elasticsearch.ElasticsearchIllegalArgumentException;
import org.elasticsearch.ExceptionsHelper;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.ShardOperationFailedException;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthStatus;
-import org.elasticsearch.action.admin.cluster.node.stats.NodeStats;
-import org.elasticsearch.action.admin.cluster.node.stats.NodesStatsResponse;
-import org.elasticsearch.action.admin.cluster.state.ClusterStateResponse;
import org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder;
import org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsResponse;
import org.elasticsearch.action.admin.indices.flush.FlushResponse;
@@ -51,7 +46,6 @@ import org.elasticsearch.client.Client;
import org.elasticsearch.client.Requests;
import org.elasticsearch.client.internal.InternalClient;
import org.elasticsearch.cluster.ClusterService;
-import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.cluster.metadata.MetaData;
import org.elasticsearch.common.Priority;
import org.elasticsearch.common.collect.Tuple;
@@ -60,17 +54,7 @@ import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.util.concurrent.EsRejectedExecutionException;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.discovery.zen.elect.ElectMasterService;
-import org.elasticsearch.index.mapper.FieldMapper.Loading;
-import org.elasticsearch.index.merge.policy.*;
-import org.elasticsearch.index.merge.scheduler.ConcurrentMergeSchedulerProvider;
-import org.elasticsearch.index.merge.scheduler.MergeSchedulerModule;
-import org.elasticsearch.index.merge.scheduler.MergeSchedulerProvider;
-import org.elasticsearch.index.merge.scheduler.SerialMergeSchedulerProvider;
-import org.elasticsearch.indices.IndexMissingException;
-import org.elasticsearch.indices.IndexTemplateMissingException;
-import org.elasticsearch.repositories.RepositoryMissingException;
import org.elasticsearch.rest.RestStatus;
-import org.elasticsearch.search.SearchService;
import org.elasticsearch.test.client.RandomizingClient;
import org.junit.After;
import org.junit.Before;
@@ -146,7 +130,7 @@ 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_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.
+ *
-D{@value org.elasticsearch.test.TestCluster#SETTING_INDEX_SEED} - a random seed used to initialize the index random context.
*
*
*/
@@ -160,13 +144,6 @@ public abstract class ElasticsearchIntegrationTest extends ElasticsearchTestCase
*/
public static final String TESTS_CLIENT_RATIO = "tests.client.ratio";
- /**
- * Key used to retrieve the index random seed from the index settings on a running node.
- * The value of this seed can be used to initialize a random context for a specific index.
- * It's set once per test via a generic index template.
- */
- public static final String INDEX_SEED_SETTING = "index.tests.seed";
-
/**
* Threshold at which indexing switches from frequently async to frequently bulk.
*/
@@ -192,7 +169,7 @@ public abstract class ElasticsearchIntegrationTest extends ElasticsearchTestCase
private static final Map, TestCluster> clusters = new IdentityHashMap, TestCluster>();
@BeforeClass
- public final static void beforeClass() throws Exception {
+ public static void beforeClass() throws Exception {
// Initialize lazily. No need for volatiles/ CASs since each JVM runs at most one test
// suite at any given moment.
if (GLOBAL_CLUSTER == null) {
@@ -221,10 +198,8 @@ public abstract class ElasticsearchIntegrationTest extends ElasticsearchTestCase
fail("Unknown Scope: [" + currentClusterScope + "]");
}
currentCluster.beforeTest(getRandom(), getPerTestTransportClientRatio());
- wipeIndices("_all");
- wipeTemplates();
+ cluster().wipe();
randomIndexTemplate();
- wipeRepositories();
logger.info("[{}#{}]: before test", getTestClass().getSimpleName(), getTestName());
} catch (OutOfMemoryError e) {
if (e.getMessage().contains("unable to create new native thread")) {
@@ -268,12 +243,8 @@ public abstract class ElasticsearchIntegrationTest extends ElasticsearchTestCase
assertThat("test leaves transient cluster metadata behind: " + metaData.transientSettings().getAsMap(), metaData
.transientSettings().getAsMap().size(), equalTo(0));
}
- wipeIndices("_all"); // wipe after to make sure we fail in the test that didn't ack the delete
- wipeTemplates();
- wipeRepositories();
- ensureAllSearchersClosed();
- ensureAllFilesClosed();
- ensureEstimatedStats();
+ cluster().wipe(); // wipe after to make sure we fail in the test that didn't ack the delete
+ cluster().assertAfterTest();
} finally {
if (currentClusterScope == Scope.TEST) {
clearClusters(); // it is ok to leave persistent / transient cluster state behind if scope is TEST
@@ -312,75 +283,19 @@ public abstract class ElasticsearchIntegrationTest extends ElasticsearchTestCase
* per index basis.
*/
private static void randomIndexTemplate() {
- // TODO move settings for random directory etc here into the index based randomized settings.
- if (cluster().size() > 0) {
- ImmutableSettings.Builder builder = setRandomNormsLoading(setRandomMerge(getRandom(), ImmutableSettings.builder())
- .put(INDEX_SEED_SETTING, randomLong()))
- .put(SETTING_NUMBER_OF_SHARDS, between(DEFAULT_MIN_NUM_SHARDS, DEFAULT_MAX_NUM_SHARDS))
- .put(SETTING_NUMBER_OF_REPLICAS, between(0, 1));
- client().admin().indices().preparePutTemplate("random_index_template")
- .setTemplate("*")
- .setOrder(0)
- .setSettings(builder)
- .execute().actionGet();
- }
- }
-
- private static ImmutableSettings.Builder setRandomNormsLoading(ImmutableSettings.Builder builder) {
- if (randomBoolean()) {
- builder.put(SearchService.NORMS_LOADING_KEY, randomFrom(Arrays.asList(Loading.EAGER, Loading.LAZY)));
- }
- return builder;
- }
-
- private static ImmutableSettings.Builder setRandomMerge(Random random, ImmutableSettings.Builder builder) {
- if (random.nextBoolean()) {
- builder.put(AbstractMergePolicyProvider.INDEX_COMPOUND_FORMAT,
- random.nextBoolean() ? random.nextDouble() : random.nextBoolean());
- }
- Class extends MergePolicyProvider>> mergePolicy = TieredMergePolicyProvider.class;
- switch (random.nextInt(5)) {
- case 4:
- mergePolicy = LogByteSizeMergePolicyProvider.class;
- break;
- case 3:
- mergePolicy = LogDocMergePolicyProvider.class;
- break;
- case 0:
- mergePolicy = null;
- }
- if (mergePolicy != null) {
- builder.put(MergePolicyModule.MERGE_POLICY_TYPE_KEY, mergePolicy.getName());
- }
-
- if (random.nextBoolean()) {
- builder.put(MergeSchedulerProvider.FORCE_ASYNC_MERGE, random.nextBoolean());
- }
- switch (random.nextInt(5)) {
- case 4:
- builder.put(MergeSchedulerModule.MERGE_SCHEDULER_TYPE_KEY, SerialMergeSchedulerProvider.class.getName());
- break;
- case 3:
- builder.put(MergeSchedulerModule.MERGE_SCHEDULER_TYPE_KEY, ConcurrentMergeSchedulerProvider.class.getName());
- break;
- }
-
- return builder;
+ cluster().randomIndexTemplate();
}
public static Iterable clients() {
return cluster();
}
- protected static final int DEFAULT_MIN_NUM_SHARDS = 1;
- protected static final int DEFAULT_MAX_NUM_SHARDS = 10;
-
protected int minimumNumberOfShards() {
- return DEFAULT_MIN_NUM_SHARDS;
+ return TestCluster.DEFAULT_MIN_NUM_SHARDS;
}
protected int maximumNumberOfShards() {
- return DEFAULT_MAX_NUM_SHARDS;
+ return TestCluster.DEFAULT_MAX_NUM_SHARDS;
}
protected int numberOfShards() {
@@ -418,89 +333,6 @@ public abstract class ElasticsearchIntegrationTest extends ElasticsearchTestCase
return builder.build();
}
- /**
- * Ensures that the breaker statistics are reset to 0 since we wiped all indices and that
- * means all stats should be set to 0 otherwise something is wrong with the field data
- * calculation.
- */
- private static void ensureEstimatedStats() {
- if (cluster().size() > 0) {
- NodesStatsResponse nodeStats = client().admin().cluster().prepareNodesStats()
- .clear().setBreaker(true).execute().actionGet();
- for (NodeStats stats : nodeStats.getNodes()) {
- assertThat("Breaker not reset to 0 on node: " + stats.getNode(),
- stats.getBreaker().getEstimated(), equalTo(0L));
- }
- }
- }
-
- /**
- * Deletes the given indices from the tests cluster. If no index name is passed to this method
- * all indices are removed.
- */
- public static void wipeIndices(String... indices) {
- assert indices != null && indices.length > 0;
- if (cluster().size() > 0) {
- try {
- assertAcked(client().admin().indices().prepareDelete(indices));
- } catch (IndexMissingException e) {
- // ignore
- } catch (ElasticsearchIllegalArgumentException e) {
- // Happens if `action.destructive_requires_name` is set to true
- // which is the case in the CloseIndexDisableCloseAllTests
- if ("_all".equals(indices[0])) {
- ClusterStateResponse clusterStateResponse = client().admin().cluster().prepareState().execute().actionGet();
- ObjectArrayList concreteIndices = new ObjectArrayList();
- for (IndexMetaData indexMetaData : clusterStateResponse.getState().metaData()) {
- concreteIndices.add(indexMetaData.getIndex());
- }
- if (!concreteIndices.isEmpty()) {
- assertAcked(client().admin().indices().prepareDelete(concreteIndices.toArray(String.class)));
- }
- }
- }
- }
- }
-
- /**
- * Deletes index templates, support wildcard notation.
- * If no template name is passed to this method all templates are removed.
- */
- public static void wipeTemplates(String... templates) {
- if (cluster().size() > 0) {
- // if nothing is provided, delete all
- if (templates.length == 0) {
- templates = new String[]{"*"};
- }
- for (String template : templates) {
- try {
- client().admin().indices().prepareDeleteTemplate(template).execute().actionGet();
- } catch (IndexTemplateMissingException e) {
- // ignore
- }
- }
- }
- }
-
- /**
- * Deletes repositories, supports wildcard notation.
- */
- public static void wipeRepositories(String... repositories) {
- if (cluster().size() > 0) {
- // if nothing is provided, delete all
- if (repositories.length == 0) {
- repositories = new String[]{"*"};
- }
- for (String repository : repositories) {
- try {
- client().admin().cluster().prepareDeleteRepository(repository).execute().actionGet();
- } catch (RepositoryMissingException ex) {
- // ignore
- }
- }
- }
- }
-
/**
* Creates one or more indices and asserts that the indices are acknowledged. If one of the indices
* already exists this method will fail and wipe all the indices created so far.
@@ -516,7 +348,7 @@ public abstract class ElasticsearchIntegrationTest extends ElasticsearchTestCase
success = true;
} finally {
if (!success && !created.isEmpty()) {
- wipeIndices(created.toArray(new String[created.size()]));
+ cluster().wipeIndices(created.toArray(new String[created.size()]));
}
}
}
diff --git a/src/test/java/org/elasticsearch/test/ElasticsearchTestCase.java b/src/test/java/org/elasticsearch/test/ElasticsearchTestCase.java
index d63e32125d1..fe96cc4074f 100644
--- a/src/test/java/org/elasticsearch/test/ElasticsearchTestCase.java
+++ b/src/test/java/org/elasticsearch/test/ElasticsearchTestCase.java
@@ -39,7 +39,6 @@ import org.elasticsearch.common.util.concurrent.EsAbortPolicy;
import org.elasticsearch.common.util.concurrent.EsRejectedExecutionException;
import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.test.cache.recycler.MockBigArrays;
-import org.elasticsearch.test.engine.MockInternalEngine;
import org.elasticsearch.test.junit.listeners.LoggingListener;
import org.elasticsearch.test.store.MockDirectoryHelper;
import org.junit.After;
@@ -54,10 +53,10 @@ import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.net.URI;
import java.util.*;
-import java.util.Map.Entry;
import java.util.concurrent.TimeUnit;
-import static org.hamcrest.Matchers.is;
+import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAllFilesClosed;
+import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAllSearchersClosed;
/**
* Base testcase for randomized unit testing with Elasticsearch
@@ -150,71 +149,6 @@ public abstract class ElasticsearchTestCase extends AbstractRandomizedTest {
MockBigArrays.ensureAllArraysAreReleased();
}
- public static void ensureAllFilesClosed() throws IOException {
- try {
- for (final MockDirectoryHelper.ElasticsearchMockDirectoryWrapper w : MockDirectoryHelper.wrappers) {
- try {
- awaitBusy(new Predicate