[TEST] Don't reuse single node tests node instance across tests

Similar to the shared cluster we should not reuse the node from
singlenodetest across tests.
This commit is contained in:
Simon Willnauer 2015-02-23 11:25:51 +01:00
parent 1848d1ba8b
commit 668d09db08
2 changed files with 41 additions and 5 deletions

View File

@ -23,6 +23,8 @@ import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.IndexService;
import org.elasticsearch.search.internal.SearchContext;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Ignore;
/**
@ -37,6 +39,17 @@ public abstract class ElasticsearchSingleNodeLuceneTestCase extends Elasticsearc
ElasticsearchSingleNodeTest.cleanup(resetNodeAfterTest());
}
@BeforeClass
public static void setUpClass() throws Exception {
ElasticsearchSingleNodeTest.setUpClass();
}
@AfterClass
public static void tearDownClass() {
ElasticsearchSingleNodeTest.tearDownClass();
}
/**
* 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

View File

@ -42,8 +42,7 @@ import org.elasticsearch.node.NodeBuilder;
import org.elasticsearch.node.internal.InternalNode;
import org.elasticsearch.search.internal.SearchContext;
import org.elasticsearch.threadpool.ThreadPool;
import org.junit.After;
import org.junit.Ignore;
import org.junit.*;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
import static org.hamcrest.Matchers.*;
@ -56,14 +55,26 @@ import static org.hamcrest.Matchers.*;
public abstract class ElasticsearchSingleNodeTest extends ElasticsearchTestCase {
private static class Holder {
// lazy init on first access
private static Node NODE = newNode();
private static Node NODE = null;
private static void reset() {
assert NODE != null;
node().stop();
Holder.NODE = newNode();
}
private static void startNode() {
assert NODE == null;
NODE = newNode();
}
private static void stopNode() {
if (NODE != null) {
Node node = NODE;
NODE = null;
node.stop();
}
}
}
static void cleanup(boolean resetNode) {
@ -79,10 +90,22 @@ public abstract class ElasticsearchSingleNodeTest extends ElasticsearchTestCase
}
@After
public void after() {
public void tearDown() throws Exception {
super.tearDown();
cleanup(resetNodeAfterTest());
}
@BeforeClass
public static void setUpClass() throws Exception {
Holder.stopNode();
Holder.startNode();
}
@AfterClass
public static void tearDownClass() {
Holder.stopNode();
}
/**
* 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