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 elastic#5542
  • Loading branch information
javanna committed Mar 26, 2014
1 parent 4e7aa1d commit c1fc66e
Show file tree
Hide file tree
Showing 21 changed files with 258 additions and 247 deletions.
Expand Up @@ -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) {
Expand Down
Expand Up @@ -54,7 +54,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 @@ -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);
Expand Down
Expand Up @@ -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()
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
Expand Up @@ -345,7 +345,7 @@ public void testEagerLoading() throws Exception {
} else {
assertThat(memoryUsage1, equalTo(memoryUsage0));
}
wipeIndices("idx");
cluster().wipeIndices("idx");
}
}

Expand Down
Expand Up @@ -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();

Expand Down
Expand Up @@ -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")
Expand Down
Expand Up @@ -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");
}
}
}
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 @@ -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);
Expand Down
Expand Up @@ -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"),
Expand Down Expand Up @@ -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"));
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 @@ -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));
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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));

Expand Down Expand Up @@ -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));

Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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<RestoreSnapshotResponse> restoreSnapshotResponseFuture =
client.admin().cluster().prepareRestoreSnapshot("test-repo", "test-snap").setWaitForCompletion(true).execute();
Expand All @@ -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));
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit c1fc66e

Please sign in to comment.