[TEST] Added the option to specify on what ES version a node should run with. Useful for testing.

This commit is contained in:
Martijn van Groningen 2014-03-17 23:29:38 +07:00
parent 0ca7fddb66
commit 7d3f49c43b
2 changed files with 23 additions and 9 deletions

View File

@ -125,7 +125,8 @@ public final class InternalNode implements Node {
Tuple<Settings, Environment> tuple = InternalSettingsPreparer.prepareSettings(pSettings, loadConfigSettings); Tuple<Settings, Environment> tuple = InternalSettingsPreparer.prepareSettings(pSettings, loadConfigSettings);
tuple = new Tuple<Settings, Environment>(TribeService.processSettings(tuple.v1()), tuple.v2()); tuple = new Tuple<Settings, Environment>(TribeService.processSettings(tuple.v1()), tuple.v2());
Version version = Version.CURRENT; // The only place we can actually fake the version a node is running on:
Version version = pSettings.getAsVersion("tests.mock.version", Version.CURRENT);
ESLogger logger = Loggers.getLogger(Node.class, tuple.v1().get("name")); ESLogger logger = Loggers.getLogger(Node.class, tuple.v1().get("name"));
logger.info("version[{}], pid[{}], build[{}/{}]", version, JvmInfo.jvmInfo().pid(), Build.CURRENT.hashShort(), Build.CURRENT.timestamp()); logger.info("version[{}], pid[{}], build[{}/{}]", version, JvmInfo.jvmInfo().pid(), Build.CURRENT.hashShort(), Build.CURRENT.timestamp());

View File

@ -27,6 +27,7 @@ import com.google.common.collect.Iterators;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import org.apache.lucene.util.IOUtils; import org.apache.lucene.util.IOUtils;
import org.elasticsearch.ElasticsearchIllegalStateException; import org.elasticsearch.ElasticsearchIllegalStateException;
import org.elasticsearch.Version;
import org.elasticsearch.cache.recycler.CacheRecycler; import org.elasticsearch.cache.recycler.CacheRecycler;
import org.elasticsearch.cache.recycler.PageCacheRecyclerModule; import org.elasticsearch.cache.recycler.PageCacheRecyclerModule;
import org.elasticsearch.client.Client; import org.elasticsearch.client.Client;
@ -357,17 +358,17 @@ public final class TestCluster implements Iterable<Client> {
} }
} }
private NodeAndClient buildNode(Settings settings) { private NodeAndClient buildNode(Settings settings, Version version) {
int ord = nextNodeId.getAndIncrement(); int ord = nextNodeId.getAndIncrement();
return buildNode(ord, random.nextLong(), settings); return buildNode(ord, random.nextLong(), settings, version);
} }
private NodeAndClient buildNode() { private NodeAndClient buildNode() {
int ord = nextNodeId.getAndIncrement(); int ord = nextNodeId.getAndIncrement();
return buildNode(ord, random.nextLong(), null); return buildNode(ord, random.nextLong(), null, Version.CURRENT);
} }
private NodeAndClient buildNode(int nodeId, long seed, Settings settings) { private NodeAndClient buildNode(int nodeId, long seed, Settings settings, Version version) {
ensureOpen(); ensureOpen();
settings = getSettings(nodeId, seed, settings); settings = getSettings(nodeId, seed, settings);
String name = buildNodeName(nodeId); String name = buildNodeName(nodeId);
@ -376,6 +377,7 @@ public final class TestCluster implements Iterable<Client> {
.put(settings) .put(settings)
.put("name", name) .put("name", name)
.put("discovery.id.seed", seed) .put("discovery.id.seed", seed)
.put("tests.mock.version", version)
.build(); .build();
Node node = nodeBuilder().settings(finalSettings).build(); Node node = nodeBuilder().settings(finalSettings).build();
return new NodeAndClient(name, node, new RandomClientFactory()); return new NodeAndClient(name, node, new RandomClientFactory());
@ -686,7 +688,7 @@ public final class TestCluster implements Iterable<Client> {
NodeAndClient nodeAndClient = nodes.get(buildNodeName); NodeAndClient nodeAndClient = nodes.get(buildNodeName);
if (nodeAndClient == null) { if (nodeAndClient == null) {
changed = true; changed = true;
nodeAndClient = buildNode(i, sharedNodesSeeds[i], null); nodeAndClient = buildNode(i, sharedNodesSeeds[i], null, Version.CURRENT);
nodeAndClient.node.start(); nodeAndClient.node.start();
logger.info("Start Shared Node [{}] not shared", nodeAndClient.name); logger.info("Start Shared Node [{}] not shared", nodeAndClient.name);
} }
@ -1001,21 +1003,32 @@ public final class TestCluster implements Iterable<Client> {
* Starts a node with default settings and returns it's name. * Starts a node with default settings and returns it's name.
*/ */
public String startNode() { public String startNode() {
return startNode(ImmutableSettings.EMPTY); return startNode(ImmutableSettings.EMPTY, Version.CURRENT);
}
/**
* Starts a node with default settings ad the specified version and returns it's name.
*/
public String startNode(Version version) {
return startNode(ImmutableSettings.EMPTY, version);
} }
/** /**
* Starts a node with the given settings builder and returns it's name. * Starts a node with the given settings builder and returns it's name.
*/ */
public String startNode(Settings.Builder settings) { public String startNode(Settings.Builder settings) {
return startNode(settings.build()); return startNode(settings.build(), Version.CURRENT);
} }
/** /**
* Starts a node with the given settings and returns it's name. * Starts a node with the given settings and returns it's name.
*/ */
public String startNode(Settings settings) { public String startNode(Settings settings) {
NodeAndClient buildNode = buildNode(settings); return startNode(settings, Version.CURRENT);
}
public String startNode(Settings settings, Version version) {
NodeAndClient buildNode = buildNode(settings, version);
buildNode.node().start(); buildNode.node().start();
publishNode(buildNode); publishNode(buildNode);
return buildNode.name; return buildNode.name;