[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.junit.Test;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.is;
@ -53,5 +54,7 @@ public class BlockClusterStatsTests extends ElasticsearchIntegrationTest {
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());
}
}

View File

@ -125,5 +125,8 @@ public class NoMasterNodeTests extends ElasticsearchIntegrationTest {
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();
}
}

View File

@ -259,16 +259,14 @@ public abstract class ElasticsearchIntegrationTest extends ElasticsearchTestCase
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 {
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();
@ -276,6 +274,11 @@ public abstract class ElasticsearchIntegrationTest extends ElasticsearchTestCase
ensureAllSearchersClosed();
ensureAllFilesClosed();
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());
} catch (OutOfMemoryError e) {
if (e.getMessage().contains("unable to create new native thread")) {