Simplify SingleNodeTest and close propperly instead of calling stop
This commit is contained in:
parent
f610774546
commit
028f379781
|
@ -29,6 +29,7 @@ import org.elasticsearch.cluster.metadata.IndexMetaData;
|
||||||
import org.elasticsearch.cluster.metadata.MetaData;
|
import org.elasticsearch.cluster.metadata.MetaData;
|
||||||
import org.elasticsearch.cluster.node.DiscoveryNode;
|
import org.elasticsearch.cluster.node.DiscoveryNode;
|
||||||
import org.elasticsearch.common.Priority;
|
import org.elasticsearch.common.Priority;
|
||||||
|
import org.elasticsearch.common.lease.Releasables;
|
||||||
import org.elasticsearch.common.settings.ImmutableSettings;
|
import org.elasticsearch.common.settings.ImmutableSettings;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.common.unit.TimeValue;
|
import org.elasticsearch.common.unit.TimeValue;
|
||||||
|
@ -54,33 +55,29 @@ import static org.hamcrest.Matchers.*;
|
||||||
@Ignore
|
@Ignore
|
||||||
public abstract class ElasticsearchSingleNodeTest extends ElasticsearchTestCase {
|
public abstract class ElasticsearchSingleNodeTest extends ElasticsearchTestCase {
|
||||||
|
|
||||||
private static class Holder {
|
private static Node NODE = null;
|
||||||
private static Node NODE = null;
|
|
||||||
|
|
||||||
private static void reset() {
|
private static void reset() {
|
||||||
assert NODE != null;
|
assert NODE != null;
|
||||||
node().stop();
|
node().stop();
|
||||||
Holder.NODE = newNode();
|
NODE = newNode();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void startNode() {
|
private static void startNode() {
|
||||||
assert NODE == null;
|
assert NODE == null;
|
||||||
NODE = newNode();
|
NODE = newNode();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void stopNode() {
|
private static void stopNode() {
|
||||||
if (NODE != null) {
|
Node node = NODE;
|
||||||
Node node = NODE;
|
NODE = null;
|
||||||
NODE = null;
|
Releasables.close(node);
|
||||||
node.stop();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cleanup(boolean resetNode) {
|
static void cleanup(boolean resetNode) {
|
||||||
assertAcked(client().admin().indices().prepareDelete("*").get());
|
assertAcked(client().admin().indices().prepareDelete("*").get());
|
||||||
if (resetNode) {
|
if (resetNode) {
|
||||||
Holder.reset();
|
reset();
|
||||||
}
|
}
|
||||||
MetaData metaData = client().admin().cluster().prepareState().get().getState().getMetaData();
|
MetaData metaData = client().admin().cluster().prepareState().get().getState().getMetaData();
|
||||||
assertThat("test leaves persistent cluster metadata behind: " + metaData.persistentSettings().getAsMap(),
|
assertThat("test leaves persistent cluster metadata behind: " + metaData.persistentSettings().getAsMap(),
|
||||||
|
@ -97,13 +94,13 @@ public abstract class ElasticsearchSingleNodeTest extends ElasticsearchTestCase
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void setUpClass() throws Exception {
|
public static void setUpClass() throws Exception {
|
||||||
Holder.stopNode();
|
stopNode();
|
||||||
Holder.startNode();
|
startNode();
|
||||||
}
|
}
|
||||||
|
|
||||||
@AfterClass
|
@AfterClass
|
||||||
public static void tearDownClass() {
|
public static void tearDownClass() {
|
||||||
Holder.stopNode();
|
stopNode();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -117,7 +114,7 @@ public abstract class ElasticsearchSingleNodeTest extends ElasticsearchTestCase
|
||||||
|
|
||||||
private static Node newNode() {
|
private static Node newNode() {
|
||||||
Node build = NodeBuilder.nodeBuilder().local(true).data(true).settings(ImmutableSettings.builder()
|
Node build = NodeBuilder.nodeBuilder().local(true).data(true).settings(ImmutableSettings.builder()
|
||||||
.put(ClusterName.SETTING, nodeName())
|
.put(ClusterName.SETTING, clusterName())
|
||||||
.put("node.name", nodeName())
|
.put("node.name", nodeName())
|
||||||
.put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1)
|
.put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1)
|
||||||
.put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0)
|
.put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0)
|
||||||
|
@ -135,35 +132,35 @@ public abstract class ElasticsearchSingleNodeTest extends ElasticsearchTestCase
|
||||||
* Returns a client to the single-node cluster.
|
* Returns a client to the single-node cluster.
|
||||||
*/
|
*/
|
||||||
public static Client client() {
|
public static Client client() {
|
||||||
return Holder.NODE.client();
|
return NODE.client();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the single test nodes name.
|
* Returns the single test nodes name.
|
||||||
*/
|
*/
|
||||||
public static String nodeName() {
|
public static String nodeName() {
|
||||||
return ElasticsearchSingleNodeTest.class.getName();
|
return "node_s_0";
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the name of the cluster used for the single test node.
|
* Returns the name of the cluster used for the single test node.
|
||||||
*/
|
*/
|
||||||
public static String clusterName() {
|
public static String clusterName() {
|
||||||
return ElasticsearchSingleNodeTest.class.getName();
|
return InternalTestCluster.clusterName("single-node", Integer.toString(CHILD_JVM_ID), randomLong());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a reference to the singleton node.
|
* Return a reference to the singleton node.
|
||||||
*/
|
*/
|
||||||
protected static Node node() {
|
protected static Node node() {
|
||||||
return Holder.NODE;
|
return NODE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get an instance for a particular class using the injector of the singleton node.
|
* Get an instance for a particular class using the injector of the singleton node.
|
||||||
*/
|
*/
|
||||||
protected static <T> T getInstanceFromNode(Class<T> clazz) {
|
protected static <T> T getInstanceFromNode(Class<T> clazz) {
|
||||||
return ((InternalNode) Holder.NODE).injector().getInstance(clazz);
|
return ((InternalNode) NODE).injector().getInstance(clazz);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue