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> 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() { - public boolean apply(Object o) { - return MockInternalEngine.INFLIGHT_ENGINE_SEARCHERS.isEmpty(); - } - }, 5, TimeUnit.SECONDS)) { - return; - } - } catch (InterruptedException ex) { - if (MockInternalEngine.INFLIGHT_ENGINE_SEARCHERS.isEmpty()) { - return; - } - } - try { - RuntimeException ex = null; - StringBuilder builder = new StringBuilder("Unclosed Searchers instance for shards: ["); - for (Entry entry : MockInternalEngine.INFLIGHT_ENGINE_SEARCHERS.entrySet()) { - ex = entry.getValue(); - builder.append(entry.getKey().shardId()).append(","); - } - builder.append("]"); - throw new RuntimeException(builder.toString(), ex); - } finally { - MockInternalEngine.INFLIGHT_ENGINE_SEARCHERS.clear(); - } - } - - public static void forceClearMockWrappers() { - MockDirectoryHelper.wrappers.clear(); - } - public static boolean hasUnclosedWrapper() { for (MockDirectoryWrapper w : MockDirectoryHelper.wrappers) { if (w.isOpen()) { @@ -186,14 +140,14 @@ public static void registerMockDirectoryHooks() throws Exception { closeAfterSuite(new Closeable() { @Override public void close() throws IOException { - ensureAllFilesClosed(); + assertAllFilesClosed(); } }); closeAfterSuite(new Closeable() { @Override public void close() throws IOException { - ensureAllSearchersClosed(); + assertAllSearchersClosed(); } }); defaultHandler = Thread.getDefaultUncaughtExceptionHandler(); @@ -320,6 +274,4 @@ private static String groupName(ThreadGroup threadGroup) { return threadGroup.getName(); } } - - } diff --git a/src/test/java/org/elasticsearch/test/TestCluster.java b/src/test/java/org/elasticsearch/test/TestCluster.java index fe729d43823c1..2ca23649bcc59 100644 --- a/src/test/java/org/elasticsearch/test/TestCluster.java +++ b/src/test/java/org/elasticsearch/test/TestCluster.java @@ -18,6 +18,7 @@ */ package org.elasticsearch.test; +import com.carrotsearch.hppc.ObjectArrayList; import com.carrotsearch.randomizedtesting.SeedUtils; import com.carrotsearch.randomizedtesting.generators.RandomPicks; import com.google.common.base.Predicate; @@ -26,7 +27,9 @@ import com.google.common.collect.Iterators; import com.google.common.collect.Sets; import org.apache.lucene.util.IOUtils; +import org.elasticsearch.ElasticsearchIllegalArgumentException; import org.elasticsearch.ElasticsearchIllegalStateException; +import org.elasticsearch.action.admin.cluster.state.ClusterStateResponse; import org.elasticsearch.cache.recycler.CacheRecycler; import org.elasticsearch.cache.recycler.PageCacheRecyclerModule; import org.elasticsearch.client.Client; @@ -34,6 +37,7 @@ import org.elasticsearch.client.transport.TransportClient; import org.elasticsearch.cluster.ClusterService; import org.elasticsearch.cluster.ClusterState; +import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.node.DiscoveryNodes; import org.elasticsearch.cluster.routing.ShardRouting; @@ -48,8 +52,17 @@ import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.env.NodeEnvironment; import org.elasticsearch.index.engine.IndexEngineModule; +import org.elasticsearch.index.mapper.FieldMapper; +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.node.Node; import org.elasticsearch.node.internal.InternalNode; +import org.elasticsearch.repositories.RepositoryMissingException; import org.elasticsearch.search.SearchService; import org.elasticsearch.test.cache.recycler.MockPageCacheRecyclerModule; import org.elasticsearch.test.engine.MockEngineModule; @@ -63,6 +76,7 @@ import java.io.Closeable; import java.io.File; +import java.io.IOException; import java.util.*; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; @@ -73,6 +87,7 @@ import static org.apache.lucene.util.LuceneTestCase.usually; import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder; import static org.elasticsearch.node.NodeBuilder.nodeBuilder; +import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.*; /** * TestCluster manages a set of JVM private nodes and allows convenient access to them. @@ -103,12 +118,18 @@ public final class TestCluster implements Iterable { */ public static final String SETTING_CLUSTER_NODE_SEED = "test.cluster.node.seed"; + /** + * 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 SETTING_INDEX_SEED = "index.tests.seed"; + private static final String CLUSTER_NAME_KEY = "cluster.name"; private static final boolean ENABLE_MOCK_MODULES = systemPropertyAsBoolean(TESTS_ENABLE_MOCK_MODULES, true); static final int DEFAULT_MIN_NUM_NODES = 2; - static final int DEFAULT_MAX_NUM_NODES = 6; /* sorted map to make traverse order reproducible */ @@ -618,7 +639,7 @@ static class TransportClientFactory extends ClientFactory { public static TransportClientFactory NO_SNIFF_CLIENT_FACTORY = new TransportClientFactory(false); public static TransportClientFactory SNIFF_CLIENT_FACTORY = new TransportClientFactory(true); - public TransportClientFactory(boolean sniff) { + private TransportClientFactory(boolean sniff) { this.sniff = sniff; } @@ -717,13 +738,149 @@ private synchronized void reset(Random random, boolean wipeData, double transpor logger.debug("Cluster is consistent again - nodes: [{}] nextNodeId: [{}] numSharedNodes: [{}]", nodes.keySet(), nextNodeId.get(), sharedNodesSeeds.length); } + public void wipe() { + wipeIndices("_all"); + wipeTemplates(); + wipeRepositories(); + } + + /** + * Deletes the given indices from the tests cluster. If no index name is passed to this method + * all indices are removed. + */ + public void wipeIndices(String... indices) { + assert indices != null && indices.length > 0; + if (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 void wipeTemplates(String... templates) { + if (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 void wipeRepositories(String... repositories) { + if (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 a randomized index template. This template is used to pass in randomized settings on a + * per index basis. + */ + public void randomIndexTemplate() { + // TODO move settings for random directory etc here into the index based randomized settings. + if (size() > 0) { + client().admin().indices().preparePutTemplate("random_index_template") + .setTemplate("*") + .setOrder(0) + .setSettings(setRandomNormsLoading(setRandomMerge(random, ImmutableSettings.builder()) + .put(SETTING_INDEX_SEED, random.nextLong()))) + .execute().actionGet(); + } + } + + + private ImmutableSettings.Builder setRandomNormsLoading(ImmutableSettings.Builder builder) { + if (random.nextBoolean()) { + builder.put(SearchService.NORMS_LOADING_KEY, RandomPicks.randomFrom(random, Arrays.asList(FieldMapper.Loading.EAGER, FieldMapper.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> 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; + } + /** * This method should be executed during tearDown */ public synchronized void afterTest() { wipeDataDirectories(); resetClients(); /* reset all clients - each test gets its own client based on the Random instance created above. */ + } + public void assertAfterTest() throws IOException { + assertAllSearchersClosed(); + assertAllFilesClosed(); } private void resetClients() { @@ -752,7 +909,7 @@ public synchronized ClusterService clusterService() { } /** - * Returns an Iterabel to all instances for the given class >T< across all nodes in the cluster. + * Returns an Iterable to all instances for the given class >T< across all nodes in the cluster. */ public synchronized Iterable getInstances(Class clazz) { List instances = new ArrayList(nodes.size()); diff --git a/src/test/java/org/elasticsearch/test/engine/MockInternalEngine.java b/src/test/java/org/elasticsearch/test/engine/MockInternalEngine.java index f82cebacf729d..f3a84e58fd2c2 100644 --- a/src/test/java/org/elasticsearch/test/engine/MockInternalEngine.java +++ b/src/test/java/org/elasticsearch/test/engine/MockInternalEngine.java @@ -43,7 +43,7 @@ import org.elasticsearch.index.store.Store; import org.elasticsearch.index.translog.Translog; import org.elasticsearch.indices.warmer.IndicesWarmer; -import org.elasticsearch.test.ElasticsearchIntegrationTest; +import org.elasticsearch.test.TestCluster; import org.elasticsearch.threadpool.ThreadPool; import java.lang.reflect.Constructor; @@ -69,7 +69,7 @@ public MockInternalEngine(ShardId shardId, @IndexSettings Settings indexSettings CodecService codecService) throws EngineException { super(shardId, indexSettings, threadPool, indexSettingsService, indexingService, warmer, store, deletionPolicy, translog, mergePolicyProvider, mergeScheduler, analysisService, similarityService, codecService); - final long seed = indexSettings.getAsLong(ElasticsearchIntegrationTest.INDEX_SEED_SETTING, 0l); + final long seed = indexSettings.getAsLong(TestCluster.SETTING_INDEX_SEED, 0l); random = new Random(seed); final double ratio = indexSettings.getAsDouble(WRAP_READER_RATIO, 0.0d); // DISABLED by default - AssertingDR is crazy slow wrapper = indexSettings.getAsClass(READER_WRAPPER_TYPE, AssertingDirectoryReader.class); diff --git a/src/test/java/org/elasticsearch/test/hamcrest/ElasticsearchAssertions.java b/src/test/java/org/elasticsearch/test/hamcrest/ElasticsearchAssertions.java index 9f09e9fd54e85..58856f0e56930 100644 --- a/src/test/java/org/elasticsearch/test/hamcrest/ElasticsearchAssertions.java +++ b/src/test/java/org/elasticsearch/test/hamcrest/ElasticsearchAssertions.java @@ -18,6 +18,7 @@ */ package org.elasticsearch.test.hamcrest; +import com.google.common.base.Predicate; import org.apache.lucene.search.BooleanQuery; import org.apache.lucene.search.Query; import org.elasticsearch.ElasticsearchException; @@ -44,18 +45,18 @@ import org.elasticsearch.common.io.stream.Streamable; import org.elasticsearch.search.SearchHit; import org.elasticsearch.search.suggest.Suggest; -import org.elasticsearch.test.ElasticsearchTestCase; +import org.elasticsearch.test.engine.MockInternalEngine; +import org.elasticsearch.test.store.MockDirectoryHelper; import org.hamcrest.Matcher; import org.hamcrest.Matchers; import java.io.IOException; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; -import java.util.Arrays; -import java.util.HashSet; -import java.util.Locale; -import java.util.Set; +import java.util.*; +import java.util.concurrent.TimeUnit; +import static org.elasticsearch.test.ElasticsearchTestCase.*; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.*; import static org.junit.Assert.assertTrue; @@ -338,8 +339,8 @@ private static BytesReference serialize(Version version, Streamable streamable) } public static void assertVersionSerializable(Streamable streamable) { - assertTrue(Version.CURRENT.after(ElasticsearchTestCase.getPreviousVersion())); - assertVersionSerializable(ElasticsearchTestCase.randomVersion(), streamable); + assertTrue(Version.CURRENT.after(getPreviousVersion())); + assertVersionSerializable(randomVersion(), streamable); } public static void assertVersionSerializable(Version version, Streamable streamable) { @@ -395,4 +396,47 @@ public static SearchResponse assertSearchResponse(SearchResponse response) { assertThat("One or more shards were not successful but didn't trigger a failure", response.getSuccessfulShards(), equalTo(response.getTotalShards())); return response; } + + public static void assertAllSearchersClosed() { + /* 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() { + public boolean apply(Object o) { + return MockInternalEngine.INFLIGHT_ENGINE_SEARCHERS.isEmpty(); + } + }, 5, TimeUnit.SECONDS)) { + return; + } + } catch (InterruptedException ex) { + if (MockInternalEngine.INFLIGHT_ENGINE_SEARCHERS.isEmpty()) { + return; + } + } + try { + RuntimeException ex = null; + StringBuilder builder = new StringBuilder("Unclosed Searchers instance for shards: ["); + for (Map.Entry entry : MockInternalEngine.INFLIGHT_ENGINE_SEARCHERS.entrySet()) { + ex = entry.getValue(); + builder.append(entry.getKey().shardId()).append(","); + } + builder.append("]"); + throw new RuntimeException(builder.toString(), ex); + } finally { + MockInternalEngine.INFLIGHT_ENGINE_SEARCHERS.clear(); + } + } + + public static void assertAllFilesClosed() throws IOException { + try { + for (MockDirectoryHelper.ElasticsearchMockDirectoryWrapper w : MockDirectoryHelper.wrappers) { + if (w.isOpen()) { + w.closeWithRuntimeException(); + } + } + } finally { + MockDirectoryHelper.wrappers.clear(); + } + } } diff --git a/src/test/java/org/elasticsearch/test/store/MockDirectoryHelper.java b/src/test/java/org/elasticsearch/test/store/MockDirectoryHelper.java index 9823f0bcf73fc..e9df739d46f63 100644 --- a/src/test/java/org/elasticsearch/test/store/MockDirectoryHelper.java +++ b/src/test/java/org/elasticsearch/test/store/MockDirectoryHelper.java @@ -38,7 +38,7 @@ 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.ElasticsearchIntegrationTest; +import org.elasticsearch.test.TestCluster; import java.io.IOException; import java.util.Random; @@ -68,7 +68,7 @@ public class MockDirectoryHelper { private final boolean failOnClose; public MockDirectoryHelper(ShardId shardId, Settings indexSettings, ESLogger logger) { - final long seed = indexSettings.getAsLong(ElasticsearchIntegrationTest.INDEX_SEED_SETTING, 0l); + final long seed = indexSettings.getAsLong(TestCluster.SETTING_INDEX_SEED, 0l); random = new Random(seed); randomIOExceptionRate = indexSettings.getAsDouble(RANDOM_IO_EXCEPTION_RATE, 0.0d); randomIOExceptionRateOnOpen = indexSettings.getAsDouble(RANDOM_IO_EXCEPTION_RATE_ON_OPEN, 0.0d); diff --git a/src/test/java/org/elasticsearch/test/store/MockFSDirectoryService.java b/src/test/java/org/elasticsearch/test/store/MockFSDirectoryService.java index 99ff19571e18d..69a6dc0609850 100644 --- a/src/test/java/org/elasticsearch/test/store/MockFSDirectoryService.java +++ b/src/test/java/org/elasticsearch/test/store/MockFSDirectoryService.java @@ -53,6 +53,4 @@ public Directory[] build() throws IOException { protected synchronized FSDirectory newFSDirectory(File location, LockFactory lockFactory) throws IOException { throw new UnsupportedOperationException(); } - - } diff --git a/src/test/java/org/elasticsearch/test/transport/AssertingLocalTransport.java b/src/test/java/org/elasticsearch/test/transport/AssertingLocalTransport.java index 85e190c96b9c0..159b4274585c6 100644 --- a/src/test/java/org/elasticsearch/test/transport/AssertingLocalTransport.java +++ b/src/test/java/org/elasticsearch/test/transport/AssertingLocalTransport.java @@ -23,8 +23,8 @@ import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.test.ElasticsearchIntegrationTest; import org.elasticsearch.test.ElasticsearchTestCase; +import org.elasticsearch.test.TestCluster; import org.elasticsearch.test.hamcrest.ElasticsearchAssertions; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.*; @@ -42,7 +42,7 @@ public class AssertingLocalTransport extends LocalTransport { @Inject public AssertingLocalTransport(Settings settings, ThreadPool threadPool, Version version) { super(settings, threadPool, version); - final long seed = settings.getAsLong(ElasticsearchIntegrationTest.INDEX_SEED_SETTING, 0l); + final long seed = settings.getAsLong(TestCluster.SETTING_INDEX_SEED, 0l); random = new Random(seed); }