Skip to content

Commit

Permalink
[Test] Run after checks even if cluster scope is == TEST
Browse files Browse the repository at this point in the history
  • Loading branch information
s1monw committed Mar 21, 2014
1 parent 2398bb4 commit 5194521
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 16 deletions.
Expand Up @@ -27,6 +27,7 @@
import org.elasticsearch.test.ElasticsearchIntegrationTest.Scope;
import org.junit.Test;

import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.is;

Expand All @@ -53,5 +54,7 @@ public void testBlocks() throws Exception {
ClusterStateResponse clusterStateResponse = client().admin().cluster().prepareState().clear().get();
assertThat(clusterStateResponse.getState().blocks().global(), hasSize(0));
assertThat(clusterStateResponse.getState().blocks().indices().size(), is(0));
assertAcked(client().admin().cluster().prepareUpdateSettings().setTransientSettings(
ImmutableSettings.settingsBuilder().put("cluster.blocks.read_only", false).build()).get());
}
}
Expand Up @@ -125,5 +125,8 @@ public boolean apply(Object o) {
assertThat(System.currentTimeMillis() - now, greaterThan(timeout.millis() - 50));
assertThat(e.status(), equalTo(RestStatus.SERVICE_UNAVAILABLE));
}

cluster().startNode(settings);
client().admin().cluster().prepareHealth().setWaitForGreenStatus().setWaitForNodes("2").execute().actionGet();
}
}
Expand Up @@ -259,23 +259,26 @@ private void clearClusters() throws IOException {
public final void after() throws IOException {
try {
logger.info("[{}#{}]: cleaning up after test", getTestClass().getSimpleName(), getTestName());
Scope currentClusterScope = getCurrentClusterScope();
if (currentClusterScope == Scope.TEST) {
clearClusters(); // it is ok to leave persistent / transient cluster state behind if scope is TEST
} else {
MetaData metaData = client().admin().cluster().prepareState().execute().actionGet().getState().getMetaData();
assertThat("test leaves persistent cluster metadata behind: " + metaData.persistentSettings().getAsMap(), metaData
.persistentSettings().getAsMap().size(), equalTo(0));
assertThat("test leaves transient cluster metadata behind: " + metaData.transientSettings().getAsMap(), metaData
.transientSettings().getAsMap().size(), equalTo(0));

final Scope currentClusterScope = getCurrentClusterScope();
try {
if (currentClusterScope != Scope.TEST) {
MetaData metaData = client().admin().cluster().prepareState().execute().actionGet().getState().getMetaData();
assertThat("test leaves persistent cluster metadata behind: " + metaData.persistentSettings().getAsMap(), metaData
.persistentSettings().getAsMap().size(), equalTo(0));
assertThat("test leaves transient cluster metadata behind: " + metaData.transientSettings().getAsMap(), metaData
.transientSettings().getAsMap().size(), equalTo(0));
}
wipeIndices("_all"); // wipe after to make sure we fail in the test that didn't ack the delete
wipeTemplates();
wipeRepositories();
ensureAllSearchersClosed();
ensureAllFilesClosed();
ensureEstimatedStats();
} finally {
if (currentClusterScope == Scope.TEST) {
clearClusters(); // it is ok to leave persistent / transient cluster state behind if scope is TEST
}
}
wipeIndices("_all"); // wipe after to make sure we fail in the test that didn't ack the delete
wipeTemplates();
wipeRepositories();
ensureAllSearchersClosed();
ensureAllFilesClosed();
ensureEstimatedStats();
logger.info("[{}#{}]: cleaned up after test", getTestClass().getSimpleName(), getTestName());
} catch (OutOfMemoryError e) {
if (e.getMessage().contains("unable to create new native thread")) {
Expand Down

0 comments on commit 5194521

Please sign in to comment.