From 7d3f49c43b23a0a4db2feafe20a0e28baf39f164 Mon Sep 17 00:00:00 2001 From: Martijn van Groningen Date: Mon, 17 Mar 2014 23:29:38 +0700 Subject: [PATCH] [TEST] Added the option to specify on what ES version a node should run with. Useful for testing. --- .../node/internal/InternalNode.java | 3 +- .../org/elasticsearch/test/TestCluster.java | 29 ++++++++++++++----- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/src/main/java/org/elasticsearch/node/internal/InternalNode.java b/src/main/java/org/elasticsearch/node/internal/InternalNode.java index ccb7a91e4c4..5b0cdc3822b 100644 --- a/src/main/java/org/elasticsearch/node/internal/InternalNode.java +++ b/src/main/java/org/elasticsearch/node/internal/InternalNode.java @@ -125,7 +125,8 @@ public final class InternalNode implements Node { Tuple tuple = InternalSettingsPreparer.prepareSettings(pSettings, loadConfigSettings); tuple = new Tuple(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()); diff --git a/src/test/java/org/elasticsearch/test/TestCluster.java b/src/test/java/org/elasticsearch/test/TestCluster.java index 4a84f9ca9d0..e2c85940b42 100644 --- a/src/test/java/org/elasticsearch/test/TestCluster.java +++ b/src/test/java/org/elasticsearch/test/TestCluster.java @@ -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 { } } - 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 { .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 { 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 { * 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;