Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test: Allow SingleNodeTest to reset the node if really needed after test. #7608

Merged
merged 1 commit into from Sep 5, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -34,7 +34,16 @@ public abstract class ElasticsearchSingleNodeLuceneTestCase extends Elasticsearc

@After
public void cleanup() {
ElasticsearchSingleNodeTest.cleanup();
ElasticsearchSingleNodeTest.cleanup(resetNodeAfterTest());
}

/**
* This method returns <code>true</code> if the node that is used in the background should be reset
* after each test. This is useful if the test changes the cluster state metadata etc. The default is
* <code>false</code>.
*/
protected boolean resetNodeAfterTest() {
return false;
}

/**
Expand Down
Expand Up @@ -58,11 +58,20 @@ public abstract class ElasticsearchSingleNodeTest extends ElasticsearchTestCase

private static class Holder {
// lazy init on first access
private static final Node NODE = newNode();
private static Node NODE = newNode();

private static void reset() {
assert NODE != null;
node().stop();
Holder.NODE = newNode();
}
}

static void cleanup() {
static void cleanup(boolean resetNode) {
assertAcked(client().admin().indices().prepareDelete("*").get());
if (resetNode) {
Holder.reset();
}
MetaData metaData = client().admin().cluster().prepareState().get().getState().getMetaData();
assertThat("test leaves persistent cluster metadata behind: " + metaData.persistentSettings().getAsMap(),
metaData.persistentSettings().getAsMap().size(), equalTo(0));
Expand All @@ -72,7 +81,16 @@ static void cleanup() {

@After
public void after() {
cleanup();
cleanup(resetNodeAfterTest());
}

/**
* This method returns <code>true</code> if the node that is used in the background should be reset
* after each test. This is useful if the test changes the cluster state metadata etc. The default is
* <code>false</code>.
*/
protected boolean resetNodeAfterTest() {
return false;
}

private static Node newNode() {
Expand Down