From c1fc66e557070cdc66c68478fee0ef4e6d931f6e Mon Sep 17 00:00:00 2001
From: javanna
Date: Wed, 26 Mar 2014 10:00:06 +0100
Subject: [PATCH] [TEST] Moved wipe* methods, randomIndexTemplate &
ensureEstimatedStats from ElasticsearchIntegrationTest to TestCluster
This is the first to make it possible to have a different impl of TestCluster (e.g. based on an external cluster) that has the same methods but a different impl for them (e.g. it might use the REST API to do the same instead of the Java API)
Closes #5542
---
.../termvector/AbstractTermVectorTests.java | 2 +-
.../document/DocumentActionsTests.java | 2 +-
.../RandomExceptionCircuitBreakerTests.java | 3 +-
.../ConcurrentDynamicTemplateTests.java | 2 +-
.../indices/store/SimpleDistributorTests.java | 4 +-
.../warmer/SimpleIndicesWarmerTests.java | 2 +-
.../percolator/PercolatorTests.java | 2 +-
.../search/aggregations/RandomTests.java | 2 +-
.../basic/SearchWhileCreatingIndexTests.java | 2 +-
.../SearchWithRandomExceptionsTests.java | 3 +-
.../search/query/SimpleQueryTests.java | 4 +-
.../DedicatedClusterSnapshotRestoreTests.java | 2 +-
.../SharedClusterSnapshotRestoreTests.java | 26 +--
.../test/ElasticsearchIntegrationTest.java | 156 +----------------
.../test/ElasticsearchTestCase.java | 58 +------
.../org/elasticsearch/test/TestCluster.java | 163 +++++++++++++++++-
.../test/engine/MockInternalEngine.java | 4 +-
.../hamcrest/ElasticsearchAssertions.java | 58 ++++++-
.../test/store/MockDirectoryHelper.java | 4 +-
.../test/store/MockFSDirectoryService.java | 2 -
.../transport/AssertingLocalTransport.java | 4 +-
21 files changed, 258 insertions(+), 247 deletions(-)
diff --git a/src/test/java/org/elasticsearch/action/termvector/AbstractTermVectorTests.java b/src/test/java/org/elasticsearch/action/termvector/AbstractTermVectorTests.java
index 88cc20adb03fa..6f897df7375cc 100644
--- a/src/test/java/org/elasticsearch/action/termvector/AbstractTermVectorTests.java
+++ b/src/test/java/org/elasticsearch/action/termvector/AbstractTermVectorTests.java
@@ -181,7 +181,7 @@ public String toString() {
}
protected void createIndexBasedOnFieldSettings(TestFieldSetting[] fieldSettings, int number_of_shards) throws IOException {
- wipeIndices("test");
+ cluster().wipeIndices("test");
XContentBuilder mappingBuilder = jsonBuilder();
mappingBuilder.startObject().startObject("type1").startObject("properties");
for (TestFieldSetting field : fieldSettings) {
diff --git a/src/test/java/org/elasticsearch/document/DocumentActionsTests.java b/src/test/java/org/elasticsearch/document/DocumentActionsTests.java
index 68b4d3e849e4b..ee9eb8db8dd75 100644
--- a/src/test/java/org/elasticsearch/document/DocumentActionsTests.java
+++ b/src/test/java/org/elasticsearch/document/DocumentActionsTests.java
@@ -54,7 +54,7 @@
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 bfdea261e5591..7be32746965ac 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.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;
@@ -194,7 +195,7 @@ static class ThrowingSubReaderWrapper extends SubReaderWrapper implements Throwi
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 693edabbf8514..fccccbc6476dc 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 void testConcurrentDynamicMapping() throws Exception {
int iters = atLeast(5);
for (int i = 0; i < iters; i++) {
- wipeIndices("test");
+ cluster().wipeIndices("test");
client().admin().indices().prepareCreate("test")
.setSettings(
ImmutableSettings.settingsBuilder()
diff --git a/src/test/java/org/elasticsearch/indices/store/SimpleDistributorTests.java b/src/test/java/org/elasticsearch/indices/store/SimpleDistributorTests.java
index b8c963121d84f..e4ec98d78044e 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 void testDirectoryToString() throws IOException {
}
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 @@ private void createIndexWithStoreType(String index, String storeType, String dis
}
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/indices/warmer/SimpleIndicesWarmerTests.java b/src/test/java/org/elasticsearch/indices/warmer/SimpleIndicesWarmerTests.java
index c8ca7a87d1362..fc1d7a1f0064d 100644
--- a/src/test/java/org/elasticsearch/indices/warmer/SimpleIndicesWarmerTests.java
+++ b/src/test/java/org/elasticsearch/indices/warmer/SimpleIndicesWarmerTests.java
@@ -345,7 +345,7 @@ public void testEagerLoading() throws Exception {
} else {
assertThat(memoryUsage1, equalTo(memoryUsage0));
}
- wipeIndices("idx");
+ cluster().wipeIndices("idx");
}
}
diff --git a/src/test/java/org/elasticsearch/percolator/PercolatorTests.java b/src/test/java/org/elasticsearch/percolator/PercolatorTests.java
index 060c4d0d2a0fb..77da1abf5d98c 100644
--- a/src/test/java/org/elasticsearch/percolator/PercolatorTests.java
+++ b/src/test/java/org/elasticsearch/percolator/PercolatorTests.java
@@ -280,7 +280,7 @@ public void percolateOnRecreatedIndex() throws Exception {
.setRefresh(true)
.execute().actionGet();
- wipeIndices("test");
+ cluster().wipeIndices("test");
prepareCreate("test").setSettings(settingsBuilder().put("index.number_of_shards", 1)).execute().actionGet();
ensureGreen();
diff --git a/src/test/java/org/elasticsearch/search/aggregations/RandomTests.java b/src/test/java/org/elasticsearch/search/aggregations/RandomTests.java
index 6a8df47d391b8..811a88adeebc5 100644
--- a/src/test/java/org/elasticsearch/search/aggregations/RandomTests.java
+++ b/src/test/java/org/elasticsearch/search/aggregations/RandomTests.java
@@ -156,7 +156,7 @@ public void testDuelTerms() throws Exception {
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 3838794431cbb..680a35a4bc992 100644
--- a/src/test/java/org/elasticsearch/search/basic/SearchWhileCreatingIndexTests.java
+++ b/src/test/java/org/elasticsearch/search/basic/SearchWhileCreatingIndexTests.java
@@ -106,7 +106,7 @@ private void searchWhileCreatingIndex(int numberOfShards, int numberOfReplicas)
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 00eab51dd205c..b2a6bb48ef56d 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.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;
@@ -251,7 +252,7 @@ static class ThrowingSubReaderWrapper extends SubReaderWrapper implements Throwi
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/query/SimpleQueryTests.java b/src/test/java/org/elasticsearch/search/query/SimpleQueryTests.java
index bb7828316d42c..073a63d6fed56 100644
--- a/src/test/java/org/elasticsearch/search/query/SimpleQueryTests.java
+++ b/src/test/java/org/elasticsearch/search/query/SimpleQueryTests.java
@@ -77,7 +77,7 @@ public void testOmitNormsOnAll() throws ExecutionException, InterruptedException
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");
assertAcked(client().admin().indices().prepareCreate("test"));
indexRandom(true, client().prepareIndex("test", "type1", "1").setSource("field1", "the quick brown fox jumps"),
@@ -372,7 +372,7 @@ public void testOmitTermFreqsAndPositions() throws Exception {
} 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 7728007d67bdd..0913f8f8bde63 100644
--- a/src/test/java/org/elasticsearch/snapshots/DedicatedClusterSnapshotRestoreTests.java
+++ b/src/test/java/org/elasticsearch/snapshots/DedicatedClusterSnapshotRestoreTests.java
@@ -137,7 +137,7 @@ public void restoreIndexWithMissingShards() throws Exception {
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 359474f780baa..754fa0ec825f1 100644
--- a/src/test/java/org/elasticsearch/snapshots/SharedClusterSnapshotRestoreTests.java
+++ b/src/test/java/org/elasticsearch/snapshots/SharedClusterSnapshotRestoreTests.java
@@ -128,7 +128,7 @@ public void basicWorkFlowTest() throws Exception {
// 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));
@@ -162,7 +162,7 @@ public void restoreWithDifferentMappingsAndSettingsTest() throws Exception {
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("refresh_interval", 5)));
assertAcked(client().admin().indices().preparePutMapping("test-idx").setType("bar").setSource("baz", "type=string"));
ensureGreen();
@@ -259,7 +259,7 @@ public void includeGlobalStateTest() throws Exception {
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));
@@ -296,8 +296,8 @@ public void includeGlobalStateTest() throws Exception {
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));
@@ -439,7 +439,7 @@ public void dataFileFailureDuringRestoreTest() throws Exception {
// 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));
@@ -484,7 +484,7 @@ public void deletionOfFailingToRecoverIndexShouldStopRestore() throws Exception
// 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();
@@ -494,7 +494,7 @@ public void deletionOfFailingToRecoverIndexShouldStopRestore() throws Exception
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));
@@ -578,7 +578,7 @@ public void deleteSnapshotTest() throws Exception {
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);
@@ -752,7 +752,7 @@ public void moveShardWhileSnapshottingTest() throws Exception {
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")
@@ -837,7 +837,7 @@ public void deleteRepositoryWhileSnapshottingTest() throws Exception {
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")
@@ -881,7 +881,7 @@ public void urlRepositoryTest() throws Exception {
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")
@@ -941,7 +941,7 @@ public void throttlingTest() throws Exception {
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 f6b0c8acfab8b..8e89127520dd3 100644
--- a/src/test/java/org/elasticsearch/test/ElasticsearchIntegrationTest.java
+++ b/src/test/java/org/elasticsearch/test/ElasticsearchIntegrationTest.java
@@ -18,12 +18,10 @@
*/
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 org.apache.lucene.util.AbstractRandomizedTest;
-import org.elasticsearch.ElasticsearchIllegalArgumentException;
import org.elasticsearch.ExceptionsHelper;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.ShardOperationFailedException;
@@ -48,7 +46,6 @@
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;
@@ -57,17 +54,8 @@
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;
@@ -143,7 +131,7 @@
*
-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.
*
*
*/
@@ -157,13 +145,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";
-
/**
* The current cluster depending on the configured {@link Scope}.
* By default if no {@link ClusterScope} is configured this will hold a reference to the global cluster carried
@@ -176,7 +157,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) {
@@ -205,10 +186,8 @@ public final void before() throws IOException {
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")) {
@@ -254,12 +233,8 @@ public final void after() throws IOException {
.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();
+ cluster().wipe(); // wipe after to make sure we fail in the test that didn't ack the delete
+ cluster().assertAfterTest();
logger.info("[{}#{}]: cleaned up after test", getTestClass().getSimpleName(), getTestName());
} catch (OutOfMemoryError e) {
if (e.getMessage().contains("unable to create new native thread")) {
@@ -293,57 +268,7 @@ public static Client client() {
* 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) {
- client().admin().indices().preparePutTemplate("random_index_template")
- .setTemplate("*")
- .setOrder(0)
- .setSettings(setRandomNormsLoading(setRandomMerge(getRandom(), ImmutableSettings.builder())
- .put(INDEX_SEED_SETTING, randomLong())))
- .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() {
@@ -359,73 +284,6 @@ public Settings indexSettings() {
return ImmutableSettings.EMPTY;
}
- /**
- * 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.
@@ -441,7 +299,7 @@ public final void createIndex(String... names) {
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 2898290c56d4a..eee6a2c145da5 100644
--- a/src/test/java/org/elasticsearch/test/ElasticsearchTestCase.java
+++ b/src/test/java/org/elasticsearch/test/ElasticsearchTestCase.java
@@ -33,7 +33,6 @@
import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.common.util.concurrent.EsAbortPolicy;
import org.elasticsearch.common.util.concurrent.EsRejectedExecutionException;
-import org.elasticsearch.test.engine.MockInternalEngine;
import org.elasticsearch.test.junit.listeners.LoggingListener;
import org.elasticsearch.test.store.MockDirectoryHelper;
import org.junit.After;
@@ -47,9 +46,11 @@
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.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAllFilesClosed;
+import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAllSearchersClosed;
+
/**
* Base testcase for randomized unit testing with Elasticsearch
*/
@@ -125,53 +126,6 @@ public void ensureAllPagesReleased() {
MockPageCacheRecycler.ensureAllPagesAreReleased();
}
- public static void ensureAllFilesClosed() throws IOException {
- try {
- for (MockDirectoryHelper.ElasticsearchMockDirectoryWrapper w : MockDirectoryHelper.wrappers) {
- if (w.isOpen()) {
- w.closeWithRuntimeException();
- }
- }
- } finally {
- forceClearMockWrappers();
- }
- }
-
- public static void ensureAllSearchersClosed() {
- /* in some cases we finish a test faster than the freeContext calls make it to the
- * shards. Let's wait for some time if there are still searchers. If the are really
- * pending we will fail anyway.*/
- try {
- if (awaitBusy(new Predicate