[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 = 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"));
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 org.apache.lucene.util.IOUtils;
import org.elasticsearch.ElasticsearchIllegalStateException;
import org.elasticsearch.Version;
import org.elasticsearch.cache.recycler.CacheRecycler;
import org.elasticsearch.cache.recycler.PageCacheRecyclerModule;
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();
return buildNode(ord, random.nextLong(), settings);
return buildNode(ord, random.nextLong(), settings, version);
}
private NodeAndClient buildNode() {
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();
settings = getSettings(nodeId, seed, settings);
String name = buildNodeName(nodeId);
@ -376,6 +377,7 @@ public final class TestCluster implements Iterable<Client> {
.put(settings)
.put("name", name)
.put("discovery.id.seed", seed)
.put("tests.mock.version", version)
.build();
Node node = nodeBuilder().settings(finalSettings).build();
return new NodeAndClient(name, node, new RandomClientFactory());
@ -686,7 +688,7 @@ public final class TestCluster implements Iterable<Client> {
NodeAndClient nodeAndClient = nodes.get(buildNodeName);
if (nodeAndClient == null) {
changed = true;
nodeAndClient = buildNode(i, sharedNodesSeeds[i], null);
nodeAndClient = buildNode(i, sharedNodesSeeds[i], null, Version.CURRENT);
nodeAndClient.node.start();
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.
*/
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.
*/
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.
*/
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();
publishNode(buildNode);
return buildNode.name;