[Test] Run after checks even if cluster scope is == TEST

This commit is contained in:
Simon Willnauer 2014-03-21 16:12:18 +01:00
parent 2398bb4f1c
commit 5194521097
3 changed files with 25 additions and 16 deletions

View File

@ -27,6 +27,7 @@ import org.elasticsearch.test.ElasticsearchIntegrationTest.ClusterScope;
import org.elasticsearch.test.ElasticsearchIntegrationTest.Scope; import org.elasticsearch.test.ElasticsearchIntegrationTest.Scope;
import org.junit.Test; import org.junit.Test;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
import static org.hamcrest.Matchers.hasSize; import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.is;
@ -53,5 +54,7 @@ public class BlockClusterStatsTests extends ElasticsearchIntegrationTest {
ClusterStateResponse clusterStateResponse = client().admin().cluster().prepareState().clear().get(); ClusterStateResponse clusterStateResponse = client().admin().cluster().prepareState().clear().get();
assertThat(clusterStateResponse.getState().blocks().global(), hasSize(0)); assertThat(clusterStateResponse.getState().blocks().global(), hasSize(0));
assertThat(clusterStateResponse.getState().blocks().indices().size(), is(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());
} }
} }

View File

@ -125,5 +125,8 @@ public class NoMasterNodeTests extends ElasticsearchIntegrationTest {
assertThat(System.currentTimeMillis() - now, greaterThan(timeout.millis() - 50)); assertThat(System.currentTimeMillis() - now, greaterThan(timeout.millis() - 50));
assertThat(e.status(), equalTo(RestStatus.SERVICE_UNAVAILABLE)); assertThat(e.status(), equalTo(RestStatus.SERVICE_UNAVAILABLE));
} }
cluster().startNode(settings);
client().admin().cluster().prepareHealth().setWaitForGreenStatus().setWaitForNodes("2").execute().actionGet();
} }
} }

View File

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