Skip to content

Commit

Permalink
[TEST] Moved wipe* methods, randomIndexTemplate & ensureEstimatedStat…
Browse files Browse the repository at this point in the history
…s 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
  • Loading branch information
javanna committed Mar 26, 2014
1 parent c2e38fb commit 89dd722
Show file tree
Hide file tree
Showing 25 changed files with 315 additions and 293 deletions.
Expand Up @@ -37,6 +37,7 @@
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;

Expand Down
1 change: 1 addition & 0 deletions src/test/java/org/elasticsearch/cluster/ack/AckTests.java
Expand Up @@ -53,6 +53,7 @@
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.*;

Expand Down
Expand Up @@ -53,7 +53,7 @@
public class DocumentActionsTests extends ElasticsearchIntegrationTest {

protected void createIndex() {
wipeIndices(getConcreteIndexName());
cluster().wipeIndices(getConcreteIndexName());
createIndex(getConcreteIndexName());
}

Expand Down
Expand Up @@ -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;
Expand Down Expand Up @@ -199,7 +200,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);
Expand Down
Expand Up @@ -52,7 +52,7 @@ public void testConcurrentDynamicMapping() throws Exception {

int iters = scaledRandomIntBetween(5, 15);
for (int i = 0; i < iters; i++) {
wipeIndices("test");
cluster().wipeIndices("test");
assertAcked(prepareCreate("test")
.addMapping(mappingType, mapping));
ensureYellow();
Expand Down
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
1 change: 1 addition & 0 deletions src/test/java/org/elasticsearch/mget/SimpleMgetTests.java
Expand Up @@ -33,6 +33,7 @@
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.*;

Expand Down
Expand Up @@ -46,6 +46,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.test.TestCluster.DEFAULT_MAX_NUM_SHARDS;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.*;
import static org.hamcrest.Matchers.*;

Expand Down
Expand Up @@ -287,7 +287,7 @@ public void percolateOnRecreatedIndex() throws Exception {
.setRefresh(true)
.execute().actionGet();

wipeIndices("test");
cluster().wipeIndices("test");
createIndex("test");
ensureGreen();

Expand Down
Expand Up @@ -146,7 +146,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")
Expand Down
Expand Up @@ -101,7 +101,7 @@ private void searchWhileCreatingIndex(boolean createIndex, int numberOfReplicas)
status = client().admin().cluster().prepareHealth("test").get().getStatus();
cluster().ensureAtLeastNumNodes(numberOfReplicas + 1);
}
wipeIndices("test");
cluster().wipeIndices("test");
}
}
}
Expand Up @@ -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;
Expand Down Expand Up @@ -287,7 +288,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);
Expand Down
Expand Up @@ -58,8 +58,8 @@
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.*;

/**
Expand Down
Expand Up @@ -58,6 +58,7 @@
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.*;

Expand All @@ -81,7 +82,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");

createIndex("test");
indexRandom(true, client().prepareIndex("test", "type1", "1").setSource("field1", "the quick brown fox jumps"),
Expand Down Expand Up @@ -375,7 +376,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"));
Expand Down
Expand Up @@ -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)
Expand Down
Expand Up @@ -130,7 +130,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));
Expand Down Expand Up @@ -167,7 +167,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(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"));
Expand Down Expand Up @@ -265,7 +265,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));

Expand Down Expand Up @@ -302,8 +302,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));

Expand Down Expand Up @@ -469,7 +469,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));
Expand Down Expand Up @@ -514,7 +514,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<RestoreSnapshotResponse> restoreSnapshotResponseFuture =
client.admin().cluster().prepareRestoreSnapshot("test-repo", "test-snap").setWaitForCompletion(true).execute();
Expand All @@ -524,7 +524,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));
Expand Down Expand Up @@ -608,7 +608,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);
Expand Down Expand Up @@ -782,7 +782,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")
Expand Down Expand Up @@ -867,7 +867,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")
Expand Down Expand Up @@ -911,7 +911,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")
Expand Down Expand Up @@ -971,7 +971,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();
Expand Down

0 comments on commit 89dd722

Please sign in to comment.